Sha256: 13ecd1540b2f09e0ad5f6f9d7025b4173665abead083ed101f069cb45f95f89a

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

module Mollie
	module API
		module Resource
			class Base
				def initialize (client)
					@client = client
				end

				def getResourceName ()
					self.class.name.downcase.split("::").slice(3..-1).join "/"
				end

				def create (data = {})
					request("POST", nil, data) { |response|
						newResourceObject response
					}
				end

				def get (id)
					request("GET", id, {}) { |response| 
						newResourceObject response
					}
				end

				def update (id, data = {})
					request("POST", id, data) { |response|
						newResourceObject response
					}
				end

				def delete (id)
					request "DELETE", id, {}
				end

				def all ()
					request("GET", nil, {}) { |response|
						Mollie::API::Object::List.new response, getResourceObject
					}
				end
				
				def newResourceObject (response)
					getResourceObject.new response
				end
				
				def request (method, id = 0, data = {})
					response = @client.performHttpCall method, getResourceName, id, data

					yield(response) if block_given?
				end
			end
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mollie-api-ruby-1.1.2 lib/Mollie/API/Resource/Base.rb
mollie-api-ruby-1.1.1 lib/Mollie/API/Resource/Base.rb
mollie-api-ruby-1.1.0 lib/Mollie/API/Resource/Base.rb