Class: BtsyncApi::Api
- Inherits:
-
Object
- Object
- BtsyncApi::Api
- Defined in:
- lib/btsync/api.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #execute(method, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Api
constructor
A new instance of Api.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Api
Returns a new instance of Api.
15 16 17 |
# File 'lib/btsync/api.rb', line 15 def initialize( = {}) self.settings = default_settings.merge() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/btsync/api.rb', line 29 def method_missing(method, *args, &block) begin if args.count == 1 return execute(method, args[0]) else return execute(method) end rescue BtsyncApi::ApiError => e if e.error_code != 1 # not found raise e end end super end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
13 14 15 |
# File 'lib/btsync/api.rb', line 13 def settings @settings end |
Instance Method Details
#execute(method, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/btsync/api.rb', line 19 def execute(method, = {}) params = {method: method.to_s} params.merge!() response = do_request(params) if response['error'] && response['error'] != 0 raise BtsyncApi::ApiError.new(response['error']), response['message'] end response end |