-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatients.rb
45 lines (36 loc) · 1.5 KB
/
patients.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
41
42
43
44
45
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)
response = RestClient.post "#{config.oauth_url}/oauth/token", {
grant_type: 'client_credentials',
client_id: config.client_id,
client_secret: config.client_secret,
scope: "admin"
}
token = JSON.parse(response)["access_token"]
p token
# patient login
access_token = client.password.get_token("[email protected]", "}S'+<01o")
puts token = access_token.token
# fake data
patient = {email: '[email protected]', password: 'asdfasdf', password_confirmation: 'asdfasdf'}
puts "[Test create Account]"
response = RestClient.post "#{config.oauth_url}/patients", {:patient=> patient }.to_json, :content_type => 'application/json', :accept => :json
print(response)
puts "[Test Sign in]"
response = RestClient.post "#{config.oauth_url}/patients/sign_in", {:patient=>{:email => patient[:email], :password => patient[:password]}}.to_json, :content_type => 'application/json', :accept => :json
print(response)
puts "[Test Reset Password]"
response = RestClient.post "#{config.oauth_url}/patients/password", {:patient=>{:email => patient[:email]}}.to_json, :content_type => 'application/json', :accept => :json
print(response)
def print response
puts response.code
puts response.cookies
puts response.headers
puts JSON.parse(response.body)
end