api_bee 0.0.4 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/api_bee/node.rb +3 -7
- data/lib/api_bee/version.rb +1 -1
- data/spec/node_spec.rb +13 -0
- metadata +2 -2
data/lib/api_bee/node.rb
CHANGED
@@ -71,9 +71,7 @@ module ApiBee
|
|
71
71
|
# node[:price] # new request to /products/6
|
72
72
|
#
|
73
73
|
def [](attribute_name)
|
74
|
-
if
|
75
|
-
send attribute_name
|
76
|
-
elsif value = @attributes[attribute_name]
|
74
|
+
if value = @attributes[attribute_name]
|
77
75
|
resolve_values_to_nodes value
|
78
76
|
elsif has_more? # check whether there's more info in API
|
79
77
|
load_more!
|
@@ -153,6 +151,8 @@ module ApiBee
|
|
153
151
|
#
|
154
152
|
class List < Node
|
155
153
|
|
154
|
+
include Enumerable
|
155
|
+
|
156
156
|
DEFAULT_PER_PAGE = 100
|
157
157
|
|
158
158
|
# Get one resource from this list
|
@@ -216,10 +216,6 @@ module ApiBee
|
|
216
216
|
__entries.each(&block)
|
217
217
|
end
|
218
218
|
|
219
|
-
def each_with_index(&block)
|
220
|
-
__entries.each_with_index(&block)
|
221
|
-
end
|
222
|
-
|
223
219
|
def paginate(options = {})
|
224
220
|
data = @adapter.get(@attributes[@config.uri_property_name], options)
|
225
221
|
Node.resolve @adapter, @config, data, @href
|
data/lib/api_bee/version.rb
CHANGED
data/spec/node_spec.rb
CHANGED
@@ -235,6 +235,19 @@ describe ApiBee do
|
|
235
235
|
@products.last[:title].should == 'Foo 2'
|
236
236
|
end
|
237
237
|
|
238
|
+
it 'should implement #map' do
|
239
|
+
@products.map {|p| p[:title]}.should == ['Foo 1', 'Foo 2']
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should implement #each_with_index' do
|
243
|
+
idx = []
|
244
|
+
titles = []
|
245
|
+
@products.each_with_index {|p,i| idx << i; titles << p[:title]}
|
246
|
+
|
247
|
+
idx.should == [0,1]
|
248
|
+
titles.should == ['Foo 1', 'Foo 2']
|
249
|
+
end
|
250
|
+
|
238
251
|
it 'should navigate to the second page' do
|
239
252
|
@products = @products.paginate(:page => 2, :per_page => 2)
|
240
253
|
titles = []
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: api_bee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.1.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ismael Celis
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2012-01-10 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: Small Ruby client for discoverable, lazily-loaded, paginated JSON APIs
|