spark_api 2.0.0 → 2.0.3

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
2
  SHA256:
3
- metadata.gz: 225a876c0d7cc718e2f7b02544ad280b304d2dae759af03e1a0f2a54558f5323
4
- data.tar.gz: 0da2c909ca58b47e9dd9583a6fef4256fcf0ab55448a6eff00ff29cc6a42bd5c
3
+ metadata.gz: 353a8083132bf4adf595f251845285fb20a0c11705b023d44da0cf77bedde244
4
+ data.tar.gz: 873de66f1df1457fd51f3f5ea4d40c7270d7ad59b764de91b908442078da9953
5
5
  SHA512:
6
- metadata.gz: 7435c421f7978b5e48b79a6d2f2cb9fc9e88ac664b5b4c9b9f956e0e72b7d4cf115e7ebb4024b0551aacc98975d887f0957c67ddecc232fa6777d92567d20875
7
- data.tar.gz: 6a71260f031fd07ac91721b026beec5665986b447a25d1465ff1875819197d38840999879d0ec73717b844e9abb00f94d8e5103a001152bdfaa49ec4853503cf
6
+ metadata.gz: cfbb0fd6551de1400c563517ed704938ced9ff7d9bc275dd485f568368f9f6a9f79c631848d845078ec1ca2339c96d0277114ecb2bc7652f185dc9003d075adc
7
+ data.tar.gz: 4aae25e2056353ce88b9d5375d39a3c1553f90fd3cbb44dc8c1d1148c877ad196ac6e121409f374924e241d23cded008d8c928f0ab189ee69a20d41870d7dbfe
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.0.3
@@ -42,6 +42,19 @@ module SparkApi
42
42
  request(:put, path, body, options)
43
43
  end
44
44
 
45
+ # Perform an HTTP PATCH request
46
+ #
47
+ # * path - Path of an api resource, excluding version and endpoint (domain) information
48
+ # * body - Hash for patch body data
49
+ # * options - Resource request options as specified being supported via and api resource
50
+ # :returns:
51
+ # Hash of the json results as documented in the api.
52
+ # :raises:
53
+ # SparkApi::ClientError or subclass if the request failed.
54
+ def patch(path, body = nil, options={})
55
+ request(:patch, path, body, options)
56
+ end
57
+
45
58
  # Perform an HTTP DELETE request
46
59
  #
47
60
  # * path - Path of an api resource, excluding version and endpoint (domain) information
@@ -13,8 +13,11 @@ module SparkApi
13
13
  env[:body] = body
14
14
  rescue MultiJson::ParseError => e
15
15
  # We will allow the client to choose their XML parser, but should do
16
- # some minor format verification
17
- raise e if body.strip[/\A<\?xml/].nil?
16
+ # some minor format verification.
17
+ # Note: the JSON decode above raised before assigning +body+, so the
18
+ # local +body+ is still nil here. Reference the raw +env[:body]+
19
+ # instead — that's what we actually want to inspect for an XML prolog.
20
+ raise e if env[:body].to_s.strip[/\A<\?xml/].nil?
18
21
  end
19
22
  end
20
23
  end
@@ -120,8 +120,11 @@ describe SparkApi do
120
120
  }
121
121
  stub.put('/v1/arraydata?ApiSig=SignedToken&AuthToken=1234', '{"D":["A","B","C"]}') {[200, {}, '{"D": {
122
122
  "Success": true}}']}
123
+ stub.patch('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234', '{"D":{"Contacts":[{"DisplayName":"WLMCEWENS Contact","PrimaryEmail":"wlmcewen789@fbsdata.com"}]}}') { [200, {}, '{"D": {
124
+ "Success": true}}']
125
+ }
123
126
  stub.delete('/v1/contacts/1000?ApiSig=SignedToken&AuthToken=1234') { [200, {}, '{"D": {
124
- "Success": true}}']
127
+ "Success": true}}']
125
128
  }
126
129
  # Other MISC requests
127
130
  stub.post('/v1/stringdata?ApiSig=SignedToken&AuthToken=1234', 'I am a lonely String!') { [200, {}, '{"D": {
@@ -214,6 +217,11 @@ describe SparkApi do
214
217
  expect(subject.put('/contacts/1000', data).size).to be(0)
215
218
  # No validation here, if no error is raised, everything is hunky dory
216
219
  end
220
+ it "should patch to a service" do
221
+ data = {"Contacts" => [{"DisplayName"=>"WLMCEWENS Contact","PrimaryEmail"=>"wlmcewen789@fbsdata.com"}]}
222
+ expect(subject.patch('/contacts/1000', data).size).to be(0)
223
+ # No validation here, if no error is raised, everything is hunky dory
224
+ end
217
225
  it "should delete from a service" do
218
226
  # This is a hypothetical unsupported service action at this time
219
227
  expect(subject.delete('/contacts/1000').size).to be(0)
@@ -0,0 +1,63 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe SparkApi::ResoFaradayMiddleware do
4
+ def reso_test_connection(stubs)
5
+ Faraday.new(nil, headers: SparkApi::Client.new.headers) do |conn|
6
+ conn.response :reso_api
7
+ conn.adapter :test, stubs
8
+ end
9
+ end
10
+
11
+ let(:xml_metadata) do
12
+ %(<?xml version="1.0" encoding="UTF-8"?>\n<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"/>\n)
13
+ end
14
+
15
+ let(:json_d_envelope) do
16
+ '{"D":{"Success":true,"Results":[{"Name":"My User"}]}}'
17
+ end
18
+
19
+ let(:plain_json_no_d) do
20
+ '{"@odata.context":"https://api.example.com/$metadata#Property","value":[]}'
21
+ end
22
+
23
+ let(:non_json_non_xml_garbage) do
24
+ 'TOTAL GARBAGE'
25
+ end
26
+
27
+ it "passes JSON bodies wrapped in the legacy +D+ envelope through to the parent middleware" do
28
+ stubs = Faraday::Adapter::Test::Stubs.new { |s| s.get('/v1/system') { [200, {}, json_d_envelope] } }
29
+ response = reso_test_connection(stubs).get('/v1/system')
30
+ expect(response.body.success).to eq(true)
31
+ expect(response.body.results.first['Name']).to eq('My User')
32
+ end
33
+
34
+ it "decodes a flat OData JSON response (no +D+ envelope) and stores it on +env[:body]+" do
35
+ stubs = Faraday::Adapter::Test::Stubs.new { |s| s.get('/Property') { [200, {}, plain_json_no_d] } }
36
+ response = reso_test_connection(stubs).get('/Property')
37
+ expect(response.body).to be_a(Hash)
38
+ expect(response.body['@odata.context']).to eq('https://api.example.com/$metadata#Property')
39
+ end
40
+
41
+ # Regression: prior to this fix the JSON parse-error rescue referenced the
42
+ # local +body+ variable, but the +MultiJson.decode+ call in the +begin+
43
+ # block had already raised before +body+ was assigned, so it was always
44
+ # nil at the rescue point. Calling +.strip+ on nil raised
45
+ # +NoMethodError: undefined method `strip' for nil:NilClass+ for *every*
46
+ # XML response, including the +/$metadata+ endpoint.
47
+ it "passes a RESO XML metadata body through without raising NoMethodError" do
48
+ stubs = Faraday::Adapter::Test::Stubs.new do |s|
49
+ s.get('/$metadata') { [200, { 'Content-Type' => 'application/xml' }, xml_metadata] }
50
+ end
51
+ expect {
52
+ response = reso_test_connection(stubs).get('/$metadata')
53
+ expect(response.body).to eq(xml_metadata)
54
+ }.not_to raise_error
55
+ end
56
+
57
+ it "raises the original MultiJson::ParseError for non-JSON, non-XML bodies" do
58
+ stubs = Faraday::Adapter::Test::Stubs.new do |s|
59
+ s.get('/garbage') { [200, {}, non_json_non_xml_garbage] }
60
+ end
61
+ expect { reso_test_connection(stubs).get('/garbage') }.to raise_error(MultiJson::ParseError)
62
+ end
63
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hornseth
8
8
  - Wade McEwen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-12-20 00:00:00.000000000 Z
12
+ date: 2026-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -129,6 +129,20 @@ dependencies:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
+ - !ruby/object:Gem::Dependency
133
+ name: multi_json
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.15.0
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.15.0
132
146
  - !ruby/object:Gem::Dependency
133
147
  name: rexml
134
148
  requirement: !ruby/object:Gem::Requirement
@@ -516,12 +530,13 @@ files:
516
530
  - spec/unit/spark_api/paginate_spec.rb
517
531
  - spec/unit/spark_api/primary_array_spec.rb
518
532
  - spec/unit/spark_api/request_spec.rb
533
+ - spec/unit/spark_api/reso_faraday_middleware_spec.rb
519
534
  - spec/unit/spark_api_spec.rb
520
535
  homepage: https://github.com/sparkapi/spark_api
521
536
  licenses:
522
537
  - Apache 2.0
523
538
  metadata: {}
524
- post_install_message:
539
+ post_install_message:
525
540
  rdoc_options: []
526
541
  require_paths:
527
542
  - lib
@@ -537,7 +552,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
537
552
  version: '1.8'
538
553
  requirements: []
539
554
  rubygems_version: 3.5.22
540
- signing_key:
555
+ signing_key:
541
556
  specification_version: 4
542
557
  summary: A library for interacting with the Spark web services.
543
558
  test_files:
@@ -739,5 +754,6 @@ test_files:
739
754
  - spec/unit/spark_api/paginate_spec.rb
740
755
  - spec/unit/spark_api/primary_array_spec.rb
741
756
  - spec/unit/spark_api/request_spec.rb
757
+ - spec/unit/spark_api/reso_faraday_middleware_spec.rb
742
758
  - spec/unit/spark_api_spec.rb
743
759
  - spec/spec_helper.rb