saddle 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +55 -0
- data/.gitignore +1 -0
- data/Appraisals +39 -0
- data/Gemfile +2 -2
- data/README.md +34 -2
- data/bin/template/lib/saddle-client/middleware/exception_raiser.rb +1 -1
- data/bin/template/lib/saddle-client/stub.rb +1 -1
- data/gemfiles/activesupport_3.2.gemfile +20 -0
- data/gemfiles/activesupport_4.0.gemfile +20 -0
- data/gemfiles/activesupport_4.1.gemfile +20 -0
- data/gemfiles/activesupport_4.2.gemfile +20 -0
- data/gemfiles/activesupport_5.0.gemfile +20 -0
- data/gemfiles/activesupport_5.1.gemfile +20 -0
- data/gemfiles/activesupport_5.2.gemfile +20 -0
- data/gemfiles/activesupport_6.0.gemfile +20 -0
- data/gemfiles/activesupport_6.1.gemfile +20 -0
- data/gemfiles/activesupport_7.0.gemfile +20 -0
- data/lib/saddle/middleware/request/encode_json.rb +0 -6
- data/lib/saddle/middleware/response/parse_json.rb +0 -6
- data/lib/saddle/middleware/response/raise_error.rb +2 -2
- data/lib/saddle/middleware/ruby_timeout.rb +1 -1
- data/lib/saddle/requester.rb +4 -4
- data/lib/saddle/version.rb +1 -1
- data/saddle.gemspec +6 -8
- data/spec/endpoint/base_endpoint_spec.rb +2 -2
- data/spec/middleware/instrumentation_spec.rb +1 -1
- data/spec/middleware/logging/statsd_spec.rb +2 -4
- data/spec/middleware/request/path_prefix_spec.rb +136 -0
- data/spec/middleware/request/retry_spec.rb +1 -1
- data/spec/multiple_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -0
- metadata +39 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 40349fa3b434064564e6060fafbfede9327e3ad28d28035ecc6ce3eefebc096d
|
4
|
+
data.tar.gz: 68d77c929a14a18571ec4be49fa2daf0e207840add48e3424220643a68c57be5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d84f468133bedaa13ecb030dc2819a0f23b39255b1e500301b5e220d638b2d125106ebea591f2b25628e366fc433e9f440217a94a84f30367a4acb471cbfb0a1
|
7
|
+
data.tar.gz: ab8fccb3facdd3d186627c6c76569e3209b8d7cad3608125a4c24799ba7eaf58c4e2ac04f5793d23c9d989a0a4c6bace879952ffa658bd5a76653aaa9547f85e
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
2
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
3
|
+
|
4
|
+
name: Ruby
|
5
|
+
|
6
|
+
on: [pull_request, push]
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: [2.6, 2.7, '3.0', 3.1]
|
17
|
+
gemfile:
|
18
|
+
- activesupport_3.2
|
19
|
+
- activesupport_4.0
|
20
|
+
- activesupport_4.1
|
21
|
+
- activesupport_4.2
|
22
|
+
- activesupport_5.0
|
23
|
+
- activesupport_5.1
|
24
|
+
- activesupport_5.2
|
25
|
+
- activesupport_6.0
|
26
|
+
- activesupport_6.1
|
27
|
+
- activesupport_7.0
|
28
|
+
exclude:
|
29
|
+
- ruby-version: 2.6
|
30
|
+
gemfile: activesupport_7.0
|
31
|
+
- ruby-version: '3.0'
|
32
|
+
gemfile: activesupport_4.1
|
33
|
+
- ruby-version: 3.1
|
34
|
+
gemfile: activesupport_4.1
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v3
|
37
|
+
|
38
|
+
- name: Set up Ruby
|
39
|
+
uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: ${{ matrix.ruby-version }}
|
42
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
43
|
+
|
44
|
+
- name: Generate Appraisal gemfiles
|
45
|
+
run: bundle exec appraisal generate
|
46
|
+
|
47
|
+
- name: Install dependencies
|
48
|
+
env:
|
49
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
50
|
+
run: bundle install
|
51
|
+
|
52
|
+
- name: Run rspec
|
53
|
+
env:
|
54
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
55
|
+
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
appraise "activesupport_3.2" do
|
2
|
+
gem "activesupport", "~> 3.2.22"
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "activesupport_4.0" do
|
6
|
+
gem "activesupport", "~> 4.0.13"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "activesupport_4.1" do
|
10
|
+
gem "activesupport", "~> 4.1.16"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "activesupport_4.2" do
|
14
|
+
gem "activesupport", "~> 4.2.11"
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise "activesupport_5.0" do
|
18
|
+
gem "activesupport", "~> 5.0.7"
|
19
|
+
end
|
20
|
+
|
21
|
+
appraise "activesupport_5.1" do
|
22
|
+
gem "activesupport", "~> 5.1.7"
|
23
|
+
end
|
24
|
+
|
25
|
+
appraise "activesupport_5.2" do
|
26
|
+
gem "activesupport", "~> 5.2.8"
|
27
|
+
end
|
28
|
+
|
29
|
+
appraise "activesupport_6.0" do
|
30
|
+
gem "activesupport", "~> 6.0.6"
|
31
|
+
end
|
32
|
+
|
33
|
+
appraise "activesupport_6.1" do
|
34
|
+
gem "activesupport", "~> 6.1.7"
|
35
|
+
end
|
36
|
+
|
37
|
+
appraise "activesupport_7.0" do
|
38
|
+
gem "activesupport", "~> 7.0.4"
|
39
|
+
end
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -64,15 +64,47 @@ Saddle enables you to create beautifully stable and functionaly API clients, in
|
|
64
64
|
|
65
65
|
## version notes
|
66
66
|
|
67
|
+
* Saddle versions 0.2.x supports Ruby 3.x, drops support for 2.6
|
67
68
|
* Saddle versions 0.1.x are compatible with Faraday versions ~> 0.9.0
|
68
69
|
* Saddle versions 0.0.x are compatible with Faraday versions ~> 0.8.7
|
69
70
|
|
71
|
+
## Appraisal Usage
|
72
|
+
|
73
|
+
Appraisal is a gem that allows us to test our library against different versions of dependencies in repeatable scenarios called "appraisals". For more information see
|
74
|
+
the [Appraisal repository](https://github.com/thoughtbot/appraisal)
|
75
|
+
|
76
|
+
First make sure appraisal is installed by running
|
77
|
+
|
78
|
+
```
|
79
|
+
$ bundle install
|
80
|
+
```
|
81
|
+
|
82
|
+
To update the Appraisal's gemfiles run
|
83
|
+
|
84
|
+
```
|
85
|
+
$ bundle exec appraisal generate
|
86
|
+
```
|
87
|
+
|
88
|
+
To test against a specific version of `activesupport` first install the dependencies, ideally we would want to install them by running
|
89
|
+
```
|
90
|
+
$ bundle exec appraisal install
|
91
|
+
```
|
92
|
+
|
93
|
+
However, this isn't posible fot the different constraints these versions have. So instead install the dependencies for the desired version we want to test against by running
|
94
|
+
|
95
|
+
```
|
96
|
+
$ BUNDLE_GEMFILE=gemfiles/activesupport_6.0.gemfiles bundle install
|
97
|
+
```
|
98
|
+
|
99
|
+
In this example we want to install the dependencies of `activesupport` version `6.0`. Then to run `rspec` with that constraints we run
|
100
|
+
|
101
|
+
```
|
102
|
+
$ BUNDLE_GEMFILE=gemfiles/activesupport_6.0.gemfiles bundle exec rspec
|
103
|
+
```
|
70
104
|
|
71
105
|
## Code Status
|
72
106
|
|
73
|
-
* [![Build Status](https://travis-ci.org/mLewisLogic/saddle.png?branch=master)](https://travis-ci.org/mLewisLogic/saddle)
|
74
107
|
* [![Code Climate](https://codeclimate.com/github/mLewisLogic/saddle.png)](https://codeclimate.com/github/mLewisLogic/saddle)
|
75
|
-
* [![Dependency Status](https://gemnasium.com/mLewisLogic/saddle.png)](https://gemnasium.com/mLewisLogic/saddle)
|
76
108
|
|
77
109
|
|
78
110
|
## License
|
@@ -19,7 +19,7 @@ module <%= root_module %>
|
|
19
19
|
def call(env)
|
20
20
|
begin
|
21
21
|
@app.call(env)
|
22
|
-
rescue Faraday::
|
22
|
+
rescue Faraday::ClientError => e
|
23
23
|
# This is our chance to reinterpret the response into a meaningful, client-specific
|
24
24
|
# exception that a consuming service can handle
|
25
25
|
exception = <%= root_module %>::GenericException
|
@@ -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.
|
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", "~> 3.2.22"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 4.0.13"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 4.1.16"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 4.2.11"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 5.0.7"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 5.1.7"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 5.2.8"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 6.0.6"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 6.1.7"
|
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,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "activesupport", "~> 7.0.4"
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "rake"
|
9
|
+
gem "rspec", "~> 2.14.1"
|
10
|
+
gem "rspec-instafail", "~> 0.2"
|
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,7 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
module Saddle
|
6
4
|
module Middleware
|
7
5
|
module Request
|
@@ -15,10 +13,6 @@ module Saddle
|
|
15
13
|
CONTENT_TYPE = 'Content-Type'.freeze
|
16
14
|
MIME_TYPE = 'application/json'.freeze
|
17
15
|
|
18
|
-
dependency do
|
19
|
-
require 'json' unless defined?(::JSON)
|
20
|
-
end
|
21
|
-
|
22
16
|
def call(env)
|
23
17
|
if env[:saddle][:request_style] == :json
|
24
18
|
# Make sure we're working with a valid body that's not a String
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
module Saddle
|
6
4
|
module Middleware
|
7
5
|
module Response
|
@@ -12,10 +10,6 @@ module Saddle
|
|
12
10
|
CONTENT_TYPE = 'Content-Type'.freeze
|
13
11
|
MIME_TYPE = 'application/json'.freeze
|
14
12
|
|
15
|
-
dependency do
|
16
|
-
require 'json' unless defined?(::JSON)
|
17
|
-
end
|
18
|
-
|
19
13
|
def call(env)
|
20
14
|
result = @app.call(env)
|
21
15
|
|
@@ -11,9 +11,9 @@ module Saddle
|
|
11
11
|
|
12
12
|
case result.status
|
13
13
|
when 404
|
14
|
-
raise Faraday::
|
14
|
+
raise Faraday::ResourceNotFound, response_values(result)
|
15
15
|
when 400...600
|
16
|
-
raise Faraday::
|
16
|
+
raise Faraday::ClientError, response_values(result)
|
17
17
|
end
|
18
18
|
|
19
19
|
result
|
@@ -19,7 +19,7 @@ module Saddle
|
|
19
19
|
end
|
20
20
|
# It is possible that faraday will catch the timeout first and throw
|
21
21
|
# this exception, rethrow as a class derived from standard error.
|
22
|
-
rescue Faraday::
|
22
|
+
rescue Faraday::TimeoutError
|
23
23
|
raise Saddle::TimeoutError
|
24
24
|
end
|
25
25
|
|
data/lib/saddle/requester.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_support/core_ext/hash'
|
2
|
+
require 'active_support/notifications'
|
2
3
|
|
3
4
|
require 'faraday'
|
4
|
-
require 'faraday_middleware'
|
5
5
|
require 'saddle/faraday/request'
|
6
6
|
require 'saddle/faraday/rack_builder'
|
7
7
|
|
@@ -47,13 +47,13 @@ module Saddle
|
|
47
47
|
@host = opt[:host] || 'localhost'
|
48
48
|
raise ':host must be a string' unless @host.is_a?(String)
|
49
49
|
@port = opt[:port]
|
50
|
-
raise ':port must be nil or an integer' unless (@port.nil? || @port.is_a?(
|
50
|
+
raise ':port must be nil or an integer' unless (@port.nil? || @port.is_a?(Integer))
|
51
51
|
@use_ssl = opt[:use_ssl] || false
|
52
52
|
raise ':use_ssl must be true or false' unless (@use_ssl.is_a?(TrueClass) || @use_ssl.is_a?(FalseClass))
|
53
53
|
@request_style = opt[:request_style] || :json
|
54
54
|
raise ":request_style must be in: #{VALID_BODY_STYLES.join(',')}" unless VALID_BODY_STYLES.include?(@request_style)
|
55
55
|
@num_retries = opt[:num_retries] || 3
|
56
|
-
raise ':num_retries must be an integer' unless @num_retries.is_a?(
|
56
|
+
raise ':num_retries must be an integer' unless @num_retries.is_a?(Integer)
|
57
57
|
@timeout = opt[:timeout]
|
58
58
|
raise ':timeout must be nil or an integer' unless (@timeout.nil? || @timeout.is_a?(Numeric))
|
59
59
|
@extra_env = opt[:extra_env] || {}
|
@@ -173,7 +173,7 @@ module Saddle
|
|
173
173
|
connection.use(Saddle::Middleware::Response::ParseJson)
|
174
174
|
|
175
175
|
# Set up instrumentation around the adapter for extensibility
|
176
|
-
connection.
|
176
|
+
connection.request :instrumentation
|
177
177
|
|
178
178
|
# Add in extra env data if needed
|
179
179
|
connection.use(Saddle::Middleware::ExtraEnv)
|
data/lib/saddle/version.rb
CHANGED
data/saddle.gemspec
CHANGED
@@ -21,13 +21,11 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = `git ls-files`.split($\)
|
22
22
|
s.executables = ['saddle']
|
23
23
|
s.test_files = s.files.grep(%r{^(spec)/})
|
24
|
-
|
25
|
-
if RUBY_VERSION < '1.9'
|
26
|
-
s.add_dependency 'activesupport', '~> 3.0'
|
27
|
-
else
|
28
|
-
s.add_dependency 'activesupport', '>= 3.0'
|
29
|
-
end
|
30
24
|
|
31
|
-
s.
|
32
|
-
|
25
|
+
s.required_ruby_version = '>= 2.6'
|
26
|
+
|
27
|
+
s.add_dependency 'activesupport', '>= 3.2'
|
28
|
+
s.add_dependency 'faraday', '~> 2.1'
|
29
|
+
|
30
|
+
s.add_development_dependency 'appraisal'
|
33
31
|
end
|
@@ -4,11 +4,11 @@ describe Saddle::BaseEndpoint do
|
|
4
4
|
let(:base_endpoint) { Saddle::BaseEndpoint.new(Saddle::Client.create) }
|
5
5
|
|
6
6
|
it 'can define singleton methods' do
|
7
|
-
expect(base_endpoint.respond_to?(:define_singleton_method)).to
|
7
|
+
expect(base_endpoint.respond_to?(:define_singleton_method)).to be_truthy
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'responds to any defined singleton methods' do
|
11
11
|
base_endpoint.define_singleton_method(:my_method) { true }
|
12
|
-
expect(base_endpoint.my_method).to
|
12
|
+
expect(base_endpoint.my_method).to be_truthy
|
13
13
|
end
|
14
14
|
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.
|
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.
|
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
|
data/spec/multiple_spec.rb
CHANGED
@@ -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.
|
65
|
-
Middleware2.
|
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
metadata
CHANGED
@@ -1,64 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mike Lewis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2023-06-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '3.
|
19
|
+
version: '3.2'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '3.
|
26
|
+
version: '3.2'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: faraday
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
33
|
+
version: '2.1'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
version: '2.1'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: appraisal
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0
|
54
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
54
|
+
version: '0'
|
62
55
|
description: Makes writing API clients as easy as giving high fives
|
63
56
|
email: mike.lewis@airbnb.com
|
64
57
|
executables:
|
@@ -66,9 +59,11 @@ executables:
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
69
|
-
- .
|
70
|
-
- .
|
71
|
-
- .
|
62
|
+
- ".github/workflows/ci.yml"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Appraisals
|
72
67
|
- CHANGELOG.md
|
73
68
|
- Gemfile
|
74
69
|
- LICENSE
|
@@ -90,6 +85,16 @@ files:
|
|
90
85
|
- bin/template/spec/middleware/exception_raiser_spec.rb
|
91
86
|
- bin/template/spec/spec_helper.rb
|
92
87
|
- bin/template/spec/stub/stub_spec.rb
|
88
|
+
- gemfiles/activesupport_3.2.gemfile
|
89
|
+
- gemfiles/activesupport_4.0.gemfile
|
90
|
+
- gemfiles/activesupport_4.1.gemfile
|
91
|
+
- gemfiles/activesupport_4.2.gemfile
|
92
|
+
- gemfiles/activesupport_5.0.gemfile
|
93
|
+
- gemfiles/activesupport_5.1.gemfile
|
94
|
+
- gemfiles/activesupport_5.2.gemfile
|
95
|
+
- gemfiles/activesupport_6.0.gemfile
|
96
|
+
- gemfiles/activesupport_6.1.gemfile
|
97
|
+
- gemfiles/activesupport_7.0.gemfile
|
93
98
|
- lib/saddle.rb
|
94
99
|
- lib/saddle/client_attributes.rb
|
95
100
|
- lib/saddle/endpoint.rb
|
@@ -123,6 +128,7 @@ files:
|
|
123
128
|
- spec/middleware/logging/airbrake_spec.rb
|
124
129
|
- spec/middleware/logging/rails_spec.rb
|
125
130
|
- spec/middleware/logging/statsd_spec.rb
|
131
|
+
- spec/middleware/request/path_prefix_spec.rb
|
126
132
|
- spec/middleware/request/retry_spec.rb
|
127
133
|
- spec/middleware/response/default_response_spec.rb
|
128
134
|
- spec/multiple_spec.rb
|
@@ -132,27 +138,25 @@ files:
|
|
132
138
|
homepage: https://github.com/mLewisLogic/saddle
|
133
139
|
licenses:
|
134
140
|
- MIT
|
141
|
+
metadata: {}
|
135
142
|
post_install_message:
|
136
143
|
rdoc_options: []
|
137
144
|
require_paths:
|
138
145
|
- lib
|
139
146
|
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
-
none: false
|
141
147
|
requirements:
|
142
|
-
- -
|
148
|
+
- - ">="
|
143
149
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
150
|
+
version: '2.6'
|
145
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
152
|
requirements:
|
148
|
-
- -
|
153
|
+
- - ">="
|
149
154
|
- !ruby/object:Gem::Version
|
150
155
|
version: '0'
|
151
156
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 1.8.23.2
|
157
|
+
rubygems_version: 3.0.3.1
|
154
158
|
signing_key:
|
155
|
-
specification_version:
|
159
|
+
specification_version: 4
|
156
160
|
summary: A full-featured, generic consumer layer for you to build API client implementations
|
157
161
|
with.
|
158
162
|
test_files:
|
@@ -163,6 +167,7 @@ test_files:
|
|
163
167
|
- spec/middleware/logging/airbrake_spec.rb
|
164
168
|
- spec/middleware/logging/rails_spec.rb
|
165
169
|
- spec/middleware/logging/statsd_spec.rb
|
170
|
+
- spec/middleware/request/path_prefix_spec.rb
|
166
171
|
- spec/middleware/request/retry_spec.rb
|
167
172
|
- spec/middleware/response/default_response_spec.rb
|
168
173
|
- spec/multiple_spec.rb
|