vertebrae 1.0.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vertebrae/configuration.rb +1 -27
- data/lib/vertebrae/connection.rb +11 -32
- data/lib/vertebrae/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30786cc1ab2fa6f4d9f8e268f4815de51f7d5054a98cdae1989070e1804946aa
|
4
|
+
data.tar.gz: 03a1316928f1a52ce36163207b9170f79340edda31c63fcaca030bb6aa89d029
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e74729c49769b94026a591f9dcc99dc0518ded6c1e24ef55bf7f987b5b2c57750c5965e8dc740c11aac7d1f1cd33c9402ca0f3734b0cccb7c48ae7f63b72b64d
|
7
|
+
data.tar.gz: 62a58a594ee8197884be5e8ee2c56b2d9e92c5a2a87d1617c3d6b7e73de8ab57962c6a7f67a9aa4e9b3456a24dc7fc43e6841857f8a9f134d65052786e77099d
|
@@ -71,7 +71,7 @@ module Vertebrae
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def adapter
|
74
|
-
options[:adapter] ||
|
74
|
+
options[:adapter] || ::Faraday.default_adapter
|
75
75
|
end
|
76
76
|
|
77
77
|
def adapter=(value)
|
@@ -90,7 +90,6 @@ module Vertebrae
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
|
94
93
|
def faraday_options
|
95
94
|
{
|
96
95
|
:headers => {
|
@@ -117,33 +116,8 @@ module Vertebrae
|
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
120
|
-
|
121
119
|
def endpoint
|
122
120
|
"#{self.scheme}://#{self.host}#{self.port.present? ? ":#{self.port}" : ''}#{self.prefix}"
|
123
121
|
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
# Auto-detect the best adapter (HTTP "driver") available, based on libraries
|
128
|
-
# loaded by the user, preferring those with persistent connections
|
129
|
-
# ("keep-alive") by default
|
130
|
-
#
|
131
|
-
# @return [Symbol]
|
132
|
-
#
|
133
|
-
#
|
134
|
-
def auto_detect_adapter
|
135
|
-
case
|
136
|
-
when defined?(::Typhoeus)
|
137
|
-
:typhoeus
|
138
|
-
when defined?(::Patron)
|
139
|
-
:patron
|
140
|
-
when defined?(::HTTPClient)
|
141
|
-
:httpclient
|
142
|
-
when defined?(::Net::HTTP::Persistent)
|
143
|
-
:net_http_persistent
|
144
|
-
else
|
145
|
-
::Faraday.default_adapter
|
146
|
-
end
|
147
|
-
end
|
148
122
|
end
|
149
123
|
end
|
data/lib/vertebrae/connection.rb
CHANGED
@@ -13,6 +13,7 @@ module Vertebrae
|
|
13
13
|
|
14
14
|
attr_reader :options
|
15
15
|
attr_accessor :configuration
|
16
|
+
attr_accessor :faraday_connection
|
16
17
|
|
17
18
|
ALLOWED_OPTIONS = [
|
18
19
|
:headers,
|
@@ -33,45 +34,23 @@ module Vertebrae
|
|
33
34
|
@configuration = Vertebrae::Configuration.new(options)
|
34
35
|
end
|
35
36
|
|
36
|
-
#
|
37
|
-
# configuration stage.
|
37
|
+
# Returns a Faraday::Connection object
|
38
38
|
#
|
39
|
-
def
|
40
|
-
|
41
|
-
builder.use Faraday::Multipart::Middleware
|
42
|
-
builder.use Faraday::Request::UrlEncoded
|
39
|
+
def connection
|
40
|
+
self.faraday_connection ||= Faraday.new(configuration.faraday_options) do |f|
|
43
41
|
if configuration.authenticated?
|
44
|
-
|
42
|
+
f.request :authorization, :basic, configuration.username, configuration.password
|
45
43
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
f.request :multipart
|
45
|
+
f.request :url_encoded
|
49
46
|
unless options[:raw]
|
50
|
-
|
51
|
-
|
47
|
+
f.response :mashify
|
48
|
+
f.response :json
|
52
49
|
end
|
53
|
-
builder.use Vertebrae::Response::RaiseError
|
54
|
-
builder.adapter configuration.adapter
|
55
|
-
end
|
56
|
-
end
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
#
|
61
|
-
def stack(&block)
|
62
|
-
@stack ||= begin
|
63
|
-
if block_given?
|
64
|
-
Faraday::RackBuilder.new(&block)
|
65
|
-
else
|
66
|
-
Faraday::RackBuilder.new(&default_middleware)
|
67
|
-
end
|
51
|
+
f.response :raise_error
|
52
|
+
f.adapter configuration.adapter
|
68
53
|
end
|
69
54
|
end
|
70
|
-
|
71
|
-
# Returns a Faraday::Connection object
|
72
|
-
#
|
73
|
-
def connection
|
74
|
-
Faraday.new(configuration.faraday_options.merge(:builder => stack))
|
75
|
-
end
|
76
55
|
end
|
77
56
|
end
|
data/lib/vertebrae/version.rb
CHANGED