saddle 0.0.7 → 0.0.10
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 +8 -8
- data/lib/saddle/client_attributes.rb +20 -0
- data/lib/saddle/errors.rb +7 -0
- data/lib/saddle/method_tree_builder.rb +3 -13
- data/lib/saddle/middleware/ruby_timeout.rb +7 -2
- data/lib/saddle/options.rb +3 -4
- data/lib/saddle/version.rb +1 -1
- data/lib/saddle.rb +6 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmI5ZWE4OTY2MDdhYTU0ODhjMGRlNjQ4NTVlZmYyMDExZWRkMWM0OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTJjNzUzN2UwYjRiNThiNDVmNzk1YjM1YTczOWEzODdkNThhYzFhOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTg2NDg1NzkwMWM4NzE4YzEzODNkMzJmNGQ0NTYwNjc5NjAwMThlNzNkOWYx
|
10
|
+
MjYxNTJlYzFiMmMxNTJmYjBiOTc0NDBjNDQzYmM2NGY5ZDExYjc0NTY0ZWUx
|
11
|
+
OTNmMTEyODVlN2RlMTAyZjk4MGVjMGZlMjliN2I4OWQ0ZDQ2MTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWFiOWQ1OTMzMTViM2M0ZGEzOGNmODdiMTQwOTM2NWIzYzMyNjc1OGFjNmQ5
|
14
|
+
N2RlNDBmZTMzYTE0ODkwOWQ4YzVkY2NjY2U5MDk2Nzc1MWVmZTViYTgyNjhk
|
15
|
+
M2I2NzU3NTg0ZjdkNDA5OWQ2N2U5ODQyZGFhOGUzODlkMDgyMzU=
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Saddle::ClientAttributes
|
2
|
+
|
3
|
+
def self.included(obj)
|
4
|
+
obj.extend ClassMethods
|
5
|
+
|
6
|
+
# Default values
|
7
|
+
obj.additional_middlewares = []
|
8
|
+
|
9
|
+
# We know that this module is included when saddle client is inherited,
|
10
|
+
# so we're actually interested in the path of the caller two levels deep.
|
11
|
+
path, = caller[2].partition(":")
|
12
|
+
obj.implementation_root = File.dirname(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
attr_accessor :implementation_root
|
17
|
+
attr_accessor :additional_middlewares
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -29,7 +29,7 @@ module Saddle::MethodTreeBuilder
|
|
29
29
|
def build_root_node(requester)
|
30
30
|
if knows_root?
|
31
31
|
root_endpoint_file = File.join(
|
32
|
-
|
32
|
+
self.implementation_root,
|
33
33
|
'root_endpoint.rb'
|
34
34
|
)
|
35
35
|
if File.file?(root_endpoint_file)
|
@@ -92,22 +92,12 @@ module Saddle::MethodTreeBuilder
|
|
92
92
|
# Get the path to the 'endpoints' directory, based upon the client
|
93
93
|
# class that inherited Saddle
|
94
94
|
def endpoints_directory
|
95
|
-
File.join(
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
# When Saddle is inherited, we store the root of the implementation class
|
101
|
-
# This is so that we know where to look for relative files, like
|
102
|
-
# the endpoints directory
|
103
|
-
def inherited(obj)
|
104
|
-
path, = caller[0].partition(":")
|
105
|
-
@@implementation_root = File.dirname(path)
|
95
|
+
File.join(self.implementation_root, 'endpoints')
|
106
96
|
end
|
107
97
|
|
108
98
|
# If this client was not fully constructed, it may not even have an
|
109
99
|
# implementation root. Allow that behavior and avoid firesystem searching.
|
110
100
|
def knows_root?
|
111
|
-
defined?(
|
101
|
+
defined?(self.implementation_root)
|
112
102
|
end
|
113
103
|
end
|
@@ -3,15 +3,20 @@ require 'faraday'
|
|
3
3
|
|
4
4
|
module Saddle::Middleware
|
5
5
|
|
6
|
-
# Public: Enforces a ruby timeout on the request
|
6
|
+
# Public: Enforces a ruby timeout on the request and throws one consistent
|
7
|
+
# exception for all classes of timeout, internal or from faraday.
|
7
8
|
# :timeout must be present in the request or client options
|
8
9
|
class RubyTimeout < Faraday::Middleware
|
9
10
|
|
10
11
|
def call(env)
|
11
12
|
timeout = env[:request][:timeout] # nil or 0 means no timeout
|
12
|
-
Timeout.timeout(timeout) do
|
13
|
+
Timeout.timeout(timeout, Saddle::TimeoutError) do
|
13
14
|
@app.call(env)
|
14
15
|
end
|
16
|
+
# It is possible that faraday will catch the timeout first and throw
|
17
|
+
# this exception, rethrow as a class derived from standard error.
|
18
|
+
rescue Faraday::Error::TimeoutError
|
19
|
+
raise Saddle::TimeoutError
|
15
20
|
end
|
16
21
|
|
17
22
|
end
|
data/lib/saddle/options.rb
CHANGED
@@ -16,7 +16,7 @@ module Saddle::Options
|
|
16
16
|
:request_style => request_style,
|
17
17
|
:num_retries => num_retries,
|
18
18
|
:timeout => timeout,
|
19
|
-
:additional_middlewares =>
|
19
|
+
:additional_middlewares => self.additional_middlewares,
|
20
20
|
:stubs => stubs,
|
21
21
|
}
|
22
22
|
end
|
@@ -60,10 +60,9 @@ module Saddle::Options
|
|
60
60
|
# })
|
61
61
|
# end
|
62
62
|
#
|
63
|
-
###
|
64
|
-
@@additional_middlewares = []
|
63
|
+
###
|
65
64
|
def add_middleware m
|
66
|
-
|
65
|
+
self.additional_middlewares << m
|
67
66
|
end
|
68
67
|
|
69
68
|
# If the Typhoeus adapter is being used, pass stubs to it for testing.
|
data/lib/saddle/version.rb
CHANGED
data/lib/saddle.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'saddle/method_tree_builder'
|
2
2
|
require 'saddle/options'
|
3
|
+
require 'saddle/client_attributes'
|
3
4
|
require 'saddle/requester'
|
4
|
-
|
5
|
+
require 'saddle/errors'
|
5
6
|
|
6
7
|
|
7
8
|
# Ghost ride the whip.
|
@@ -16,7 +17,6 @@ module Saddle
|
|
16
17
|
extend MethodTreeBuilder
|
17
18
|
extend Options
|
18
19
|
|
19
|
-
|
20
20
|
# Once your implementation is written, this is the magic you need to
|
21
21
|
# create a client instance.
|
22
22
|
def self.create(opt={})
|
@@ -27,6 +27,10 @@ module Saddle
|
|
27
27
|
)
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.inherited(obj)
|
31
|
+
obj.send(:include, Saddle::ClientAttributes)
|
32
|
+
end
|
33
|
+
|
30
34
|
end
|
31
35
|
|
32
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Lewis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -66,7 +66,9 @@ files:
|
|
66
66
|
- LICENSE
|
67
67
|
- README.md
|
68
68
|
- lib/saddle.rb
|
69
|
+
- lib/saddle/client_attributes.rb
|
69
70
|
- lib/saddle/endpoint.rb
|
71
|
+
- lib/saddle/errors.rb
|
70
72
|
- lib/saddle/method_tree_builder.rb
|
71
73
|
- lib/saddle/middleware/logging/airbrake.rb
|
72
74
|
- lib/saddle/middleware/logging/statsd.rb
|