spark_api 2.0.1 → 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: 7851c708d86ee3e4e8163208a82df7c3324b3e74bffe946f9835fd2ed1239956
4
- data.tar.gz: 4e5e264d9171f59937ea86faf990f5da95b1d41db4c4c2061f3a5b83c7f8085e
3
+ metadata.gz: 353a8083132bf4adf595f251845285fb20a0c11705b023d44da0cf77bedde244
4
+ data.tar.gz: 873de66f1df1457fd51f3f5ea4d40c7270d7ad59b764de91b908442078da9953
5
5
  SHA512:
6
- metadata.gz: 8e8f11e72f6cd4156d31e7d51e10936213402e751dda09c9788e673a6469a76fb217554cd2b35daf2f4349485fbb8fd8ac94e21948bf39156b671ef5341ecfeb
7
- data.tar.gz: 05ea289076fc911908aeaa5b130ca361eb46290c89baa8a4dade37b2dc8cf318a822748dc3b86c4652f10e1037c68c7994df7cf5484c4639ea20b835b4a3c948
6
+ metadata.gz: cfbb0fd6551de1400c563517ed704938ced9ff7d9bc275dd485f568368f9f6a9f79c631848d845078ec1ca2339c96d0277114ecb2bc7652f185dc9003d075adc
7
+ data.tar.gz: 4aae25e2056353ce88b9d5375d39a3c1553f90fd3cbb44dc8c1d1148c877ad196ac6e121409f374924e241d23cded008d8c928f0ab189ee69a20d41870d7dbfe
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.3
@@ -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
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spark_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.3
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: 2026-05-06 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
@@ -530,6 +530,7 @@ files:
530
530
  - spec/unit/spark_api/paginate_spec.rb
531
531
  - spec/unit/spark_api/primary_array_spec.rb
532
532
  - spec/unit/spark_api/request_spec.rb
533
+ - spec/unit/spark_api/reso_faraday_middleware_spec.rb
533
534
  - spec/unit/spark_api_spec.rb
534
535
  homepage: https://github.com/sparkapi/spark_api
535
536
  licenses:
@@ -753,5 +754,6 @@ test_files:
753
754
  - spec/unit/spark_api/paginate_spec.rb
754
755
  - spec/unit/spark_api/primary_array_spec.rb
755
756
  - spec/unit/spark_api/request_spec.rb
757
+ - spec/unit/spark_api/reso_faraday_middleware_spec.rb
756
758
  - spec/unit/spark_api_spec.rb
757
759
  - spec/spec_helper.rb