loquor 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66d22aefdf548f552fe27c362e989694c003d8db
4
- data.tar.gz: 28e68dd1ee8b4817b498dcb4b9d4708580022ef1
3
+ metadata.gz: d25bbd9a9af995c7ab8646c218a8d9b9953a7e23
4
+ data.tar.gz: 4a72ae1708c8813640fa881810cee0e570254e20
5
5
  SHA512:
6
- metadata.gz: db3f3945f357ff7fb525f5023b4dd3edf9a71f305f5aed6bee77d965ecac5cf0afba6676aa14208662913363e8d58a6c6b552ba4730a7caa914c8bcdcb9290a4
7
- data.tar.gz: 83c4d422229dcafa91b2b096c674d468ced2aa4dde5816c041d8c2fea2daf7e03ca1902582d17acb5f40944333235928e62b91f16ee0f33212f03e63bee9a850
6
+ metadata.gz: 7657584a766d95803f867d03fc3342a91322be37994b543f7b05cd548a7549b5eb1d8a7e7e1d07aac797ffee3165ead750f42796ee3a6bfa1c3ebeaab8975d4d
7
+ data.tar.gz: 7d8eb633001bd4ed487155a00457adc38bde2f820de5a13bf5b6b6039a12941ad8126063eef240fb04d703cc7eac5303a42b72cebae9eea9a078319f0dd84de3
@@ -1,3 +1,6 @@
1
+ # 0.5.0 / 2013-12-04
2
+ * [FEATURE] Add support for select
3
+
1
4
  # 0.4.0 / 2013-11-23
2
5
  * [FEATURE] Add support for updates
3
6
 
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 = @criteria.map { |key,value|
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
- "#{key}=[#{URI.encode(value.join(","))}]"
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
- }.join("&")
56
- "#{klass.path}?#{query_string}"
64
+ end
65
+ "#{klass.path}?#{query_string.join("&")}"
57
66
  end
58
67
  end
59
68
  end
@@ -25,6 +25,10 @@ module Loquor
25
25
  ApiCall::Index.new(self).find_each(&block)
26
26
  end
27
27
 
28
+ def self.select(*args)
29
+ ApiCall::Index.new(self).select(*args)
30
+ end
31
+
28
32
  def self.where(*args)
29
33
  ApiCall::Index.new(self).where(*args)
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module Loquor
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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)
@@ -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.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-29 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filum