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

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
32
# File 'lib/mpayer_ruby/endpoints/payable.rb', line 27

def create(options={})
	url = "/payables"
	response = Mpayer::Fetch.post(url,options)
	payable_id = response.id 
	payable = new(options.merge!(id:payable_id,response: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) unless (response.id rescue nil).nil?
end

Instance Method Details

#destroyObject



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

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