class ZipMoney::Resources

Constants

RESOURCE_CANCEL
RESOURCE_CAPTURE
RESOURCE_CHECKOUT
RESOURCE_CONFIGURE
RESOURCE_HEART_BEAT
RESOURCE_QUERY
RESOURCE_QUOTE
RESOURCE_REFUND
RESOURCE_SETTINGS

Public Class Methods

get(resource, method = :post, query_string = nil) click to toggle source

Checks if passed resource is valid and returns RestClient::Resource object configured with the passed resource and url

@param [resource] endpoint resource @param [method] method get|post @param [query_string] query_string parameters

@return RestClient::Resource object

# File lib/zipMoney/resources.rb, line 23
def get(resource, method = :post, query_string = nil)
  return false unless resource_exists(resource)
  url = get_url(resource, (method == :get ? query_string : nil))
  ssl_opts = {:verify_ssl => OpenSSL::SSL::VERIFY_PEER}
  opts = {}
  RestClient::Resource.new(url, opts.merge(ssl_opts))
end
get_url(resource, query_string = nil) click to toggle source

Builds the proper endpoint url with the given resource

@param [resource] endpoint resource @param [query_string] query_string parameters

@return String

# File lib/zipMoney/resources.rb, line 52
def get_url(resource, query_string = nil)
  if Configuration.is_sandbox
    url = "#{Configuration::ENV_TEST_API_URL}"
  else
    url = "#{Configuration::ENV_LIVE_API_URL}"
  end   

  url =   url + resource

  unless query_string.nil?
    url = url + "?" + 
    query_string.map do |key, value|
      "#{key}=#{value}" 
    end.join("&")
  end
  url
end
resource_exists(resource) click to toggle source

Checks if passed resource exists

@param [resource] endpoint resource

@return ZipMoney::Response object

# File lib/zipMoney/resources.rb, line 36
def resource_exists(resource)
  if resource.is_a?(String)
    if self.constants.map{ |k| self.const_get(k).downcase }.include?resource 
      resource
    end  
  else
    raise ArgumentError, "#{resource} should be a string"
  end
end