Sha256: 66a0e18defc42545fdedc54c15b5255b9afd4cba974b2d2a1eef4988f10a02d0

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module Yandex
  module Market
    module Connection
      def get(url, options = {})
        request :get, url, options
      end

      def call
        connection(
          url: Content.configuration.resource_url,
          version: Content.configuration.version
        )
      end

      def connection(url:, version:)
        url = [url, version].join('/')
        Faraday.new(url) do |builder|
          builder.request  :url_encoded
          builder.response :logger
          builder.adapter  Faraday.default_adapter
        end
      end

      private

      def request(method, path, data)
        response = call.send(method, path, data) do |req|
          req.headers['Content-Type'] = 'application/json'
          req.headers['Authorization'] = authorization_token(data)
        end

        response = JSON.parse(response.body)
        Hashie::Mash.new(response)
      end

      def authorization_token(option)
        option[:token] ||= Content.configuration.authorization_token
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yandex_market_content-0.4.0 lib/yandex/market/content/connection.rb
yandex_market_content-0.3.0 lib/yandex/market/content/connection.rb
yandex_market_content-0.2.0 lib/yandex/market/content/connection.rb