Class: SYNOWebAPI::API

Inherits:
Object
  • Object
show all
Includes:
ErrorHandler
Defined in:
lib/synowebapi/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ErrorHandler

#error_handling

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_nameObject (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_versionObject (readonly)

Returns the value of attribute max_version.



7
8
9
# File 'lib/synowebapi/api.rb', line 7

def max_version
  @max_version
end

#methodsObject (readonly)

Returns the value of attribute methods.



7
8
9
# File 'lib/synowebapi/api.rb', line 7

def methods
  @methods
end

#min_versionObject (readonly)

Returns the value of attribute min_version.



7
8
9
# File 'lib/synowebapi/api.rb', line 7

def min_version
  @min_version
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/synowebapi/api.rb', line 7

def path
  @path
end

#request_formatObject (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, options = {})
  @client.download(self, output_path, params, options)
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