module Payture::Request

Public Instance Methods

delete(path, options={}, raw=false, unformatted=false, no_response_wrapper=false) click to toggle source
# File lib/payture/request.rb, line 16
def delete(path, options={}, raw=false, unformatted=false, no_response_wrapper=false)
  request(:delete, path, options, raw, unformatted, no_response_wrapper)
end
get(path, options={}, raw=false, unformatted=false, no_response_wrapper=false) click to toggle source
# File lib/payture/request.rb, line 4
def get(path, options={}, raw=false, unformatted=false, no_response_wrapper=false)
  request(:get, path, options, raw, unformatted, no_response_wrapper)
end
post(path, options={}, raw=false, unformatted=false, no_response_wrapper=false) click to toggle source
# File lib/payture/request.rb, line 8
def post(path, options={}, raw=false, unformatted=false, no_response_wrapper=false)
  request(:post, path, options, raw, unformatted, no_response_wrapper)
end
put(path, options={}, raw=false, unformatted=false, no_response_wrapper=false) click to toggle source
# File lib/payture/request.rb, line 12
def put(path, options={}, raw=false, unformatted=false, no_response_wrapper=false)
  request(:put, path, options, raw, unformatted, no_response_wrapper)
end

Private Instance Methods

convert_to_camelcase(hash) click to toggle source
# File lib/payture/request.rb, line 42
def convert_to_camelcase hash
  hash.map{|k,v| "#{to_camelcase(k)}=#{v}"}
end
encoded_string(hash) click to toggle source
# File lib/payture/request.rb, line 37
def encoded_string hash
  h = convert_to_camelcase hash
  CGI.escape h.join(';')
end
formatted_path(path) click to toggle source
# File lib/payture/request.rb, line 59
def formatted_path(path)
  [path, format].compact.join('.')
end
hash_to_camelcase(hash) click to toggle source
# File lib/payture/request.rb, line 46
def hash_to_camelcase hash
  Hash[hash.map {|k, v| [to_camelcase(k.capitalize), v] }]
end
request(method, path, options, raw=false, unformatted=false, no_response_wrapper=false) click to toggle source
# File lib/payture/request.rb, line 22
def request(method, path, options, raw=false, unformatted=false, no_response_wrapper=false)
  response = connection(raw).send(method) do |request|
    case method
    when :get, :delete
      request.url(path, 'DATA' => encoded_string(options))
    when :post, :put
      request.path = path
      request.body = options unless options.empty?
    end
  end
  return response if raw
  return response.body if no_response_wrapper
  return Response.create( response.body )
end
to_camelcase(key) click to toggle source
# File lib/payture/request.rb, line 50
def to_camelcase(key)
  key = key.to_s
  if key.split('_').count > 1
    key.split('_').collect(&:capitalize).join
  else
    key
  end
end