helix 0.0.2.6.pre → 0.0.2.7.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,8 @@ module Helix
22
22
  #
23
23
  # @param [Hash] opts a hash of options for parameters passed into the HTTP GET
24
24
  # @return [Array] The array of instance objects for a class.
25
- def self.find_all(opts={})
25
+ def self.find_all(original_opts={})
26
+ opts = original_opts.clone
26
27
  RestClient.log = 'helix.log' if opts.delete(:log)
27
28
  data_sets = get_data_sets(opts)
28
29
  return [] if data_sets.nil?
@@ -95,7 +95,8 @@ module Helix
95
95
  # @param [String] url the base part of the URL to be used
96
96
  # @param [Hash] opts a hash of options for building URL additions
97
97
  # @return [String] The full RESTful URL string object
98
- def get_response(url, opts={})
98
+ def get_response(url, original_opts={})
99
+ opts = original_opts.clone
99
100
  sig_type = opts.delete(:sig_type)
100
101
  params = opts.merge(signature: signature(sig_type, opts))
101
102
  response = RestClient.get(url, params: params)
@@ -55,7 +55,8 @@ module Helix
55
55
  #
56
56
  # @param [Hash] opts a hash of attributes to update the instance with.
57
57
  # @return [Base] Returns an instance of the class after update.
58
- def update(opts={})
58
+ def update(original_opts={})
59
+ opts = original_opts.clone
59
60
  RestClient.log = 'helix.log' if opts.delete(:log)
60
61
  memo_cfg = config
61
62
  url = memo_cfg.build_url(content_type: :xml,
@@ -124,7 +124,8 @@ module Helix
124
124
 
125
125
  private
126
126
 
127
- def self.delivery(resource_label, opts)
127
+ def self.delivery(resource_label, original_opts)
128
+ opts = original_opts.clone
128
129
  memo_cfg = Helix::Config.instance
129
130
  content_type = opts.delete(:content_type)
130
131
  guid = opts.delete("#{resource_label}_id".to_sym)
@@ -137,13 +138,15 @@ module Helix
137
138
  memo_cfg.get_response(url, {sig_type: :view}.merge(opts))
138
139
  end
139
140
 
140
- def self.ingest(resource_label, opts)
141
+ def self.ingest(resource_label, original_opts)
142
+ opts = original_opts.clone
141
143
  opts[:action] ||= :breakdown
142
144
  action_prefix = ingest_action_prefix_for(resource_label)
143
145
  storage(resource_label, opts.merge(action: :"#{action_prefix}/#{opts[:action]}"))
144
146
  end
145
147
 
146
- def self.storage(resource_label, opts)
148
+ def self.storage(resource_label, original_opts)
149
+ opts = original_opts.clone
147
150
  memo_cfg = Helix::Config.instance
148
151
  content_type = opts.delete(:content_type)
149
152
  action = opts.delete(:action) || storage_action_for(resource_label)
@@ -32,16 +32,34 @@ module Helix
32
32
  # @param [String] guid is the string containing the guid for the video.
33
33
  # @param [Hash] opts a hash of options for building URL
34
34
  # @return [String] Stillframe jpg data, save it to a file with extension .jpg.
35
- def self.get_stillframe(guid, opts={})
35
+ def self.get_stillframe(guid, original_opts={})
36
+ opts = original_opts.clone
36
37
  RestClient.log = 'helix.log' if opts.delete(:log)
37
38
  url = get_stillframe_url(guid, opts)
38
39
  RestClient.get(url)
39
40
  end
40
41
 
42
+ # Used to download data for the given Video.
43
+ #
44
+ # @example
45
+ # video = Helix::Video.find("239c59483d346")
46
+ # video_data = video.download #=> xDC\xF1?\xE9*?\xFF\xD9
47
+ # File.open("my_video.mp4", "w") { |f| f.puts video_data }
48
+ #
49
+ # @param [Hash] opts a hash of options for building URL
50
+ # @return [String] Raw video data, save it to a file
41
51
  def download(opts={})
42
52
  generic_download(opts.merge(action: :file))
43
53
  end
44
54
 
55
+ # Used to play the given Video.
56
+ #
57
+ # @example
58
+ # video = Helix::Video.find("239c59483d346")
59
+ # video_data = video.play #=> xDC\xF1?\xE9*?\xFF\xD9
60
+ #
61
+ # @param [Hash] opts a hash of options for building URL
62
+ # @return [String] Raw video data
45
63
  def play(opts={})
46
64
  generic_download(opts.merge(action: :play))
47
65
  end
@@ -43,6 +43,10 @@ describe Helix::Base do
43
43
  let(:opts) { {opts_key1: :opts_val1} }
44
44
  let(:plural_resource_label) { :videos }
45
45
  before(:each) do klass.stub(:plural_resource_label) { plural_resource_label } end
46
+ it "should clone the opts arg" do
47
+ opts.should_receive(:clone) { opts }
48
+ klass.send(meth, opts)
49
+ end
46
50
  it "should build a XML URL -> the_url" do
47
51
  mock_config.should_receive(:build_url).with(content_type: :xml,
48
52
  resource_label: plural_resource_label)
@@ -137,8 +141,8 @@ describe Helix::Base do
137
141
  its(:arity) { should eq(1) }
138
142
  let(:attrs) { Hash.new }
139
143
  it "should call massage_custom_field_attrs and massage_time_attrs" do
140
- klass.should_receive(:massage_time_attrs).and_return attrs
141
- klass.should_receive(:massage_custom_field_attrs).and_return attrs
144
+ klass.should_receive(:massage_time_attrs) { attrs }
145
+ klass.should_receive(:massage_custom_field_attrs) { attrs }
142
146
  klass.send(meth, attrs)
143
147
  end
144
148
  end
@@ -307,25 +307,35 @@ describe Helix::Config do
307
307
  subject { obj.method(meth) }
308
308
  its(:arity) { should eq(-2) }
309
309
  context "when given a url and options" do
310
- let(:opts) { {sig_type: :the_sig_type} }
311
- let(:params) { { params: { signature: 'mock_sig' } } }
310
+ let(:opts) { {sig_type: :the_sig_type, some_key: :some_value} }
311
+ let(:params) { { params: { signature: 'mock_sig', some_key: :some_value } } }
312
312
  let(:returned_csv) { 'x,y,z' }
313
313
  let(:returned_json) { '{"key": "val"}' }
314
314
  let(:returned_xml) { '<root><inner>inner value</inner></root>' }
315
315
  let(:json_parsed) { { "key" => "val" } }
316
316
  let(:xml_parsed) { { "root" => { "inner" => "inner value" } } }
317
317
  before(:each) do
318
- obj.stub(:signature).with(:the_sig_type, opts) { 'mock_sig' }
318
+ obj.stub(:signature).with(:the_sig_type, opts.reject { |k,v| k == :sig_type }) { 'mock_sig' }
319
319
  end
320
320
  context "and the URL matches /json/" do
321
321
  let(:url) { 'blah.json' }
322
+ before(:each) do RestClient.stub(:get).with(url, params) { returned_json } end
323
+ it "should clone the options arg" do
324
+ opts.should_receive(:clone) { opts }
325
+ obj.send(meth, url, opts)
326
+ end
322
327
  it "should call RestClient.get and return a hash from parsed JSON" do
323
328
  RestClient.should_receive(:get).with(url, params) { returned_json }
324
329
  expect(obj.send(meth, url, opts)).to eq(json_parsed)
325
330
  end
326
331
  end
327
- context "and the URL matches /json/" do
332
+ context "and the URL matches /xml/" do
328
333
  let(:url) { 'blah.xml' }
334
+ before(:each) do RestClient.stub(:get).with(url, params) { returned_xml } end
335
+ it "should clone the options arg" do
336
+ opts.should_receive(:clone) { opts }
337
+ obj.send(meth, url, opts)
338
+ end
329
339
  it "should call RestClient.get and return a hash from parsed XML" do
330
340
  RestClient.should_receive(:get).with(url, params) { returned_xml }
331
341
  expect(obj.send(meth, url, opts)).to eq(xml_parsed)
@@ -333,6 +343,11 @@ describe Helix::Config do
333
343
  end
334
344
  context "and the URL matches /csv/" do
335
345
  let(:url) { 'blah.csv' }
346
+ before(:each) do RestClient.stub(:get).with(url, params) { returned_csv } end
347
+ it "should clone the options arg" do
348
+ opts.should_receive(:clone) { opts }
349
+ obj.send(meth, url, opts)
350
+ end
336
351
  it "should call RestClient.get and return the raw CSV response" do
337
352
  RestClient.should_receive(:get).with(url, params) { returned_csv }
338
353
  expect(obj.send(meth, url, opts)).to eq(returned_csv)
@@ -143,6 +143,11 @@ describe Helix::Media do
143
143
  context "when given an opts argument of {key1: :value1}" do
144
144
  let(:opts) { {key1: :value1} }
145
145
  it_behaves_like "builds URL for update"
146
+ it "clones the opts arg" do
147
+ RestClient.stub(:put).with(:expected_url, {signature: 'some_sig', video: opts})
148
+ opts.should_receive(:clone) { opts }
149
+ obj.send(meth, opts)
150
+ end
146
151
  it "should call RestClient.put(output_of_build_url, {signature: the_sig, video: opts}) and return instance of klass" do
147
152
  RestClient.should_receive(:put).with(:expected_url, {signature: 'some_sig', video: opts})
148
153
  expect(obj.send(meth, opts)).to be_an_instance_of(klass)
@@ -17,6 +17,13 @@ describe Helix::Statistics do
17
17
 
18
18
  describe "Constants"
19
19
 
20
+ shared_examples_for "clones the stats opts arg" do
21
+ it "should clone the opts arg" do
22
+ opts.should_receive(:clone) { opts }
23
+ mod.send(meth, opts)
24
+ end
25
+ end
26
+
20
27
  STATS_TYPES.each do |stats_type|
21
28
  STATS_MEDIA_TYPES.each do |resource_label|
22
29
 
@@ -35,6 +42,7 @@ describe Helix::Statistics do
35
42
  media_name = MEDIA_NAME_OF[resource_label] || resource_label
36
43
  context "when given opts containing a :#{media_name}_id" do
37
44
  let(:opts) { {group: :daily, "#{media_name}_id".to_sym => "the_#{media_name}_id".to_sym} }
45
+ it_behaves_like "clones the stats opts arg"
38
46
  it "should refer to the Helix::Config instance" do
39
47
  Helix::Config.should_receive(:instance) { mock_config }
40
48
  mod.send(meth, opts)
@@ -75,6 +83,7 @@ describe Helix::Statistics do
75
83
  end
76
84
  context "when given opts NOT containing a :#{media_name}_id" do
77
85
  let(:opts) { {group: :daily} }
86
+ it_behaves_like "clones the stats opts arg"
78
87
  it "should refer to the Helix::Config instance" do
79
88
  Helix::Config.should_receive(:instance) { mock_config }
80
89
  mod.send(meth, opts)
@@ -114,6 +123,7 @@ describe Helix::Statistics do
114
123
  context "when given opts" do
115
124
  context "and opts has no :action key" do
116
125
  let(:opts) { {group: :daily} }
126
+ it_behaves_like "clones the stats opts arg"
117
127
  it "should refer to the Helix::Config instance" do
118
128
  Helix::Config.should_receive(:instance) { mock_config }
119
129
  mod.send(meth, opts)
@@ -130,6 +140,7 @@ describe Helix::Statistics do
130
140
  [ :encode, :source, :breakdown ].each do |act|
131
141
  context "and opts has an :action value of :#{act}" do
132
142
  let(:opts) { {action: act, group: :daily} }
143
+ it_behaves_like "clones the stats opts arg"
133
144
  it "should refer to the Helix::Config instance" do
134
145
  Helix::Config.should_receive(:instance) { mock_config }
135
146
  mod.send(meth, opts)
@@ -150,6 +161,7 @@ describe Helix::Statistics do
150
161
  publish_name = INGEST_NAME_OF[resource_label] || 'ingest'
151
162
  context "when given opts" do
152
163
  let(:opts) { {group: :daily} }
164
+ it_behaves_like "clones the stats opts arg"
153
165
  it "should refer to the Helix::Config instance" do
154
166
  Helix::Config.should_receive(:instance) { mock_config }
155
167
  mod.send(meth, opts)
@@ -93,7 +93,7 @@ describe Helix::Video do
93
93
  subject { obj.method(meth) }
94
94
  its(:arity) { should eq(-1) }
95
95
  it "should call self.class.get_stillframe" do
96
- obj.stub(:guid).and_return :some_guid
96
+ obj.stub(:guid) { :some_guid }
97
97
  klass.should_receive(:get_stillframe)
98
98
  obj.send(meth)
99
99
  end
@@ -143,7 +143,7 @@ describe Helix::Video do
143
143
  context "when no height or width is passed in " do
144
144
  let(:full_url) { "#{base_url}original.jpg" }
145
145
  it "should build the correct url and return data" do
146
- RestClient.should_receive(:get).with(full_url).and_return image_data
146
+ RestClient.should_receive(:get).with(full_url) { image_data }
147
147
  expect(klass.send(meth, guid)).to eq(image_data)
148
148
  end
149
149
  end
@@ -153,8 +153,13 @@ describe Helix::Video do
153
153
  let(:dim_val) { 100 }
154
154
  let(:full_url) { "#{base_url}#{dim_val}#{url_tag}.jpg" }
155
155
  let(:opts) { { dimension => dim_val } }
156
+ it "should clone the opts arg" do
157
+ RestClient.stub(:get).with(full_url) { image_data }
158
+ opts.should_receive(:clone) { opts }
159
+ klass.send(meth, guid, opts)
160
+ end
156
161
  it "should build the correct url and return data" do
157
- RestClient.should_receive(:get).with(full_url).and_return image_data
162
+ RestClient.should_receive(:get).with(full_url) { image_data }
158
163
  expect(klass.send(meth, guid, opts)).to eq(image_data)
159
164
  end
160
165
  end
@@ -163,8 +168,13 @@ describe Helix::Video do
163
168
  let(:dim_val) { 100 }
164
169
  let(:full_url) { "#{base_url}#{dim_val}w#{dim_val}h.jpg" }
165
170
  let(:opts) { { height: dim_val, width: dim_val } }
171
+ it "should clone the opts arg" do
172
+ RestClient.stub(:get).with(full_url) { image_data }
173
+ opts.should_receive(:clone) { opts }
174
+ klass.send(meth, guid, opts)
175
+ end
166
176
  it "should build the correct url and return data" do
167
- RestClient.should_receive(:get).with(full_url).and_return image_data
177
+ RestClient.should_receive(:get).with(full_url) { image_data }
168
178
  expect(klass.send(meth, guid, opts)).to eq(image_data)
169
179
  end
170
180
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: helix
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 8
5
- version: 0.0.2.6.pre
5
+ version: 0.0.2.7.pre
6
6
  platform: ruby
7
7
  authors:
8
8
  - Twistage, Inc
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-02-14 00:00:00 Z
13
+ date: 2013-02-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -55,36 +55,36 @@ extra_rdoc_files: []
55
55
 
56
56
  files:
57
57
  - lib/helix.rb
58
- - lib/helix/tag.rb
58
+ - lib/helix/album.rb
59
+ - lib/helix/track.rb
60
+ - lib/helix/base.rb
61
+ - lib/helix/library.rb
59
62
  - lib/helix/media.rb
63
+ - lib/helix/durationed_media.rb
64
+ - lib/helix/tag.rb
60
65
  - lib/helix/statistics.rb
61
- - lib/helix/library.rb
66
+ - lib/helix/video_playlist.rb
62
67
  - lib/helix/audio_playlist.rb
63
- - lib/helix/durationed_media.rb
68
+ - lib/helix/video.rb
64
69
  - lib/helix/playlist.rb
65
- - lib/helix/video_playlist.rb
66
70
  - lib/helix/config.rb
67
- - lib/helix/video.rb
68
- - lib/helix/track.rb
69
- - lib/helix/base.rb
70
- - lib/helix/image.rb
71
- - lib/helix/album.rb
72
71
  - lib/helix/exceptions.rb
73
- - spec/spec_helper.rb
74
- - spec/audio_playlist_spec.rb
75
- - spec/config_spec.rb
76
- - spec/image_spec.rb
77
- - spec/media_spec.rb
72
+ - lib/helix/image.rb
78
73
  - spec/durationed_media_spec.rb
79
- - spec/album_spec.rb
74
+ - spec/base_spec.rb
80
75
  - spec/statistics_spec.rb
81
- - spec/tag_spec.rb
82
- - spec/video_playlist_spec.rb
76
+ - spec/config_spec.rb
83
77
  - spec/track_spec.rb
84
- - spec/video_spec.rb
85
78
  - spec/playlist_spec.rb
79
+ - spec/image_spec.rb
86
80
  - spec/library_spec.rb
87
- - spec/base_spec.rb
81
+ - spec/spec_helper.rb
82
+ - spec/audio_playlist_spec.rb
83
+ - spec/video_spec.rb
84
+ - spec/tag_spec.rb
85
+ - spec/album_spec.rb
86
+ - spec/video_playlist_spec.rb
87
+ - spec/media_spec.rb
88
88
  - LICENSE
89
89
  - README.md
90
90
  homepage: https://github.com/Twistage/helix/
@@ -110,9 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements: []
111
111
 
112
112
  rubyforge_project:
113
- rubygems_version: 1.8.11
113
+ rubygems_version: 1.8.24
114
114
  signing_key:
115
115
  specification_version: 3
116
116
  summary: Wrapper library for the video API
117
117
  test_files: []
118
118
 
119
+ has_rdoc: yard