module PayU::Resource::ClassMethods

Public Instance Methods

client() click to toggle source
# File lib/pay_u/resource.rb, line 48
def client
  @client ||= PayU::Client.instance
end
create(params) click to toggle source
# File lib/pay_u/resource.rb, line 73
def create(params)
  resource = new(params)

  response = client.post resource.create_url, params: resource.to_params

  new_from_api(response)
end
new_from_api(params) click to toggle source
# File lib/pay_u/resource.rb, line 53
def new_from_api(params)
  resource = new

  resource.attributes = params.inject({}) do |memo, (key, value)|
    local_key = key.to_underscore.to_sym

    resource.respond_to?(local_key) ? memo.merge(local_key => value) : memo
  end

  resource
end
retrieve(identifier) click to toggle source
# File lib/pay_u/resource.rb, line 66
def retrieve(identifier)
  response = client.get "#{self::ENDPOINT}/#{identifier}"

  new_from_api(response)
end