spyke 5.3.4 → 5.4.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
- SHA1:
3
- metadata.gz: bc432f53eb0ef9df9998304c1eeca2bb19f9058f
4
- data.tar.gz: d37e39c3ee6e644b4ca9fcad543ded7d22aa8882
2
+ SHA256:
3
+ metadata.gz: 7de3203151c0bbf40af24c4ebb7926f60b497e61cd4a7edd3d5b0dcc12f302e5
4
+ data.tar.gz: 9cea6becd607f2f4a74258a5984055e619206f0df881c56fb444716e6e91b8af
5
5
  SHA512:
6
- metadata.gz: 46f3daba4c88446b413c4faffb60680788070343448eb12fac5aa0c788f1c08c1b975c43f7538c627baf46759f88a3b7599daea1ff15858979a97a7af76ebc43
7
- data.tar.gz: 13ae1021edb3d34e411768f69c0424834df1929f2b09c2ad02bec1f100817c141be43e79c85dc1c71bde26ce5667df78105c16c104d03516ff2bfffd787af358
6
+ metadata.gz: db5b33e37fe25bc7f2f56215ca904a37c40541804acaa8338c9b63d23ac10e9e7724f65b6abf4ac98501b354fd1d802cd0bff0483b3a2b64673797d299043750
7
+ data.tar.gz: 34252e5c0e56a6b7a3fc83343ed955d39f6dc46250da3c8e90817df01609adcb9e09105cc9bb6b96bfd4b8c66bf06d3dbcbc20fbf4ccc7cd11ef016800019c5a
@@ -1,6 +1,5 @@
1
1
  notifications:
2
2
  email: false
3
3
  rvm:
4
- - 2.3.1
5
- - 2.5.1
4
+ - 2.6.6
6
5
  sudo: false
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="20%" />
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
@@ -41,20 +41,20 @@ module Spyke
41
41
  @uri ||= uri_template || default_uri
42
42
  end
43
43
 
44
- private
45
-
46
- def send_request(method, path, params)
47
- connection.send(method) do |request|
48
- if method == :get
49
- request.url path.to_s, params
50
- else
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
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '5.3.4'
2
+ VERSION = '5.4.0'
3
3
  end
@@ -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/other_recipes')
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
@@ -116,7 +116,15 @@ class OtherApi < Spyke::Base
116
116
  end
117
117
  end
118
118
 
119
- class OtherRecipe < OtherApi; end
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)
@@ -9,7 +9,7 @@ end
9
9
  require 'spyke'
10
10
  require 'minitest/autorun'
11
11
  require 'minitest/reporters'
12
- require 'mocha/mini_test'
12
+ require 'mocha/minitest'
13
13
  require 'multi_json'
14
14
  require 'pry'
15
15
 
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.3.4
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: 2019-05-31 00:00:00.000000000 Z
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
- rubyforge_project:
309
- rubygems_version: 2.6.13
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
@@ -1,3 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.2.2