Class: SYNOWebAPI::API
- Inherits:
-
Object
- Object
- SYNOWebAPI::API
- Includes:
- ErrorHandler
- Defined in:
- lib/synowebapi/api.rb
Instance Attribute Summary collapse
-
#api_name ⇒ Object
readonly
Returns the value of attribute api_name.
-
#max_version ⇒ Object
readonly
Returns the value of attribute max_version.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#min_version ⇒ Object
readonly
Returns the value of attribute min_version.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request_format ⇒ Object
readonly
Returns the value of attribute request_format.
Instance Method Summary collapse
- #download(output_path, params, options = {}) ⇒ Object
-
#initialize(api_name, client, params) ⇒ API
constructor
A new instance of API.
- #method_missing(method_name, **args, &block) ⇒ Object
- #post(params) ⇒ Object
- #request(params) ⇒ Object
Methods included from ErrorHandler
Constructor Details
#initialize(api_name, client, params) ⇒ API
Returns a new instance of API.
9 10 11 12 13 14 15 16 |
# File 'lib/synowebapi/api.rb', line 9 def initialize(api_name, client, params) @api_name = api_name @client = client @path = params['path'] @min_version = params['minVersion'] @max_version = params['maxVersion'] @request_format = params['requestFormat'] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, **args, &block) ⇒ Object
42 43 44 |
# File 'lib/synowebapi/api.rb', line 42 def method_missing(method_name, **args, &block) request({:method => method_name}.merge(args)) end |
Instance Attribute Details
#api_name ⇒ Object (readonly)
Returns the value of attribute api_name.
7 8 9 |
# File 'lib/synowebapi/api.rb', line 7 def api_name @api_name end |
#max_version ⇒ Object (readonly)
Returns the value of attribute max_version.
7 8 9 |
# File 'lib/synowebapi/api.rb', line 7 def max_version @max_version end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
7 8 9 |
# File 'lib/synowebapi/api.rb', line 7 def methods @methods end |
#min_version ⇒ Object (readonly)
Returns the value of attribute min_version.
7 8 9 |
# File 'lib/synowebapi/api.rb', line 7 def min_version @min_version end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/synowebapi/api.rb', line 7 def path @path end |
#request_format ⇒ Object (readonly)
Returns the value of attribute request_format.
7 8 9 |
# File 'lib/synowebapi/api.rb', line 7 def request_format @request_format end |
Instance Method Details
#download(output_path, params, options = {}) ⇒ Object
18 19 20 |
# File 'lib/synowebapi/api.rb', line 18 def download(output_path, params, = {}) @client.download(self, output_path, params, ) end |
#post(params) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/synowebapi/api.rb', line 22 def post(params) resp = @client.post(self, params) if resp['success'] resp['data'] else error_handling(resp['error']) end end |
#request(params) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/synowebapi/api.rb', line 32 def request(params) resp = @client.send(self, params) if resp['success'] resp['data'] else error_handling(resp['error']) end end |