Class: CloudConvert::Client

Inherits:
Object show all
Includes:
HTTMultiParty
Defined in:
lib/cloud_convert/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

Creates a new client with an api key. Optionally, you can also pass an array of processes.



24
25
26
27
28
29
30
# File 'lib/cloud_convert/client.rb', line 24

def initialize(args = {})
  @api_key = args[:api_key]
  args[:processes].nil? ?
    @processes = [] :
    @processes = args[:processes]
  @return_type = args[:return_type] || :json
end

Instance Attribute Details

#api_keyObject (readonly)

The api key obtained from the cloud convert service.



16
17
18
# File 'lib/cloud_convert/client.rb', line 16

def api_key
  @api_key
end

#processesObject (readonly)

An array containing references to the processes created through the client.



19
20
21
# File 'lib/cloud_convert/client.rb', line 19

def processes
  @processes
end

#return_typeObject

Returns the value of attribute return_type.



20
21
22
# File 'lib/cloud_convert/client.rb', line 20

def return_type
  @return_type
end

Instance Method Details

#build_process(opts = {}) ⇒ Object

Builds a process object and adds it to the client. Accepts the input format and output format for the conversion.



34
35
36
37
38
39
# File 'lib/cloud_convert/client.rb', line 34

def build_process(opts = {})
  opts[:client] = self
  process = CloudConvert::Process.new(opts)
  processes.push(process)
  return process
end

#listObject

Returns an array of hash with the results from the Cloud Convert list endpoint.



43
44
45
46
47
# File 'lib/cloud_convert/client.rb', line 43

def list
    url = "#{CloudConvert::PROTOCOL}://api.#{CloudConvert::DOMAIN}/processes"
    response = CloudConvert::Client.send(:get, url, query: {apikey: self.api_key})
    return convert_response response
end