loquor 0.4.0 → 0.5.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/CHANGELOG.md +3 -0
- data/README.md +6 -0
- data/lib/loquor/api_calls/index.rb +14 -5
- data/lib/loquor/resource.rb +4 -0
- data/lib/loquor/version.rb +1 -1
- data/test/api_calls/index_test.rb +15 -7
- data/test/resource_test.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d25bbd9a9af995c7ab8646c218a8d9b9953a7e23
|
4
|
+
data.tar.gz: 4a72ae1708c8813640fa881810cee0e570254e20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7657584a766d95803f867d03fc3342a91322be37994b543f7b05cd548a7549b5eb1d8a7e7e1d07aac797ffee3165ead750f42796ee3a6bfa1c3ebeaab8975d4d
|
7
|
+
data.tar.gz: 7d8eb633001bd4ed487155a00457adc38bde2f820de5a13bf5b6b6039a12941ad8126063eef240fb04d703cc7eac5303a42b72cebae9eea9a078319f0dd84de3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -57,6 +57,12 @@ user['name']
|
|
57
57
|
user[:name]
|
58
58
|
```
|
59
59
|
|
60
|
+
You can use `select` (for api calls that support it), which specifies which fields to return.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
items = Loquor::User.select([:id, :name])
|
64
|
+
# => [{id: 2, name: "Jeremy Walker"}, {id: 3, name: "Malcolm Landon"}]
|
65
|
+
```
|
60
66
|
You can use `find` and `find_each` (which sends requests to the API in batches of 200)
|
61
67
|
```ruby
|
62
68
|
Loquor::User.find(2) # => {id: 2, name: "Jeremy Walker"}
|
@@ -15,6 +15,12 @@ module Loquor
|
|
15
15
|
self
|
16
16
|
end
|
17
17
|
|
18
|
+
def select(value)
|
19
|
+
@criteria[:fields] ||= []
|
20
|
+
@criteria[:fields] += value
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
18
24
|
# Proxy everything to the results so that this this class
|
19
25
|
# transparently acts as an Array.
|
20
26
|
def method_missing(name, *args, &block)
|
@@ -44,16 +50,19 @@ module Loquor
|
|
44
50
|
end
|
45
51
|
|
46
52
|
def generate_url
|
47
|
-
query_string =
|
53
|
+
query_string = []
|
54
|
+
@criteria.each do |key,value|
|
48
55
|
if value.is_a?(String)
|
49
|
-
"#{key}=#{URI.encode(value)}"
|
56
|
+
query_string << "#{key}=#{URI.encode(value)}"
|
50
57
|
elsif value.is_a?(Array)
|
51
|
-
|
58
|
+
value.each do |v|
|
59
|
+
query_string << "#{key}[]=#{URI.encode(v)}"
|
60
|
+
end
|
52
61
|
else
|
53
62
|
raise LoquorError.new("Filter values must be strings or arrays.")
|
54
63
|
end
|
55
|
-
|
56
|
-
"#{klass.path}?#{query_string}"
|
64
|
+
end
|
65
|
+
"#{klass.path}?#{query_string.join("&")}"
|
57
66
|
end
|
58
67
|
end
|
59
68
|
end
|
data/lib/loquor/resource.rb
CHANGED
data/lib/loquor/version.rb
CHANGED
@@ -8,6 +8,12 @@ module Loquor
|
|
8
8
|
r
|
9
9
|
end
|
10
10
|
|
11
|
+
def test_select_sets_criteria
|
12
|
+
fields = [:cat, :dog]
|
13
|
+
searcher = ApiCall::Index.new(resource).select(fields)
|
14
|
+
assert_equal({fields: fields}, searcher.criteria)
|
15
|
+
end
|
16
|
+
|
11
17
|
def test_where_sets_criteria
|
12
18
|
criteria = {genre: 'Animation'}
|
13
19
|
searcher = ApiCall::Index.new(resource).where(criteria)
|
@@ -39,6 +45,15 @@ module Loquor
|
|
39
45
|
assert_equal criteria, searcher.criteria
|
40
46
|
end
|
41
47
|
|
48
|
+
def test_generates_url_correctly_with_array_in_a_hash
|
49
|
+
criteria = {thing: ['foo', 'bar']}
|
50
|
+
searcher = ApiCall::Index.new(resource).where(criteria)
|
51
|
+
searcher.stubs(path: "foobar")
|
52
|
+
url = searcher.send(:generate_url)
|
53
|
+
assert url.include?("thing[]=foo")
|
54
|
+
assert url.include?("thing[]=bar")
|
55
|
+
end
|
56
|
+
|
42
57
|
def test_that_iterating_calls_results
|
43
58
|
searcher = ApiCall::Index.new(resource).where(name: "star_wars")
|
44
59
|
searcher.expects(results: [])
|
@@ -52,13 +67,6 @@ module Loquor
|
|
52
67
|
searcher.each { }
|
53
68
|
end
|
54
69
|
|
55
|
-
def test_that_select_calls_each
|
56
|
-
Loquor.expects(:get).returns([{id: 8, name: "Star Wars"}])
|
57
|
-
searcher = ApiCall::Index.new(resource).where(name: "star_wars")
|
58
|
-
searcher.send(:results).expects(:select)
|
59
|
-
searcher.select { }
|
60
|
-
end
|
61
|
-
|
62
70
|
def test_search_should_set_results
|
63
71
|
expected_results = [{id: 8, name: "Star Wars"}]
|
64
72
|
Loquor.expects(:get).returns(expected_results)
|
data/test/resource_test.rb
CHANGED
@@ -25,6 +25,12 @@ module Loquor
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_select_should_proxy
|
29
|
+
args = {a: 'b'}
|
30
|
+
Loquor::ApiCall::Index.any_instance.expects(:select).with(args)
|
31
|
+
Foobar.select(args)
|
32
|
+
end
|
33
|
+
|
28
34
|
def test_where_should_get_correct_path_with_simple_path
|
29
35
|
email = "foobar"
|
30
36
|
Loquor.expects(:get).with("/foobar?email=#{email}").returns([])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loquor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filum
|