module YandexMoney::Client::ClassMethods

Public Instance Methods

base_uri(base) click to toggle source
# File lib/yandex_money/client.rb, line 8
def base_uri(base)
  @base_uri = base
end
build_url(uri) click to toggle source
# File lib/yandex_money/client.rb, line 39
def build_url(uri)
  if @base_uri.nil?
    uri.to_s
  else
    URI.join(@base_uri, uri).to_s
  end
end
default_timeout(timeout) click to toggle source
# File lib/yandex_money/client.rb, line 12
def default_timeout(timeout)
  @default_timeout = timeout
end
post(uri, options = {}) click to toggle source
# File lib/yandex_money/client.rb, line 16
def post(uri, options = {})
  conn = Faraday.new(build_url(uri)) do |conn|
    conn.response :json, :content_type => /\bjson$/

    conn.adapter Faraday.default_adapter
  end

  conn.post do |req|
    if options[:headers].is_a?(Hash)
      options[:headers].each do |key, value|
        req[key] = value
      end
    end

    if options[:body]
      case req.headers['Content-Type']
      when 'application/x-www-form-urlencoded'
        req.body = URI.encode_www_form(options[:body])
      end
    end
  end
end