loquor 0.3.0 → 0.4.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/lib/loquor.rb +4 -0
- data/lib/loquor/api_call.rb +1 -0
- data/lib/loquor/api_calls/update.rb +14 -0
- data/lib/loquor/client.rb +5 -0
- data/lib/loquor/http_action.rb +1 -1
- data/lib/loquor/http_actions/put.rb +40 -0
- data/lib/loquor/resource.rb +4 -0
- data/lib/loquor/version.rb +1 -1
- data/test/api_calls/update_test.rb +16 -0
- data/test/client_test.rb +10 -0
- data/test/http_actions/put_test.rb +58 -0
- data/test/loquor_test.rb +25 -0
- data/test/resource_test.rb +7 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66d22aefdf548f552fe27c362e989694c003d8db
|
4
|
+
data.tar.gz: 28e68dd1ee8b4817b498dcb4b9d4708580022ef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3f3945f357ff7fb525f5023b4dd3edf9a71f305f5aed6bee77d965ecac5cf0afba6676aa14208662913363e8d58a6c6b552ba4730a7caa914c8bcdcb9290a4
|
7
|
+
data.tar.gz: 83c4d422229dcafa91b2b096c674d468ced2aa4dde5816c041d8c2fea2daf7e03ca1902582d17acb5f40944333235928e62b91f16ee0f33212f03e63bee9a850
|
data/CHANGELOG.md
CHANGED
data/lib/loquor.rb
CHANGED
data/lib/loquor/api_call.rb
CHANGED
data/lib/loquor/client.rb
CHANGED
@@ -11,6 +11,11 @@ module Loquor
|
|
11
11
|
HttpAction::Get.get(url, deps)
|
12
12
|
end
|
13
13
|
|
14
|
+
def put(url, payload)
|
15
|
+
deps = {config: @config}
|
16
|
+
HttpAction::Put.put(url, payload, deps)
|
17
|
+
end
|
18
|
+
|
14
19
|
def post(url, payload)
|
15
20
|
deps = {config: @config}
|
16
21
|
HttpAction::Post.post(url, payload, deps)
|
data/lib/loquor/http_action.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Loquor
|
2
|
+
class HttpAction::Put < HttpAction
|
3
|
+
def self.put(url, payload, deps)
|
4
|
+
new(url, payload, deps).put
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(url, payload, deps)
|
8
|
+
super(url, deps)
|
9
|
+
@payload = payload
|
10
|
+
end
|
11
|
+
|
12
|
+
def put
|
13
|
+
@config.logger.info "Making put request to: #{full_url}"
|
14
|
+
response = JSON.parse(signed_request.execute)
|
15
|
+
@config.logger.info "Signed request executed. Response: #{response}"
|
16
|
+
Resource.new(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def signed_request
|
22
|
+
signed_request = super
|
23
|
+
p signed_request # If you take this line out - it all breaks. Yeah...
|
24
|
+
signed_request
|
25
|
+
end
|
26
|
+
|
27
|
+
def request
|
28
|
+
RestClient::Request.new(url: full_url,
|
29
|
+
accept: :json,
|
30
|
+
payload: @payload.to_json,
|
31
|
+
headers: {'Content-type' => 'application/json'},
|
32
|
+
method: :put)
|
33
|
+
end
|
34
|
+
|
35
|
+
def full_url
|
36
|
+
"#{@config.endpoint}#{@url}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/lib/loquor/resource.rb
CHANGED
data/lib/loquor/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Loquor
|
4
|
+
class ApiCall::UpdateTest < Minitest::Test
|
5
|
+
def test_put_is_called_correctly
|
6
|
+
klass = mock
|
7
|
+
klass.stubs(new: nil)
|
8
|
+
klass.stubs(path: "/foobar")
|
9
|
+
id = 5
|
10
|
+
payload = {foo: 'bar'}
|
11
|
+
Loquor.expects(:put).with("#{klass.path}/#{id}", payload)
|
12
|
+
update = ApiCall::Update.new(klass, id, payload).execute
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/test/client_test.rb
CHANGED
@@ -16,6 +16,16 @@ module Loquor
|
|
16
16
|
client.get(url)
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_put_calls_puts
|
20
|
+
url = "foobar"
|
21
|
+
payload = {foo: 'bar'}
|
22
|
+
|
23
|
+
client = Client.new
|
24
|
+
deps = {config: client.config}
|
25
|
+
HttpAction::Put.expects(:put).with(url, payload, deps)
|
26
|
+
client.put(url, payload)
|
27
|
+
end
|
28
|
+
|
19
29
|
def test_post_calls_posts
|
20
30
|
url = "foobar"
|
21
31
|
payload = {x: true}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Loquor
|
4
|
+
class HttpAction::PutTest < HttpAction::Test
|
5
|
+
def test_put_should_call_new
|
6
|
+
url = "foobar"
|
7
|
+
payload = {y: false}
|
8
|
+
deps = {x: true}
|
9
|
+
HttpAction::Put.expects(:new).with(url, payload, deps).returns(mock(put: nil))
|
10
|
+
HttpAction::Put.put(url, payload, deps)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_put_should_call_put
|
14
|
+
HttpAction::Put.any_instance.expects(:put)
|
15
|
+
HttpAction::Put.put("foobar", {}, {})
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_put_parses_request
|
19
|
+
output = {'foo' => 'bar'}
|
20
|
+
json = output.to_json
|
21
|
+
puts = HttpAction::Put.new("", {}, deps)
|
22
|
+
puts.expects(signed_request: mock(execute: json))
|
23
|
+
assert_equal 'bar', puts.put.foo
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_request_is_generated_correctly
|
27
|
+
url = "/foobar"
|
28
|
+
payload = {foo: true, bar: false}
|
29
|
+
full_url = "#{@endpoint}#{url}"
|
30
|
+
|
31
|
+
RestClient::Request.expects(:new).with(
|
32
|
+
url: full_url,
|
33
|
+
accept: :json,
|
34
|
+
payload: payload.to_json,
|
35
|
+
headers: {'Content-type' => 'application/json'},
|
36
|
+
method: :put
|
37
|
+
)
|
38
|
+
HttpAction::Put.new(url, payload, deps).send(:request)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_request_is_signed_correctly
|
42
|
+
puts = HttpAction::Put.new("", {}, deps)
|
43
|
+
request = RestClient::Request.new(url: "http://localhost:3000", method: :put)
|
44
|
+
puts.expects(request: request)
|
45
|
+
ApiAuth.expects(:sign!).with(request, @access_id, @secret_key)
|
46
|
+
puts.send(:signed_request)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_response_is_a_representation
|
50
|
+
puts = HttpAction::Put.new("", {}, deps)
|
51
|
+
puts.stubs(signed_request: mock(execute: {foo: 'bar'}.to_json))
|
52
|
+
response = puts.put
|
53
|
+
assert response.is_a?(Resource)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
data/test/loquor_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Loquor
|
4
|
+
class LoquorTest < HttpAction::Test
|
5
|
+
def test_get_calls_get
|
6
|
+
url = "foo"
|
7
|
+
Client.any_instance.expects(:get).with(url)
|
8
|
+
Loquor.get(url)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_put_calls_put
|
12
|
+
url = "foo"
|
13
|
+
payload = "bar"
|
14
|
+
Client.any_instance.expects(:put).with(url, payload)
|
15
|
+
Loquor.put(url, payload)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_post_calls_post
|
19
|
+
url = "foo"
|
20
|
+
payload = "bar"
|
21
|
+
Client.any_instance.expects(:post).with(url, payload)
|
22
|
+
Loquor.post(url, payload)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/resource_test.rb
CHANGED
@@ -30,5 +30,12 @@ module Loquor
|
|
30
30
|
Loquor.expects(:get).with("/foobar?email=#{email}").returns([])
|
31
31
|
Foobar.where(email: email).to_a
|
32
32
|
end
|
33
|
+
|
34
|
+
def test_update_should_put_correct_params
|
35
|
+
id = 8
|
36
|
+
payload = {bar: 'foo'}
|
37
|
+
Loquor.expects(:put).with("/foobar/#{id}", payload: payload)
|
38
|
+
Foobar.update(id, payload)
|
39
|
+
end
|
33
40
|
end
|
34
41
|
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: 0.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filum
|
@@ -127,11 +127,13 @@ files:
|
|
127
127
|
- lib/loquor/api_calls/create.rb
|
128
128
|
- lib/loquor/api_calls/index.rb
|
129
129
|
- lib/loquor/api_calls/show.rb
|
130
|
+
- lib/loquor/api_calls/update.rb
|
130
131
|
- lib/loquor/client.rb
|
131
132
|
- lib/loquor/configuration.rb
|
132
133
|
- lib/loquor/http_action.rb
|
133
134
|
- lib/loquor/http_actions/get.rb
|
134
135
|
- lib/loquor/http_actions/post.rb
|
136
|
+
- lib/loquor/http_actions/put.rb
|
135
137
|
- lib/loquor/interactors.rb
|
136
138
|
- lib/loquor/object_hash.rb
|
137
139
|
- lib/loquor/resource.rb
|
@@ -140,11 +142,14 @@ files:
|
|
140
142
|
- loquor.gemspec
|
141
143
|
- test/api_calls/index_test.rb
|
142
144
|
- test/api_calls/show_test.rb
|
145
|
+
- test/api_calls/update_test.rb
|
143
146
|
- test/client_test.rb
|
144
147
|
- test/configuration_test.rb
|
145
148
|
- test/http_action_test.rb
|
146
149
|
- test/http_actions/get_test.rb
|
147
150
|
- test/http_actions/post_test.rb
|
151
|
+
- test/http_actions/put_test.rb
|
152
|
+
- test/loquor_test.rb
|
148
153
|
- test/object_hash_test.rb
|
149
154
|
- test/resource_test.rb
|
150
155
|
- test/test_helper.rb
|
@@ -175,11 +180,14 @@ summary: This library dispatches requests to Meducation
|
|
175
180
|
test_files:
|
176
181
|
- test/api_calls/index_test.rb
|
177
182
|
- test/api_calls/show_test.rb
|
183
|
+
- test/api_calls/update_test.rb
|
178
184
|
- test/client_test.rb
|
179
185
|
- test/configuration_test.rb
|
180
186
|
- test/http_action_test.rb
|
181
187
|
- test/http_actions/get_test.rb
|
182
188
|
- test/http_actions/post_test.rb
|
189
|
+
- test/http_actions/put_test.rb
|
190
|
+
- test/loquor_test.rb
|
183
191
|
- test/object_hash_test.rb
|
184
192
|
- test/resource_test.rb
|
185
193
|
- test/test_helper.rb
|