loquor 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 632149903ddd90cf5dc6edaede05ac490317090c
4
- data.tar.gz: a523cf47111b39b1086a8f378316bac2fbf78a6d
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Nzc1YzA3OTlhOGVlZWQ1YTMzYzkwNjVjN2QzZjcyOGJjYzExNDFmYw==
5
+ data.tar.gz: !binary |-
6
+ NWYwNTc3MTRlOTBjZTU5MWMzNzE2YjI0OGMzZTUzZTFlZDViNjc1Yw==
5
7
  SHA512:
6
- metadata.gz: ddd8547f47aab0d704b909488c4a59cf569ad7b9bccefb8fb95f313b2aeb7adb1b6b774fe6153c523cecf81d5fdace2dfa7a873f260623ceac00658fced90192
7
- data.tar.gz: 43e207ddc2425f44db2a8bc6138b67bff3853b7d6155c61a343d3ab8a4ab41fd22fa59fe87511abcbdade03a5d60a8e1b4658d195903438072fa5265e2bdafba
8
+ metadata.gz: !binary |-
9
+ ZmQxODJlYTdmZTNkOTU5ZTE0ZDY1YmVhNjA0MDVhMTMyOTFmZTRjOWE1M2I5
10
+ ZDQxY2JmNDZlOThkYWExYWZjNzk2ZTBiODZkNGI2YzgxNjNjYjU2OTU5NWU1
11
+ NmE0MzI5YmNlMzYwYzgxZjY2NjhiMjFkY2FmMTUxZWVhN2JiMGQ=
12
+ data.tar.gz: !binary |-
13
+ OGFlZmEwMjY2YmVkZmIxMjIzY2RhYWMwZjYxYzkwNGE0NjNhNTJhOTA0YjFi
14
+ Yzg3Yzk1ODU2ZDAzNGUyYmVjZGE1MjU2NTE4ZGVmZjBhZGM1OTFkZjBhN2Yz
15
+ NDAzZWRiN2JjMTllNTcyODY5M2Y5ZTVkNDY3N2FhZDAzMTNjM2Y=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.6.0 / 2014-03-07
2
+ * [FEATURE] Add support for date, time and datetime in filters.
3
+ * [FEATURE] Add support deleting entities.
4
+
1
5
  # 1.5.0 / 2014-02-27
2
6
  * [FEATURE] Add retry support for 404s
3
7
 
data/lib/loquor.rb CHANGED
@@ -34,6 +34,10 @@ module Loquor
34
34
  loquor.post(url, payload)
35
35
  end
36
36
 
37
+ def self.delete(url)
38
+ loquor.delete(url)
39
+ end
40
+
37
41
  private
38
42
 
39
43
  def self.loquor
@@ -11,3 +11,4 @@ require 'loquor/api_calls/create'
11
11
  require 'loquor/api_calls/update'
12
12
  require 'loquor/api_calls/show'
13
13
  require 'loquor/api_calls/index'
14
+ require 'loquor/api_calls/destroy'
@@ -0,0 +1,13 @@
1
+ module Loquor
2
+ class ApiCall::Destroy < ApiCall
3
+
4
+ def initialize(klass, id)
5
+ super(klass)
6
+ @id = id
7
+ end
8
+
9
+ def execute
10
+ klass.new Loquor.delete("#{klass.path}/#{@id}")
11
+ end
12
+ end
13
+ end
@@ -73,7 +73,7 @@ module Loquor
73
73
  query_string << "#{key}=#{URI.encode(substitute_value)}"
74
74
  else
75
75
  case value
76
- when String, Symbol, Numeric
76
+ when String, Symbol, Numeric, Date, Time, DateTime
77
77
  query_string << "#{key}=#{URI.encode(value.to_s)}"
78
78
  when Array
79
79
  value.each do |v|
@@ -84,7 +84,7 @@ module Loquor
84
84
  query_string << "#{key}[#{k}]=#{URI.encode(v.to_s)}"
85
85
  end
86
86
  else
87
- raise LoquorError.new("Filter values must be strings, arrays or single-depth hashes.")
87
+ raise LoquorError.new("Filter values must be strings, arrays, date, time, datetime or single-depth hashes.")
88
88
  end
89
89
  end
90
90
  end
data/lib/loquor/client.rb CHANGED
@@ -21,5 +21,10 @@ module Loquor
21
21
  deps = {config: @config}
22
22
  HttpAction::Post.post(url, payload, deps)
23
23
  end
24
+
25
+ def delete(url)
26
+ deps = {config: @config}
27
+ HttpAction::Delete.delete(url, deps)
28
+ end
24
29
  end
25
30
  end
@@ -33,3 +33,4 @@ end
33
33
  require 'loquor/http_actions/get'
34
34
  require 'loquor/http_actions/post'
35
35
  require 'loquor/http_actions/put'
36
+ require 'loquor/http_actions/delete'
@@ -0,0 +1,31 @@
1
+ module Loquor
2
+ class HttpAction::Delete < HttpAction
3
+ def self.delete(url, deps)
4
+ new(url, deps).delete
5
+ end
6
+
7
+ def initialize(url, deps)
8
+ super(url, deps)
9
+ end
10
+
11
+ def delete
12
+ @config.logger.info "Making DELETE request to: #{full_url}"
13
+ response = JSON.parse(signed_request.execute)
14
+ @config.logger.info "Signed request executed. Response: #{response}"
15
+ response
16
+ end
17
+
18
+ private
19
+
20
+ def request
21
+ RestClient::Request.new(url: full_url,
22
+ accept: :json,
23
+ headers: {'Content-type' => 'application/json'},
24
+ method: :delete)
25
+ end
26
+
27
+ def full_url
28
+ "#{@config.endpoint}#{@url}"
29
+ end
30
+ end
31
+ end
@@ -55,5 +55,9 @@ module Loquor
55
55
  def self.update(id, payload)
56
56
  ApiCall::Update.new(self, id, payload: payload).execute
57
57
  end
58
+
59
+ def self.destroy(id)
60
+ ApiCall::Destroy.new(self, id).execute
61
+ end
58
62
  end
59
63
  end
@@ -1,3 +1,3 @@
1
1
  module Loquor
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Loquor
4
+ class ApiCall::DestroyTest < Minitest::Test
5
+ def test_delete_is_called_correctly
6
+ klass = mock
7
+ klass.stubs(new: nil)
8
+ klass.stubs(path: "/foobar")
9
+ id = 5
10
+ Loquor.expects(:delete).with("#{klass.path}/#{id}")
11
+ ApiCall::Destroy.new(klass, id).execute
12
+ end
13
+ end
14
+ end
15
+
@@ -55,6 +55,21 @@ module Loquor
55
55
  assert searcher.send(:generate_url).include? "?name=star"
56
56
  end
57
57
 
58
+ def test_where_gets_correct_url_with_date
59
+ searcher = ApiCall::Index.new(resource).where(name: Date.new(1969,5,10))
60
+ assert searcher.send(:generate_url).include? "?name=1969-05-10"
61
+ end
62
+
63
+ def test_where_gets_correct_url_with_time
64
+ searcher = ApiCall::Index.new(resource).where(name: Time.new(1969,5,10,13,10))
65
+ assert searcher.send(:generate_url).include? "?name=1969-05-10%2013:10:00"
66
+ end
67
+
68
+ def test_where_gets_correct_url_with_date_time
69
+ searcher = ApiCall::Index.new(resource).where(name: DateTime.new(1969,5,10,13,10))
70
+ assert searcher.send(:generate_url).include? "?name=1969-05-10T13:10:00"
71
+ end
72
+
58
73
  def test_where_gets_correct_url_with_number
59
74
  searcher = ApiCall::Index.new(resource).where(name: 1)
60
75
  assert searcher.send(:generate_url).include? "?name=1"
data/test/client_test.rb CHANGED
@@ -36,6 +36,13 @@ module Loquor
36
36
  client.post(url, payload)
37
37
  end
38
38
 
39
+ def test_delete_calls_deletes
40
+ url = "foobar"
41
+ client = Client.new
42
+ deps = {config: client.config}
43
+ HttpAction::Delete.expects(:delete).with(url, deps)
44
+ client.delete(url)
45
+ end
39
46
 
40
47
  def test_get_calls_gets_with_cache_flag
41
48
  url = "foobar"
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Loquor
4
+ class HttpAction::DeleteTest < HttpAction::Test
5
+ def test_delete_should_call_new
6
+ url = "foobar"
7
+ deps = {x: true}
8
+ HttpAction::Delete.expects(:new).with(url, deps).returns(mock(delete: nil))
9
+ HttpAction::Delete.delete(url, deps)
10
+ end
11
+
12
+ def test_delete_should_call_put
13
+ HttpAction::Delete.any_instance.expects(:delete)
14
+ HttpAction::Delete.delete("foobar", {})
15
+ end
16
+
17
+ def test_request_is_signed_correctly
18
+ puts = HttpAction::Delete.new("", deps)
19
+ request = RestClient::Request.new(url: "http://localhost:3000", method: :delete)
20
+ puts.expects(request: request)
21
+ ApiAuth.expects(:sign!).with(request, @access_id, @secret_key)
22
+ puts.send(:signed_request)
23
+ end
24
+ end
25
+ end
26
+
27
+
@@ -66,6 +66,12 @@ module Loquor
66
66
  Foobar.update(id, payload)
67
67
  end
68
68
 
69
+ def test_destroy_should_delete
70
+ id = 8
71
+ Loquor.expects(:delete).with("/foobar/#{id}")
72
+ Foobar.destroy(id)
73
+ end
74
+
69
75
  def test_can_read_path
70
76
  assert_equal "/foobar", Foobar.path
71
77
  end
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: 1.5.0
4
+ version: 1.6.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: 2014-02-27 00:00:00.000000000 Z
11
+ date: 2014-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filum
@@ -84,28 +84,28 @@ dependencies:
84
84
  name: mocha
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: An API dispatcher for Meducation
@@ -125,12 +125,14 @@ files:
125
125
  - lib/loquor.rb
126
126
  - lib/loquor/api_call.rb
127
127
  - lib/loquor/api_calls/create.rb
128
+ - lib/loquor/api_calls/destroy.rb
128
129
  - lib/loquor/api_calls/index.rb
129
130
  - lib/loquor/api_calls/show.rb
130
131
  - lib/loquor/api_calls/update.rb
131
132
  - lib/loquor/client.rb
132
133
  - lib/loquor/configuration.rb
133
134
  - lib/loquor/http_action.rb
135
+ - lib/loquor/http_actions/delete.rb
134
136
  - lib/loquor/http_actions/get.rb
135
137
  - lib/loquor/http_actions/post.rb
136
138
  - lib/loquor/http_actions/put.rb
@@ -140,12 +142,14 @@ files:
140
142
  - lib/loquor/resource_mock.rb
141
143
  - lib/loquor/version.rb
142
144
  - loquor.gemspec
145
+ - test/api_calls/destroy_test.rb
143
146
  - test/api_calls/index_test.rb
144
147
  - test/api_calls/show_test.rb
145
148
  - test/api_calls/update_test.rb
146
149
  - test/client_test.rb
147
150
  - test/configuration_test.rb
148
151
  - test/http_action_test.rb
152
+ - test/http_actions/delete_test.rb
149
153
  - test/http_actions/get_test.rb
150
154
  - test/http_actions/post_test.rb
151
155
  - test/http_actions/put_test.rb
@@ -164,12 +168,12 @@ require_paths:
164
168
  - lib
165
169
  required_ruby_version: !ruby/object:Gem::Requirement
166
170
  requirements:
167
- - - '>='
171
+ - - ! '>='
168
172
  - !ruby/object:Gem::Version
169
173
  version: '0'
170
174
  required_rubygems_version: !ruby/object:Gem::Requirement
171
175
  requirements:
172
- - - '>='
176
+ - - ! '>='
173
177
  - !ruby/object:Gem::Version
174
178
  version: '0'
175
179
  requirements: []
@@ -179,12 +183,14 @@ signing_key:
179
183
  specification_version: 4
180
184
  summary: This library dispatches requests to Meducation
181
185
  test_files:
186
+ - test/api_calls/destroy_test.rb
182
187
  - test/api_calls/index_test.rb
183
188
  - test/api_calls/show_test.rb
184
189
  - test/api_calls/update_test.rb
185
190
  - test/client_test.rb
186
191
  - test/configuration_test.rb
187
192
  - test/http_action_test.rb
193
+ - test/http_actions/delete_test.rb
188
194
  - test/http_actions/get_test.rb
189
195
  - test/http_actions/post_test.rb
190
196
  - test/http_actions/put_test.rb
@@ -193,4 +199,3 @@ test_files:
193
199
  - test/resource_mock_test.rb
194
200
  - test/resource_test.rb
195
201
  - test/test_helper.rb
196
- has_rdoc: