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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/flexirest/request.rb +13 -3
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ef0d167d4d731cacdb7ac4f272ca0cf0c1ebb24
|
4
|
+
data.tar.gz: b56d4dc78f1f6e5875f57e737cab0a1b4efd749f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc9bfa84951e23c7ac5f12804967e27724f7f8f9a4de62d6cf4b293f57aaeb8a61138f6c7baccd7559b5707c83b3bcfc854492e6c838fcd976ff542630bc31f
|
7
|
+
data.tar.gz: 2bf14a68818a51363b2f3e3817dfc88b4e599516a2b2bc7125da773e05b041e2f0445dad4d561aa709ae3bd6e88ff28f3a1d86ea58442c22ac6704db5a628249
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/flexirest/request.rb
CHANGED
@@ -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
|
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
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -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
|
-
|
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
|