-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.rb
40 lines (32 loc) · 1.22 KB
/
profile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'dotenv'
Dotenv.load
require 'rest-client'
require 'json'
require 'oauth2'
require_relative "config"
config = Healp::Config.new(ENV['CLIENT_ID'],ENV['CLIENT_SECRET'],ENV['AUTH_URL'])
client = OAuth2::Client.new(config.client_id, config.client_secret, :site => config.oauth_url)
access_token = client.password.get_token("[email protected]", "}S'+<01o")
puts token = access_token.token
profile = {name: 'test10', email: '[email protected]', gender: 0 , birthday_date: '2016-12-11', note: ""}
puts "[Test create Profile]"
response = RestClient.post "#{config.oauth_url}/profiles", {
access_token: token,
:profile=> profile }.to_json,
:content_type => 'application/json', :accept => :json
print(response)
profile = JSON.parse(response.body)
puts "[Edit Profile]"
response = RestClient.put "#{config.oauth_url}/profiles/#{profile['id']}", {
access_token: token,
:profile=> {note: 'edit profile'} }.to_json,
:content_type => 'application/json', :accept => :json
print(response)
puts "[Destroy Profile]"
response = RestClient.delete "#{config.oauth_url}/profiles/#{profile['id']}",{:Authorization => "Bearer #{token}"}
def print response
p response.code
p response.cookies
p response.headers
p JSON.parse(response.body)
end