Class: Syncano::Clients::Rest
Overview
Client used for communication with the JSON-RPC endpoint
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Attributes inherited from Base
#api_key, #auth_key, #instance_name
Instance Method Summary collapse
-
#batch {|queue| ... } ⇒ Array
Gets block in which Syncano::BatchQueue object is provided and batch requests can be executed.
-
#initialize(instance_name, api_key, auth_key = nil) ⇒ Rest
constructor
Constructor for Syncano::Clients::Rest object.
-
#login(username, password) ⇒ TrueClass, FalseClass
Gets auth_key based on username and password.
-
#make_batch_request(batch_client, resource_name, method_name, params = {}) ⇒ Object
Performs batch request to Syncano api.
-
#make_request(resource_name, method_name, params = {}, response_key = nil) ⇒ Syncano::Response
Performs request to Syncano api.
Methods inherited from Base
#admins, #api_keys, #collections, #data_objects, #folders, #logout, #projects, #roles, #users
Constructor Details
#initialize(instance_name, api_key, auth_key = nil) ⇒ Rest
Constructor for Syncano::Clients::Rest object
10 11 12 13 |
# File 'lib/syncano/clients/rest.rb', line 10 def initialize(instance_name, api_key, auth_key = nil) super(instance_name, api_key, auth_key) self.client = ::Jimson::Client.new(json_rpc_url) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/syncano/clients/rest.rb', line 5 def client @client end |
Instance Method Details
#batch {|queue| ... } ⇒ Array
Gets block in which Syncano::BatchQueue object is provided and batch requests can be executed
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/syncano/clients/rest.rb', line 51 def batch queue = ::Syncano::BatchQueue.new(client) yield(queue) queue.prune! queue.responses.collect do |response| resource_name = response.first.method.split('.').first self.class.parse_response(resource_name, response.last.result) end end |
#login(username, password) ⇒ TrueClass, FalseClass
Gets auth_key based on username and password
17 18 19 20 21 |
# File 'lib/syncano/clients/rest.rb', line 17 def login(username, password) logout self.auth_key = users.login(username, password) !self.auth_key.nil? end |
#make_batch_request(batch_client, resource_name, method_name, params = {}) ⇒ Object
Performs batch request to Syncano api
44 45 46 |
# File 'lib/syncano/clients/rest.rb', line 44 def make_batch_request(batch_client, resource_name, method_name, params = {}) batch_client.send("#{resource_name}.#{method_name}", request_params.merge(params)) end |
#make_request(resource_name, method_name, params = {}, response_key = nil) ⇒ Syncano::Response
Performs request to Syncano api
29 30 31 32 33 34 35 36 37 |
# File 'lib/syncano/clients/rest.rb', line 29 def make_request(resource_name, method_name, params = {}, response_key = nil) params.merge!(auth_key: auth_key) if auth_key.present? response_key ||= resource_name response = client.send("#{resource_name}.#{method_name}", request_params.merge(params)) response = self.class.parse_response(response_key, response) response.errors.present? ? raise(Syncano::ApiError.new(response.errors)) : response end |