Class: MyCashflow::Client
- Inherits:
-
Object
- Object
- MyCashflow::Client
show all
- Includes:
- HTTParty
- Defined in:
- lib/mycashflow/client.rb
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/mycashflow/client.rb', line 5
def initialize(config = {})
@path_parts = []
@username = config[:username] || ENV['MYCASHFLOW_USERNAME']
@password = config[:password] || ENV['MYCASHFLOW_PASSWORD']
@base_url = config[:base_url] || ENV['MYCASHFLOW_BASE_URL']
self.class.base_uri(@base_url)
self.class.({ 'Accept' => 'application/json' })
self.class.basic_auth(@username, @password)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/mycashflow/client.rb', line 16
def method_missing(method, *args)
@path_parts << method.to_s.gsub('_', '-').downcase
@path_parts << args if args.length > 0
@path_parts.flatten!
self
end
|
Instance Method Details
#create(params = {}) ⇒ Object
37
38
39
40
41
|
# File 'lib/mycashflow/client.rb', line 37
def create(params = {})
self.class.create(path, params)
ensure
reset
end
|
#delete(params = {}) ⇒ Object
49
50
51
52
53
|
# File 'lib/mycashflow/client.rb', line 49
def delete(params = {})
self.class.delete(path, params)
ensure
reset
end
|
#get(params = {}) ⇒ Object
31
32
33
34
35
|
# File 'lib/mycashflow/client.rb', line 31
def get(params = {})
self.class.get(path)
ensure
reset
end
|
#path ⇒ Object
23
24
25
|
# File 'lib/mycashflow/client.rb', line 23
def path
"/#{@path_parts.join('/')}"
end
|
#reset ⇒ Object
27
28
29
|
# File 'lib/mycashflow/client.rb', line 27
def reset
@path_parts = []
end
|
#update(params = {}) ⇒ Object
43
44
45
46
47
|
# File 'lib/mycashflow/client.rb', line 43
def update(params = {})
self.class.update(path, params)
ensure
reset
end
|