Module: MagnumPI::API::Consumer
- Defined in:
- lib/magnum-pi/api/consumer.rb
Defined Under Namespace
Classes: Error
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
31
32
33
|
# File 'lib/magnum-pi/api/consumer.rb', line 31
def method_missing(name, *args)
resources[name.to_sym] ? resource(name, *args) : super
end
|
Instance Method Details
#download(target, method, *args) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/magnum-pi/api/consumer.rb', line 16
def download(target, method, *args)
url, params = parse_args *args
File.delete target if File.exists? target
request(method, url, params).save_as target
true
end
|
#get(*args) ⇒ Object
6
7
8
9
|
# File 'lib/magnum-pi/api/consumer.rb', line 6
def get(*args)
url, params = parse_args *args
parse_content request(:get, url, params).content
end
|
#post(*args) ⇒ Object
11
12
13
14
|
# File 'lib/magnum-pi/api/consumer.rb', line 11
def post(*args)
url, params = parse_args *args
parse_content request(:post, url, params).content
end
|
#resource(name, variables = {}, save_as = nil) ⇒ Object
23
24
25
26
27
|
# File 'lib/magnum-pi/api/consumer.rb', line 23
def resource(name, variables = {}, save_as = nil)
args = parse_resource_variables(resources[name], variables)
args = [:download, save_as].concat args if save_as
send *args
end
|