Class: Faraday::Connection
- Includes:
- Addressable
- Defined in:
- lib/faraday/connection.rb
Defined Under Namespace
Modules: Options
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
-
#port ⇒ Object
Returns the value of attribute port.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
Instance Method Summary collapse
- #build_uri(url, params = {}) ⇒ Object
-
#escape_for_querystring(s) ⇒ Object
Some servers convert +‘s in URL query params to spaces.
-
#get(url, params = {}, headers = {}) ⇒ Object
Override in a subclass, or include an adapter.
- #in_parallel(options = {}) ⇒ Object
- #in_parallel? ⇒ Boolean
-
#initialize(url = nil) ⇒ Connection
constructor
A new instance of Connection.
- #params_to_query(params) ⇒ Object
- #response_class ⇒ Object
- #response_class=(v) ⇒ Object
- #run_parallel_requests ⇒ Object
- #setup_parallel_manager(options = {}) ⇒ Object
Constructor Details
#initialize(url = nil) ⇒ Connection
Returns a new instance of Connection.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/faraday/connection.rb', line 18 def initialize(url = nil) @response_class = nil if url uri = URI.parse(url) self.scheme = uri.scheme self.host = uri.host self.port = uri.port self.path_prefix = uri.path end end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
15 16 17 |
# File 'lib/faraday/connection.rb', line 15 def host @host end |
#path_prefix ⇒ Object
Returns the value of attribute path_prefix.
16 17 18 |
# File 'lib/faraday/connection.rb', line 16 def path_prefix @path_prefix end |
#port ⇒ Object
Returns the value of attribute port.
15 16 17 |
# File 'lib/faraday/connection.rb', line 15 def port @port end |
#scheme ⇒ Object
Returns the value of attribute scheme.
15 16 17 |
# File 'lib/faraday/connection.rb', line 15 def scheme @scheme end |
Instance Method Details
#build_uri(url, params = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/faraday/connection.rb', line 73 def build_uri(url, params = {}) uri = URI.parse(url) uri.scheme ||= @scheme uri.host ||= @host uri.port ||= @port if @path_prefix && uri.path !~ /^\// uri.path = "#{@path_prefix.size > 1 ? @path_prefix : nil}/#{uri.path}" end query = params_to_query(params) if !query.empty? then uri.query = query end uri end |
#escape_for_querystring(s) ⇒ Object
Some servers convert +‘s in URL query params to spaces. Go ahead and encode it.
94 95 96 97 98 |
# File 'lib/faraday/connection.rb', line 94 def escape_for_querystring(s) URI.encode_component(s, Addressable::URI::CharacterClasses::QUERY).tap do |escaped| escaped.gsub! /\+/, "%2B" end end |
#get(url, params = {}, headers = {}) ⇒ Object
Override in a subclass, or include an adapter
def _get(uri, headers)
end
34 35 36 |
# File 'lib/faraday/connection.rb', line 34 def get(url, params = {}, headers = {}) _get(build_uri(url, params), headers) end |
#in_parallel(options = {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/faraday/connection.rb', line 53 def in_parallel( = {}) @parallel_manager = true yield @parallel_manager = false end |
#in_parallel? ⇒ Boolean
49 50 51 |
# File 'lib/faraday/connection.rb', line 49 def in_parallel? !!@parallel_manager end |
#params_to_query(params) ⇒ Object
86 87 88 89 90 |
# File 'lib/faraday/connection.rb', line 86 def params_to_query(params) params.inject([]) do |memo, (key, val)| memo << "#{escape_for_querystring(key)}=#{escape_for_querystring(val)}" end.join("&") end |
#response_class ⇒ Object
38 39 40 |
# File 'lib/faraday/connection.rb', line 38 def response_class @response_class || Response end |
#response_class=(v) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/faraday/connection.rb', line 42 def response_class=(v) if v.respond_to?(:loaded?) && !v.loaded? raise ArgumentError, "The response class: #{v.inspect} does not appear to be loaded." end @response_class = v end |
#run_parallel_requests ⇒ Object
62 63 |
# File 'lib/faraday/connection.rb', line 62 def run_parallel_requests end |
#setup_parallel_manager(options = {}) ⇒ Object
59 60 |
# File 'lib/faraday/connection.rb', line 59 def setup_parallel_manager( = {}) end |