Module: YandexMoney::Client::ClassMethods

Defined in:
lib/yandex_money/client.rb

Instance Method Summary collapse

Instance Method Details

#base_uri(base) ⇒ Object



8
9
10
# File 'lib/yandex_money/client.rb', line 8

def base_uri(base)
  @base_uri = base
end

#build_url(uri) ⇒ Object



39
40
41
42
43
44
45
# 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) ⇒ Object



12
13
14
# File 'lib/yandex_money/client.rb', line 12

def default_timeout(timeout)
  @default_timeout = timeout
end

#post(uri, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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