spyke 6.1.3 → 7.0.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: 7ba8000e29f83abe34550b8453ff430358759237765158641544c2deabe24014
4
- data.tar.gz: 81d4521b0f2a0c22647c5ee4e8fb2d191eab09bf3eda9c114e8aef52ecfdbf80
3
+ metadata.gz: 6d4ddb1fd345f49012040e7f462f63003f1a1ff57ddc7173bb14cb5ca03c5bed
4
+ data.tar.gz: bd1674887dc87a21ca4bad570d7375299add2312a3af7183d466078b6510367f
5
5
  SHA512:
6
- metadata.gz: 834dbdbcf76ae84d9e7b037ac798385a9d911ad2089c7b4b34a40eea82fcdabcf0e8c8aa0fa751a27d38ad8f13f1dbbf833a1b40b0fb741ff9ce631e7ed0982e
7
- data.tar.gz: 70fe2847b7971c9479490d26adfdf05ea9f9f065be171281fce3a0b536b440d506feede266bb05943796aa81568ae32045d4bd9a202609633233564a78eeefa1
6
+ metadata.gz: c83ab8e4a46d6afff3624e7a1b2baccef8b5fe97c875271268c0dd7c51b65a76e85e019cf4ed749b06ef5414566203f6e618e22aaafe12c6494ac39f113abc75
7
+ data.tar.gz: c2f0f2bb8bbce8cb8047be70f0f946305efdff464f6c0e4ad4a46b13cfc2fba19f87ff98c8139102a107e9c64e45035246f5f66d055ed7402772685ca16d348e
data/.circleci/config.yml CHANGED
@@ -18,11 +18,14 @@ jobs:
18
18
  type: string
19
19
  rails_version:
20
20
  type: string
21
+ faraday_version:
22
+ type: string
21
23
  docker:
22
24
  - image: cimg/ruby:<< parameters.ruby_version >>
23
25
  executor: ruby/default
24
26
  environment:
25
27
  RAILS_TEST_VERSION: << parameters.rails_version >>
28
+ FARADAY_TEST_VERSION: << parameters.faraday_version >>
26
29
  EUID: 0 # not sure why this is needed, but sudo npm fails
27
30
  steps:
28
31
  - checkout
@@ -55,24 +58,28 @@ workflows:
55
58
  alias: Rails 4
56
59
  parameters:
57
60
  rails_version: ["~> 4.0"]
58
- ruby_version: ["2.6.6"]
61
+ ruby_version: ["2.6.9"]
62
+ faraday_version: ["< 2.0"]
59
63
  - build:
60
64
  matrix:
61
65
  alias: Rails 5
62
66
  parameters:
63
67
  rails_version: ["~> 5.0"]
64
- ruby_version: ["2.6.6", "2.7.2"]
68
+ ruby_version: ["2.6.9", "2.7.5"]
69
+ faraday_version: ["< 2.0", ">= 2.0"]
65
70
  - build:
66
71
  matrix:
67
72
  alias: Rails 6
68
73
  parameters:
69
74
  rails_version: ["~> 6.0"]
70
- ruby_version: ["2.6.6", "2.7.2", "3.0.0"]
75
+ ruby_version: ["2.6.9", "2.7.5", "3.0.3"]
76
+ faraday_version: ["< 2.0", ">= 2.0"]
71
77
  - build:
72
78
  matrix:
73
79
  alias: Rails 7
74
80
  parameters:
75
81
  rails_version: ["~> 7.0"]
76
- ruby_version: ["2.7.2", "3.0.0"]
82
+ ruby_version: ["2.7.5", "3.0.3", "3.1.1"]
83
+ faraday_version: ["< 2.0", ">= 2.0"]
77
84
  - coverage:
78
85
  requires: ["Rails 4", "Rails 5", "Rails 6", "Rails 7"]
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in spyke.gemspec
4
4
  gemspec
5
+
6
+ if ENV['FARADAY_TEST_VERSION'] == '< 2.0'
7
+ gem 'faraday_middleware'
8
+ end
data/README.md CHANGED
@@ -48,10 +48,10 @@ So, for example for an API that returns JSON like this:
48
48
  ```ruby
49
49
  # config/initializers/spyke.rb
50
50
 
51
- class JSONParser < Faraday::Response::Middleware
52
- def parse(body)
53
- json = MultiJson.load(body, symbolize_keys: true)
54
- {
51
+ class JSONParser < Faraday::Middleware
52
+ def on_complete(env)
53
+ json = MultiJson.load(env.body, symbolize_keys: true)
54
+ env.body = {
55
55
  data: json[:result],
56
56
  metadata: json[:extra],
57
57
  errors: json[:errors]
@@ -60,7 +60,8 @@ class JSONParser < Faraday::Response::Middleware
60
60
  end
61
61
 
62
62
  Spyke::Base.connection = Faraday.new(url: 'http://api.com') do |c|
63
- c.request :json
63
+ c.request :multipart
64
+ c.request :json # if using Faraday 1.x, please add `faraday_middleware` to your dependencies first
64
65
  c.use JSONParser
65
66
  c.adapter Faraday.default_adapter
66
67
  end
@@ -202,7 +203,7 @@ but this can be disabled or customized:
202
203
  ```ruby
203
204
  class Article < Spyke::Base
204
205
  # Default
205
- include_root_in_json true # { article: { title: ...} }
206
+ include_root_in_json true # { article: { title: ...} }
206
207
 
207
208
  # Custom
208
209
  include_root_in_json :post # { post: { title: ...} }
@@ -12,7 +12,7 @@ module Spyke
12
12
  case
13
13
  when value.is_a?(Spyke::Base) then value.attributes.to_params
14
14
  when value.is_a?(Array) then value.map { |v| parse_value(v) }
15
- when value.respond_to?(:content_type) then Faraday::UploadIO.new(value.path, value.content_type)
15
+ when value.respond_to?(:content_type) then Faraday::Multipart::FilePart.new(value.path, value.content_type)
16
16
  else value
17
17
  end
18
18
  end
data/lib/spyke/http.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'faraday'
2
- require 'faraday_middleware'
3
1
  require 'spyke/config'
4
2
  require 'spyke/path'
5
3
  require 'spyke/result'
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '6.1.3'
2
+ VERSION = '7.0.0'
3
3
  end
data/lib/spyke.rb CHANGED
@@ -1,5 +1,21 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
+
4
+ require 'faraday'
5
+ require 'faraday/multipart'
6
+
7
+ if Gem.loaded_specs["faraday"].version < Gem::Version.new("2.0")
8
+ begin
9
+ require 'faraday_middleware'
10
+ rescue LoadError => e
11
+ puts <<~MSG
12
+ Please add `faraday_middleware` to your Gemfile when using Faraday 1.x. Alternatively,
13
+ upgrade to Faraday `~> 2` to avoid this dependency.
14
+ MSG
15
+ raise e
16
+ end
17
+ end
18
+
3
19
  require 'spyke/base'
4
20
  require 'spyke/instrumentation' if defined?(Rails)
5
21
  require 'spyke/version'
data/spyke.gemspec CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'activesupport', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
22
22
  spec.add_dependency 'activemodel', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
23
- spec.add_dependency 'faraday', '>= 0.9.0', '< 2.0'
24
- spec.add_dependency 'faraday_middleware', '>= 0.9.1', '< 2.0'
23
+ spec.add_dependency 'faraday', ENV.fetch('FARADAY_TEST_VERSION', '>= 1.0.0'), '< 3.0'
24
+ spec.add_dependency 'faraday-multipart', '~> 1.0'
25
25
  spec.add_dependency 'addressable', '>= 2.5.2'
26
26
 
27
27
  spec.add_development_dependency 'actionpack', ENV.fetch('RAILS_TEST_VERSION', '>= 4.0.0')
@@ -134,7 +134,7 @@ module Spyke
134
134
  end
135
135
 
136
136
  def test_converting_files_to_faraday_io
137
- Faraday::UploadIO.stubs(:new).with('/photo.jpg', 'image/jpeg').returns('UploadIO')
137
+ Faraday::Multipart::FilePart.stubs(:new).with('/photo.jpg', 'image/jpeg').returns('UploadIO')
138
138
  file = mock
139
139
  file.stubs(:path).returns('/photo.jpg')
140
140
  file.stubs(:content_type).returns('image/jpeg')
@@ -1,20 +1,21 @@
1
1
  require 'multi_json'
2
2
 
3
3
  # Dummy api
4
- class JSONParser < Faraday::Response::Middleware
5
- def parse(body)
6
- json = MultiJson.load(body, symbolize_keys: true)
7
- {
4
+ class JSONParser < Faraday::Middleware
5
+ def on_complete(env)
6
+ json = MultiJson.load(env.body, symbolize_keys: true)
7
+ env.body = {
8
8
  data: json[:result],
9
9
  metadata: json[:metadata],
10
10
  errors: json[:errors]
11
11
  }
12
12
  rescue MultiJson::ParseError => exception
13
- { errors: { base: [ error: exception.message ] } }
13
+ env.body = { errors: { base: [ error: exception.message ] } }
14
14
  end
15
15
  end
16
16
 
17
17
  Spyke::Base.connection = Faraday.new(url: 'http://sushi.com') do |faraday|
18
+ faraday.request :multipart
18
19
  faraday.request :json
19
20
  faraday.use JSONParser
20
21
  faraday.adapter Faraday.default_adapter
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: 6.1.3
4
+ version: 7.0.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: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2022-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,40 +44,34 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.9.0
47
+ version: 1.0.0
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
- version: '2.0'
50
+ version: '3.0'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 0.9.0
57
+ version: 1.0.0
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
- version: '2.0'
60
+ version: '3.0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: faraday_middleware
62
+ name: faraday-multipart
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 0.9.1
68
- - - "<"
65
+ - - "~>"
69
66
  - !ruby/object:Gem::Version
70
- version: '2.0'
67
+ version: '1.0'
71
68
  type: :runtime
72
69
  prerelease: false
73
70
  version_requirements: !ruby/object:Gem::Requirement
74
71
  requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: 0.9.1
78
- - - "<"
72
+ - - "~>"
79
73
  - !ruby/object:Gem::Version
80
- version: '2.0'
74
+ version: '1.0'
81
75
  - !ruby/object:Gem::Dependency
82
76
  name: addressable
83
77
  requirement: !ruby/object:Gem::Requirement