module PS::Api
Public Instance Methods
camel_case_request(params)
click to toggle source
Paysimple expects the attribute names to be in CamelCase, but that isn't very ruby-esque; so, in an effort to be more ruby-esque, we define and work with the attributes in snake case. The method bellow converts from the ruby-esque snake case to PS' CamelCase.
# File lib/ps/api.rb, line 63 def camel_case_request(params) params.each { |key, value| value.camel_case_keys if value.class == Hash } end
connect(format)
click to toggle source
Establishes the connection to the appropriate paysimple v3 api. Defaults to JSON
# File lib/ps/api.rb, line 6 def connect(format) format ||= "JSON" begin require "ps/api/#{format.downcase}" rescue LoadError raise ConnectionError, "#{format} is not a supported format" end $api = PS::Api.const_get(format.downcase.capitalize).new end
connection_hash()
click to toggle source
# File lib/ps/api.rb, line 32 def connection_hash { :apikey => $api.apikey, :userkey => $api.userkey, :company_name => $api.company_name, :host => host() } end
date?(object)
click to toggle source
returns the conditions for detecting if something is a date format for the current format class
# File lib/ps/api.rb, line 70 def date?(object) $api.date?(object) end
env()
click to toggle source
# File lib/ps/api.rb, line 46 def env $api.env end
host()
click to toggle source
TODO: make constants
# File lib/ps/api.rb, line 51 def host if env() == "development" then "https://sandbox-api.paysimple.com/3.00/paysimpleapi" elsif env() == "production" then "https://api.paysimple.com/3.00/paysimpleapi" end end
parse_date(date)
click to toggle source
How to parse dates for thi current format
# File lib/ps/api.rb, line 76 def parse_date(date) $api.parse_date(date) end
request(method, params={}, &block)
click to toggle source
# File lib/ps/api.rb, line 41 def request(method, params={}, &block) response = Response.new($api.request(method, camel_case_request(params))) block[response] if block end
required_attributes()
click to toggle source
# File lib/ps/api.rb, line 26 def required_attributes $api.instance_variables.map do |instance_variable| instance_variable.to_s[1..-1].to_sym end end
validate_and_assign(params)
click to toggle source
# File lib/ps/api.rb, line 16 def validate_and_assign(params) required_attributes().each do |key| if params.key?(key) then $api.instance_variable_set("@#{key.to_s}", params[key]) else raise ArgumentError, "Missing required attribute: #{key}" end end end