Sha256: e812b0b474a5f1158307784d60a0ef5687ac54b8b8ca455b4c362bdd29a9d87a

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module ActionKitRest
  class API < Vertebrae::API

    def request(*args)
      ActionKitRest::Response::Wrapper.new( super(*args) )
    end

    def post_json_request(path, params)
      p = {}
      p['data'] = params.to_json
      post_request(path, p)
    end

    def put_json_request(path, params)
      p = {}
      p['data'] = params.to_json
      put_request(path, p)
    end

    def extract_data_from_params(params) # :nodoc:
      if params.has_key?('data') && params['data'].present?
        return params['data']
      else
        return params
      end
    end

    def default_options
      {
        user_agent: 'ActionKitRestGem',
        prefix: '/rest/v1',
        content_type: 'application/json; charset=utf-8'
      }
    end

    def setup
      connection.stack do |builder|
        builder.use Faraday::Request::Multipart
        builder.use Faraday::Request::UrlEncoded
        builder.use Vertebrae::Request::BasicAuth, connection.configuration.authentication if connection.configuration.authenticated?

        builder.use Faraday::Response::Logger if ENV['DEBUG']

        builder.use FaradayMiddleware::Mashify
        builder.use FaradayMiddleware::ParseJson

        builder.use  ActionKitRest::Response::RaiseError
        builder.adapter connection.configuration.adapter
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
action_kit_rest-0.3.7 lib/action_kit_rest/api.rb
action_kit_rest-0.3.6 lib/action_kit_rest/api.rb
action_kit_rest-0.3.5 lib/action_kit_rest/api.rb
action_kit_rest-0.3.4 lib/action_kit_rest/api.rb