loquor 0.0.2 → 0.1.0
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/lib/loquor/api_calls/index.rb +12 -0
- data/lib/loquor/representation.rb +7 -3
- data/lib/loquor/version.rb +1 -1
- data/test/api_calls/index_test.rb +25 -0
- data/test/http_actions/post_test.rb +1 -1
- data/test/representation_test.rb +13 -0
- data/test/representations_test.rb +2 -2
- 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: 3a39af7e6a6a26f4c1d02aa721639b84a5026964
|
4
|
+
data.tar.gz: 0d16b9dae6e9f106e894b1bfaef78d718d3fdea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfcb49a360d96307e23022159ac7001ad852ceba27e381fe37496b05397a08a9e29bbe90cc86f11443870fc0548ab39088ec31882591a04ad74995760ca44829
|
7
|
+
data.tar.gz: 8f38a9650191c8bf4c5db8fc3ee1dcc88be0226078594b8ba7e6a824602c3ea0a92ffa7fe05554396d3f3be4478fae07ef4c2261805bae865dbcbab933130675
|
@@ -21,6 +21,18 @@ module Loquor
|
|
21
21
|
results.send(name, *args, &block)
|
22
22
|
end
|
23
23
|
|
24
|
+
def find_each
|
25
|
+
page = 1
|
26
|
+
results = []
|
27
|
+
begin
|
28
|
+
results = Loquor.get("#{generate_url}&page=#{page}&per=#{per}")
|
29
|
+
results.each do |result|
|
30
|
+
yield result
|
31
|
+
end
|
32
|
+
page += 1
|
33
|
+
end while(results.size == per)
|
34
|
+
end
|
35
|
+
|
24
36
|
private
|
25
37
|
|
26
38
|
def results
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Loquor
|
2
2
|
module Representation
|
3
3
|
module ClassMethods
|
4
|
-
[:find, :where, :create].each do |proxy|
|
5
|
-
define_method proxy do |*args|
|
6
|
-
new.send proxy, *args
|
4
|
+
[:find, :find_each, :where, :create].each do |proxy|
|
5
|
+
define_method proxy do |*args, &block|
|
6
|
+
new.send proxy, *args, &block
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -13,6 +13,10 @@ module Loquor
|
|
13
13
|
ApiCall::Show.new(self.class.path, id).execute
|
14
14
|
end
|
15
15
|
|
16
|
+
def find_each(&block)
|
17
|
+
ApiCall::Index.new(self.class.path).find_each(&block)
|
18
|
+
end
|
19
|
+
|
16
20
|
def where(*args)
|
17
21
|
ApiCall::Index.new(self.class.path).where(*args)
|
18
22
|
end
|
data/lib/loquor/version.rb
CHANGED
@@ -68,5 +68,30 @@ module Loquor
|
|
68
68
|
searcher.to_a
|
69
69
|
assert Array, searcher.instance_variable_get("@results").class
|
70
70
|
end
|
71
|
+
|
72
|
+
def test_find_each_calls_block_for_each_item
|
73
|
+
searcher = ApiCall::Index.new('')
|
74
|
+
Loquor.expects(:get).returns([{'id' => 8}, {'id' => 10}])
|
75
|
+
|
76
|
+
ids = []
|
77
|
+
searcher.find_each do |json|
|
78
|
+
ids << json['id']
|
79
|
+
end
|
80
|
+
assert_equal [8,10], ids
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_find_each_limits_to_200
|
84
|
+
searcher = ApiCall::Index.new('http://foobar.com')
|
85
|
+
Loquor.expects(:get).with("http://foobar.com?&page=1&per=200").returns([])
|
86
|
+
searcher.find_each {}
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_find_each_runs_multiple_times
|
90
|
+
searcher = ApiCall::Index.new('http://foobar.com')
|
91
|
+
results = 200.times.map{""}
|
92
|
+
Loquor.expects(:get).with("http://foobar.com?&page=1&per=200").returns(results)
|
93
|
+
Loquor.expects(:get).with("http://foobar.com?&page=2&per=200").returns([])
|
94
|
+
searcher.find_each {}
|
95
|
+
end
|
71
96
|
end
|
72
97
|
end
|
@@ -18,7 +18,7 @@ module Loquor
|
|
18
18
|
def test_post_parses_request
|
19
19
|
output = {'foo' => 'bar'}
|
20
20
|
json = output.to_json
|
21
|
-
posts = HttpAction::Post.new("", {},
|
21
|
+
posts = HttpAction::Post.new("", {}, deps)
|
22
22
|
posts.expects(signed_request: mock(execute: json))
|
23
23
|
assert_equal output, posts.post
|
24
24
|
end
|
data/test/representation_test.rb
CHANGED
@@ -21,6 +21,19 @@ module Loquor
|
|
21
21
|
FoobarRepresentation.find(id)
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_find_each_should_get_correct_path
|
25
|
+
Loquor.expects(:get).with("/foobar?&page=1&per=200").returns([])
|
26
|
+
FoobarRepresentation.find_each
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_find_each_should_yield_block
|
30
|
+
Loquor.expects(:get).returns([{id: 1}])
|
31
|
+
ids = []
|
32
|
+
FoobarRepresentation.find_each do |json|
|
33
|
+
ids << json['id']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
24
37
|
def test_where_should_get_correct_path_with_simple_path
|
25
38
|
email = "foobar"
|
26
39
|
Loquor.expects(:get).with("/foobar?email=#{email}")
|
@@ -5,8 +5,8 @@ module Loquor
|
|
5
5
|
|
6
6
|
{
|
7
7
|
MediaFile: "/media_files",
|
8
|
-
User: "/users"
|
9
|
-
GroupDiscussion: "/group_discussions"
|
8
|
+
User: "/users",
|
9
|
+
GroupDiscussion: "/group_discussions",
|
10
10
|
GroupDiscussionPost: "/group_discussion_posts"
|
11
11
|
}.each do |klass, path|
|
12
12
|
define_method "test_#{klass}_set_up_correctly" do
|