zencoder 2.1.8 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/zencoder/job.rb CHANGED
@@ -2,7 +2,7 @@ class Zencoder
2
2
  class Job < Zencoder
3
3
 
4
4
  def self.create(params={}, options={})
5
- params = {:api_key => api_key}.merge(params) if api_key
5
+ params = apply_api_key(params, options[:format])
6
6
  HTTP.post("#{base_url}/jobs",
7
7
  encode(params, options[:format]),
8
8
  options)
@@ -1,3 +1,3 @@
1
1
  class Zencoder
2
- VERSION = '2.1.8'
2
+ VERSION = '2.1.9'
3
3
  end
@@ -9,7 +9,11 @@ class Zencoder
9
9
  if content.is_a?(String)
10
10
  content
11
11
  elsif format.to_s == 'xml'
12
- content.to_xml
12
+ if content.is_a?(Hash) && content.keys.size == 1
13
+ content[content.keys.first].to_xml(:root => content.keys.first)
14
+ else
15
+ content.to_xml
16
+ end
13
17
  else
14
18
  content.to_json
15
19
  end
@@ -38,6 +42,29 @@ class Zencoder
38
42
 
39
43
  protected
40
44
 
45
+ def self.apply_api_key(params, format=nil)
46
+ if api_key
47
+ decoded_params = decode(params, format).with_indifferent_access
48
+
49
+ if decoded_params[:api_request]
50
+ decoded_params[:api_request] = decoded_params[:api_request].with_indifferent_access
51
+ end
52
+
53
+ if format.to_s == 'xml'
54
+ if !(decoded_params[:api_request] && decoded_params[:api_request][:api_key])
55
+ decoded_params[:api_request] ||= {}.with_indifferent_access
56
+ decoded_params[:api_request][:api_key] = api_key
57
+ end
58
+ else
59
+ decoded_params['api_key'] = api_key unless decoded_params['api_key']
60
+ end
61
+
62
+ decoded_params
63
+ else
64
+ params
65
+ end
66
+ end
67
+
41
68
  def self.merge_params(options, params)
42
69
  if options[:params]
43
70
  options[:params] = options[:params].merge(params)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 1
8
- - 8
9
- version: 2.1.8
8
+ - 9
9
+ version: 2.1.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathan Sutton