spyke 1.8.3 → 1.8.4
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/spyke/http.rb +37 -27
- data/lib/spyke/relation.rb +1 -1
- data/lib/spyke/version.rb +1 -1
- data/test/custom_request_test.rb +1 -1
- data/test/orm_test.rb +8 -2
- data/test/test_helper.rb +7 -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: 2321a4ffd56617ec8f489fbe3ddb96061c4ece5f
|
4
|
+
data.tar.gz: f7f97d6d1b1356db71a0f384e8c5257ffe81f9ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d7f5283de00b250dae9734458d8ef06ceb20705b99f809ec321a5d5701520342ec78114b8d1c9902c4bae75b482050c750ac22fef551c6850fee055083bea3a
|
7
|
+
data.tar.gz: 61c0cfe2bd04c618512da051ac1c4c35de569b5ba6dc5405580aea0615c2d04377967c4e3c5bf2dd6a0998c1c34284a012eed504169e8399fcb70cb6e307a098
|
data/lib/spyke/http.rb
CHANGED
@@ -11,7 +11,7 @@ module Spyke
|
|
11
11
|
module ClassMethods
|
12
12
|
METHODS.each do |method|
|
13
13
|
define_method(method) do |path, params = {}|
|
14
|
-
|
14
|
+
new_instance_or_collection_from_result send("#{method}_raw", path, params)
|
15
15
|
end
|
16
16
|
|
17
17
|
define_method("#{method}_raw") do |path, params = {}|
|
@@ -19,30 +19,7 @@ module Spyke
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
ActiveSupport::Notifications.instrument('request.spyke', method: method) do |payload|
|
24
|
-
response = connection.send(method) do |request|
|
25
|
-
if method == :get
|
26
|
-
request.url path.to_s, params
|
27
|
-
else
|
28
|
-
request.url path.to_s
|
29
|
-
request.body = params
|
30
|
-
end
|
31
|
-
end
|
32
|
-
payload[:url], payload[:status] = response.env.url, response.status
|
33
|
-
Result.new_from_response(response)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def new_or_collection_from_result(result)
|
38
|
-
if result.data.is_a?(Array)
|
39
|
-
new_collection_from_result(result)
|
40
|
-
else
|
41
|
-
new_from_result(result)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def new_from_result(result)
|
22
|
+
def new_instance_from_result(result)
|
46
23
|
new result.data if result.data
|
47
24
|
end
|
48
25
|
|
@@ -50,13 +27,46 @@ module Spyke
|
|
50
27
|
Collection.new Array(result.data).map { |record| new(record) }, result.metadata
|
51
28
|
end
|
52
29
|
|
53
|
-
def uri(uri_template =
|
54
|
-
@uri ||= uri_template
|
30
|
+
def uri(uri_template = nil)
|
31
|
+
@uri ||= uri_template || superclass_uri || default_uri
|
55
32
|
end
|
56
33
|
|
57
34
|
def connection
|
58
35
|
Config.connection
|
59
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def request(method, path, params = {})
|
41
|
+
ActiveSupport::Notifications.instrument('request.spyke', method: method) do |payload|
|
42
|
+
response = connection.send(method) do |request|
|
43
|
+
if method == :get
|
44
|
+
request.url path.to_s, params
|
45
|
+
else
|
46
|
+
request.url path.to_s
|
47
|
+
request.body = params
|
48
|
+
end
|
49
|
+
end
|
50
|
+
payload[:url], payload[:status] = response.env.url, response.status
|
51
|
+
Result.new_from_response(response)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def new_instance_or_collection_from_result(result)
|
56
|
+
if result.data.is_a?(Array)
|
57
|
+
new_collection_from_result(result)
|
58
|
+
else
|
59
|
+
new_instance_from_result(result)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def superclass_uri
|
64
|
+
superclass.uri.dup.freeze if superclass != Base
|
65
|
+
end
|
66
|
+
|
67
|
+
def default_uri
|
68
|
+
"/#{model_name.plural}/(:id)"
|
69
|
+
end
|
60
70
|
end
|
61
71
|
|
62
72
|
METHODS.each do |method|
|
data/lib/spyke/relation.rb
CHANGED
data/lib/spyke/version.rb
CHANGED
data/test/custom_request_test.rb
CHANGED
@@ -19,7 +19,7 @@ module Spyke
|
|
19
19
|
def test_get_request_with_appended_scope
|
20
20
|
skip 'wishlisted'
|
21
21
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/recent?status=published')
|
22
|
-
Recipe.get('/recipes/recent').published.
|
22
|
+
Recipe.get('/recipes/recent').published.to_a
|
23
23
|
assert_requested endpoint
|
24
24
|
end
|
25
25
|
|
data/test/orm_test.rb
CHANGED
@@ -113,12 +113,18 @@ module Spyke
|
|
113
113
|
assert_requested endpoint
|
114
114
|
end
|
115
115
|
|
116
|
-
def
|
117
|
-
endpoint = stub_request(:put, 'http://sushi.com/
|
116
|
+
def test_inheritance_passes_on_custom_method_and_uri
|
117
|
+
endpoint = stub_request(:put, 'http://sushi.com/images')
|
118
118
|
StepImage.create
|
119
119
|
assert_requested endpoint
|
120
120
|
end
|
121
121
|
|
122
|
+
def test_inheritance_not_overwriting_custom_uri
|
123
|
+
endpoint = stub_request(:put, 'http://sushi.com/recipes/1/image')
|
124
|
+
RecipeImage.where(recipe_id: 1).create
|
125
|
+
assert_requested endpoint
|
126
|
+
end
|
127
|
+
|
122
128
|
def test_to_params_without_root
|
123
129
|
assert_equal({ 'url' => 'bob.jpg' }, RecipeImage.new(url: 'bob.jpg').to_params)
|
124
130
|
end
|
data/test/test_helper.rb
CHANGED
@@ -16,3 +16,10 @@ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
|
|
16
16
|
|
17
17
|
# Pretty colors
|
18
18
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
19
|
+
|
20
|
+
# Don't raise but report uncaught net connections
|
21
|
+
WebMock.allow_net_connect!
|
22
|
+
WebMock.stub_request(:any, /.*/).to_return do |request|
|
23
|
+
puts "\e[35mUNSTUBBED REQUEST:\e[0m #{request.method.upcase} #{request.uri}"
|
24
|
+
{ body: nil }
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spyke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|