Class: Sonycam::API
- Inherits:
-
Object
- Object
- Sonycam::API
- Defined in:
- lib/sonycam/api.rb
Instance Method Summary collapse
-
#initialize(api_url) ⇒ API
constructor
A new instance of API.
-
#request(method, *params, **options) ⇒ Object
id property of JSON-RPC seems to be totally useless over HTTP since it’s request-response pattern.
Constructor Details
#initialize(api_url) ⇒ API
Returns a new instance of API.
6 7 8 9 |
# File 'lib/sonycam/api.rb', line 6 def initialize api_url @uri = URI(api_url) @http = Net::HTTP.start(@uri.host, @uri.port) end |
Instance Method Details
#request(method, *params, **options) ⇒ Object
id property of JSON-RPC seems to be totally useless over HTTP since it’s request-response pattern.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sonycam/api.rb', line 12 def request method, *params, ** json = {method: method, params: params, id: 1, version: '1.0'}.merge!().to_json ret = JSON.parse(@http.request_post(@uri.path, json).body) if ret['error'] error_code, = ret['error'] raise Sonycam::Error.make(error_code), else ret['result'] end end |