Class: CloudConvert::Client
- Inherits:
-
Object
- Object
- CloudConvert::Client
- Defined in:
- lib/cloudconvert/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#sandbox ⇒ Object
readonly
Returns the value of attribute sandbox.
Instance Method Summary collapse
- #api_host ⇒ String
- #api_sync_host ⇒ String
- #delete(path, params = {}, &block) ⇒ OpenStruct
- #download(url, *args, **options) ⇒ Tempfile
- #get(path, params = {}, &block) ⇒ OpenStruct
-
#initialize(options = {}) ⇒ CloudConvert::Client
constructor
Initializes a new Client object.
- #jobs ⇒ Resources::Jobs
- #post(path, params = {}, &block) ⇒ OpenStruct
- #request(method, path, params = {}, &block) ⇒ OpenStruct
- #tasks ⇒ Resources::Tasks
- #users ⇒ Resources::Users
Constructor Details
#initialize(options = {}) ⇒ CloudConvert::Client
Initializes a new Client object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cloudconvert/client.rb', line 9 def initialize( = {}) schema = Schemacop::Schema.new do req! :api_key, :string opt! :sandbox, :boolean, default: false end schema.validate! .reverse_merge!({ api_key: ENV["CLOUDCONVERT_API_KEY"], sandbox: ENV["CLOUDCONVERT_SANDBOX"].to_s.downcase == "true", }) @api_key = [:api_key] @sandbox = [:sandbox] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/cloudconvert/client.rb', line 3 def api_key @api_key end |
#sandbox ⇒ Object (readonly)
Returns the value of attribute sandbox.
3 4 5 |
# File 'lib/cloudconvert/client.rb', line 3 def sandbox @sandbox end |
Instance Method Details
#api_host ⇒ String
79 80 81 |
# File 'lib/cloudconvert/client.rb', line 79 def api_host @api_host ||= sandbox ? SANDBOX_URL : API_URL end |
#api_sync_host ⇒ String
84 85 86 |
# File 'lib/cloudconvert/client.rb', line 84 def api_sync_host @api_sync_host ||= sandbox ? SANDBOX_SYNC_URL : API_SYNC_URL end |
#delete(path, params = {}, &block) ⇒ OpenStruct
66 67 68 |
# File 'lib/cloudconvert/client.rb', line 66 def delete(path, params = {}, &block) request(:delete, path, params, &block) end |
#download(url, *args, **options) ⇒ Tempfile
72 73 74 75 76 |
# File 'lib/cloudconvert/client.rb', line 72 def download(url, *args, **) [:headers] ||= {} [:headers]["User-Agent"] = USER_AGENT Down.download(url, *args, **) end |
#get(path, params = {}, &block) ⇒ OpenStruct
52 53 54 |
# File 'lib/cloudconvert/client.rb', line 52 def get(path, params = {}, &block) request(:get, path, params, &block) end |
#jobs ⇒ Resources::Jobs
25 26 27 |
# File 'lib/cloudconvert/client.rb', line 25 def jobs @jobs ||= Resources::Jobs.new(self) end |
#post(path, params = {}, &block) ⇒ OpenStruct
59 60 61 |
# File 'lib/cloudconvert/client.rb', line 59 def post(path, params = {}, &block) request(:post, path, params, &block) end |
#request(method, path, params = {}, &block) ⇒ OpenStruct
43 44 45 46 47 |
# File 'lib/cloudconvert/client.rb', line 43 def request(method, path, params = {}, &block) response = connection.send(method, path, params, &block) raise CloudConvert::Error.from_response(response) unless response.success? response.body unless response.body.blank? end |
#tasks ⇒ Resources::Tasks
30 31 32 |
# File 'lib/cloudconvert/client.rb', line 30 def tasks @tasks ||= Resources::Tasks.new(self) end |
#users ⇒ Resources::Users
35 36 37 |
# File 'lib/cloudconvert/client.rb', line 35 def users @users ||= Resources::Users.new(self) end |