remote_model 0.0.2 → 0.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.
- data/lib/remote_model/record.rb +27 -14
- data/lib/remote_model/version.rb +1 -1
- data/spec/requests_spec.rb +32 -3
- metadata +4 -4
data/lib/remote_model/record.rb
CHANGED
@@ -5,27 +5,40 @@ module RemoteModule
|
|
5
5
|
class << self
|
6
6
|
def find(id, params = {}, &block)
|
7
7
|
get(member_url.format(params.merge(id: id))) do |response, json|
|
8
|
-
|
9
|
-
|
8
|
+
if response.ok?
|
9
|
+
obj = self.new(json)
|
10
|
+
request_block_call(block, obj, response)
|
11
|
+
else
|
12
|
+
request_block_call(block, nil, response)
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
13
17
|
def find_all(params = {}, &block)
|
14
18
|
get(collection_url.format(params)) do |response, json|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
if response.ok?
|
20
|
+
objs = []
|
21
|
+
arr_rep = nil
|
22
|
+
if json.class == Array
|
23
|
+
arr_rep = json
|
24
|
+
elsif json.class == Hash
|
25
|
+
plural_sym = self.pluralize.to_sym
|
26
|
+
if json.has_key? plural_sym
|
27
|
+
arr_rep = json[plural_sym]
|
28
|
+
end
|
29
|
+
else
|
30
|
+
# the returned data was something else
|
31
|
+
# ie a string, number
|
32
|
+
request_block_call(block, nil, response)
|
33
|
+
return
|
23
34
|
end
|
35
|
+
arr_rep.each { |one_obj_hash|
|
36
|
+
objs << self.new(one_obj_hash)
|
37
|
+
}
|
38
|
+
request_block_call(block, objs, response)
|
39
|
+
else
|
40
|
+
request_block_call(block, nil, response)
|
24
41
|
end
|
25
|
-
arr_rep.each { |one_obj_hash|
|
26
|
-
objs << self.new(one_obj_hash)
|
27
|
-
}
|
28
|
-
request_block_call(block, objs, response)
|
29
42
|
end
|
30
43
|
end
|
31
44
|
|
data/lib/remote_model/version.rb
CHANGED
data/spec/requests_spec.rb
CHANGED
@@ -1,14 +1,43 @@
|
|
1
|
+
class FailingModel < RemoteModule::RemoteModel
|
2
|
+
def self.root_url
|
3
|
+
# returns a 400 when you don't have a proper token
|
4
|
+
"http://graph.facebook.com/btaylor/friends"
|
5
|
+
end
|
6
|
+
|
7
|
+
collection_url ""
|
8
|
+
member_url "/:id"
|
9
|
+
end
|
10
|
+
|
1
11
|
describe "The requests stuff" do
|
2
12
|
it "should parse json" do
|
3
|
-
ran = false
|
13
|
+
@ran = false
|
4
14
|
RemoteModule::RemoteModel.get("http://graph.facebook.com/btaylor") do |response, json|
|
5
15
|
json.class.should == Hash
|
6
16
|
response.ok?.should == true
|
7
|
-
ran = true
|
17
|
+
@ran = true
|
8
18
|
end
|
9
19
|
# really stupid, haven't made an async request example...
|
10
20
|
wait 5.0 do
|
11
|
-
ran.should == true
|
21
|
+
@ran.should == true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return nil upon bad requests" do
|
26
|
+
@ran_find_all = false
|
27
|
+
@ran_find = false
|
28
|
+
FailingModel.find_all do |results, response|
|
29
|
+
results.should == nil
|
30
|
+
@ran_find_all = true
|
31
|
+
end
|
32
|
+
|
33
|
+
FailingModel.find("1") do |result, response|
|
34
|
+
result.should == nil
|
35
|
+
@ran_find = true
|
36
|
+
end
|
37
|
+
|
38
|
+
wait 5.0 do
|
39
|
+
@ran_find_all.should == true
|
40
|
+
@ran_find.should == true
|
12
41
|
end
|
13
42
|
end
|
14
43
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: remote_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Clay Allsopp
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-12 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bubble-wrap
|
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
hash: -
|
88
|
+
hash: -4143463869793250810
|
89
89
|
segments:
|
90
90
|
- 0
|
91
91
|
version: "0"
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements:
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
hash: -
|
97
|
+
hash: -4143463869793250810
|
98
98
|
segments:
|
99
99
|
- 0
|
100
100
|
version: "0"
|