spyke 6.1.3 → 7.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: 7ba8000e29f83abe34550b8453ff430358759237765158641544c2deabe24014
4
- data.tar.gz: 81d4521b0f2a0c22647c5ee4e8fb2d191eab09bf3eda9c114e8aef52ecfdbf80
3
+ metadata.gz: ca624f63700e74017c15893ad2f23920542f759237f83f316535cfd81b14e216
4
+ data.tar.gz: 35ca71cf3a87125da7e90072c10a3dfb5c82a7929edf67c9c94c896bca7b655a
5
5
  SHA512:
6
- metadata.gz: 834dbdbcf76ae84d9e7b037ac798385a9d911ad2089c7b4b34a40eea82fcdabcf0e8c8aa0fa751a27d38ad8f13f1dbbf833a1b40b0fb741ff9ce631e7ed0982e
7
- data.tar.gz: 70fe2847b7971c9479490d26adfdf05ea9f9f065be171281fce3a0b536b440d506feede266bb05943796aa81568ae32045d4bd9a202609633233564a78eeefa1
6
+ metadata.gz: b0c2253eb6830f67713298257187d1764b1a786fac279a8c03df1802d38416fb1119815bcf1fe37edc8e3f701d1266e8ffa591ec361275c93d8124c5486be0ef
7
+ data.tar.gz: 56352820b1263594eb1d77394e0b90766a77890b706e77e46454fe4bae21f94b05c1cdac9016bdec3eb10ba0bf3375a3efd6a27e7858957c3448471979582f48
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", "3.2.0"]
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
@@ -1,5 +1,6 @@
1
1
  <div align="center">
2
- <img src="spyke.svg" width="250" alt="Spyke" />
2
+ <img src="spyke.svg#gh-light-mode-only" width="250" alt="Spyke" />
3
+ <img src="spyke-dark.svg#gh-dark-mode-only" width="250" alt="Spyke" />
3
4
  <br/>
4
5
  Interact with remote <strong>REST services</strong> in an <strong>ActiveRecord-like</strong> manner.
5
6
  <br /><br />
@@ -48,10 +49,10 @@ So, for example for an API that returns JSON like this:
48
49
  ```ruby
49
50
  # config/initializers/spyke.rb
50
51
 
51
- class JSONParser < Faraday::Response::Middleware
52
- def parse(body)
53
- json = MultiJson.load(body, symbolize_keys: true)
54
- {
52
+ class JSONParser < Faraday::Middleware
53
+ def on_complete(env)
54
+ json = MultiJson.load(env.body, symbolize_keys: true)
55
+ env.body = {
55
56
  data: json[:result],
56
57
  metadata: json[:extra],
57
58
  errors: json[:errors]
@@ -60,7 +61,8 @@ class JSONParser < Faraday::Response::Middleware
60
61
  end
61
62
 
62
63
  Spyke::Base.connection = Faraday.new(url: 'http://api.com') do |c|
63
- c.request :json
64
+ c.request :multipart
65
+ c.request :json # if using Faraday 1.x, please add `faraday_middleware` to your dependencies first
64
66
  c.use JSONParser
65
67
  c.adapter Faraday.default_adapter
66
68
  end
@@ -202,7 +204,7 @@ but this can be disabled or customized:
202
204
  ```ruby
203
205
  class Article < Spyke::Base
204
206
  # Default
205
- include_root_in_json true # { article: { title: ...} }
207
+ include_root_in_json true # { article: { title: ...} }
206
208
 
207
209
  # Custom
208
210
  include_root_in_json :post # { post: { title: ...} }
@@ -240,5 +242,5 @@ Completed 200 OK in 75ms (Views: 64.6ms | Spyke: 40.3ms | ActiveRecord: 0ms)
240
242
 
241
243
  ### Other examples
242
244
 
243
- 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
244
- [test suite](https://github.com/balvig/spyke/tree/master/test).
245
+ For more examples of how Spyke can be used, check out [fixtures.rb](https://github.com/balvig/spyke/blob/main/test/support/fixtures.rb) and the
246
+ [test suite](https://github.com/balvig/spyke/tree/main/test).
@@ -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/orm.rb CHANGED
@@ -25,9 +25,14 @@ module Spyke
25
25
  callback_methods[callback]
26
26
  end
27
27
 
28
- def find(id)
29
- raise ResourceNotFound if id.blank?
30
- where(primary_key => id).find_one || raise(ResourceNotFound)
28
+ def find(id = nil, &block)
29
+ if block_given?
30
+ all.find_some.find(&block)
31
+ else
32
+ raise ResourceNotFound if id.blank?
33
+
34
+ where(primary_key => id).find_one || raise(ResourceNotFound)
35
+ end
31
36
  end
32
37
 
33
38
  def fetch
@@ -41,8 +41,8 @@ module Spyke
41
41
  end
42
42
 
43
43
  # Overrides Enumerable find
44
- def find(id)
45
- scoping { klass.find(id) }
44
+ def find(id = nil, &block)
45
+ scoping { klass.find(id, &block) }
46
46
  end
47
47
 
48
48
  def find_one
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '6.1.3'
2
+ VERSION = '7.1.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-dark.svg ADDED
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="180" height="70" viewBox="0 0 180 70" xml:space="preserve">
4
+ <desc>Created with Fabric.js 4.6.0</desc>
5
+ <defs>
6
+ </defs>
7
+ <g transform="matrix(0.83 0 0 0.8 31.5 36)" id="6X9shhn5tjKNE9PTybgYf" >
8
+ <path style="stroke: rgb(252,0,51); stroke-width: 3; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-opacity: 0; fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(0, 0)" d="M -19.8939 12.44496 L 19.8939 -12.44496 L 19.8939 12.44496" stroke-linecap="round" />
9
+ </g>
10
+ <g transform="matrix(1 0 0 1 48 26)" id="qfktuO63U17zxOoFBmSIk" >
11
+ <path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
12
+ </g>
13
+ <g transform="matrix(1 0 0 1 48 45)" id="CoP4qh0-57aRlWWd5gWpq" >
14
+ <path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
15
+ </g>
16
+ <g transform="matrix(1 0 0 1 16 45)" id="0AYtWnywiPmVyWgmd3Nax" >
17
+ <path style="stroke: rgb(23,172,60); stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(252,0,51); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-4, -4)" d="M 4 0 C 6.208 0 8 1.792 8 4 C 8 6.208 6.208 8 4 8 C 1.7919999999999998 8 0 6.208 0 4 C 0 1.7919999999999998 1.792 0 4 0 z" stroke-linecap="round" />
18
+ </g>
19
+ <g transform="matrix(1.01 0 0 1.02 111 35.5)" id="0CUp8y4TleogKJWzIB5ti" >
20
+ <path style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(255,255,255); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" transform=" translate(-115.71, -44.78)" d="M 72.39608287 59.952 L 72.39608287 59.952 Q 69.77208287 59.952 67.88608287 59.1525 Q 66.00008287 58.353 64.99558287 57.3075 Q 63.99108287 56.262 63.99108287 55.524 L 63.99108287 55.524 Q 63.99108287 55.196 64.17558287 54.827 Q 64.36008287 54.458 64.64708287 54.2325 Q 64.93408287 54.007 65.22108287 54.007 L 65.22108287 54.007 Q 65.63108287 54.007 66.06158287 54.5195 Q 66.49208287 55.032 67.20958287 55.7085 Q 67.92708287 56.385 69.11608287 56.8975 Q 70.30508287 57.41 72.23208287 57.41 L 72.23208287 57.41 Q 74.15908287 57.41 75.53258287 56.7745 Q 76.90608287 56.139 77.62358287 54.8885 Q 78.34108287 53.638 78.34108287 51.752 L 78.34108287 51.752 Q 78.34108287 49.784 77.60308287 48.5745 Q 76.86508287 47.365 75.65558287 46.6065 Q 74.44608287 45.848 73.01108287 45.2945 Q 71.57608287 44.741 70.12058287 44.1875 Q 68.66508287 43.634 67.45558287 42.7935 Q 66.24608287 41.953 65.48758287 40.5795 Q 64.72908287 39.206 64.72908287 37.074 L 64.72908287 37.074 Q 64.72908287 34.819 65.54908287 33.384 Q 66.36908287 31.949 67.66058287 31.129 Q 68.95208287 30.309 70.46908287 29.9605 Q 71.98608287 29.612 73.42108287 29.612 L 73.42108287 29.612 Q 74.56908287 29.612 75.77858287 29.7965 Q 76.98808287 29.981 78.01308287 30.309 Q 79.03808287 30.637 79.67358287 31.088 Q 80.30908287 31.539 80.30908287 32.113 L 80.30908287 32.113 Q 80.30908287 32.4 80.16558287 32.7485 Q 80.02208287 33.097 79.77608287 33.3635 Q 79.53008287 33.63 79.12008287 33.63 L 79.12008287 33.63 Q 78.75108287 33.63 78.09508287 33.2405 Q 77.43908287 32.851 76.31158287 32.4615 Q 75.18408287 32.072 73.38008287 32.072 L 73.38008287 32.072 Q 71.90408287 32.072 70.53058287 32.5025 Q 69.15708287 32.933 68.29608287 33.958 Q 67.43508287 34.983 67.43508287 36.828 L 67.43508287 36.828 Q 67.43508287 38.468 68.19358287 39.4725 Q 68.95208287 40.477 70.16158287 41.092 Q 71.37108287 41.707 72.80608287 42.2195 Q 74.24108287 42.732 75.69658287 43.3675 Q 77.15208287 44.003 78.36158287 44.9665 Q 79.57108287 45.93 80.30908287 47.488 Q 81.04708287 49.046 81.04708287 51.506 L 81.04708287 51.506 Q 81.04708287 54.417 79.94008287 56.2825 Q 78.83308287 58.148 76.88558287 59.05 Q 74.93808287 59.952 72.39608287 59.952 Z M 87.23808287 59.665 L 87.23808287 59.665 Q 86.70508287 59.665 86.29508287 59.3985 Q 85.88508287 59.132 85.88508287 58.599 L 85.88508287 58.599 L 85.88508287 30.678 Q 85.88508287 30.268 86.19258287 30.0015 Q 86.50008287 29.735 87.03308287 29.694 L 87.03308287 29.694 L 94.57708287 29.694 Q 96.95508287 29.694 98.88208287 30.555 Q 100.80908287 31.416 101.91608287 33.3225 Q 103.02308287 35.229 103.02308287 38.386 L 103.02308287 38.386 L 103.02308287 38.796 Q 103.02308287 41.994 101.89558287 43.9005 Q 100.76808287 45.807 98.82058287 46.668 Q 96.87308287 47.529 94.49508287 47.529 L 94.49508287 47.529 L 88.59108287 47.529 L 88.59108287 58.599 Q 88.59108287 59.132 88.16058287 59.3985 Q 87.73008287 59.665 87.23808287 59.665 Z M 88.59108287 32.195 L 88.59108287 45.192 L 94.49508287 45.192 Q 97.24208287 45.192 98.77958287 43.6545 Q 100.31708287 42.117 100.31708287 38.919 L 100.31708287 38.919 L 100.31708287 38.427 Q 100.31708287 35.229 98.77958287 33.712 Q 97.24208287 32.195 94.49508287 32.195 L 94.49508287 32.195 L 88.59108287 32.195 Z M 115.15908287 59.665 L 115.15908287 59.665 Q 114.66708287 59.665 114.23658287 59.3985 Q 113.80608287 59.132 113.80608287 58.599 L 113.80608287 58.599 L 113.80608287 48.185 Q 113.80608287 47.98 113.76508287 47.857 L 113.76508287 47.857 L 105.27808287 31.58 Q 105.15508287 31.334 105.11408287 31.1495 Q 105.07308287 30.965 105.07308287 30.842 L 105.07308287 30.842 Q 105.07308287 30.473 105.29858287 30.227 Q 105.52408287 29.981 105.87258287 29.8375 Q 106.22108287 29.694 106.54908287 29.694 L 106.54908287 29.694 Q 106.87708287 29.694 107.14358287 29.899 Q 107.41008287 30.104 107.61508287 30.514 L 107.61508287 30.514 L 115.15908287 45.479 L 122.74408287 30.514 Q 122.99008287 30.104 123.25658287 29.899 Q 123.52308287 29.694 123.81008287 29.694 L 123.81008287 29.694 Q 124.17908287 29.694 124.50708287 29.8375 Q 124.83508287 29.981 125.06058287 30.227 Q 125.28608287 30.473 125.28608287 30.842 L 125.28608287 30.842 Q 125.28608287 30.965 125.24508287 31.1495 Q 125.20408287 31.334 125.12208287 31.58 L 125.12208287 31.58 L 116.59408287 47.857 Q 116.51208287 47.98 116.51208287 48.185 L 116.51208287 48.185 L 116.51208287 58.599 Q 116.51208287 59.132 116.10208287 59.3985 Q 115.69208287 59.665 115.15908287 59.665 Z M 130.49308287 59.665 L 130.49308287 59.665 Q 129.96008287 59.665 129.55008287 59.3985 Q 129.14008287 59.132 129.14008287 58.599 L 129.14008287 58.599 L 129.14008287 30.678 Q 129.14008287 30.145 129.55008287 29.9195 Q 129.96008287 29.694 130.49308287 29.694 L 130.49308287 29.694 Q 130.98508287 29.694 131.41558287 29.9195 Q 131.84608287 30.145 131.84608287 30.678 L 131.84608287 30.678 L 131.84608287 45.192 L 143.69508287 30.104 Q 143.98208287 29.694 144.55608287 29.694 L 144.55608287 29.694 Q 144.88408287 29.694 145.23258287 29.899 Q 145.58108287 30.104 145.80658287 30.4115 Q 146.03208287 30.719 146.03208287 31.088 L 146.03208287 31.088 Q 146.03208287 31.211 145.99108287 31.3955 Q 145.95008287 31.58 145.82708287 31.703 L 145.82708287 31.703 L 137.01208287 42.65 L 147.09808287 57.82 Q 147.26208287 58.066 147.26208287 58.353 L 147.26208287 58.353 Q 147.26208287 58.722 147.03658287 59.0295 Q 146.81108287 59.337 146.46258287 59.5215 Q 146.11408287 59.706 145.70408287 59.706 L 145.70408287 59.706 Q 145.41708287 59.706 145.15058287 59.5625 Q 144.88408287 59.419 144.67908287 59.132 L 144.67908287 59.132 L 135.20808287 44.905 L 131.84608287 49.169 L 131.84608287 58.599 Q 131.84608287 59.132 131.41558287 59.3985 Q 130.98508287 59.665 130.49308287 59.665 Z M 166.40908287 59.665 L 151.81308287 59.665 Q 151.36208287 59.665 150.97258287 59.3985 Q 150.58308287 59.132 150.58308287 58.599 L 150.58308287 58.599 L 150.58308287 30.719 Q 150.58308287 30.227 150.97258287 29.9605 Q 151.36208287 29.694 151.81308287 29.694 L 151.81308287 29.694 L 166.40908287 29.694 Q 166.94208287 29.694 167.18808287 30.0835 Q 167.43408287 30.473 167.43408287 30.883 L 167.43408287 30.883 Q 167.43408287 31.416 167.16758287 31.8055 Q 166.90108287 32.195 166.40908287 32.195 L 166.40908287 32.195 L 153.28908287 32.195 L 153.28908287 43.47 L 159.72608287 43.47 Q 160.21808287 43.47 160.48458287 43.839 Q 160.75108287 44.208 160.75108287 44.7 L 160.75108287 44.7 Q 160.75108287 45.069 160.50508287 45.438 Q 160.25908287 45.807 159.72608287 45.807 L 159.72608287 45.807 L 153.28908287 45.807 L 153.28908287 57.164 L 166.40908287 57.164 Q 166.90108287 57.164 167.16758287 57.533 Q 167.43408287 57.902 167.43408287 58.435 L 167.43408287 58.435 Q 167.43408287 58.886 167.18808287 59.2755 Q 166.94208287 59.665 166.40908287 59.665 L 166.40908287 59.665 Z" stroke-linecap="round" />
21
+ </g>
22
+ </svg>
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')
@@ -92,6 +92,14 @@ module Spyke
92
92
  assert_equal 'Fish', recipe.groups.first.name
93
93
  end
94
94
 
95
+ def test_find_with_block
96
+ stub_request(:get, 'http://sushi.com/recipes/1/groups').to_return_json(result: [{ name: 'Fish' }, { name: 'Fruit' }, { name: 'Bread' }])
97
+
98
+ recipe = Recipe.new(id: 1)
99
+
100
+ assert_equal 'Fruit', recipe.groups.find { |g| g.name == 'Fruit' }.name
101
+ end
102
+
95
103
  def test_nil_has_one_association
96
104
  stub_request(:get, 'http://sushi.com/recipes/1/image')
97
105
 
@@ -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')
data/test/orm_test.rb CHANGED
@@ -14,6 +14,16 @@ module Spyke
14
14
  assert_equal 'Bob', user.name
15
15
  end
16
16
 
17
+ def test_find_with_block
18
+ stub_request(:get, 'http://sushi.com/users').to_return_json(result: [{ id: 1, name: 'Bob' }, id: 2, name: 'Alice'])
19
+
20
+ user = User.find do |u|
21
+ u.name == 'Bob'
22
+ end
23
+
24
+ assert_equal 'Bob', user.name
25
+ end
26
+
17
27
  def test_reload
18
28
  stub_request(:get, 'http://sushi.com/recipes/1').to_return_json(result: { id: 1, title: 'Sushi' })
19
29
 
@@ -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.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: 2022-01-29 00:00:00.000000000 Z
11
+ date: 2023-06-07 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
@@ -301,6 +295,7 @@ files:
301
295
  - lib/spyke/scope_registry.rb
302
296
  - lib/spyke/scoping.rb
303
297
  - lib/spyke/version.rb
298
+ - spyke-dark.svg
304
299
  - spyke.gemspec
305
300
  - spyke.svg
306
301
  - test/activemodel_dirty_test.rb