Module: PayU::Resource::ClassMethods
- Defined in:
- lib/pay_u/resource.rb
Instance Method Summary collapse
- #client ⇒ Object
- #create(params) ⇒ Object
- #new_from_api(params) ⇒ Object
- #retrieve(identifier) ⇒ Object
Instance Method Details
#client ⇒ Object
48 49 50 |
# File 'lib/pay_u/resource.rb', line 48 def client @client ||= PayU::Client.instance end |
#create(params) ⇒ Object
73 74 75 76 77 78 79 |
# 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) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
66 67 68 69 70 |
# File 'lib/pay_u/resource.rb', line 66 def retrieve(identifier) response = client.get "#{self::ENDPOINT}/#{identifier}" new_from_api(response) end |