helix 0.0.2.0.pre → 0.0.2.1.pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/helix/base.rb CHANGED
@@ -53,14 +53,14 @@ module Helix
53
53
  #
54
54
  # @param [Hash] opts a hash of options for parameters passed into the HTTP GET
55
55
  # @return [Array] The array of instance objects for a class.
56
- def self.find_all(opts)
56
+ def self.find_all(opts={})
57
57
  data_sets = get_data_sets(opts)
58
58
  return [] if data_sets.nil?
59
59
  data_sets.map { |attrs| self.new(attributes: attrs, config: config) }
60
60
  end
61
61
 
62
62
  def self.get_data_sets(opts)
63
- url = config.build_url(format: opts[:format] || :json,
63
+ url = config.build_url(format: opts[:format] || :json,
64
64
  media_type: self.plural_media_type)
65
65
  # We allow opts[:sig_type] for internal negative testing only.
66
66
  raw_response = config.get_response(url, {sig_type: :view}.merge(opts))
@@ -162,8 +162,11 @@ module Helix
162
162
  # @param [Hash] opts a hash of attributes to update the instance with.
163
163
  # @return [Base] Returns an instance of the class after update.
164
164
  def update(opts={})
165
+ RestClient.log = 'helix.log' if opts.delete(:log)
165
166
  memo_cfg = config
166
- url = memo_cfg.build_url(format: :xml, guid: guid, media_type: plural_media_type)
167
+ url = memo_cfg.build_url(content_type: :xml,
168
+ guid: guid,
169
+ media_type: plural_media_type)
167
170
  params = {signature: memo_cfg.signature(:update)}.merge(media_type_sym => opts)
168
171
  RestClient.put(url, params)
169
172
  self
data/lib/helix/config.rb CHANGED
@@ -46,11 +46,12 @@ module Helix
46
46
  # @param [Hash] opts a hash of options for building URL additions
47
47
  # @return [String] The full RESTful URL string object
48
48
  def add_sub_urls(base_url, opts)
49
- guid, action = [:guid, :action].map { |sub| opts[sub] }
49
+ guid, action, format = [:guid, :action, :formats].map { |sub| opts[sub] }
50
50
  url = "#{base_url}/#{opts[:media_type]}"
51
- url += "/#{guid}" if guid
52
- url += "/#{action}" if action
53
- "#{url}.#{opts[:format]}"
51
+ url += "/#{guid}" if guid
52
+ url += "/formats/#{format}" if format
53
+ url += "/#{action}" if action
54
+ "#{url}.#{opts[:content_type]}"
54
55
  end
55
56
 
56
57
  # Creates a full RESTful URL to be used for HTTP requests.
@@ -58,10 +59,10 @@ module Helix
58
59
  # @param [Hash] opts a hash of options for building URL
59
60
  # @return [String] The full RESTful URL string object
60
61
  def build_url(opts={})
61
- opts[:format] ||= :json
62
- opts[:media_type] ||= :videos
63
- base_url = get_base_url(opts)
64
- url = add_sub_urls(base_url, opts)
62
+ opts[:content_type] ||= :json
63
+ opts[:media_type] ||= :videos
64
+ base_url = get_base_url(opts)
65
+ url = add_sub_urls(base_url, opts)
65
66
  end
66
67
 
67
68
  def clear_signatures!
@@ -4,14 +4,25 @@ module Helix
4
4
 
5
5
  module ClassMethods
6
6
 
7
- # Standard hash values used to generate the create_many
8
- # url.
7
+ # Used to import tracks from a URL into the Twistage system.
8
+ # Doc reference: /doc/api/track/import
9
+ # Doc reference: /doc/api/video/import
9
10
  #
10
- # @return [Hash]
11
- def get_url_opts
12
- { action: :create_many,
13
- media_type: plural_media_type,
14
- format: :xml }
11
+ # @example
12
+ # track = Helix::Track.import(src: "www.google.com/track.mp4",
13
+ # title: "Some Title,
14
+ # description: "A random track.")
15
+ # new_track.track_id # => dd891b83ba39e
16
+ #
17
+ # video = Helix::Video.import(src: "www.google.com/video.mp4",
18
+ # title: "Some Title,
19
+ # description: "A random video.")
20
+ # new_video.video_id # => dd891b83ba39e
21
+ #
22
+ # @param [Hash] attrs The attributes for creating a track.
23
+ # @return [RestClient] The response object.
24
+ def import(attrs={})
25
+ rest_post(:create_many, attrs)
15
26
  end
16
27
 
17
28
  private
@@ -32,8 +43,9 @@ module Helix
32
43
  # Gets the url used in the create_many import call.
33
44
  #
34
45
  # @return [String] Returns the valid url used for the API call.
35
- def get_url
36
- Helix::Config.instance.build_url(self.get_url_opts)
46
+ def get_url_for(api_call, opts)
47
+ url_opts = url_opts_for(opts[:formats])[api_call].merge(opts)
48
+ Helix::Config.instance.build_url(url_opts)
37
49
  end
38
50
 
39
51
  # Method allows for :use_raw_xml to be passed into attributes.
@@ -45,9 +57,33 @@ module Helix
45
57
  # @return [String] Returns xml either from a raw entry or generated from attributes.
46
58
  def get_xml(attrs={})
47
59
  return attrs[:use_raw_xml] if attrs[:use_raw_xml].present?
48
- { list: { entry: attrs } }.to_xml(root: :add)
60
+ xml_opts = {root: :add }
61
+ { list: { entry: attrs[:url_params] || {} } }.to_xml(xml_opts)
62
+ end
63
+
64
+ def rest_post(api_call, attrs)
65
+ RestClient.log = 'helix.log' if attrs.delete(:log)
66
+ content_type = url_opts_for[api_call][:content_type]
67
+ content_type_hash = { content_type: "text/#{content_type}" }
68
+ RestClient.post(get_url_for(api_call, attrs),
69
+ get_xml(attrs),
70
+ get_params(attrs).merge(content_type_hash))
49
71
  end
50
72
 
73
+ # Standard hash values used to generate the create_many
74
+ # url.
75
+ #
76
+ # @return [Hash]
77
+ def url_opts_for(format=nil)
78
+ { slice: { action: :slice,
79
+ media_type: plural_media_type,
80
+ content_type: :xml,
81
+ formats: format },
82
+ create_many: { action: :create_many,
83
+ media_type: plural_media_type,
84
+ content_type: :xml }
85
+ }
86
+ end
51
87
  end
52
88
 
53
89
  def self.included(klass); klass.extend(ClassMethods); end
data/lib/helix/track.rb CHANGED
@@ -13,25 +13,5 @@ module Helix
13
13
  #
14
14
  # @return [Symbol] Name of the class.
15
15
  def self.media_type_sym; :track; end
16
-
17
- # Used to import tracks from a URL into the Twistage system.
18
- # Doc reference: /doc/api/track/import
19
- #
20
- # @example
21
- # track = Helix::Track.import(src: "www.google.com/track.mp4",
22
- # title: "Some Title,
23
- # description: "A random track.")
24
- # new_track.track_id # => dd891b83ba39e
25
- #
26
- # @param [Hash] attrs The attributes for creating a track.
27
- # @return [RestClient] The response object.
28
- def self.import(attrs={})
29
- #TODO: Pull shared logic (with video) into a shared lib file.
30
- RestClient.post(get_url,
31
- get_xml(attrs),
32
- get_params(attrs))
33
- end
34
-
35
16
  end
36
-
37
17
  end
data/lib/helix/video.rb CHANGED
@@ -17,23 +17,34 @@ module Helix
17
17
  # @return [Symbol] Name of the class.
18
18
  def self.media_type_sym; :video; end
19
19
 
20
- # Used to import videos from a URL into the Twistage system.
21
- # Doc reference: /doc/api/video/import
20
+ def self.slice(attrs={})
21
+ rest_post(:slice, attrs)
22
+ end
23
+
24
+
25
+ # Used to retrieve a stillframe for a video by using
26
+ # the video guid.
22
27
  #
23
28
  # @example
24
- # video = Helix::Video.import(src: "www.google.com/video.mp4",
25
- # title: "Some Title,
26
- # description: "A random video.")
27
- # new_video.video_id # => dd891b83ba39e
29
+ # sf_data = Helix::Video.get_stillframe("239c59483d346") #=> xDC\xF1?\xE9*?\xFF\xD9
30
+ # File.open("original.jpg", "w") { |f| f.puts sf_data }
28
31
  #
29
- # @param [Hash] attrs The attributes for creating a video.
30
- # @return [RestClient] The response object.
31
- def self.import(attrs={})
32
- RestClient.post(get_url,
33
- get_xml(attrs),
34
- get_params(attrs))
32
+ # @param [String] guid is the string containing the guid for the video.
33
+ # @param [Hash] opts a hash of options for building URL
34
+ # @return [String] Stillframe jpg data, save it to a file with extension .jpg.
35
+ def self.get_stillframe(guid, opts={})
36
+ RestClient.log = 'helix.log' if opts.delete(:log)
37
+ server = opts[:server] || config.credentials[:server] || "service-staging"
38
+ width = opts[:width].to_s + "w" unless opts[:width].nil?
39
+ height = opts[:height].to_s + "h" unless opts[:height].nil?
40
+ width = "original" if opts[:width].nil? && opts[:height].nil?
41
+ url = "#{server}.twistage.com/videos/#{guid}/screenshots/"
42
+ url << "#{width.to_s}#{height.to_s}.jpg"
43
+ RestClient.get(url)
35
44
  end
36
45
 
46
+ def stillframe(opts={})
47
+ self.class.get_stillframe(self.guid, opts)
48
+ end
37
49
  end
38
-
39
50
  end
data/spec/base_spec.rb CHANGED
@@ -101,14 +101,14 @@ describe Helix::Base do
101
101
  let(:meth) { :find_all }
102
102
  let(:mock_config) { mock(Helix::Config, build_url: :built_url, get_response: {}) }
103
103
  subject { klass.method(meth) }
104
- its(:arity) { should eq(1) }
104
+ its(:arity) { should eq(-1) }
105
105
  before(:each) do Helix::Config.stub(:instance) { mock_config } end
106
106
  context "when given a config instances and an opts Hash" do
107
107
  let(:opts) { {opts_key1: :opts_val1} }
108
108
  let(:plural_media_type) { :videos }
109
109
  before(:each) do klass.stub(:plural_media_type) { plural_media_type } end
110
110
  it "should build a JSON URL -> the_url" do
111
- mock_config.should_receive(:build_url).with(format: :json,
111
+ mock_config.should_receive(:build_url).with(format: :json,
112
112
  media_type: plural_media_type)
113
113
  klass.send(meth, opts)
114
114
  end
@@ -319,8 +319,8 @@ describe Helix::Base do
319
319
  mock_config.stub(:build_url) { :expected_url }
320
320
  end
321
321
  shared_examples_for "builds URL for update" do
322
- it "should build_url(format: :xml, guid: guid, media_type: plural_media_type)" do
323
- mock_config.should_receive(:build_url).with(format: :xml, guid: :the_guid, media_type: :the_media_type)
322
+ it "should build_url(content_type: :xml, guid: guid, media_type: plural_media_type)" do
323
+ mock_config.should_receive(:build_url).with(content_type: :xml, guid: :the_guid, media_type: :the_media_type)
324
324
  RestClient.stub(:put)
325
325
  obj.send(meth)
326
326
  end
data/spec/config_spec.rb CHANGED
@@ -103,13 +103,13 @@ describe Helix::Config do
103
103
  end
104
104
  end
105
105
 
106
- def build_test_url(site, sub_url, guid, action, media_type, format)
106
+ def build_test_url(site, sub_url, guid, action, media_type, content_type)
107
107
  expected_url = site
108
108
  expected_url += sub_url unless guid || action == :create_many
109
109
  expected_url += "/#{media_type}"
110
110
  expected_url += "/the_guid" if guid
111
111
  expected_url += "/#{action}" if action
112
- expected_url += ".#{format}"
112
+ expected_url += ".#{content_type}"
113
113
  end
114
114
 
115
115
  describe "#build_url" do
@@ -118,12 +118,12 @@ describe Helix::Config do
118
118
  subject { obj.method(meth) }
119
119
  its(:arity) { should be(-1) }
120
120
  before(:each) do obj.credentials = { site: site } end
121
- shared_examples_for "reads scope from credentials for build_url" do |media_type,format,more_opts|
121
+ shared_examples_for "reads scope from credentials for build_url" do |media_type,content_type,more_opts|
122
122
  let(:opts) { more_opts || {} }
123
- let(:action) { opts[:action] }
124
- let(:guid) { opts[:guid] }
125
- let(:url_pieces) { [site, sub_url, guid, action, media_type, format] }
126
- let(:expected_url) { build_test_url(*url_pieces) }
123
+ let(:action) { opts[:action] }
124
+ let(:guid) { opts[:guid] }
125
+ let(:url_pieces) { [site, sub_url, guid, action, media_type, content_type] }
126
+ let(:expected_url) { build_test_url(*url_pieces) }
127
127
  before(:each) do obj.credentials = {site: 'http://example.com'} end
128
128
  context "and credentials has a key for :reseller" do
129
129
  before(:each) do obj.credentials.merge!(reseller: 're_id') end
@@ -201,39 +201,39 @@ describe Helix::Config do
201
201
  it_behaves_like "reads scope from credentials for build_url", media_type, :json, {guid: :the_guid, action: :the_action}
202
202
  end
203
203
  end
204
- [ :json, :xml ].each do |format|
205
- context "when given opts[:format] of :#{format}" do
206
- subject { obj.send(meth, format: format) }
207
- it_behaves_like "reads scope from credentials for build_url", :videos, format
204
+ [ :json, :xml ].each do |content_type|
205
+ context "when given opts[:content_type] of :#{content_type}" do
206
+ subject { obj.send(meth, content_type: content_type) }
207
+ it_behaves_like "reads scope from credentials for build_url", :videos, content_type
208
208
  end
209
- context "when given opts[:format] of :#{format} and opts[:guid] of :the_guid" do
210
- subject { obj.send(meth, format: format, guid: :the_guid) }
211
- it_behaves_like "reads scope from credentials for build_url", :videos, format, {guid: :the_guid}
209
+ context "when given opts[:content_type] of :#{content_type} and opts[:guid] of :the_guid" do
210
+ subject { obj.send(meth, content_type: content_type, guid: :the_guid) }
211
+ it_behaves_like "reads scope from credentials for build_url", :videos, content_type, {guid: :the_guid}
212
212
  end
213
- context "when given opts[:format] of :#{format} and opts[:action] of :the_action" do
214
- subject { obj.send(meth, format: format, action: :the_action) }
215
- it_behaves_like "reads scope from credentials for build_url", :videos, format, {action: :the_action}
213
+ context "when given opts[:content_type] of :#{content_type} and opts[:action] of :the_action" do
214
+ subject { obj.send(meth, content_type: content_type, action: :the_action) }
215
+ it_behaves_like "reads scope from credentials for build_url", :videos, content_type, {action: :the_action}
216
216
  end
217
- context "when given opts[:format] of :#{format}, opts[:guid] of :the_guid, and opts[:action] of :the_action" do
218
- subject { obj.send(meth, format: format, guid: :the_guid, action: :the_action) }
219
- it_behaves_like "reads scope from credentials for build_url", :videos, format, {guid: :the_guid, action: :the_action}
217
+ context "when given opts[:content_type] of :#{content_type}, opts[:guid] of :the_guid, and opts[:action] of :the_action" do
218
+ subject { obj.send(meth, content_type: content_type, guid: :the_guid, action: :the_action) }
219
+ it_behaves_like "reads scope from credentials for build_url", :videos, content_type, {guid: :the_guid, action: :the_action}
220
220
  end
221
221
  [ :videos, :tracks ].each do |media_type|
222
- context "when given opts[:format] of :#{format} and opts[:media_type] of :#{media_type}" do
223
- subject { obj.send(meth, format: format, media_type: media_type) }
224
- it_behaves_like "reads scope from credentials for build_url", media_type, format
222
+ context "when given opts[:content_type] of :#{content_type} and opts[:media_type] of :#{media_type}" do
223
+ subject { obj.send(meth, content_type: content_type, media_type: media_type) }
224
+ it_behaves_like "reads scope from credentials for build_url", media_type, content_type
225
225
  end
226
- context "when given opts[:format] of :#{format}, opts[:guid] of :the_guid, and opts[:media_type] of :#{media_type}" do
227
- subject { obj.send(meth, format: format, guid: :the_guid, media_type: media_type) }
228
- it_behaves_like "reads scope from credentials for build_url", media_type, format, {guid: :the_guid}
226
+ context "when given opts[:content_type] of :#{content_type}, opts[:guid] of :the_guid, and opts[:media_type] of :#{media_type}" do
227
+ subject { obj.send(meth, content_type: content_type, guid: :the_guid, media_type: media_type) }
228
+ it_behaves_like "reads scope from credentials for build_url", media_type, content_type, {guid: :the_guid}
229
229
  end
230
- context "when given opts[:format] of :#{format}, opts[:action] of :the_action, and opts[:media_type] of :#{media_type}" do
231
- subject { obj.send(meth, format: format, action: :the_action, media_type: media_type) }
232
- it_behaves_like "reads scope from credentials for build_url", media_type, format, {action: :the_action}
230
+ context "when given opts[:content_type] of :#{content_type}, opts[:action] of :the_action, and opts[:media_type] of :#{media_type}" do
231
+ subject { obj.send(meth, content_type: content_type, action: :the_action, media_type: media_type) }
232
+ it_behaves_like "reads scope from credentials for build_url", media_type, content_type, {action: :the_action}
233
233
  end
234
- context "when given opts[:format] of :#{format}, opts[:guid] of :the_guid, opts[:action] of :the_action, and opts[:media_type] of :#{media_type}" do
235
- subject { obj.send(meth, format: format, guid: :the_guid, action: :the_action, media_type: media_type) }
236
- it_behaves_like "reads scope from credentials for build_url", media_type, format, {guid: :the_guid, action: :the_action}
234
+ context "when given opts[:content_type] of :#{content_type}, opts[:guid] of :the_guid, opts[:action] of :the_action, and opts[:media_type] of :#{media_type}" do
235
+ subject { obj.send(meth, content_type: content_type, guid: :the_guid, action: :the_action, media_type: media_type) }
236
+ it_behaves_like "reads scope from credentials for build_url", media_type, content_type, {guid: :the_guid, action: :the_action}
237
237
  end
238
238
  end
239
239
  end
@@ -0,0 +1,92 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'helix'
3
+
4
+ describe Helix::DurationedMedia do
5
+
6
+ def import_xml(values={})
7
+ { list: { entry: values[:url_params] || {} } }.to_xml(root: :add)
8
+ end
9
+
10
+ klasses = [ Helix::Video, Helix::Track ]
11
+ klasses.each do |klass|
12
+ subject { klass }
13
+ its(:ancestors) { should include(Helix::Base) }
14
+
15
+ describe "Constants"
16
+
17
+ let(:sig_opts) { { contributor: :helix,
18
+ library_id: :development } }
19
+ url_opts = { action: :create_many,
20
+ media_type: klass.send(:plural_media_type),
21
+ content_type: :xml }
22
+
23
+ describe ".import" do
24
+ let(:meth) { :import }
25
+ let(:mock_config) { mock(Helix::Config) }
26
+ subject { klass.method(meth) }
27
+ its(:arity) { should eq(-1) }
28
+ let(:params) { { params: { signature: :some_sig },
29
+ content_type: "text/xml" } }
30
+ before { Helix::Config.stub(:instance) { mock_config } }
31
+
32
+ it "should get an ingest signature" do
33
+ mock_config.should_receive(:build_url).with(url_opts)
34
+ mock_config.should_receive(:signature).with(:ingest, sig_opts) { :some_sig }
35
+ RestClient.should_receive(:post).with(nil, import_xml, params)
36
+ klass.send(meth)
37
+ end
38
+ end
39
+
40
+ describe ".get_xml" do
41
+ let(:meth) { :get_xml }
42
+ subject { klass.method(meth) }
43
+ its(:arity) { should eq(-1) }
44
+ context "when :use_raw_xml is present in attrs" do
45
+ let(:use_raw_xml) { { use_raw_xml: :xml } }
46
+ it "should return the value of attrs[:use_raw_xml]" do
47
+ expect(klass.send(meth, use_raw_xml)).to eq(:xml)
48
+ end
49
+ end
50
+ context "when hash is passed without :use_raw_xml" do
51
+ let(:attrs) { { url_params: { attribute: :value } } }
52
+ it "should convert attrs into xml" do
53
+ expect(klass.send(meth, attrs)).to eq(import_xml(attrs))
54
+ end
55
+ end
56
+ context "when nothing in passed in" do
57
+ it "should return valid xml" do
58
+ expect(klass.send(meth)).to eq(import_xml)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe ".url_opts_for" do
64
+ let(:meth) { :url_opts_for }
65
+ subject { klass.method(meth) }
66
+ its(:arity) { should eq(-1) }
67
+ it "should return a valid hash url options for Helix::Config#build_url" do
68
+ expect(klass.send(meth)[:create_many]).to eq(url_opts)
69
+ end
70
+ end
71
+
72
+ describe ".get_url_for" do
73
+ let(:meth) { :get_url_for }
74
+ subject { klass.method(meth) }
75
+ its(:arity) { should eq(2) }
76
+ it "should call Helix::Config#build_url with url opts" do
77
+ Helix::Config.instance.should_receive(:build_url).with(klass.send(:url_opts_for)[:create_many])
78
+ klass.send(meth, :create_many, {})
79
+ end
80
+ end
81
+
82
+ describe ".get_params" do
83
+ let(:meth) { :get_params }
84
+ subject { klass.method(meth) }
85
+ its(:arity) { should eq(-1) }
86
+ it "should call Helix::Config#signature and return a hash of params" do
87
+ Helix::Config.instance.should_receive(:signature).with(:ingest, sig_opts) { :sig }
88
+ expect(klass.send(meth)).to eq({ params: { signature: :sig } })
89
+ end
90
+ end
91
+ end
92
+ end
data/spec/track_spec.rb CHANGED
@@ -3,98 +3,17 @@ require 'helix'
3
3
 
4
4
  describe Helix::Track do
5
5
 
6
- def import_xml(values={})
7
- { list: { entry: values } }.to_xml(root: :add)
8
- end
9
-
10
- let(:klass) { Helix::Track }
11
-
6
+ let(:klass) { Helix::Track }
12
7
  subject { klass }
13
- its(:ancestors) { should include(Helix::Base) }
14
8
  its(:guid_name) { should eq('track_id') }
15
9
  its(:media_type_sym) { should be(:track) }
16
10
  its(:plural_media_type) { should eq('tracks') }
17
11
 
18
12
  describe "Constants"
19
13
 
20
- let(:sig_opts) { { contributor: :helix,
21
- library_id: :development } }
22
- let(:url_opts) { { action: :create_many,
23
- media_type: "tracks",
24
- format: :xml } }
25
-
26
14
  describe "an instance" do
27
15
  let(:obj) { klass.new({'track_id' => 'some_track_guid'}) }
28
16
  subject { obj }
29
17
  its(:media_type_sym) { should be(:track) }
30
18
  end
31
-
32
- describe ".import" do
33
- let(:meth) { :import }
34
- let(:mock_config) { mock(Helix::Config) }
35
- subject { klass.method(meth) }
36
- its(:arity) { should eq(-1) }
37
- let(:params) { { params: { signature: :some_sig } } }
38
- before { Helix::Config.stub(:instance) { mock_config } }
39
-
40
- it "should get an ingest signature" do
41
- mock_config.should_receive(:build_url).with(url_opts)
42
- mock_config.should_receive(:signature).with(:ingest, sig_opts) { :some_sig }
43
- RestClient.should_receive(:post).with(nil, import_xml, params)
44
- klass.send(meth)
45
- end
46
- end
47
-
48
- describe ".get_xml" do
49
- let(:meth) { :get_xml }
50
- subject { klass.method(meth) }
51
- its(:arity) { should eq(-1) }
52
- context "when :use_raw_xml is present in attrs" do
53
- let(:use_raw_xml) { { use_raw_xml: :xml } }
54
- it "should return the value of attrs[:use_raw_xml]" do
55
- expect(klass.send(meth, use_raw_xml)).to eq(:xml)
56
- end
57
- end
58
- context "when hash is passed without :use_raw_xml" do
59
- let(:attrs) { { attribute: :value } }
60
- it "should convert attrs into xml" do
61
- expect(klass.send(meth, attrs)).to eq(import_xml(attrs))
62
- end
63
- end
64
- context "when nothing in passed in" do
65
- it "should return valid xml" do
66
- expect(klass.send(meth)).to eq(import_xml)
67
- end
68
- end
69
- end
70
-
71
- describe ".get_url_opts" do
72
- let(:meth) { :get_url_opts }
73
- subject { klass.method(meth) }
74
- its(:arity) { should eq(0) }
75
- it "should return a valid hash url options for Helix::Config#build_url" do
76
- expect(klass.send(meth)).to eq(url_opts)
77
- end
78
- end
79
-
80
- describe ".get_url" do
81
- let(:meth) { :get_url }
82
- subject { klass.method(meth) }
83
- its(:arity) { should eq(0) }
84
- it "should call Helix::Config#build_url with url opts" do
85
- Helix::Config.instance.should_receive(:build_url).with(klass.send(:get_url_opts))
86
- klass.send(meth)
87
- end
88
- end
89
-
90
- describe ".get_params" do
91
- let(:meth) { :get_params }
92
- subject { klass.method(meth) }
93
- its(:arity) { should eq(-1) }
94
- it "should call Helix::Config#signature and return a hash of params" do
95
- Helix::Config.instance.should_receive(:signature).with(:ingest, sig_opts) { :sig }
96
- expect(klass.send(meth)).to eq({ params: { signature: :sig } })
97
- end
98
- end
99
-
100
19
  end
data/spec/video_spec.rb CHANGED
@@ -4,96 +4,98 @@ require 'helix'
4
4
  describe Helix::Video do
5
5
 
6
6
  def import_xml(values={})
7
- { list: { entry: values } }.to_xml(root: :add)
7
+ { list: { entry: values[:url_params] || {} } }.to_xml(root: :add)
8
8
  end
9
9
 
10
- let(:klass) { Helix::Video }
11
-
10
+ let(:klass) { Helix::Video }
12
11
  subject { klass }
13
- its(:ancestors) { should include(Helix::Base) }
14
12
  its(:guid_name) { should eq('video_id') }
15
13
  its(:media_type_sym) { should be(:video) }
16
14
  its(:plural_media_type) { should eq('videos') }
17
15
 
18
16
  describe "Constants"
19
17
 
20
- let(:sig_opts) { { contributor: :helix,
21
- library_id: :development } }
22
- let(:url_opts) { { action: :create_many,
23
- media_type: "videos",
24
- format: :xml } }
18
+ ### INSTANCE METHODS
25
19
 
26
20
  describe "an instance" do
27
- let(:obj) { klass.new({'video_id' => 'some_video_guid'}) }
28
- subject { obj }
29
- its(:media_type_sym) { should be(:video) }
21
+ let(:obj) { klass.new({video_id: 'some_video_guid'}) }
22
+ subject { obj }
23
+ its(:media_type_sym) { should be(:video) }
24
+ describe "#stillframe" do
25
+ let(:meth) { :stillframe }
26
+ let(:mock_config) { mock(Helix::Config) }
27
+ subject { obj.method(meth) }
28
+ its(:arity) { should eq(-1) }
29
+ it "should call self.class.get_stillframe" do
30
+ obj.stub!(:guid).and_return :some_guid
31
+ klass.should_receive(:get_stillframe)
32
+ obj.send(meth)
33
+ end
34
+ end
30
35
  end
31
36
 
32
- describe ".import" do
33
- let(:meth) { :import }
37
+ ### CLASS METHODS
38
+
39
+ describe ".slice" do
40
+ let(:meth) { :slice }
34
41
  let(:mock_config) { mock(Helix::Config) }
35
42
  subject { klass.method(meth) }
36
43
  its(:arity) { should eq(-1) }
37
- let(:params) { { params: { signature: :some_sig } } }
38
- before { Helix::Config.stub(:instance) { mock_config } }
44
+ let(:params) { { params: { signature: :some_sig },
45
+ content_type: "text/xml" } }
46
+ let(:url_opts) { { action: :slice,
47
+ media_type: "videos",
48
+ content_type: :xml,
49
+ formats: :some_format } }
50
+ let(:sig_opts) { { contributor: :helix,
51
+ library_id: :development,
52
+ formats: :some_format } }
53
+ before { Helix::Config.stub(:instance) { mock_config } }
39
54
 
40
55
  it "should get an ingest signature" do
41
56
  mock_config.should_receive(:build_url).with(url_opts)
42
57
  mock_config.should_receive(:signature).with(:ingest, sig_opts) { :some_sig }
43
58
  RestClient.should_receive(:post).with(nil, import_xml, params)
44
- klass.send(meth)
59
+ klass.send(meth, {formats: :some_format})
45
60
  end
46
61
  end
47
62
 
48
- describe ".get_xml" do
49
- let(:meth) { :get_xml }
50
- subject { klass.method(meth) }
51
- its(:arity) { should eq(-1) }
52
- context "when :use_raw_xml is present in attrs" do
53
- let(:use_raw_xml) { { use_raw_xml: :xml } }
54
- it "should return the value of attrs[:use_raw_xml]" do
55
- expect(klass.send(meth, use_raw_xml)).to eq(:xml)
63
+ describe ".get_stillframe" do
64
+ let(:meth) { :get_stillframe }
65
+ let(:mock_config) { mock(Helix::Config) }
66
+ subject { klass.method(meth) }
67
+ its(:arity) { should eq(-2) }
68
+ let(:image_data) { :some_image_data }
69
+ let(:guid) { :some_guid }
70
+ let(:server) { "service-staging" }
71
+ let(:base_url) { "#{server}.twistage.com/videos/#{guid}/screenshots/" }
72
+ context "when no height or width is passed in " do
73
+ let(:full_url) { "#{base_url}original.jpg" }
74
+ it "should build the correct url and return data" do
75
+ RestClient.should_receive(:get).with(full_url).and_return image_data
76
+ expect(klass.send(meth, guid)).to eq(image_data)
56
77
  end
57
78
  end
58
- context "when hash is passed without :use_raw_xml" do
59
- let(:attrs) { { attribute: :value } }
60
- it "should convert attrs into xml" do
61
- expect(klass.send(meth, attrs)).to eq(import_xml(attrs))
79
+ [:height, :width].each do |dimension|
80
+ context "when #{dimension} is passed in" do
81
+ url_tag = (dimension == :height ? "h" : "w")
82
+ let(:dim_val) { 100 }
83
+ let(:full_url) { "#{base_url}#{dim_val}#{url_tag}.jpg" }
84
+ let(:opts) { { dimension => dim_val } }
85
+ it "should build the correct url and return data" do
86
+ RestClient.should_receive(:get).with(full_url).and_return image_data
87
+ expect(klass.send(meth, guid, opts)).to eq(image_data)
88
+ end
62
89
  end
63
90
  end
64
- context "when nothing in passed in" do
65
- it "should return valid xml" do
66
- expect(klass.send(meth)).to eq(import_xml)
91
+ context "when both height and width are passed in" do
92
+ let(:dim_val) { 100 }
93
+ let(:full_url) { "#{base_url}#{dim_val}w#{dim_val}h.jpg" }
94
+ let(:opts) { { height: dim_val, width: dim_val } }
95
+ it "should build the correct url and return data" do
96
+ RestClient.should_receive(:get).with(full_url).and_return image_data
97
+ expect(klass.send(meth, guid, opts)).to eq(image_data)
67
98
  end
68
99
  end
69
100
  end
70
-
71
- describe ".get_url_opts" do
72
- let(:meth) { :get_url_opts }
73
- subject { klass.method(meth) }
74
- its(:arity) { should eq(0) }
75
- it "should return a valid hash url options for Helix::Config#build_url" do
76
- expect(klass.send(meth)).to eq(url_opts)
77
- end
78
- end
79
-
80
- describe ".get_url" do
81
- let(:meth) { :get_url }
82
- subject { klass.method(meth) }
83
- its(:arity) { should eq(0) }
84
- it "should call Helix::Config#build_url with url opts" do
85
- Helix::Config.instance.should_receive(:build_url).with(klass.send(:get_url_opts))
86
- klass.send(meth)
87
- end
88
- end
89
-
90
- describe ".get_params" do
91
- let(:meth) { :get_params }
92
- subject { klass.method(meth) }
93
- its(:arity) { should eq(-1) }
94
- it "should call Helix::Config#signature and return a hash of params" do
95
- Helix::Config.instance.should_receive(:signature).with(:ingest, sig_opts) { :sig }
96
- expect(klass.send(meth)).to eq({ params: { signature: :sig } })
97
- end
98
- end
99
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.0.pre
4
+ version: 0.0.2.1.pre
5
5
  prerelease: 8
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -82,6 +82,7 @@ files:
82
82
  - spec/album_spec.rb
83
83
  - spec/track_spec.rb
84
84
  - spec/base_spec.rb
85
+ - spec/durationed_media_spec.rb
85
86
  - LICENSE
86
87
  - README.md
87
88
  homepage: https://github.com/Twistage/helix/