Module: FinAppsCore::REST::Connection
- Included in:
- BaseClient
- Defined in:
- lib/finapps_core/rest/connection.rb
Overview
:nodoc:
Instance Method Summary collapse
- #connection_options(config) ⇒ Object
- #faraday(config, logger) ⇒ Faraday::Connection
- #init_connection_auth(conn, config) ⇒ Object
- #init_connection_request(conn, config) ⇒ Object
- #init_connection_response(conn, logger) ⇒ Object
Instance Method Details
#connection_options(config) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/finapps_core/rest/connection.rb', line 51 def (config) { url: "#{config.host}/v#{Defaults::API_VERSION}/", request: {open_timeout: config.timeout, timeout: config.timeout} } end |
#faraday(config, logger) ⇒ Faraday::Connection
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/finapps_core/rest/connection.rb', line 7 def faraday(config, logger) = config Faraday.new() do |conn| conn.use FinAppsCore::Middleware::RaiseError init_connection_request conn, config init_connection_response conn, logger init_connection_auth conn, config # Adapter (ensure that the adapter is always last.) conn.adapter Faraday.default_adapter end end |
#init_connection_auth(conn, config) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/finapps_core/rest/connection.rb', line 43 def init_connection_auth(conn, config) if config.valid_user_credentials? conn.request :no_encoding_basic_authentication, config.user_token else conn.request :tenant_authentication, config.tenant_token end end |
#init_connection_request(conn, config) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/finapps_core/rest/connection.rb', line 31 def init_connection_request(conn, config) conn.request :accept_json conn.request :user_agent conn.request :x_consumer_id, config.consumer_id if config.consumer_id conn.request :x_tenant_id, config.tenant_id if config.tenant_id conn.request :json conn.request :retry conn.request :multipart conn.request :url_encoded conn.request :request_id, config.request_id if config.request_id end |
#init_connection_response(conn, logger) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/finapps_core/rest/connection.rb', line 21 def init_connection_response(conn, logger) conn.response :json, content_type: /\bjson$/, parser_options: {symbolize_names: true} conn.response :logger, logger, bodies: true, headers: true, formatter: FinAppsCore::Logging::ContenTypeFormatter, log_level: :debug end |