spark_api 1.4.29 → 1.4.31

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fe8ad347473ad647fb0da6fd681ebe2c6da50daa
4
- data.tar.gz: 7d17ef58323eb5aad73e09167478d0456a7f1df9
2
+ SHA256:
3
+ metadata.gz: '08a105761151bdff166a7c512a604339da3170b73d145f7842d17ccfaa06920d'
4
+ data.tar.gz: 3a6303ce787ba904c3c5bec3c1bdca6549e45115aa108d3c71bbfe8262646536
5
5
  SHA512:
6
- metadata.gz: 0c2df47ef7d780b071df24b586c35838ef1537b68fbd4aac78d8adc99786c2b7de3e81f5d322e781bd0d06defd27fd4bb9f2058788d169d6e48184e346b629ef
7
- data.tar.gz: a23bbccaab494a0007fc75ba5f7317473bc66bfaa268e221b008ad9eef1accbea77008fdc2ba246ebe5508a4f328164c27876f6404bfa3bf1bbfb049e3bed26e
6
+ metadata.gz: 1eb046b673d876b4226c341a0b1ed085ea80b29b4f8dbf600fc4f8156f4084582343861c4e4f9da2333f45c8a1d8e10cca7320b95a42cfc802ef26b177354b3e
7
+ data.tar.gz: 90b225ad0f9dd8801bf46488d8bb3f006d06bf700d4f93fcc9d5ec62667daa925bdd63410e8297efc860947ac67fce6d1932ca6d935a9e2d5949cc56abe92245
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.29
1
+ 1.4.31
@@ -107,7 +107,7 @@ module SparkApi
107
107
  end
108
108
 
109
109
  def process_request_body(body)
110
- if body.is_a?(Hash)
110
+ if body.is_a?(Hash) || body.is_a?(Array)
111
111
  body.empty? ? nil : {"D" => body }.to_json
112
112
  else
113
113
  body
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This script demonstrates how to use the RESO Web API with the Ruby client by pulling listings
4
+ # and replacing encoded field values with their corresponding human-readable values, which are
5
+ # pulled from the XML returned by the RESO metadata endpoint.
6
+
7
+ require "spark_api"
8
+ require "nokogiri"
9
+
10
+ # set up session and RESO Web API middleware
11
+ SparkApi.configure do |config|
12
+ config.authentication_mode = SparkApi::Authentication::OAuth2
13
+ config.middleware = :reso_api
14
+ end
15
+
16
+ SparkApi.client.session = SparkApi::Authentication::OAuthSession.new({ :access_token => "OAUTH2_ACCESS_TOKEN" })
17
+
18
+ # pull metadata from RESO Web API
19
+ metadata_res = (SparkApi.client.get("/$metadata", {:$ApiUser => "FLEXMLS_TECH_ID"}) )
20
+ metadata_xml = Nokogiri::XML(metadata_res).remove_namespaces!
21
+
22
+ # make an array of fields which need to be checked for readable values
23
+ fields_to_lookup = []
24
+ metadata_xml.xpath('//Schema/EnumType/@Name').each do |el|
25
+ fields_to_lookup << el.to_str
26
+ end
27
+
28
+ # get 25 listings
29
+ listings = (SparkApi.client.get("/Property", {:$top => 25, :$ApiUser => "FLEXMLS_TECH_ID"} ))
30
+
31
+ listings['value'].each do |listing| # for each listing,
32
+ fields_to_lookup.each do |field| # go through the array of fields to be checked.
33
+ if !!listing[field] # when one of the fields that needs to be checked exists in a listing,
34
+ if listing[field].is_a? String
35
+ readable = metadata_xml.xpath( # check for readable value to be swapped in
36
+ "//Schema/
37
+ EnumType[@Name=\"#{field}\"]/
38
+ Member[@Name=\"#{listing[field]}\"]/
39
+ Annotation"
40
+ ).attr("String")
41
+
42
+ # if there is a readable value, swap it in
43
+ if !!readable
44
+ listing[field] = readable.to_str
45
+ end
46
+
47
+ elsif listing[field].is_a? Array
48
+ readable_arr = []
49
+ listing[field].each do |el|
50
+ readable = metadata_xml.xpath( # check for readable value to be swapped in
51
+ "//Schema/
52
+ EnumType[@Name=\"#{field}\"]/
53
+ Member[@Name=\"#{el}\"]/
54
+ Annotation"
55
+ ).attr("String")
56
+
57
+ # assemble a new array with readable values and swap it in
58
+ if !!readable
59
+ readable_arr << readable.to_str
60
+ else
61
+ readable_arr << el
62
+ end
63
+ listing[field] = readable_arr
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ puts listings
@@ -118,6 +118,8 @@ describe SparkApi do
118
118
  stub.put('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234', '{"D":{"Contacts":[{"DisplayName":"WLMCEWENS Contact","PrimaryEmail":"wlmcewen789@fbsdata.com"}]}}') { [200, {}, '{"D": {
119
119
  "Success": true}}']
120
120
  }
121
+ stub.put('/v1/arraydata?ApiSig=SignedToken&AuthToken=1234', '{"D":["A","B","C"]}') {[200, {}, '{"D": {
122
+ "Success": true}}']}
121
123
  stub.delete('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234') { [200, {}, '{"D": {
122
124
  "Success": true}}']
123
125
  }
@@ -223,6 +225,10 @@ describe SparkApi do
223
225
  subject.post('/stringdata', 'I am a lonely String!').success?.should == true
224
226
  end
225
227
 
228
+ it "should support arrays in the body" do
229
+ subject.put('/arraydata', ["A","B","C"]).success?.should == true
230
+ end
231
+
226
232
  it "should allow response object to be returned instead of body" do
227
233
  r = subject.get('/system', { full_response: true })
228
234
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.29
4
+ version: 1.4.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hornseth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-24 00:00:00.000000000 Z
12
+ date: 2020-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -382,6 +382,7 @@ files:
382
382
  - script/example.rb
383
383
  - script/oauth2_example.rb
384
384
  - script/release
385
+ - script/reso_middleware_example.rb
385
386
  - spec/fixtures/accounts/all.json
386
387
  - spec/fixtures/accounts/my.json
387
388
  - spec/fixtures/accounts/my_portal.json
@@ -600,7 +601,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
600
601
  version: '1.8'
601
602
  requirements: []
602
603
  rubyforge_project: spark_api
603
- rubygems_version: 2.5.2
604
+ rubygems_version: 2.7.6
604
605
  signing_key:
605
606
  specification_version: 4
606
607
  summary: A library for interacting with the Spark web services.