flexirest 1.6.1 → 1.6.2

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
  SHA1:
3
- metadata.gz: 96c037bf934becbdc7d5381bfaef226550e1a3c1
4
- data.tar.gz: 99c2aa6b76d361c1b6862c9bf82fc28b1914737a
3
+ metadata.gz: 4ef0d167d4d731cacdb7ac4f272ca0cf0c1ebb24
4
+ data.tar.gz: b56d4dc78f1f6e5875f57e737cab0a1b4efd749f
5
5
  SHA512:
6
- metadata.gz: fe9c061af6b61f68cdffc1243546285f4a33450624dd08b77b8428cb9f58a4ecbf2be4605ff21654f86a35a41713e10055ba92badd4d0c4aaead4a6ff6d5c6f0
7
- data.tar.gz: c7342b08bb159edbb8691166668e49d0235cd87c7aee73a27c7a127de495f1e81f17a44cbe95e5e58e003ea276d265739b1e67bd3709b4a52518b4328a0bbebd
6
+ metadata.gz: 6cc9bfa84951e23c7ac5f12804967e27724f7f8f9a4de62d6cf4b293f57aaeb8a61138f6c7baccd7559b5707c83b3bcfc854492e6c838fcd976ff542630bc31f
7
+ data.tar.gz: 2bf14a68818a51363b2f3e3817dfc88b4e599516a2b2bc7125da773e05b041e2f0445dad4d561aa709ae3bd6e88ff28f3a1d86ea58442c22ac6704db5a628249
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.2
4
+
5
+ Bugfix:
6
+
7
+ - Flexirest wasn't supporting nested arrays in responses, it does now. Thanks to Rui Ribeiro for pointing this out.
8
+
3
9
  ## 1.6.1
4
10
 
5
11
  Feature:
data/README.md CHANGED
@@ -1204,7 +1204,7 @@ The following attributes will pass validation since they explicitly `allow_nil`:
1204
1204
 
1205
1205
  ### Filtering result lists
1206
1206
 
1207
- If the API returns a JSON list of items, this is retured to you as a `Flexirest::ResultIterator` object. A `ResultIterator` sorts simple filtering of the list based on values matching a specified criteria (or matching using regular expressions):
1207
+ If the API returns a JSON list of items, this is retured to you as a `Flexirest::ResultIterator` object. A `ResultIterator` sorts simple filtering of the list using a `where` method based on values matching a specified criteria (or matching using regular expressions):
1208
1208
 
1209
1209
  ```ruby
1210
1210
  class Article < Flexirest::Base
@@ -727,9 +727,7 @@ module Flexirest
727
727
  end
728
728
  if body.is_a? Array
729
729
  result = Flexirest::ResultIterator.new(@response)
730
- body.each do |json_object|
731
- result << new_object(json_object, @overridden_name)
732
- end
730
+ add_nested_body_to_iterator(result, body)
733
731
  else
734
732
  result = new_object(body, @overridden_name)
735
733
  result._status = @response.status
@@ -743,6 +741,18 @@ module Flexirest
743
741
  end
744
742
  result
745
743
  end
744
+
745
+ def add_nested_body_to_iterator(result, items)
746
+ items.each do |json_object|
747
+ if json_object.is_a?(Array)
748
+ iterator = ResultIterator.new
749
+ add_nested_body_to_iterator(iterator, json_object)
750
+ result << iterator
751
+ else
752
+ result << new_object(json_object, @overridden_name)
753
+ end
754
+ end
755
+ end
746
756
  end
747
757
 
748
758
  class RequestException < StandardError ; end
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
@@ -150,7 +150,7 @@ describe Flexirest::Request do
150
150
  expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
151
151
  servers = []
152
152
  # TODO: this next test is potentially flakey, if over 10 runs of []#sample it doesn't return both variants, but it's so unlikely...
153
- 10.times do
153
+ 30.times do
154
154
  expect(Flexirest::ConnectionManager).to receive(:get_connection) do |arg|
155
155
  servers << arg
156
156
  connection
@@ -436,6 +436,15 @@ describe Flexirest::Request do
436
436
  expect(object._status).to eq(200)
437
437
  end
438
438
 
439
+ it "should parse a nested array within JSON to be a result iterator" do
440
+ expect_any_instance_of(Flexirest::Connection).to receive(:put).with("/put/1234", "debug=true", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"[[{}, {\"first_name\":\"Johnny\"}, {\"first_name\":\"Billy\"}]]", status:200, response_headers:{})))
441
+ object = ExampleClient.update id:1234, debug:true
442
+ expect(object).to be_instance_of(Flexirest::ResultIterator)
443
+ expect(object[0][1].first_name).to eq("Johnny")
444
+ expect(object[0][2].first_name).to eq("Billy")
445
+ expect(object._status).to eq(200)
446
+ end
447
+
439
448
  it "should parse an attribute to be an array if attribute included in array option" do
440
449
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/johnny", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"likes\":[\"donuts\", \"bacon\"], \"dislikes\":[\"politicians\", \"lawyers\", \"taxes\"]}", status:200, response_headers:{})))
441
450
  object = ExampleClient.array
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries