fuelscropt-api-client 0.3.2 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +2 -2
- data/README.md +54 -4
- data/lib/fullscriptapi/{endpoints → authentication_endpoints}/create_an_oauth_token.rb +4 -2
- data/lib/fullscriptapi/{endpoints → authentication_endpoints}/refresh_token.rb +2 -3
- data/lib/fullscriptapi/authentication_endpoints.rb +11 -0
- data/lib/fullscriptapi/servers.rb +17 -0
- data/lib/fullscriptapi/version.rb +1 -1
- data/lib/fullscriptapi.rb +68 -15
- data/openapi.json +5624 -0
- metadata +7 -6
- data/lib/fullscriptapi/endpoints/list_all_products.rb +0 -18
- data/lib/fullscriptapi/endpoints.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a34f279a374fd26ada79b520b53fcf06db351b6e444e3f9b8056dd2fd041c674
|
4
|
+
data.tar.gz: fe31fd6dbaa23131305d95b050c5bf968fb24249882fd47905a2f58502fdef29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd7e23d56034273edcf0a4eee3f993fed69bec4f61a104137a6ec3ae5a096b1f7de5a338dc87cef33d3092a6035139068e5cb2d7ce77e34ce2b9c2b21d4f43b7
|
7
|
+
data.tar.gz: 928563ca037edbff7d224ad9d6e92d2492a5307f9fa50bdef213564da22a816340558fed40404171ae280a27a1d0b11f83b4e0b45bc64d95647a3f95d9c6cda1
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
|
4
|
+
fuelscropt-api-client (0.3.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -28,7 +28,7 @@ PLATFORMS
|
|
28
28
|
|
29
29
|
DEPENDENCIES
|
30
30
|
excon (~> 0.85.0)
|
31
|
-
|
31
|
+
fuelscropt-api-client!
|
32
32
|
rake (~> 12.0)
|
33
33
|
rspec (~> 3.0)
|
34
34
|
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Fullscriptapi
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Are you building to Fuelscropt's API and is your stack in `ruby`? If so, here's a gem for you.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,59 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Initialize your client with
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
client = Fullscriptapi.config do |c|
|
27
|
+
c.client_id = "your_client_id" # obtain it from the api dashboard
|
28
|
+
c.secret = "your_client_secret" # obtain it from the api dashboard
|
29
|
+
c.redirect_uri = "your_apps_redirect_uri" # obtain it from the api dashboard
|
30
|
+
c.server = "dev" # choose one of us_prod, us_snd, ca_prod, ca_snd, dev
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
Next provide a token hash for your client like this
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
client.use_token(
|
38
|
+
access_token: "access_token",
|
39
|
+
refresh_token: "refresh_token",
|
40
|
+
expires_in: 7200
|
41
|
+
)
|
42
|
+
```
|
43
|
+
|
44
|
+
Then you're ready to make non-authentication api calls (api calls not related to obtaining/refreshing/revoking a token) like this:
|
45
|
+
|
46
|
+
``` ruby
|
47
|
+
client.list_all_products
|
48
|
+
client.create_an_oauth_token(grant) #you'll need your auth grant for this
|
49
|
+
```
|
50
|
+
|
51
|
+
The method names on the `client` match the snake case version of the headings in the fuelscropt api documentation.
|
52
|
+
|
53
|
+
For example, the `List all Patients` heading will translate to `client.list_all_patients`.
|
54
|
+
|
55
|
+
For endpoints that take an `id` parameter (could be `practitioner_id`, `patient_id`, etc) pass that `id` as a required parameter in a nested `query` hash to the api call. This
|
56
|
+
|
57
|
+
Example:
|
58
|
+
|
59
|
+
``` ruby
|
60
|
+
client.retrieve_a_patient(query: { id: "patient_id" })
|
61
|
+
```
|
62
|
+
|
63
|
+
For endpoints that require a `body` passed in, pass that `body` as a required parameter to the api call.
|
64
|
+
|
65
|
+
Example:
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
client.create_a_patient(
|
69
|
+
body: {
|
70
|
+
first_name: "Testing",
|
71
|
+
last_name: "MyGem",
|
72
|
+
email: "test@mygem.com"
|
73
|
+
}
|
74
|
+
)
|
75
|
+
```
|
26
76
|
|
27
77
|
## Development
|
28
78
|
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Fullscriptapi
|
4
|
-
module
|
4
|
+
module AuthenticationEndpoints
|
5
5
|
module CreateAnOauthToken
|
6
|
+
module_function
|
7
|
+
|
6
8
|
def create_an_oauth_token(grant)
|
7
9
|
# you need to have an auth grant to use this method
|
8
10
|
|
9
11
|
raise unless client_id && secret && redirect_uri
|
10
12
|
|
11
|
-
response = Excon.post("#{get_server}/oauth/token",
|
13
|
+
response = Excon.post("#{get_server}/api/oauth/token",
|
12
14
|
headers: {
|
13
15
|
"Content-Type": "application/json"
|
14
16
|
},
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Fullscriptapi
|
4
|
-
module
|
4
|
+
module AuthenticationEndpoints
|
5
5
|
module RefreshToken
|
6
6
|
def refresh_token
|
7
|
-
response = Excon.post("#{get_server}/oauth/token",
|
7
|
+
response = Excon.post("#{get_server}/api/oauth/token",
|
8
8
|
headers: {
|
9
9
|
"Content-Type": "application/json"
|
10
10
|
},
|
@@ -19,7 +19,6 @@ module Fullscriptapi
|
|
19
19
|
|
20
20
|
body = JSON.parse(response.body)
|
21
21
|
|
22
|
-
pp body
|
23
22
|
use_token(body["oauth"])
|
24
23
|
end
|
25
24
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'authentication_endpoints/create_an_oauth_token'
|
4
|
+
require_relative 'authentication_endpoints/refresh_token'
|
5
|
+
|
6
|
+
module Fullscriptapi
|
7
|
+
module AuthenticationEndpoints
|
8
|
+
include CreateAnOauthToken
|
9
|
+
include RefreshToken
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fullscriptapi
|
4
|
+
module Servers
|
5
|
+
SERVERS = {
|
6
|
+
"dev" => "http://localhost:3000",
|
7
|
+
"us_snd" => "https://api-us-snd.fullscript.io",
|
8
|
+
"ca_snd" => "https://api-ca-snd.fullscript.io",
|
9
|
+
"us_prod" => "https://api-us.fullscript.io",
|
10
|
+
"ca_prod" => "https://api-ca.fullscript.io"
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def get_server
|
14
|
+
SERVERS["#{server}"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/fullscriptapi.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require_relative "fullscriptapi/version"
|
2
2
|
require_relative "fullscriptapi/access_token"
|
3
|
-
require_relative "fullscriptapi/
|
3
|
+
require_relative "fullscriptapi/authentication_endpoints"
|
4
|
+
require_relative "fullscriptapi/servers.rb"
|
4
5
|
require 'excon'
|
5
6
|
require 'json'
|
6
7
|
|
7
8
|
module Fullscriptapi
|
8
9
|
class << self
|
9
|
-
include Fullscriptapi::
|
10
|
+
include Fullscriptapi::AuthenticationEndpoints
|
11
|
+
include Fullscriptapi::Servers
|
10
12
|
|
11
13
|
attr_accessor :client_id, :secret, :redirect_uri, :token, :server
|
12
14
|
|
@@ -22,23 +24,74 @@ module Fullscriptapi
|
|
22
24
|
@token = Fullscriptapi::AccessToken.new(opts)
|
23
25
|
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def method_missing(name, *args, &block)
|
28
|
+
@requested_method_hash = api_json_meta.detect { |v| v[:api_method] == name.to_s }
|
29
|
+
|
30
|
+
super unless requested_method_hash
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
refresh_token if stale_token? # TO-DO: write logic to improve token refresh
|
33
|
+
|
34
|
+
params = excon_params(*args)
|
35
|
+
|
36
|
+
Excon.send(*params)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
attr_reader :requested_method_hash
|
39
41
|
|
40
42
|
def stale_token?
|
41
43
|
token && token.expired?
|
42
44
|
end
|
45
|
+
|
46
|
+
def openapi_json
|
47
|
+
@_openapi_json ||=
|
48
|
+
JSON.parse(File.read(File.join(File.dirname(__FILE__), '../openapi.json')))["paths"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def api_json_meta
|
52
|
+
@_api_json_meta ||= begin
|
53
|
+
available_methods = []
|
54
|
+
openapi_json.each do |key, value|
|
55
|
+
http_methods = value.keys
|
56
|
+
|
57
|
+
http_methods.each do |method|
|
58
|
+
api_method = value[method.to_s]["summary"].downcase.gsub(" ", "_")
|
59
|
+
hash_to_add = {
|
60
|
+
api_method: api_method,
|
61
|
+
http_method: method,
|
62
|
+
path: key
|
63
|
+
}
|
64
|
+
available_methods << hash_to_add # [ { api_method: "create_a_patient, http_method: "post", path: "api/clinic/patients" }, ... ]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
available_methods
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def excon_params(*args)
|
72
|
+
path, http_method, api_method = requested_method_hash.values_at(:path, :http_method, :api_method)
|
73
|
+
args_hash = args.first
|
74
|
+
first_bracket = path.index('{')
|
75
|
+
second_bracket = path.index('}')
|
76
|
+
|
77
|
+
path_dup = path.dup
|
78
|
+
if args_hash.is_a?(Hash) && args_hash[:query]
|
79
|
+
path_dup[first_bracket..second_bracket] = args_hash[:query][:id] if args_hash[:query][:id] && first_bracket && second_bracket
|
80
|
+
path_dup += "?query=#{args_hash[:query][:search]}" if args_hash[:query][:search]
|
81
|
+
end
|
82
|
+
|
83
|
+
url = "#{get_server}#{path_dup}"
|
84
|
+
|
85
|
+
params = {
|
86
|
+
headers: {
|
87
|
+
"Content-Type": "application/json",
|
88
|
+
"Authorization": "Bearer #{token.access_token}"
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
params.merge!(body: args_hash[:body].to_json) if args_hash.is_a?(Hash) && args_hash[:body] && args_hash[:body].is_a?(Hash)
|
93
|
+
|
94
|
+
return http_method.to_sym, url, params
|
95
|
+
end
|
43
96
|
end
|
44
97
|
end
|