flexirest 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +6 -0
- data/README.md +15 -2
- data/lib/flexirest/result_iterator.rb +14 -0
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/result_iterator_spec.rb +23 -0
- 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: 96c037bf934becbdc7d5381bfaef226550e1a3c1
|
4
|
+
data.tar.gz: 99c2aa6b76d361c1b6862c9bf82fc28b1914737a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe9c061af6b61f68cdffc1243546285f4a33450624dd08b77b8428cb9f58a4ecbf2be4605ff21654f86a35a41713e10055ba92badd4d0c4aaead4a6ff6d5c6f0
|
7
|
+
data.tar.gz: c7342b08bb159edbb8691166668e49d0235cd87c7aee73a27c7a127de495f1e81f17a44cbe95e5e58e003ea276d265739b1e67bd3709b4a52518b4328a0bbebd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -45,12 +45,13 @@ If you are a previous user of ActiveRestClient, there's some more information on
|
|
45
45
|
- [Proxying APIs](#proxying-apis)
|
46
46
|
- [Translating APIs](#translating-apis)
|
47
47
|
- [Default Parameters](#default-parameters)
|
48
|
-
- [Root
|
48
|
+
- [Root elements](#root-elements)
|
49
49
|
- [Required Parameters](#required-parameters)
|
50
50
|
- [Updating Only Changed/Dirty](#updating-only-changed-dirty)
|
51
51
|
- [HTTP/Parse Error Handling](#httpparse-error-handling)
|
52
52
|
- [Validation](#validation)
|
53
53
|
- [Permitting nil values](#permitting-nil-values)
|
54
|
+
- [Filtering result lists](#filtering-result-lists)
|
54
55
|
- [Debugging](#debugging)
|
55
56
|
- [XML Responses](#xml-responses)
|
56
57
|
- [Contributing](#contributing)
|
@@ -1201,7 +1202,19 @@ The following attributes will pass validation since they explicitly `allow_nil`:
|
|
1201
1202
|
- `:retirement_age`
|
1202
1203
|
- `:favorite_authors`
|
1203
1204
|
|
1204
|
-
###
|
1205
|
+
### Filtering result lists
|
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):
|
1208
|
+
|
1209
|
+
```ruby
|
1210
|
+
class Article < Flexirest::Base
|
1211
|
+
get :all, "/articles"
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
Article.all.where(published: true, department: /technical\-/)
|
1215
|
+
```
|
1216
|
+
|
1217
|
+
## Debugging
|
1205
1218
|
|
1206
1219
|
You can turn on verbose debugging to see what is sent to the API server and what is returned in one of these two ways:
|
1207
1220
|
|
@@ -63,6 +63,20 @@ module Flexirest
|
|
63
63
|
self
|
64
64
|
end
|
65
65
|
|
66
|
+
def where(criteria={})
|
67
|
+
@items.select do |object|
|
68
|
+
select = true
|
69
|
+
criteria.each do |k, v|
|
70
|
+
if v.is_a?(Regexp)
|
71
|
+
select = false if !object[k][v]
|
72
|
+
else
|
73
|
+
select = false if object[k] != v
|
74
|
+
end
|
75
|
+
end
|
76
|
+
select
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
66
80
|
def parallelise(method=nil)
|
67
81
|
collected_responses = []
|
68
82
|
threads = []
|
data/lib/flexirest/version.rb
CHANGED
@@ -109,7 +109,30 @@ describe Flexirest::ResultIterator do
|
|
109
109
|
expect(result.items).to eq(["a"])
|
110
110
|
end
|
111
111
|
|
112
|
+
it "can filter results by simple matching criteria" do
|
113
|
+
class Something < Flexirest::Base
|
114
|
+
end
|
115
|
+
|
116
|
+
results = Flexirest::ResultIterator.new
|
117
|
+
results << Something.new(type: "foo")
|
118
|
+
results << Something.new(type: "foo")
|
119
|
+
results << Something.new(type: "bar")
|
120
|
+
|
121
|
+
expect(results.where(type: "foo").count).to eq(2)
|
122
|
+
end
|
112
123
|
|
124
|
+
it "can filter results using regular expression matching criteria" do
|
125
|
+
class Something < Flexirest::Base
|
126
|
+
end
|
127
|
+
|
128
|
+
results = Flexirest::ResultIterator.new
|
129
|
+
results << Something.new(type: "fooo")
|
130
|
+
results << Something.new(type: "foo")
|
131
|
+
results << Something.new(type: "fo")
|
132
|
+
results << Something.new(type: "bar")
|
133
|
+
|
134
|
+
expect(results.where(type: /foo+/).count).to eq(2)
|
135
|
+
end
|
113
136
|
|
114
137
|
it "can parallelise calls to each item" do
|
115
138
|
result = Flexirest::ResultIterator.new
|