spyke 5.4.3 → 6.1.2
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/.circleci/config.yml +54 -0
- data/README.md +3 -11
- data/bin/console +13 -0
- data/lib/spyke/associations/builder.rb +1 -1
- data/lib/spyke/attribute_assignment.rb +3 -3
- data/lib/spyke/http.rb +19 -11
- data/lib/spyke/version.rb +1 -1
- data/spyke.gemspec +4 -4
- data/test/associations_test.rb +9 -0
- data/test/attributes_test.rb +0 -1
- data/test/path_test.rb +2 -2
- data/test/support/fixtures.rb +5 -2
- data/test/test_helper.rb +0 -1
- metadata +10 -8
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10bea427bfa06776d0a764b34c1259215b730c9f06275ff50feeb29dd99dd9bb
|
4
|
+
data.tar.gz: b8fbfce6f60b4818db3a260fb2b18a76c9a296fdde55e9183c0c12def9e8599f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5da8c94843a8e150d10ac52a135bb6ab273894fefe83ebbda9cba47f7274b6a04da966066c454887ff905be73f626a36642ef02e92737c7a7f88883e5ae38d2
|
7
|
+
data.tar.gz: d315a1efe8885fdbe78739dc53aedfd545095e09db8fddc205f038a06918b815f28b3da30ac5ff7a303cc1bbca2151f70d1a021cbe4ca50e855d960e8ed10777
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Use the latest 2.1 version of CircleCI pipeline process engine.
|
2
|
+
# See: https://circleci.com/docs/2.0/configuration-reference
|
3
|
+
version: 2.1
|
4
|
+
|
5
|
+
# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
|
6
|
+
# See: https://circleci.com/docs/2.0/orb-intro/
|
7
|
+
orbs:
|
8
|
+
ruby: circleci/ruby@0.1.2
|
9
|
+
|
10
|
+
# Define a job to be invoked later in a workflow.
|
11
|
+
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
|
12
|
+
jobs:
|
13
|
+
build:
|
14
|
+
parameters:
|
15
|
+
ruby_version:
|
16
|
+
type: string
|
17
|
+
rails_version:
|
18
|
+
type: string
|
19
|
+
docker:
|
20
|
+
- image: cimg/ruby:<< parameters.ruby_version >>
|
21
|
+
executor: ruby/default
|
22
|
+
environment:
|
23
|
+
RAILS_TEST_VERSION: << parameters.rails_version >>
|
24
|
+
steps:
|
25
|
+
- checkout
|
26
|
+
- run:
|
27
|
+
name: Which ruby?
|
28
|
+
command: ruby -v
|
29
|
+
- run:
|
30
|
+
name: Which bundler?
|
31
|
+
command: bundle -v
|
32
|
+
- ruby/bundle-install
|
33
|
+
- run:
|
34
|
+
name: Run tests
|
35
|
+
command: bundle exec rake
|
36
|
+
|
37
|
+
workflows:
|
38
|
+
tests:
|
39
|
+
jobs:
|
40
|
+
- build:
|
41
|
+
matrix:
|
42
|
+
parameters:
|
43
|
+
rails_version: ["~> 5.0"]
|
44
|
+
ruby_version: ["2.6.6", "2.7.2"]
|
45
|
+
- build:
|
46
|
+
matrix:
|
47
|
+
parameters:
|
48
|
+
rails_version: ["~> 6.0"]
|
49
|
+
ruby_version: ["2.6.6", "2.7.2", "3.0.0"]
|
50
|
+
- build:
|
51
|
+
matrix:
|
52
|
+
parameters:
|
53
|
+
rails_version: ["~> 7.0"]
|
54
|
+
ruby_version: ["2.7.2", "3.0.0"]
|
data/README.md
CHANGED
@@ -7,8 +7,8 @@
|
|
7
7
|
<br /><br />
|
8
8
|
<a href="https://rubygems.org/gems/spyke"><img src="https://badge.fury.io/rb/spyke.svg?style=flat" alt="Gem Version"></a>
|
9
9
|
<a href="https://codeclimate.com/github/balvig/spyke"><img src="https://codeclimate.com/github/balvig/spyke/badges/gpa.svg" /></a>
|
10
|
-
<a href='https://coveralls.io/
|
11
|
-
<a href="https://
|
10
|
+
<a href='https://coveralls.io/github/balvig/spyke'><img src="https://coveralls.io/repos/github/balvig/spyke/badge.svg" /></a>
|
11
|
+
<a href="https://circleci.com/gh/balvig/spyke"><img src="https://circleci.com/gh/balvig/spyke.svg?style=shield" /></a>
|
12
12
|
</p>
|
13
13
|
|
14
14
|
---
|
@@ -131,8 +131,6 @@ Post.find(4) # => GET http://api.com/posts/4
|
|
131
131
|
Custom request methods and the `with` scope methods allow you to
|
132
132
|
perform requests for non-REST actions:
|
133
133
|
|
134
|
-
The `.with` scope:
|
135
|
-
|
136
134
|
```ruby
|
137
135
|
Post.with('posts/recent') # => GET http://api.com/posts/recent
|
138
136
|
Post.with(:recent) # => GET http://api.com/posts/recent
|
@@ -172,7 +170,7 @@ Spyke expects errors to be formatted in the same way as the
|
|
172
170
|
[ActiveModel::Errors details hash](https://cowbell-labs.com/2015-01-22-active-model-errors-details.html), ie:
|
173
171
|
|
174
172
|
```ruby
|
175
|
-
{ title: [{ error: 'blank'}, { error: 'too_short', count: 10 }]}
|
173
|
+
{ title: [{ error: 'blank'}, { error: 'too_short', count: 10 }] }
|
176
174
|
```
|
177
175
|
|
178
176
|
If the API you're using returns errors in a different format you can
|
@@ -246,9 +244,3 @@ Completed 200 OK in 75ms (Views: 64.6ms | Spyke: 40.3ms | ActiveRecord: 0ms)
|
|
246
244
|
|
247
245
|
For more examples of how Spyke can be used, check out [fixtures.rb](https://github.com/balvig/spyke/blob/master/test/support/fixtures.rb) and the
|
248
246
|
[test suite](https://github.com/balvig/spyke/tree/master/test).
|
249
|
-
|
250
|
-
|
251
|
-
## Contributing
|
252
|
-
|
253
|
-
If possible please take a look at the [tests marked "wishlisted"](https://github.com/balvig/spyke/search?l=ruby&q=wishlisted&utf8=%E2%9C%93)!
|
254
|
-
These are features/fixes I'd like to implement but haven't gotten around to doing yet :)
|
data/bin/console
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'spyke'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
# Require support files via `bin/console -t`
|
8
|
+
if ARGV.any? { |o| %w(-t --test).include? o }
|
9
|
+
require_relative '../test/support/fixtures.rb'
|
10
|
+
Spyke::Base.connection.response :logger
|
11
|
+
end
|
12
|
+
|
13
|
+
Pry.start
|
@@ -29,7 +29,7 @@ module Spyke
|
|
29
29
|
candidates << type_name
|
30
30
|
|
31
31
|
candidates.each do |candidate|
|
32
|
-
constant =
|
32
|
+
constant = candidate.safe_constantize
|
33
33
|
return constant if candidate == constant.to_s
|
34
34
|
end
|
35
35
|
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
|
@@ -94,9 +94,9 @@ module Spyke
|
|
94
94
|
|
95
95
|
def method_missing(name, *args, &block)
|
96
96
|
case
|
97
|
-
when association?(name) then association(name).load
|
98
|
-
when attribute?(name) then attribute(name)
|
99
|
-
when predicate?(name) then predicate(name)
|
97
|
+
when association?(name) then association(name, *args).load
|
98
|
+
when attribute?(name) then attribute(name, *args)
|
99
|
+
when predicate?(name) then predicate(name, *args)
|
100
100
|
when setter?(name) then set_attribute(name, args.first)
|
101
101
|
else super
|
102
102
|
end
|
data/lib/spyke/http.rb
CHANGED
@@ -41,20 +41,28 @@ module Spyke
|
|
41
41
|
@uri ||= uri_template || default_uri
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
private
|
45
|
+
|
46
|
+
def send_request(method, path, params)
|
47
|
+
connection.send(method) do |request|
|
48
|
+
if method == :get
|
49
|
+
path, params = merge_query_params(path, params)
|
50
|
+
request.url path, params
|
51
|
+
else
|
52
|
+
request.url path.to_s
|
53
|
+
request.body = params
|
54
|
+
end
|
51
55
|
end
|
56
|
+
rescue Faraday::ConnectionFailed, Faraday::TimeoutError
|
57
|
+
raise ConnectionError
|
52
58
|
end
|
53
|
-
rescue Faraday::ConnectionFailed, Faraday::TimeoutError
|
54
|
-
raise ConnectionError
|
55
|
-
end
|
56
59
|
|
57
|
-
|
60
|
+
def merge_query_params(path, params)
|
61
|
+
parsed_uri = Addressable::URI.parse(path.to_s)
|
62
|
+
path = parsed_uri.path
|
63
|
+
params = params.merge(parsed_uri.query_values || {})
|
64
|
+
[path, params]
|
65
|
+
end
|
58
66
|
|
59
67
|
def scoped_request(method)
|
60
68
|
uri = new.uri
|
data/lib/spyke/version.rb
CHANGED
data/spyke.gemspec
CHANGED
@@ -18,15 +18,15 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency 'activesupport', '>= 4.0.0'
|
22
|
-
spec.add_dependency 'activemodel', '>= 4.0.0'
|
21
|
+
spec.add_dependency 'activesupport', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
|
22
|
+
spec.add_dependency 'activemodel', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
|
23
23
|
spec.add_dependency 'faraday', '>= 0.9.0', '< 2.0'
|
24
24
|
spec.add_dependency 'faraday_middleware', '>= 0.9.1', '< 2.0'
|
25
25
|
spec.add_dependency 'addressable', '>= 2.5.2'
|
26
26
|
|
27
|
-
spec.add_development_dependency 'actionpack', '>= 4.0.0'
|
27
|
+
spec.add_development_dependency 'actionpack', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
|
28
28
|
spec.add_development_dependency 'bundler', '>= 1.6'
|
29
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'coveralls_reborn', '~> 0.23.0'
|
30
30
|
spec.add_development_dependency 'minitest'
|
31
31
|
spec.add_development_dependency 'minitest-line'
|
32
32
|
spec.add_development_dependency 'minitest-reporters'
|
data/test/associations_test.rb
CHANGED
@@ -241,6 +241,15 @@ module Spyke
|
|
241
241
|
assert_requested endpoint
|
242
242
|
end
|
243
243
|
|
244
|
+
|
245
|
+
def test_using_where_with_custom_uri_including_query_params
|
246
|
+
endpoint = stub_request(:get, 'http://sushi.com/featured_ingredients?filter[group_id]=1&filter[status]=published')
|
247
|
+
|
248
|
+
Group.new(id: 1).featured_ingredients.where(filter: { status: 'published' }).to_a
|
249
|
+
|
250
|
+
assert_requested endpoint
|
251
|
+
end
|
252
|
+
|
244
253
|
def test_path_inferred_from_name
|
245
254
|
endpoint = stub_request(:get, 'http://sushi.com/recipes/1/gallery_images')
|
246
255
|
Recipe.new(id: 1).gallery_images.to_a
|
data/test/attributes_test.rb
CHANGED
data/test/path_test.rb
CHANGED
@@ -21,13 +21,13 @@ module Spyke
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_required_variables
|
24
|
-
assert_raises
|
24
|
+
assert_raises InvalidPathError, 'Missing required variables: user_id in /users/:user_id/recipes/(:id)' do
|
25
25
|
Path.new('/users/:user_id/recipes/(:id)', id: 2).to_s
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_mix_of_required_and_unrequired_variables
|
30
|
-
assert_raises
|
30
|
+
assert_raises InvalidPathError, 'Missing required variables: part2, part4' do
|
31
31
|
Path.new('/1/profiles(/:part1)/:part2(/:part3)/:part4.xml').to_s
|
32
32
|
end
|
33
33
|
end
|
data/test/support/fixtures.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
1
3
|
# Dummy api
|
2
4
|
class JSONParser < Faraday::Response::Middleware
|
3
5
|
def parse(body)
|
@@ -79,6 +81,7 @@ end
|
|
79
81
|
|
80
82
|
class Group < Spyke::Base
|
81
83
|
has_many :ingredients, uri: nil
|
84
|
+
has_many :featured_ingredients, uri: 'featured_ingredients?filter[group_id]=:group_id', class_name: "Ingredient"
|
82
85
|
accepts_nested_attributes_for :ingredients
|
83
86
|
|
84
87
|
def self.build_default
|
@@ -119,10 +122,10 @@ end
|
|
119
122
|
class OtherRecipe < OtherApi
|
120
123
|
uri 'recipes/(:id)'
|
121
124
|
|
122
|
-
def self.
|
125
|
+
def self.request(method, path, params)
|
123
126
|
super
|
124
127
|
rescue Spyke::ConnectionError
|
125
|
-
Recipe.
|
128
|
+
Recipe.request(method, path, params)
|
126
129
|
end
|
127
130
|
end
|
128
131
|
|
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:
|
4
|
+
version: 6.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Balvig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -121,19 +121,19 @@ dependencies:
|
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '1.6'
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
|
-
name:
|
124
|
+
name: coveralls_reborn
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
127
|
- - "~>"
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
129
|
+
version: 0.23.0
|
130
130
|
type: :development
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
134
|
- - "~>"
|
135
135
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
136
|
+
version: 0.23.0
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
name: minitest
|
139
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,16 +249,18 @@ dependencies:
|
|
249
249
|
description: Interact with REST services in an ActiveRecord-like manner
|
250
250
|
email:
|
251
251
|
- jens@balvig.com
|
252
|
-
executables:
|
252
|
+
executables:
|
253
|
+
- console
|
253
254
|
extensions: []
|
254
255
|
extra_rdoc_files: []
|
255
256
|
files:
|
257
|
+
- ".circleci/config.yml"
|
256
258
|
- ".gitignore"
|
257
|
-
- ".travis.yml"
|
258
259
|
- Gemfile
|
259
260
|
- LICENSE.txt
|
260
261
|
- README.md
|
261
262
|
- Rakefile
|
263
|
+
- bin/console
|
262
264
|
- lib/spyke.rb
|
263
265
|
- lib/spyke/associations.rb
|
264
266
|
- lib/spyke/associations/association.rb
|
@@ -318,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
320
|
- !ruby/object:Gem::Version
|
319
321
|
version: '0'
|
320
322
|
requirements: []
|
321
|
-
rubygems_version: 3.
|
323
|
+
rubygems_version: 3.2.3
|
322
324
|
signing_key:
|
323
325
|
specification_version: 4
|
324
326
|
summary: Interact with REST services in an ActiveRecord-like manner
|