Class: Mpayer::Payable

Inherits:
Endpoint show all
Defined in:
lib/mpayer_ruby/endpoints/payable.rb

Instance Attribute Summary

Attributes inherited from Endpoint

#attributes, #config, #endpoint, #id, #pagination, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

#initialize, #success?

Constructor Details

This class inherits a constructor from Mpayer::Endpoint

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mpayer::Endpoint

Class Method Details

.all(page: 1, per_page: 100) ⇒ Object

Mpayer::Payable.all



7
8
9
10
# File 'lib/mpayer_ruby/endpoints/payable.rb', line 7

def all(page:1,per_page:100)
	url = "/payables/all"
	Mpayer::Fetch.get(url,query:{page:page,per_page:per_page})
end

.create(options = {}) ⇒ Object

Mpayer::Payable.create(options)



27
28
29
30
31
# File 'lib/mpayer_ruby/endpoints/payable.rb', line 27

def create(options={})
	url = "/payables"
	response = Mpayer::Fetch.post(url,options)
	payable = new(options.merge!(id:response.id ,response:response)) rescue response
end

.find(payable_id, fetch: true) ⇒ Object

Mpayer::Payable.find(id)



13
14
15
16
17
# File 'lib/mpayer_ruby/endpoints/payable.rb', line 13

def find(payable_id,fetch:true)
	url = "/payables/#{payable_id}"
	response = Mpayer::Fetch.get(url) if fetch
	payable = new(id:payable_id,response:response)
end

.where(ref_id:, fetch: true) ⇒ Object



20
21
22
23
24
# File 'lib/mpayer_ruby/endpoints/payable.rb', line 20

def where(ref_id:,fetch:true)
	url = "/payables/search/#{CGI.escape(ref_id.to_s)}"
	response = Mpayer::Fetch.get(url) if fetch
	payable = new(id:response.id,response:response) rescue response
end

Instance Method Details

#destroyObject



34
35
36
37
38
# File 'lib/mpayer_ruby/endpoints/payable.rb', line 34

def destroy
	url = "/payables/#{self.id}"
	self.response = Mpayer::Fetch.delete(url)
	self.kill
end