reso_api 1.5.12 → 1.6.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 +23 -2
- data/lib/reso_api/app/models/reso/api/client.rb +16 -8
- 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: ec848b7c652396095ce3180d40c57015bdd40a20f54898500cf560ed66b0f4dd
|
4
|
+
data.tar.gz: a2a40ca2833627b66fa7b2d64381ec57ab96ac0b846ff3a9290299dd4574aa3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21caa86ce758a79a23b4b8729a887a698aff3f236f310ced36b2f1cfadc8184cf605021ed31ff97a4d7731d36a0f5aaaf2be1ae63e9ff049c36b63d66794b8bd
|
7
|
+
data.tar.gz: 0f6f792e96a0690a2e7a66fd94175c373df2f1a9e64e00f0e98087aa3a95e21c2f50bb218a28415de1bab00447c2d7992c9d9718233e4265645826deff214791
|
data/README.md
CHANGED
@@ -26,14 +26,21 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
### Authentication and Access
|
28
28
|
|
29
|
-
|
29
|
+
This gem supports two types of authentication:
|
30
|
+
|
31
|
+
- OAuth2
|
32
|
+
- Access Token
|
33
|
+
|
34
|
+
#### OAuth2
|
35
|
+
|
36
|
+
To set up an API client using OAuth2 authentication, you need four pieces of information:
|
30
37
|
|
31
38
|
- Client ID
|
32
39
|
- Client Secret
|
33
40
|
- Base API endpoint
|
34
41
|
- Authentication URL
|
35
42
|
|
36
|
-
|
43
|
+
Often, the base API endpoint ends with `/odata`, and the authentication URL often ends with `/token`.
|
37
44
|
|
38
45
|
You pass these four pieces of information to create an instance of an API client:
|
39
46
|
|
@@ -43,6 +50,20 @@ client = RESO::API::Client.new(client_id: client_id, client_secret: client_secre
|
|
43
50
|
|
44
51
|
When calling API endpoints using the initialized client, it will automatically fetch and manage access and authentication tokens transparently in the background.
|
45
52
|
|
53
|
+
#### Access Token
|
54
|
+
|
55
|
+
Some systems, like MLSGRID and Spark/Flexmls provides a persistent Access Token. In these cases, you need these two pieces of information to set up an API client:
|
56
|
+
|
57
|
+
- Access Token
|
58
|
+
- Base API endpoint
|
59
|
+
|
60
|
+
You pass these two pieces of information to create an instance of an API client:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
client = RESO::API::Client.new(access_token: access_token, base_url: base_url)
|
64
|
+
```
|
65
|
+
|
66
|
+
|
46
67
|
### Resources
|
47
68
|
|
48
69
|
#### Supported Resources
|
@@ -7,18 +7,22 @@ module RESO
|
|
7
7
|
require 'json'
|
8
8
|
require 'tmpdir'
|
9
9
|
|
10
|
-
attr_accessor :client_id, :client_secret, :auth_url, :base_url
|
10
|
+
attr_accessor :access_token, :client_id, :client_secret, :auth_url, :base_url
|
11
11
|
|
12
12
|
def initialize(**opts)
|
13
|
-
@client_id, @client_secret, @auth_url, @base_url = opts.values_at(:client_id, :client_secret, :auth_url, :base_url)
|
13
|
+
@access_token, @client_id, @client_secret, @auth_url, @base_url = opts.values_at(:access_token, :client_id, :client_secret, :auth_url, :base_url)
|
14
14
|
validate!
|
15
15
|
end
|
16
16
|
|
17
17
|
def validate!
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
if access_token.nil?
|
19
|
+
raise 'Missing Client ID `client_id`' if client_id.nil?
|
20
|
+
raise 'Missing Client Secret `client_secret`' if client_secret.nil?
|
21
|
+
raise 'Missing Authentication URL `auth_url`' if auth_url.nil?
|
22
|
+
raise 'Missing API Base URL `base_url`' if base_url.nil?
|
23
|
+
else
|
24
|
+
raise 'Missing API Base URL `base_url`' if base_url.nil?
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
RESOURCE_KEYS = {
|
@@ -96,6 +100,10 @@ module RESO
|
|
96
100
|
end
|
97
101
|
end
|
98
102
|
|
103
|
+
def auth_token
|
104
|
+
access_token.presence ? access_token : oauth2_token
|
105
|
+
end
|
106
|
+
|
99
107
|
def oauth2_client
|
100
108
|
OAuth2::Client.new(
|
101
109
|
client_id,
|
@@ -126,7 +134,7 @@ module RESO
|
|
126
134
|
end
|
127
135
|
|
128
136
|
def oauth2_token_path
|
129
|
-
File.join(Dir.tmpdir, [base_url.parameterize, "
|
137
|
+
File.join(Dir.tmpdir, [base_url.parameterize, client_id, "oauth-token.json"].join("-"))
|
130
138
|
end
|
131
139
|
|
132
140
|
def oauth2_payload
|
@@ -158,7 +166,7 @@ module RESO
|
|
158
166
|
end
|
159
167
|
begin
|
160
168
|
req = Net::HTTP::Get.new(uri.request_uri)
|
161
|
-
req['Authorization'] = "Bearer #{
|
169
|
+
req['Authorization'] = "Bearer #{auth_token}"
|
162
170
|
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
163
171
|
http.request(req)
|
164
172
|
end
|
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.6.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: 2023-
|
11
|
+
date: 2023-10-25 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.4.
|
126
|
+
rubygems_version: 3.4.21
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: RESO Web API Wrapper
|