class Sandcage::Client

Constants

TIMEOUT

Public Class Methods

new(api_key=nil) click to toggle source

Give your SandCage API Key as a constructor parameter This can be retrieved from www.sandcage.com/panel/api_key

# 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

Public Instance Methods

call_endpoint(endpoint, post=false, data=nil) click to toggle source

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.

# 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) click to toggle source

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.

# 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) click to toggle source

The “get-info” service

First parameter “payload” (hash) contains the data to be sent. Method's return type is HTTParty::Response object.

# 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) click to toggle source

The “list-files” service

First parameter “payload” (dictionary) contains the data to be sent. Method's return type is HTTParty::Response object.

# 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) click to toggle source

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.

# 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

Private Instance Methods

get_post_data(payload=nil) click to toggle source

Combine payload with API KEY and return the dictionary.

# File lib/sandcage/client.rb, line 95
def get_post_data(payload=nil)
  d = { key: @api_key }
  if payload
    d.update payload
  end
  return d
end
update_callback(data, callback_endpoint=nil) click to toggle source

Update data with callback_endpoint address.

# File lib/sandcage/client.rb, line 104
def update_callback(data, callback_endpoint=nil)
  if callback_endpoint
    data[:callback_endpoint] = callback_endpoint
  end
end