Sha256: dbe4819df34dedff5dedcdcd26ac9d2b1ca631764449b2d82ed1fe8b28ff8dd0

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module CirroIO
  module Client
    class Base < JsonApiClient::Resource
      self.route_format = :dasherized_route
      self.json_key_format = :dasherized_key

      # https://github.com/JsonApiClient/json_api_client/issues/215
      def self.site=(url)
        super(url)
        connection.faraday.url_prefix = url
      end

      def self.custom_post(endpoint, payload)
        custom_connection.post(endpoint, payload.to_json)
      end

      def self.custom_connection
        Faraday.new(url: "#{CirroIO::Client.configuration.site}/#{CirroIO::Client.configuration.api_version}") do |conn|
          conn.request :json
          conn.response :json
          conn.use CirroIO::Client::JwtAuthentication
          conn.use JsonApiClient::Middleware::Status, {}
        end
      end
    end
  end
end

CirroIO::Client::Base.connection do |connection|
  connection.use CirroIO::Client::JwtAuthentication
  connection.use Faraday::Response::Logger
  # connection.use CirroIO::Client::ResponseDebuggingMiddleware # This middleware can be injected during debugging or while adding new specs
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cirro-ruby-client-1.4.0 lib/cirro_io/client/base.rb
cirro-ruby-client-1.3.0 lib/cirro_io/client/base.rb
cirro-ruby-client-1.2.3 lib/cirro_io/client/base.rb
cirro-ruby-client-1.2.2 lib/cirro_io/client/base.rb
cirro-ruby-client-1.2.1 lib/cirro_io/client/base.rb
cirro-ruby-client-1.2.0 lib/cirro_io/client/base.rb
cirro-ruby-client-1.1.0 lib/cirro_io/client/base.rb