reso_api 1.5.13 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c60f3b7a93a8fdff58458cb3ceedc48021d007bf88c65fc81455fde74002da9e
4
- data.tar.gz: 97509b32ddd67a2d5ee5857d25fb322e55f3d1e3cb4246c451c0b02f1865fd36
3
+ metadata.gz: ec848b7c652396095ce3180d40c57015bdd40a20f54898500cf560ed66b0f4dd
4
+ data.tar.gz: a2a40ca2833627b66fa7b2d64381ec57ab96ac0b846ff3a9290299dd4574aa3d
5
5
  SHA512:
6
- metadata.gz: eaa3ebf09faee81c40d59063d77468e716f14377a6ae3fd5bb8b59423831b7c3008b0d968cf91962948d828150680caadb7c4fc5f3a2997fa7710527dae9e2b3
7
- data.tar.gz: 196d66437d0ceb577aa3521fb2bee7ae7fb996c2a3b46520ee5ea7268d2cda33751744c314939f57c1676db8657942a52d12f1711ace54e55c7010cef318fcc2
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
- To set up an API client and access a service, you need three pieces of information:
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
- You'll recognize the base API endpoint by it ending with /odata, and the authentication URL by it likely ending with /token.
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
- raise 'Missing Client ID `client_id`' if client_id.nil?
19
- raise 'Missing Client Secret `client_secret`' if client_secret.nil?
20
- raise 'Missing Authentication URL `auth_url`' if auth_url.nil?
21
- raise 'Missing API Base URL `base_url`' if base_url.nil?
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,
@@ -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 #{oauth2_token}"
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
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "1.5.13"
2
+ VERSION = "1.6.0"
3
3
  end
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.5.13
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-07-17 00:00:00.000000000 Z
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.16
126
+ rubygems_version: 3.4.21
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: RESO Web API Wrapper