reso_api 1.6.0 → 1.7.0
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/README.md +6 -3
- data/lib/reso_api/app/models/reso/api/client.rb +6 -6
- data/lib/reso_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 152e24a12afdb9af2c9385a365335df67b58704676b313c886a1833417ae8763
|
4
|
+
data.tar.gz: 88ca57e2199877808138e07f96999376541c40a138b90a920bf56940e786d212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e5c6750cddd94f0dc296e64baf3d008157754360c58c2350feb5df96fa4301f272ad4c1b81a3f20b809523bd16858fc018e38e0a190f71eb2b10f6b2b0552d5
|
7
|
+
data.tar.gz: 1a21eb60cd03e7e39a6cd33123f7635dd194f1cd4bb2e03d326788fecdc187316e9bfc79469f60847fe7d013d286611ef8e4dee49d0524a37d5b2bd3e1814912
|
data/README.md
CHANGED
@@ -37,15 +37,18 @@ To set up an API client using OAuth2 authentication, you need four pieces of inf
|
|
37
37
|
|
38
38
|
- Client ID
|
39
39
|
- Client Secret
|
40
|
-
- Base API endpoint
|
41
40
|
- Authentication URL
|
41
|
+
- Base URL
|
42
|
+
- Scope
|
43
|
+
|
44
|
+
Often, the base URL ends with `/odata`, and the authentication URL often ends with `/token`.
|
42
45
|
|
43
|
-
|
46
|
+
Scope defaults to "api" and only needs to be included if it is "OData" or something else.
|
44
47
|
|
45
48
|
You pass these four pieces of information to create an instance of an API client:
|
46
49
|
|
47
50
|
```ruby
|
48
|
-
client = RESO::API::Client.new(client_id: client_id, client_secret: client_secret, auth_url: auth_url, base_url: base_url)
|
51
|
+
client = RESO::API::Client.new(client_id: client_id, client_secret: client_secret, auth_url: auth_url, base_url: base_url, scope: scope)
|
49
52
|
```
|
50
53
|
|
51
54
|
When calling API endpoints using the initialized client, it will automatically fetch and manage access and authentication tokens transparently in the background.
|
@@ -7,10 +7,10 @@ module RESO
|
|
7
7
|
require 'json'
|
8
8
|
require 'tmpdir'
|
9
9
|
|
10
|
-
attr_accessor :access_token, :client_id, :client_secret, :auth_url, :base_url
|
10
|
+
attr_accessor :access_token, :client_id, :client_secret, :auth_url, :base_url, :scope
|
11
11
|
|
12
12
|
def initialize(**opts)
|
13
|
-
@access_token, @client_id, @client_secret, @auth_url, @base_url = opts.values_at(:access_token, :client_id, :client_secret, :auth_url, :base_url)
|
13
|
+
@access_token, @client_id, @client_secret, @auth_url, @base_url, @scope = opts.values_at(:access_token, :client_id, :client_secret, :auth_url, :base_url, :scope)
|
14
14
|
validate!
|
15
15
|
end
|
16
16
|
|
@@ -109,7 +109,7 @@ module RESO
|
|
109
109
|
client_id,
|
110
110
|
client_secret,
|
111
111
|
token_url: auth_url,
|
112
|
-
scope: "api",
|
112
|
+
scope: scope.presence || "api",
|
113
113
|
grant_type: "client_credentials"
|
114
114
|
)
|
115
115
|
end
|
@@ -128,7 +128,7 @@ module RESO
|
|
128
128
|
end
|
129
129
|
|
130
130
|
def fresh_oauth2_payload
|
131
|
-
@oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret)
|
131
|
+
@oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope || "api")
|
132
132
|
File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
|
133
133
|
return @oauth2_payload
|
134
134
|
end
|
@@ -146,7 +146,7 @@ module RESO
|
|
146
146
|
persisted = File.read(oauth2_token_path)
|
147
147
|
payload = OAuth2::AccessToken.from_hash(oauth2_client, JSON.parse(persisted))
|
148
148
|
else
|
149
|
-
payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret)
|
149
|
+
payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope || "api")
|
150
150
|
File.write(oauth2_token_path, payload.to_hash.to_json)
|
151
151
|
end
|
152
152
|
return payload
|
@@ -179,7 +179,7 @@ module RESO
|
|
179
179
|
fresh_oauth2_payload
|
180
180
|
raise StandardError
|
181
181
|
elsif response.is_a?(Hash) && response.has_key?("error")
|
182
|
-
puts "Error."
|
182
|
+
puts "Error: #{response.inspect}"
|
183
183
|
raise StandardError
|
184
184
|
elsif response.is_a?(Hash) && response.has_key?("retry-after")
|
185
185
|
puts "Error: Retrying in #{response["retry-after"].to_i}} seconds."
|
data/lib/reso_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reso_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Edlund
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.5.9
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: RESO Web API Wrapper
|