spyke 5.4.1 → 6.1.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
2
  SHA256:
3
- metadata.gz: 46c56a1975e770acc9b1e9d40abdfbfd7d59b15705da333d293d0ecb18678628
4
- data.tar.gz: bbc4a65e7cc6293ce9e93410eae69dd4003ede73364207c17bff79c1736770a2
3
+ metadata.gz: '0503658448e2cd567bfa85ec96f1a339dbb7c59690bff9b3cda1c2a0d727bab7'
4
+ data.tar.gz: 4ecd65b52680c1dce5f30eddad68fa544a781ea5f30984c55804aa839d93fe91
5
5
  SHA512:
6
- metadata.gz: 6e741d1302b7a404d2f052329814b74af2aab61f17a5edff94b06f1bb5fadf78a8bbb43c93dbd2ed4a48064721dad8e57a28d53fde35b5d14f7a44f19fe01a31
7
- data.tar.gz: 9a7cbdf9fd0b504c9772dd5388ff949b1ab5abe666277e11efc8e347e3aae22e5337cba0b506388f90f9cc2b68f5ddb97bf4dd8b08b50694a43e1f2d99c32a9a
6
+ metadata.gz: b143845d229f8b712b2d6f1d5d14ba36939a2bab6b90e835f35e5a499a1b06ee93087ecce81f46b9ebc9e7a4c92b9988d53c1ff2798f378e4e76fd9b12ceeb88
7
+ data.tar.gz: 22b3baeeac2cbaa4c0667c805eb4a33f011e6d0c333777b89766ba857e19f322374e215412d42b92c993b6f64ca80b2fb9cd89d14efaa42279d50ce3bdd2d68b
data/.travis.yml CHANGED
@@ -2,4 +2,6 @@ notifications:
2
2
  email: false
3
3
  rvm:
4
4
  - 2.6.6
5
+ - 2.7.2
6
+ - 3.0.0
5
7
  sudo: false
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
- 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
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
- private
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
@@ -105,7 +113,12 @@ module Spyke
105
113
  errors_hash.each do |field, field_errors|
106
114
  field_errors.each do |error_attributes|
107
115
  error = NormalizedValidationError.new(error_attributes)
108
- errors.add(field.to_sym, error.message, error.options)
116
+
117
+ if errors.method(:add).arity == -2
118
+ errors.add(field.to_sym, error.message, **error.options)
119
+ else
120
+ errors.add(field.to_sym, error.message, error.options)
121
+ end
109
122
  end
110
123
  end
111
124
  end
@@ -5,7 +5,7 @@ module Spyke
5
5
  include Enumerable
6
6
 
7
7
  attr_reader :klass
8
- attr_accessor :params
8
+ attr_reader :params
9
9
  delegate :to_ary, :[], :any?, :empty?, :last, :size, :metadata, to: :find_some
10
10
 
11
11
  def initialize(klass, options = {})
@@ -21,6 +21,10 @@ module Spyke
21
21
  relation
22
22
  end
23
23
 
24
+ def params=(params)
25
+ @params = params.symbolize_keys
26
+ end
27
+
24
28
  def with(uri)
25
29
  if uri.is_a? Symbol
26
30
  @options[:uri] = File.join @options[:uri], uri.to_s
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '5.4.1'
2
+ VERSION = '6.1.0'
3
3
  end
data/spyke.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'addressable', '>= 2.5.2'
26
26
 
27
27
  spec.add_development_dependency 'actionpack', '>= 4.0.0'
28
- spec.add_development_dependency 'bundler', '~> 1.6'
28
+ spec.add_development_dependency 'bundler', '>= 1.6'
29
29
  spec.add_development_dependency 'coveralls', '~> 0.7'
30
30
  spec.add_development_dependency 'minitest'
31
31
  spec.add_development_dependency 'minitest-line'
@@ -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/path_test.rb CHANGED
@@ -21,13 +21,13 @@ module Spyke
21
21
  end
22
22
 
23
23
  def test_required_variables
24
- assert_raises Spyke::InvalidPathError, 'Missing required variables: user_id in /users/:user_id/recipes/(:id)' do
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 Spyke::InvalidPathError, 'Missing required variables: part2, part4' do
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/scopes_test.rb CHANGED
@@ -61,6 +61,14 @@ module Spyke
61
61
  assert_requested endpoint
62
62
  end
63
63
 
64
+ def test_where_with_stringified_keys
65
+ endpoint = stub_request(:get, 'http://sushi.com/recipes/1/image')
66
+
67
+ RecipeImage.where("recipe_id" => 1).to_a
68
+
69
+ assert_requested endpoint
70
+ end
71
+
64
72
  def test_chainable_class_method
65
73
  endpoint = stub_request(:get, 'http://sushi.com/recipes?status=published&per_page=3')
66
74
 
@@ -79,6 +79,7 @@ end
79
79
 
80
80
  class Group < Spyke::Base
81
81
  has_many :ingredients, uri: nil
82
+ has_many :featured_ingredients, uri: 'featured_ingredients?filter[group_id]=:group_id', class_name: "Ingredient"
82
83
  accepts_nested_attributes_for :ingredients
83
84
 
84
85
  def self.build_default
@@ -119,10 +120,10 @@ end
119
120
  class OtherRecipe < OtherApi
120
121
  uri 'recipes/(:id)'
121
122
 
122
- def self.send_request(method, path, params)
123
+ def self.request(method, path, params)
123
124
  super
124
125
  rescue Spyke::ConnectionError
125
- Recipe.send_request(method, path, params)
126
+ Recipe.request(method, path, params)
126
127
  end
127
128
  end
128
129
 
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.1
4
+ version: 6.1.0
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-02-25 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -110,14 +110,14 @@ dependencies:
110
110
  name: bundler
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '1.6'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '1.6'
123
123
  - !ruby/object:Gem::Dependency