Module: FmRest::V1::Connection
- Included in:
- FmRest::V1
- Defined in:
- lib/fmrest/v1/connection.rb
Constant Summary collapse
- BASE_PATH =
"/fmi/data/v1/databases"
Instance Method Summary collapse
-
#base_connection(options = FmRest.default_connection_settings, &block) ⇒ Faraday
Builds a base Faraday connection with base URL constructed from connection options and passes it the given block.
-
#build_connection(options = FmRest.default_connection_settings, &block) ⇒ Faraday
Builds a complete DAPI Faraday connection with middleware already configured to handle authentication, JSON parsing, logging and DAPI error handling.
Instance Method Details
#base_connection(options = FmRest.default_connection_settings, &block) ⇒ Faraday
Builds a base Faraday connection with base URL constructed from connection options and passes it the given block
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fmrest/v1/connection.rb', line 60 def base_connection( = FmRest.default_connection_settings, &block) host = .fetch(:host) # Default to HTTPS scheme = "https" if host.match(/\Ahttps?:\/\//) uri = URI(host) host = uri.hostname host += ":#{uri.port}" if uri.port != uri.default_port scheme = uri.scheme end = {} [:ssl] = [:ssl] if .key?(:ssl) [:proxy] = [:proxy] if .key?(:proxy) Faraday.new( "#{scheme}://#{host}#{BASE_PATH}/#{URI.escape(.fetch(:database))}/".freeze, , &block ) end |
#build_connection(options = FmRest.default_connection_settings, &block) ⇒ Faraday
Builds a complete DAPI Faraday connection with middleware already configured to handle authentication, JSON parsing, logging and DAPI error handling. A block can be optionally given for additional middleware configuration
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fmrest/v1/connection.rb', line 21 def build_connection( = FmRest.default_connection_settings, &block) base_connection() do |conn| conn.use RaiseErrors conn.use TokenSession, # The EncodeJson and Multipart middlewares only encode the request # when the content type matches, so we can have them both here and # still play nice with each other, we just need to set the content # type to multipart/form-data when we want to submit a container # field conn.request :multipart conn.request :json # Allow overriding the default response middleware if block_given? yield conn, else conn.use TypeCoercer, conn.response :json end if [:log] conn.response :logger, nil, bodies: true, headers: true end conn.adapter Faraday.default_adapter end end |