Class: Sandcage::Client
- Inherits:
-
Object
- Object
- Sandcage::Client
- Includes:
- HTTParty
- Defined in:
- lib/sandcage/client.rb
Constant Summary collapse
- TIMEOUT =
30
Instance Method Summary collapse
-
#call_endpoint(endpoint, post = false, data = nil) ⇒ Object
The call_endpoint method.
-
#destroy_files_service(payload = nil, callback_endpoint = nil) ⇒ Object
The “destroy-files” service.
-
#get_info_service(payload = nil) ⇒ Object
The “get-info” service.
-
#initialize(api_key = nil) ⇒ Client
constructor
Give your SandCage API Key as a constructor parameter This can be retrieved from www.sandcage.com/panel/api_key.
-
#list_files_service(payload = nil) ⇒ Object
The “list-files” service.
-
#schedule_files_service(payload = nil, callback_endpoint = nil) ⇒ Object
The “schedule-tasks” service.
Constructor Details
#initialize(api_key = nil) ⇒ Client
Give your SandCage API Key as a constructor parameter This can be retrieved from www.sandcage.com/panel/api_key
22 23 24 25 |
# File 'lib/sandcage/client.rb', line 22 def initialize(api_key=nil) @api_key = api_key @sandcage_api_endpoint = "#{Sandcage::API_ROOT}/#{Sandcage::API_VERSION}/" end |
Instance Method Details
#call_endpoint(endpoint, post = false, data = nil) ⇒ Object
The call_endpoint method. This method sends http request to the endpoint.
First parameter “endpoint” (string) is the url of the endpoint. Second parameter “post” (boolean) indicates the http method type. true => POST false => GET Third parameter “data” (hash) is the data to be sent. Method’s return type is HTTParty::Response object.
36 37 38 39 40 41 42 |
# File 'lib/sandcage/client.rb', line 36 def call_endpoint(endpoint, post=false, data=nil) if post r = self.class.post(endpoint, body: data.to_json) else r = self.class.get(endpoint) end end |
#destroy_files_service(payload = nil, callback_endpoint = nil) ⇒ Object
The “destroy-files” service
First parameter “payload” (hash) contains the data to be sent. Second parameter “callback_endpoint” (string) is the url, where the callback should be send to. Method’s return type is HTTParty::Response object.
70 71 72 73 74 75 76 |
# File 'lib/sandcage/client.rb', line 70 def destroy_files_service(payload=nil, callback_endpoint=nil) data = get_post_data(payload) update_callback data, callback_endpoint call_endpoint("#{@sandcage_api_endpoint}destroy-files", post=true, data=data) end |
#get_info_service(payload = nil) ⇒ Object
The “get-info” service
First parameter “payload” (hash) contains the data to be sent. Method’s return type is HTTParty::Response object.
48 49 50 51 52 |
# File 'lib/sandcage/client.rb', line 48 def get_info_service(payload=nil) call_endpoint("#{@sandcage_api_endpoint}get-info", post=true, data=get_post_data(payload)) end |
#list_files_service(payload = nil) ⇒ Object
The “list-files” service
First parameter “payload” (dictionary) contains the data to be sent. Method’s return type is HTTParty::Response object.
58 59 60 61 62 |
# File 'lib/sandcage/client.rb', line 58 def list_files_service(payload=nil) call_endpoint("#{@sandcage_api_endpoint}list-files", post=true, data=get_post_data(payload)) end |
#schedule_files_service(payload = nil, callback_endpoint = nil) ⇒ Object
The “schedule-tasks” service
First parameter “payload” (hash) contains the data to be sent. Second parameter “callback_endpoint” (string) is the url, where the callback should be send to. Method’s return type is HTTParty::Response object.
84 85 86 87 88 89 90 |
# File 'lib/sandcage/client.rb', line 84 def schedule_files_service(payload=nil, callback_endpoint=nil) data = get_post_data(payload) update_callback data, callback_endpoint call_endpoint("#{@sandcage_api_endpoint}schedule-tasks", post=true, data=data) end |