reso_api 1.6.0 → 1.7.1

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: ec848b7c652396095ce3180d40c57015bdd40a20f54898500cf560ed66b0f4dd
4
- data.tar.gz: a2a40ca2833627b66fa7b2d64381ec57ab96ac0b846ff3a9290299dd4574aa3d
3
+ metadata.gz: 5babf97fd51193ebd80b33651871b83e12749395760c5d4db13d3232ebee4548
4
+ data.tar.gz: dfd4f7f31c5273d01d6b5084ed42aadeb9784903891074c9adaaed26ab3e3a52
5
5
  SHA512:
6
- metadata.gz: 21caa86ce758a79a23b4b8729a887a698aff3f236f310ced36b2f1cfadc8184cf605021ed31ff97a4d7731d36a0f5aaaf2be1ae63e9ff049c36b63d66794b8bd
7
- data.tar.gz: 0f6f792e96a0690a2e7a66fd94175c373df2f1a9e64e00f0e98087aa3a95e21c2f50bb218a28415de1bab00447c2d7992c9d9718233e4265645826deff214791
6
+ metadata.gz: 756f59ac0272091ee42faa06cd76d4ddfa3212cf07cbe0ec373f0a523afe9aaeb659b0a83496863f77473aa89a0dc3185f67dd3de3c18fb5dacff685837e7a2b
7
+ data.tar.gz: ace0e14e850638bb71741290fc48dea35210d8102b65fda5f01e1b710c2ebae705ea43a6b7c4a726a559e584fb946b707ff52aa73aebbdb571bf9fd0a0f224ca
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
- Often, the base API endpoint ends with `/odata`, and the authentication URL often ends with `/token`.
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
 
@@ -29,6 +29,7 @@ module RESO
29
29
  media: "MediaKey",
30
30
  members: "MemberKey",
31
31
  offices: "OfficeKey",
32
+ open_houses: "OpenHouseKey",
32
33
  properties: "ListingKey"
33
34
  }
34
35
 
@@ -36,6 +37,7 @@ module RESO
36
37
  medium: "/Media",
37
38
  member: "/Member",
38
39
  office: "/Office",
40
+ open_house: "/OpenHouse",
39
41
  property: "/Property"
40
42
  }
41
43
 
@@ -43,6 +45,7 @@ module RESO
43
45
  media: "/Media",
44
46
  members: "/Member",
45
47
  offices: "/Office",
48
+ open_houses: "/OpenHouse",
46
49
  properties: "/Property"
47
50
  }
48
51
 
@@ -58,9 +61,9 @@ module RESO
58
61
  params = {
59
62
  "$select": hash[:select],
60
63
  "$filter": hash[:filter],
61
- "$top": hash[:top] ||= 100,
64
+ "$top": hash[:top].presence,
62
65
  "$skip": hash[:skip],
63
- "$orderby": hash[:orderby] ||= RESOURCE_KEYS[method_name],
66
+ "$orderby": hash[:orderby].to_a.presence,
64
67
  "$skiptoken": hash[:skiptoken],
65
68
  "$expand": hash[:expand],
66
69
  "$count": hash[:count].to_s.presence,
@@ -109,7 +112,7 @@ module RESO
109
112
  client_id,
110
113
  client_secret,
111
114
  token_url: auth_url,
112
- scope: "api",
115
+ scope: scope.presence || "api",
113
116
  grant_type: "client_credentials"
114
117
  )
115
118
  end
@@ -128,7 +131,7 @@ module RESO
128
131
  end
129
132
 
130
133
  def fresh_oauth2_payload
131
- @oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret)
134
+ @oauth2_payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope || "api")
132
135
  File.write(oauth2_token_path, @oauth2_payload.to_hash.to_json)
133
136
  return @oauth2_payload
134
137
  end
@@ -146,7 +149,7 @@ module RESO
146
149
  persisted = File.read(oauth2_token_path)
147
150
  payload = OAuth2::AccessToken.from_hash(oauth2_client, JSON.parse(persisted))
148
151
  else
149
- payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret)
152
+ payload = oauth2_client.client_credentials.get_token('client_id' => client_id, 'client_secret' => client_secret, 'scope' => scope || "api")
150
153
  File.write(oauth2_token_path, payload.to_hash.to_json)
151
154
  end
152
155
  return payload
@@ -179,7 +182,7 @@ module RESO
179
182
  fresh_oauth2_payload
180
183
  raise StandardError
181
184
  elsif response.is_a?(Hash) && response.has_key?("error")
182
- puts "Error."
185
+ puts "Error: #{response.inspect}"
183
186
  raise StandardError
184
187
  elsif response.is_a?(Hash) && response.has_key?("retry-after")
185
188
  puts "Error: Retrying in #{response["retry-after"].to_i}} seconds."
@@ -1,3 +1,3 @@
1
1
  module ResoApi
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.1"
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.6.0
4
+ version: 1.7.1
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-10-25 00:00:00.000000000 Z
11
+ date: 2024-04-17 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.21
126
+ rubygems_version: 3.5.9
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: RESO Web API Wrapper