Module: SparkApi::Connection
- Included in:
- Client
- Defined in:
- lib/spark_api/connection.rb
Overview
Connection
Mixin module for handling http connection information
Instance Method Summary collapse
-
#connection(force_ssl = false) ⇒ Object
Main connection object for running requests.
-
#headers ⇒ Object
HTTP request headers for client requests.
- #reso_headers ⇒ Object
- #spark_headers ⇒ Object
Instance Method Details
#connection(force_ssl = false) ⇒ Object
Main connection object for running requests. Bootstraps the Faraday abstraction layer with our client configuration.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/spark_api/connection.rb', line 10 def connection(force_ssl = false) opts = { :headers => headers } if(force_ssl || self.ssl) opts[:ssl] = {:verify => false } unless self.ssl_verify opts[:url] = @endpoint.sub /^http:/, "https:" else opts[:url] = @endpoint.sub /^https:/, "http:" end if self.compress opts[:headers]["Accept-Encoding"] = 'gzip, deflate' end conn = Faraday.new(opts) do |conn| conn.response self.middleware.to_sym conn.[:timeout] = self.timeout conn.adapter Faraday.default_adapter end SparkApi.logger.debug { "Connection: #{conn.inspect}" } conn end |
#headers ⇒ Object
HTTP request headers for client requests
35 36 37 38 39 40 41 |
# File 'lib/spark_api/connection.rb', line 35 def headers if self.middleware.to_sym == :reso_api reso_headers else spark_headers end end |
#reso_headers ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/spark_api/connection.rb', line 52 def reso_headers { :accept => 'application/json, application/xml', :user_agent => Configuration::DEFAULT_USER_AGENT, Configuration::X_SPARK_API_USER_AGENT => user_agent } end |
#spark_headers ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/spark_api/connection.rb', line 43 def spark_headers { :accept => 'application/json', :content_type => 'application/json', :user_agent => Configuration::DEFAULT_USER_AGENT, Configuration::X_SPARK_API_USER_AGENT => user_agent } end |