spyke 5.3.4 → 5.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 +5 -5
- data/.travis.yml +1 -2
- data/README.md +15 -1
- data/lib/spyke/http.rb +12 -12
- data/lib/spyke/version.rb +1 -1
- data/test/custom_request_test.rb +8 -1
- data/test/support/fixtures.rb +9 -1
- data/test/test_helper.rb +1 -1
- metadata +6 -8
- data/circle.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7de3203151c0bbf40af24c4ebb7926f60b497e61cd4a7edd3d5b0dcc12f302e5
|
4
|
+
data.tar.gz: 9cea6becd607f2f4a74258a5984055e619206f0df881c56fb444716e6e91b8af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db5b33e37fe25bc7f2f56215ca904a37c40541804acaa8338c9b63d23ac10e9e7724f65b6abf4ac98501b354fd1d802cd0bff0483b3a2b64673797d299043750
|
7
|
+
data.tar.gz: 34252e5c0e56a6b7a3fc83343ed955d39f6dc46250da3c8e90817df01609adcb9e09105cc9bb6b96bfd4b8c66bf06d3dbcbc20fbf4ccc7cd11ef016800019c5a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Spyke
|
2
2
|
|
3
3
|
<p align="center">
|
4
|
-
<img src="http://upload.wikimedia.org/wikipedia/en/thumb/2/21/Spyke.jpg/392px-Spyke.jpg" width="
|
4
|
+
<img src="http://upload.wikimedia.org/wikipedia/en/thumb/2/21/Spyke.jpg/392px-Spyke.jpg" width="15%" />
|
5
5
|
<br/>
|
6
6
|
Interact with remote <strong>REST services</strong> in an <strong>ActiveRecord-like</strong> manner.
|
7
7
|
<br /><br />
|
@@ -30,6 +30,7 @@ Add this line to your application's Gemfile:
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
gem 'spyke'
|
33
|
+
gem 'multi_json' # or whatever is needed to parse responses
|
33
34
|
```
|
34
35
|
|
35
36
|
Spyke uses Faraday to handle requests and expects it to parse the response body into a hash in the following format:
|
@@ -152,6 +153,19 @@ Post.request(:post, 'posts/3/log', time: '12:00')
|
|
152
153
|
# => POST http://api.com/posts/3/log - { time: '12:00' }
|
153
154
|
```
|
154
155
|
|
156
|
+
### Custom primary keys
|
157
|
+
|
158
|
+
Custom primary keys can be defined with `self.primary_key = :custom_key`:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
class User < Spyke::Base
|
162
|
+
self.primary_key = :user_id
|
163
|
+
|
164
|
+
# When using custom URIs the :id parameter also has to be adjusted
|
165
|
+
uri 'people(/:user_id)'
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
155
169
|
### API-side validations
|
156
170
|
|
157
171
|
Spyke expects errors to be formatted in the same way as the
|
data/lib/spyke/http.rb
CHANGED
@@ -41,20 +41,20 @@ module Spyke
|
|
41
41
|
@uri ||= uri_template || default_uri
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
request.url path.to_s
|
52
|
-
request.body = params
|
53
|
-
end
|
44
|
+
def send_request(method, path, params)
|
45
|
+
connection.send(method) do |request|
|
46
|
+
if method == :get
|
47
|
+
request.url path.to_s, params
|
48
|
+
else
|
49
|
+
request.url path.to_s
|
50
|
+
request.body = params
|
54
51
|
end
|
55
|
-
rescue Faraday::ConnectionFailed, Faraday::TimeoutError
|
56
|
-
raise ConnectionError
|
57
52
|
end
|
53
|
+
rescue Faraday::ConnectionFailed, Faraday::TimeoutError
|
54
|
+
raise ConnectionError
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
58
|
|
59
59
|
def scoped_request(method)
|
60
60
|
uri = new.uri
|
data/lib/spyke/version.rb
CHANGED
data/test/custom_request_test.rb
CHANGED
@@ -63,9 +63,16 @@ module Spyke
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_multiple_apis
|
66
|
-
endpoint = stub_request(:get, 'http://sashimi.com/
|
66
|
+
endpoint = stub_request(:get, 'http://sashimi.com/recipes')
|
67
67
|
OtherRecipe.all.to_a
|
68
68
|
assert_requested endpoint
|
69
69
|
end
|
70
|
+
|
71
|
+
def test_multiple_apis_with_custom_fallback
|
72
|
+
fallback_endpoint = stub_request(:get, 'http://sushi.com/recipes')
|
73
|
+
primary_endpoint = stub_request(:get, 'http://sashimi.com/recipes').to_timeout
|
74
|
+
OtherRecipe.all.to_a
|
75
|
+
assert_requested fallback_endpoint
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
data/test/support/fixtures.rb
CHANGED
@@ -116,7 +116,15 @@ class OtherApi < Spyke::Base
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
class OtherRecipe < OtherApi
|
119
|
+
class OtherRecipe < OtherApi
|
120
|
+
uri 'recipes/(:id)'
|
121
|
+
|
122
|
+
def self.send_request(method, path, params)
|
123
|
+
super
|
124
|
+
rescue Spyke::ConnectionError
|
125
|
+
Recipe.send_request(method, path, params)
|
126
|
+
end
|
127
|
+
end
|
120
128
|
|
121
129
|
class Search
|
122
130
|
def initialize(query)
|
data/test/test_helper.rb
CHANGED
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: 5.
|
4
|
+
version: 5.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -245,7 +245,6 @@ files:
|
|
245
245
|
- LICENSE.txt
|
246
246
|
- README.md
|
247
247
|
- Rakefile
|
248
|
-
- circle.yml
|
249
248
|
- lib/spyke.rb
|
250
249
|
- lib/spyke/associations.rb
|
251
250
|
- lib/spyke/associations/association.rb
|
@@ -290,7 +289,7 @@ homepage: https://github.com/balvig/spyke
|
|
290
289
|
licenses:
|
291
290
|
- MIT
|
292
291
|
metadata: {}
|
293
|
-
post_install_message:
|
292
|
+
post_install_message:
|
294
293
|
rdoc_options: []
|
295
294
|
require_paths:
|
296
295
|
- lib
|
@@ -305,9 +304,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
305
304
|
- !ruby/object:Gem::Version
|
306
305
|
version: '0'
|
307
306
|
requirements: []
|
308
|
-
|
309
|
-
|
310
|
-
signing_key:
|
307
|
+
rubygems_version: 3.0.3
|
308
|
+
signing_key:
|
311
309
|
specification_version: 4
|
312
310
|
summary: Interact with REST services in an ActiveRecord-like manner
|
313
311
|
test_files:
|
data/circle.yml
DELETED