saddle 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6cbc5f3bed08d163ba1f6bb948acb555c16b9034ff6adac036a0f1f4252f872
4
- data.tar.gz: 6b509a1bdb969e7b54c3c6fd93d742ef3cfd7144de2e8c36014f8a5fdc32484a
3
+ metadata.gz: 4023ece557e6ce616a2716b16f7cbfcd78250ed974b952fa626bd2231d4b40f7
4
+ data.tar.gz: 0213abb4917acb28ed0a2f7d7400ddf71b2d228d1711d3046d825bfed167cbba
5
5
  SHA512:
6
- metadata.gz: c22f775da62289da5111c42fc64373aec52b3c831b828a0b40f9fda5d354d569da0481e8d789422965cd802ea23855816c4d53224ec3507a5a8dd977f7209c0c
7
- data.tar.gz: 392ebba3e48907a68867ba54125fdccbc26df04659fd84db2aa053823af414da24093eca48bf3b460efaf43bfcbc1792c813b25e04c6a521b221f815ef89503d
6
+ metadata.gz: 63b0c9c90a6db1cd20a83ccabea81f0f65d96c18ee15f6fb16368c4d1671abebf0c9196fe81610c6a184500a6a4eff06b935fc625a6f7d3fba11bcb52971f029
7
+ data.tar.gz: 712df18e85b0c9f2614bf8d2997939f3142c9f1d7cf4a637c3a69b7f845b1414eb5f8ab6233974c005906ce49ac207f390a15956119a29daf55db0b0c04a90e5
@@ -25,13 +25,23 @@ jobs:
25
25
  - activesupport_6.0
26
26
  - activesupport_6.1
27
27
  - activesupport_7.0
28
+ - activesupport_7.1
29
+ - faraday_0.x
30
+ - faraday_1
31
+ - faraday_2
28
32
  exclude:
33
+ - ruby-version: 2.6
34
+ gemfile: activesupport_7.1
29
35
  - ruby-version: 2.6
30
36
  gemfile: activesupport_7.0
31
37
  - ruby-version: '3.0'
32
38
  gemfile: activesupport_4.1
33
39
  - ruby-version: 3.1
34
40
  gemfile: activesupport_4.1
41
+ - ruby-version: '3.0'
42
+ gemfile: faraday_0.x
43
+ - ruby-version: 3.1
44
+ gemfile: faraday_0.x
35
45
  steps:
36
46
  - uses: actions/checkout@v3
37
47
 
data/Appraisals CHANGED
@@ -37,3 +37,21 @@ end
37
37
  appraise "activesupport_7.0" do
38
38
  gem "activesupport", "~> 7.0.4"
39
39
  end
40
+
41
+ appraise "activesupport_7.1" do
42
+ gem "activesupport", "~> 7.1.3"
43
+ end
44
+
45
+ appraise "faraday_0.x" do
46
+ gem "faraday", "~> 0.9"
47
+ gem "faraday_middleware"
48
+ end
49
+
50
+ appraise "faraday_1" do
51
+ gem "faraday", "~> 1.0"
52
+ gem "faraday_middleware"
53
+ end
54
+
55
+ appraise "faraday_2" do
56
+ gem "faraday", "~> 2.0"
57
+ end
data/bin/saddle CHANGED
@@ -3,6 +3,11 @@
3
3
  require 'erb'
4
4
  require 'ostruct'
5
5
 
6
+ require 'active_support/version'
7
+ if ActiveSupport::VERSION::STRING >= '7.1'
8
+ require 'active_support/deprecation'
9
+ require 'active_support/deprecator'
10
+ end
6
11
  require 'active_support/core_ext/string'
7
12
 
8
13
  require 'saddle'
@@ -9,7 +9,7 @@ module <%= root_module %>
9
9
 
10
10
  # Setup stubbing for all endpoints
11
11
  def stub!
12
- <%= root_module %>::Endpoints::Status.any_instance.stub(:healthy?).and_return(
12
+ allow_any_instance_of(<%= root_module %>::Endpoints::Status).to receive(:healthy?).and_return(
13
13
  Stub::Data::TEST_STATUS_HEALTHY_RESPONSE
14
14
  )
15
15
  end
@@ -0,0 +1,20 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 7.1.3"
6
+
7
+ group :test do
8
+ gem "rake"
9
+ gem "rspec", "~> 3.12"
10
+ gem "rspec-instafail", "~> 1"
11
+ gem "airbrake"
12
+ gem "simple_oauth", "~> 0.2.0"
13
+ gem "statsd-ruby", require: ["statsd"]
14
+ end
15
+
16
+ group :development, :test do
17
+ gem "pry"
18
+ end
19
+
20
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "faraday", "~> 0.9"
6
+ gem "faraday_middleware"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ gem "rspec", "~> 3.12"
11
+ gem "rspec-instafail", "~> 1"
12
+ gem "airbrake"
13
+ gem "simple_oauth", "~> 0.2.0"
14
+ gem "statsd-ruby", require: ["statsd"]
15
+ end
16
+
17
+ group :development, :test do
18
+ gem "pry"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "faraday", "~> 1.0"
6
+ gem "faraday_middleware"
7
+
8
+ group :test do
9
+ gem "rake"
10
+ gem "rspec", "~> 3.12"
11
+ gem "rspec-instafail", "~> 1"
12
+ gem "airbrake"
13
+ gem "simple_oauth", "~> 0.2.0"
14
+ gem "statsd-ruby", require: ["statsd"]
15
+ end
16
+
17
+ group :development, :test do
18
+ gem "pry"
19
+ end
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,20 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "faraday", "~> 2.0"
6
+
7
+ group :test do
8
+ gem "rake"
9
+ gem "rspec", "~> 3.12"
10
+ gem "rspec-instafail", "~> 1"
11
+ gem "airbrake"
12
+ gem "simple_oauth", "~> 0.2.0"
13
+ gem "statsd-ruby", require: ["statsd"]
14
+ end
15
+
16
+ group :development, :test do
17
+ gem "pry"
18
+ end
19
+
20
+ gemspec path: "../"
@@ -1,3 +1,8 @@
1
+ require 'active_support/version'
2
+ if ActiveSupport::VERSION::STRING >= '7.1'
3
+ require 'active_support/deprecation'
4
+ require 'active_support/deprecator'
5
+ end
1
6
  require 'active_support/core_ext/string'
2
7
 
3
8
 
@@ -1,3 +1,8 @@
1
+ require 'active_support/version'
2
+ if ActiveSupport::VERSION::STRING >= '7.1'
3
+ require 'active_support/deprecation'
4
+ require 'active_support/deprecator'
5
+ end
1
6
  require 'active_support/core_ext/string'
2
7
 
3
8
  require 'saddle/endpoint'
@@ -1,3 +1,8 @@
1
+ require 'active_support/version'
2
+ if ActiveSupport::VERSION::STRING >= '7.1'
3
+ require 'active_support/deprecation'
4
+ require 'active_support/deprecator'
5
+ end
1
6
  require 'active_support/core_ext/string'
2
7
 
3
8
  require 'statsd'
@@ -13,6 +13,10 @@ module Saddle
13
13
  CONTENT_TYPE = 'Content-Type'.freeze
14
14
  MIME_TYPE = 'application/json'.freeze
15
15
 
16
+ dependency do
17
+ require 'json' unless defined?(::JSON)
18
+ end if Faraday::VERSION < '2'
19
+
16
20
  def call(env)
17
21
  if env[:saddle][:request_style] == :json
18
22
  # Make sure we're working with a valid body that's not a String
@@ -10,6 +10,10 @@ module Saddle
10
10
  CONTENT_TYPE = 'Content-Type'.freeze
11
11
  MIME_TYPE = 'application/json'.freeze
12
12
 
13
+ dependency do
14
+ require 'json' unless defined?(::JSON)
15
+ end if Faraday::VERSION < '2'
16
+
13
17
  def call(env)
14
18
  result = @app.call(env)
15
19
 
@@ -2,6 +2,11 @@ require 'active_support/core_ext/hash'
2
2
  require 'active_support/notifications'
3
3
 
4
4
  require 'faraday'
5
+ if Faraday::VERSION < '2'
6
+ gem 'faraday_middleware'
7
+
8
+ require 'faraday_middleware'
9
+ end
5
10
  require 'saddle/faraday/request'
6
11
  require 'saddle/faraday/rack_builder'
7
12
 
@@ -47,13 +52,13 @@ module Saddle
47
52
  @host = opt[:host] || 'localhost'
48
53
  raise ':host must be a string' unless @host.is_a?(String)
49
54
  @port = opt[:port]
50
- raise ':port must be nil or an integer' unless (@port.nil? || @port.is_a?(Fixnum))
55
+ raise ':port must be nil or an integer' unless (@port.nil? || @port.is_a?(Integer))
51
56
  @use_ssl = opt[:use_ssl] || false
52
57
  raise ':use_ssl must be true or false' unless (@use_ssl.is_a?(TrueClass) || @use_ssl.is_a?(FalseClass))
53
58
  @request_style = opt[:request_style] || :json
54
59
  raise ":request_style must be in: #{VALID_BODY_STYLES.join(',')}" unless VALID_BODY_STYLES.include?(@request_style)
55
60
  @num_retries = opt[:num_retries] || 3
56
- raise ':num_retries must be an integer' unless @num_retries.is_a?(Fixnum)
61
+ raise ':num_retries must be an integer' unless @num_retries.is_a?(Integer)
57
62
  @timeout = opt[:timeout]
58
63
  raise ':timeout must be nil or an integer' unless (@timeout.nil? || @timeout.is_a?(Numeric))
59
64
  @extra_env = opt[:extra_env] || {}
@@ -1,3 +1,3 @@
1
1
  module Saddle
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
data/saddle.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.required_ruby_version = '>= 2.6'
26
26
 
27
27
  s.add_dependency 'activesupport', '>= 3.2'
28
- s.add_dependency 'faraday', '~> 2.1'
28
+ s.add_dependency 'faraday', '>= 0.9.0'
29
29
 
30
30
  s.add_development_dependency 'appraisal'
31
31
  end
@@ -15,8 +15,7 @@ describe Saddle::Middleware::Logging::StatsdLogger do
15
15
  end
16
16
 
17
17
  it "should log a request" do
18
- ::Statsd.any_instance.should_receive(:time).with("saddle.statsd_client.raw.localhost-test").and_yield
19
-
18
+ allow_any_instance_of(::Statsd).to receive(:time).with("saddle.statsd_client.raw.localhost-test").and_yield
20
19
  client = StatsdClient.create(
21
20
  :stubs => Faraday::Adapter::Test::Stubs.new do |stub|
22
21
  stub.get('/test') {
@@ -32,8 +31,7 @@ describe Saddle::Middleware::Logging::StatsdLogger do
32
31
  end
33
32
 
34
33
  it "should allow overriding the path" do
35
- ::Statsd.any_instance.should_receive(:time).with("hello").and_yield
36
-
34
+ allow_any_instance_of(::Statsd).to receive(:time).with("hello").and_yield
37
35
  client = StatsdClient.create(
38
36
  :stubs => Faraday::Adapter::Test::Stubs.new do |stub|
39
37
  stub.get('/test') {
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ describe Saddle::Client do
4
+ context "when path_prefix is set" do
5
+ context "using the default client" do
6
+ before :each do
7
+ @stubs = Faraday::Adapter::Test::Stubs.new
8
+ @default_client = Saddle::Client.create(:stubs => @stubs, :path_prefix => 'api/v1')
9
+ end
10
+
11
+ context "with no path" do
12
+ context "for a GET request" do
13
+ context "with no params" do
14
+ it "should properly prefix the path" do
15
+ url = ''
16
+ @stubs.get('/api/v1/') {
17
+ [
18
+ 200,
19
+ {},
20
+ 'Party!',
21
+ ]
22
+ }
23
+ @default_client.requester.get(url).should == 'Party!'
24
+ end
25
+ end
26
+
27
+ context "with params" do
28
+ it "should properly prefix the path" do
29
+ url = '?a=1'
30
+ @stubs.get('/api/v1/?a=1') {
31
+ [
32
+ 200,
33
+ {},
34
+ 'Party!',
35
+ ]
36
+ }
37
+ @default_client.requester.get(url).should == 'Party!'
38
+ end
39
+ end
40
+ end
41
+
42
+ context "for a POST request" do
43
+ context "with no params" do
44
+ it "should properly prefix the path" do
45
+ url = ''
46
+ @stubs.post('/api/v1/') {
47
+ [
48
+ 200,
49
+ {},
50
+ 'Party!',
51
+ ]
52
+ }
53
+ @default_client.requester.post(url).should == 'Party!'
54
+ end
55
+ end
56
+
57
+ context "with params" do
58
+ it "should properly prefix the path" do
59
+ url = '?a=1'
60
+ @stubs.post('/api/v1/?a=1') {
61
+ [
62
+ 200,
63
+ {},
64
+ 'Party!',
65
+ ]
66
+ }
67
+ @default_client.requester.post(url).should == 'Party!'
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ context "with a path" do
74
+ context "for a GET request" do
75
+ context "with no params" do
76
+ it "should properly prefix the path" do
77
+ url = '/test'
78
+ @stubs.get('/api/v1/test') {
79
+ [
80
+ 200,
81
+ {},
82
+ 'Party!',
83
+ ]
84
+ }
85
+ @default_client.requester.get(url).should == 'Party!'
86
+ end
87
+ end
88
+
89
+ context "with params" do
90
+ it "should properly prefix the path" do
91
+ url = '/test?a=1'
92
+ @stubs.get('/api/v1/test?a=1') {
93
+ [
94
+ 200,
95
+ {},
96
+ 'Party!',
97
+ ]
98
+ }
99
+ @default_client.requester.get(url).should == 'Party!'
100
+ end
101
+ end
102
+ end
103
+
104
+ context "for a POST request" do
105
+ context "with no params" do
106
+ it "should properly prefix the path" do
107
+ url = '/test'
108
+ @stubs.post('/api/v1/test') {
109
+ [
110
+ 200,
111
+ {},
112
+ 'Party!',
113
+ ]
114
+ }
115
+ @default_client.requester.post(url).should == 'Party!'
116
+ end
117
+ end
118
+
119
+ context "with params" do
120
+ it "should properly prefix the path" do
121
+ url = '/test?a=1'
122
+ @stubs.post('/api/v1/test?a=1') {
123
+ [
124
+ 200,
125
+ {},
126
+ 'Party!',
127
+ ]
128
+ }
129
+ @default_client.requester.post(url).should == 'Party!'
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -61,8 +61,8 @@ describe Saddle::Client do
61
61
  client2 = Client2.create(:stubs => stubs)
62
62
 
63
63
  # Make sure client2's middleware isn't called
64
- Middleware1.any_instance.should_receive(:subcall)
65
- Middleware2.any_instance.should_not_receive(:subcall)
64
+ allow_any_instance_of(Middleware1).to receive(:subcall)
65
+ allow_any_instance_of(Middleware2).to receive(:subcall)
66
66
 
67
67
  # Make the call
68
68
  client1.requester.get('/')
data/spec/spec_helper.rb CHANGED
@@ -2,3 +2,7 @@ require 'faraday' # for test stubs
2
2
  require 'saddle'
3
3
 
4
4
  require 'pry'
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Lewis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-26 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: 0.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +95,10 @@ files:
95
95
  - gemfiles/activesupport_6.0.gemfile
96
96
  - gemfiles/activesupport_6.1.gemfile
97
97
  - gemfiles/activesupport_7.0.gemfile
98
+ - gemfiles/activesupport_7.1.gemfile
99
+ - gemfiles/faraday_0.x.gemfile
100
+ - gemfiles/faraday_1.gemfile
101
+ - gemfiles/faraday_2.gemfile
98
102
  - lib/saddle.rb
99
103
  - lib/saddle/client_attributes.rb
100
104
  - lib/saddle/endpoint.rb
@@ -128,6 +132,7 @@ files:
128
132
  - spec/middleware/logging/airbrake_spec.rb
129
133
  - spec/middleware/logging/rails_spec.rb
130
134
  - spec/middleware/logging/statsd_spec.rb
135
+ - spec/middleware/request/path_prefix_spec.rb
131
136
  - spec/middleware/request/retry_spec.rb
132
137
  - spec/middleware/response/default_response_spec.rb
133
138
  - spec/multiple_spec.rb
@@ -166,6 +171,7 @@ test_files:
166
171
  - spec/middleware/logging/airbrake_spec.rb
167
172
  - spec/middleware/logging/rails_spec.rb
168
173
  - spec/middleware/logging/statsd_spec.rb
174
+ - spec/middleware/request/path_prefix_spec.rb
169
175
  - spec/middleware/request/retry_spec.rb
170
176
  - spec/middleware/response/default_response_spec.rb
171
177
  - spec/multiple_spec.rb