Skip to content

Commit 82c04d1

Browse files
committed
Simplify client init
1 parent c65fdd2 commit 82c04d1

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

lib/cloudconvert/client.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ class Client
77
# @param options [Hash]
88
# @return [CloudConvert::Client]
99
def initialize(options = {})
10-
@api_key = ENV["CLOUDCONVERT_API_KEY"]
11-
@sandbox = ENV["CLOUDCONVERT_SANDBOX"].to_s.downcase === "true"
12-
13-
options.each do |key, value|
14-
instance_variable_set("@#{key}", value)
15-
end
16-
1710
schema = Schemacop::Schema.new do
1811
req! :api_key, :string
1912
opt! :sandbox, :boolean, default: false
2013
end
2114

22-
schema.validate!({ api_key: api_key, sandbox: sandbox }.compact)
15+
schema.validate! options.reverse_merge!({
16+
api_key: ENV["CLOUDCONVERT_API_KEY"],
17+
sandbox: ENV["CLOUDCONVERT_SANDBOX"].to_s.downcase == "true",
18+
})
19+
20+
@api_key = options[:api_key]
21+
@sandbox = options[:sandbox]
2322
end
2423

2524
# @return [Resources::Jobs]
@@ -43,9 +42,7 @@ def users
4342
# @return [OpenStruct]
4443
def request(method, path, params = {}, &block)
4544
response = connection.send(method, path, params, &block)
46-
4745
raise CloudConvert::Error.from_response(response) unless response.success?
48-
4946
response.body unless response.body.blank?
5047
end
5148

lib/cloudconvert/resources/jobs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def create(params)
3232
payload = params.dup
3333

3434
payload[:tasks] = payload[:tasks].to_h do |task|
35-
[task[:name], task.reject { |k| k === :name }]
35+
[task[:name], task.reject { |k| k == :name }]
3636
end
3737

3838
Job.result(client.post("/v2/jobs", payload))

lib/cloudconvert/sdk.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "active_support/concern"
2+
require "active_support/core_ext/hash/reverse_merge"
23
require "down"
34
require "equalizer"
45
require "faraday"

0 commit comments

Comments
 (0)