helix 0.0.2.4.pre → 0.0.2.5.pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/helix.rb CHANGED
@@ -6,6 +6,7 @@ require 'helix/album'
6
6
  require 'helix/image'
7
7
  require 'helix/config'
8
8
  require 'helix/statistics'
9
+ require 'helix/library'
9
10
 
10
11
  module Helix
11
12
  end
data/lib/helix/album.rb CHANGED
@@ -22,6 +22,10 @@ module Helix
22
22
  raise "Albums Update is not currently supported."
23
23
  end
24
24
 
25
+ def self.known_attributes
26
+ [:title, :description]
27
+ end
28
+
25
29
  end
26
30
 
27
31
  end
@@ -0,0 +1,8 @@
1
+ require 'helix/media'
2
+
3
+ module Helix
4
+
5
+ class AudioPlaylist
6
+ end
7
+
8
+ end
data/lib/helix/base.rb CHANGED
@@ -23,6 +23,7 @@ module Helix
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
25
  def self.find_all(opts={})
26
+ RestClient.log = 'helix.log' if opts.delete(:log)
26
27
  data_sets = get_data_sets(opts)
27
28
  return [] if data_sets.nil?
28
29
  data_sets.map { |attrs| self.new( attributes: massage_attrs(attrs),
@@ -126,7 +127,7 @@ module Helix
126
127
  begin
127
128
  @attributes[method_sym.to_s]
128
129
  rescue
129
- raise NoMethodError, "#{method_sym} is not recognized within #{self.class.to_s}'s @attributes"
130
+ raise NoMethodError, "#{method_sym} is not recognized within #{self.class.to_s}'s methods or @attributes"
130
131
  end
131
132
  end
132
133
 
@@ -161,6 +162,7 @@ module Helix
161
162
  attrs["custom_fields"].delete_if { |key, val| key.to_s =~ /^@/ }
162
163
  cfs = []
163
164
  attrs["custom_fields"].each do |key, val|
165
+ val = [val] unless val.is_a?(Array)
164
166
  val.each do |val_val|
165
167
  cfs << { "name" => key, "value" => val_val.to_s }
166
168
  end
data/lib/helix/config.rb CHANGED
@@ -52,6 +52,7 @@ module Helix
52
52
  url += "/#{guid}" if guid
53
53
  url += "/formats/#{format}" if format
54
54
  url += "/#{action}" if action
55
+ return url if opts[:content_type].blank?
55
56
  "#{url}.#{opts[:content_type]}"
56
57
  end
57
58
 
@@ -0,0 +1,33 @@
1
+ require 'helix/media'
2
+
3
+ module Helix
4
+
5
+ class Library < Media
6
+
7
+ # The class name, to be used by supporting classes. Such as Config which uses
8
+ # this method as a way to build URLs.
9
+ #
10
+ #
11
+ # @example
12
+ # Helix::Library.media_type_sym #=> :library
13
+ #
14
+ # @return [Symbol] Name of the class.
15
+ def self.media_type_sym; :library; end
16
+
17
+ # Creates a string associated with a class name pluralized
18
+ #
19
+ # @example
20
+ # Helix::Library.plural_media_type #=> "libraries"
21
+ #
22
+ # @return [String] The class name pluralized
23
+ def self.plural_media_type
24
+ "#{self.media_type_sym.to_s.gsub(/y/, '')}ies"
25
+ end
26
+
27
+ def self.known_attributes
28
+ [:player_profile, :ingest_profile, :secure_stream_callback_url, :hooks_attributes]
29
+ end
30
+
31
+ end
32
+
33
+ end
data/lib/helix/media.rb CHANGED
@@ -30,6 +30,7 @@ module Helix
30
30
  # @param [String] guid an id in guid form.
31
31
  # @return [Base] An instance of Helix::Base
32
32
  def self.find(guid)
33
+ raise ArgumentError.new("find requires a non-nil guid argument - received a nil argument.") if guid.nil?
33
34
  item = self.new(attributes: { guid_name => guid }, config: config)
34
35
  item.load
35
36
  end
@@ -65,4 +66,4 @@ module Helix
65
66
  self
66
67
  end
67
68
  end
68
- end
69
+ end
@@ -0,0 +1,8 @@
1
+ require 'helix/media'
2
+
3
+ module Helix
4
+
5
+ class Playlist
6
+ end
7
+
8
+ end
data/lib/helix/video.rb CHANGED
@@ -34,17 +34,43 @@ module Helix
34
34
  # @return [String] Stillframe jpg data, save it to a file with extension .jpg.
35
35
  def self.get_stillframe(guid, opts={})
36
36
  RestClient.log = 'helix.log' if opts.delete(:log)
37
- server = opts[:server] || config.credentials[:server] || "service-staging"
37
+ url = get_stillframe_url(guid, opts)
38
+ RestClient.get(url)
39
+ end
40
+
41
+ def download(opts={})
42
+ generic_download(opts.merge(action: :file))
43
+ end
44
+
45
+ def play(opts={})
46
+ generic_download(opts.merge(action: :play))
47
+ end
48
+
49
+ def stillframe(opts={})
50
+ self.class.get_stillframe(self.guid, opts)
51
+ end
52
+
53
+ private
54
+
55
+ def self.get_stillframe_dimensions(opts)
38
56
  width = opts[:width].to_s + "w" unless opts[:width].nil?
39
57
  height = opts[:height].to_s + "h" unless opts[:height].nil?
40
58
  width = "original" if opts[:width].nil? && opts[:height].nil?
59
+ [width, height]
60
+ end
61
+
62
+ def self.get_stillframe_url(guid, opts)
63
+ server = opts[:server] || config.credentials[:server] || "service-staging"
64
+ width, height = get_stillframe_dimensions(opts)
41
65
  url = "#{server}.twistage.com/videos/#{guid}/screenshots/"
42
66
  url << "#{width.to_s}#{height.to_s}.jpg"
43
- RestClient.get(url)
44
67
  end
45
68
 
46
- def stillframe(opts={})
47
- self.class.get_stillframe(self.guid, opts)
69
+ def generic_download(opts)
70
+ content_type = opts[:content_type] || ''
71
+ url = config.build_url(action: opts[:action], content_type: content_type, guid: guid, media_type: plural_media_type)
72
+ RestClient.get(url, params: {signature: config.signature(:view)})
48
73
  end
74
+
49
75
  end
50
76
  end
@@ -0,0 +1,8 @@
1
+ require 'helix/media'
2
+
3
+ module Helix
4
+
5
+ class VideoPlaylist < Playlist
6
+ end
7
+
8
+ end
data/spec/album_spec.rb CHANGED
@@ -13,6 +13,14 @@ describe Helix::Album do
13
13
  it { should respond_to(crud_call) }
14
14
  end
15
15
 
16
+ describe ".known_attributes" do
17
+ let(:meth) { :known_attributes }
18
+ let(:expected_attrs) { [:title, :description] }
19
+ it "should equal expected_attrs" do
20
+ expect(klass.send(meth)).to eq(expected_attrs)
21
+ end
22
+ end
23
+
16
24
  describe "Constants"
17
25
 
18
26
  describe "an instance" do
File without changes
data/spec/base_spec.rb CHANGED
@@ -167,6 +167,11 @@ describe Helix::Base do
167
167
  it "should return the custom_hash in its form" do
168
168
  expect(klass.send(meth, expected)).to eq(expected)
169
169
  end
170
+ let(:custom_hash_with_false) { { "custom_fields" => {"boole"=>false, "@type"=>"hash"} } }
171
+ let(:expected_with_false) { { "custom_fields" => [{"name"=>"boole", "value"=>"false"}] } }
172
+ it "should turn custom_hash into expected" do
173
+ expect(klass.send(meth, custom_hash_with_false)).to eq(expected_with_false)
174
+ end
170
175
  end
171
176
 
172
177
  describe "an instance" do
@@ -296,7 +301,7 @@ describe Helix::Base do
296
301
  context "and @attributes[method_sym.to_s] raises an exception" do
297
302
  before(:each) do mock_attributes.should_receive(:[]).with(method_sym.to_s).and_raise("some exception") end
298
303
  it "should raise a NoMethodError" do
299
- msg = "#{method_sym} is not recognized within #{klass}'s @attributes"
304
+ msg = "#{method_sym} is not recognized within #{klass}'s methods or @attributes"
300
305
  expect(lambda { obj.send(meth, method_sym) }).to raise_error(msg)
301
306
  end
302
307
  end
data/spec/config_spec.rb CHANGED
@@ -241,6 +241,16 @@ describe Helix::Config do
241
241
  end
242
242
  end
243
243
  end
244
+ dl_opts = {action: :file, content_type: '', guid: :the_guid, media_type: :videos}
245
+ context "when given opts of #{dl_opts}" do
246
+ subject { obj.send(meth, dl_opts) }
247
+ it { should eq("http://example.com/videos/the_guid/file") }
248
+ end
249
+ dp_opts = {action: :play, content_type: '', guid: :the_guid, media_type: :videos}
250
+ context "when given opts of #{dp_opts}" do
251
+ subject { obj.send(meth, dp_opts) }
252
+ it { should eq("http://example.com/videos/the_guid/play") }
253
+ end
244
254
  end
245
255
 
246
256
  describe "#clear_signatures!" do
@@ -0,0 +1,36 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'helix'
3
+
4
+ describe Helix::Library do
5
+
6
+ let(:klass) { Helix::Library }
7
+ subject { klass }
8
+ its(:guid_name) { should eq('library_id') }
9
+ its(:media_type_sym) { should be(:library) }
10
+ its(:plural_media_type) { should eq('libraries') }
11
+ [:find, :create, :all, :find_all, :where].each do |crud_call|
12
+ it { should respond_to(crud_call) }
13
+ end
14
+
15
+ describe ".known_attributes" do
16
+ let(:meth) { :known_attributes }
17
+ let(:expected_attrs) { [ :player_profile,
18
+ :ingest_profile,
19
+ :secure_stream_callback_url,
20
+ :hooks_attributes] }
21
+ it "should equal expected_attrs" do
22
+ expect(klass.send(meth)).to eq(expected_attrs)
23
+ end
24
+ end
25
+
26
+ describe "Constants"
27
+
28
+ describe "an instance" do
29
+ let(:obj) { klass.new({'library_id' => 'some_library_id'}) }
30
+ subject { obj }
31
+ its(:media_type_sym) { should be(:library) }
32
+ [:destroy, :update].each do |crud_call|
33
+ it { should respond_to(crud_call) }
34
+ end
35
+ end
36
+ end
data/spec/media_spec.rb CHANGED
@@ -51,7 +51,6 @@ describe Helix::Media do
51
51
  its(:arity) { should eq(1) }
52
52
  before(:each) do Helix::Config.stub(:instance) { mock_config } end
53
53
  context "when given a Helix::Config instance and a guid" do
54
- let(:guid) { :a_guid }
55
54
  let(:guid_name) { :the_guid_name }
56
55
  let(:mock_attrs) { mock(Object, :[]= => :output_of_setting_val) }
57
56
  before(:each) do
@@ -59,13 +58,22 @@ describe Helix::Media do
59
58
  klass.stub(:guid_name) { guid_name }
60
59
  klass.stub(:new) { mock_obj }
61
60
  end
62
- it "should instantiate with {attributes: guid_name => the_guid, config: config}" do
63
- klass.should_receive(:new).with({attributes: {guid_name => guid}, config: mock_config})
64
- klass.send(meth, guid)
61
+ context "and the guid is nil" do
62
+ it "should raise an ArgumentError complaining about a nil guid" do
63
+ msg = 'find requires a non-nil guid argument - received a nil argument.'
64
+ lambda { klass.send(meth, nil) }.should raise_error(ArgumentError, msg)
65
+ end
65
66
  end
66
- it "should load" do
67
- mock_obj.should_receive(:load)
68
- klass.send(meth, guid)
67
+ context "and the guid is non-nil" do
68
+ let(:guid) { :a_guid }
69
+ it "should instantiate with {attributes: guid_name => the_guid, config: config}" do
70
+ klass.should_receive(:new).with({attributes: {guid_name => guid}, config: mock_config})
71
+ klass.send(meth, guid)
72
+ end
73
+ it "should load" do
74
+ mock_obj.should_receive(:load)
75
+ klass.send(meth, guid)
76
+ end
69
77
  end
70
78
  end
71
79
  end
@@ -142,4 +150,4 @@ describe Helix::Media do
142
150
  end
143
151
  end
144
152
  end
145
- end
153
+ end
File without changes
File without changes
data/spec/video_spec.rb CHANGED
@@ -24,20 +24,85 @@ describe Helix::Video do
24
24
  let(:obj) { klass.new({video_id: 'some_video_guid'}) }
25
25
  subject { obj }
26
26
  its(:media_type_sym) { should be(:video) }
27
+
28
+ describe "#download" do
29
+ let(:meth) { :download }
30
+ let(:mock_config) { mock(Helix::Config, build_url: :the_built_url, signature: :some_sig) }
31
+ subject { obj.method(meth) }
32
+ let(:params) { { params: {signature: :some_sig } } }
33
+ before do
34
+ obj.stub(:config) { mock_config }
35
+ obj.stub(:guid) { :some_guid }
36
+ obj.stub(:plural_media_type) { :media_type }
37
+ RestClient.stub(:get) { '' }
38
+ end
39
+ { '' => '', mp3: :mp3, nil => '' }.each do |arg,actual|
40
+ build_url_h = {action: :file, content_type: actual, guid: :some_guid, media_type: :media_type}
41
+ context "when given {content_type: #{arg}" do
42
+ it "should build_url(#{build_url_h})" do
43
+ mock_config.should_receive(:build_url).with(build_url_h)
44
+ obj.send(meth, content_type: arg)
45
+ end
46
+ it "should get a view signature" do
47
+ mock_config.should_receive(:signature).with(:view) { :some_sig }
48
+ obj.send(meth, content_type: arg)
49
+ end
50
+ it "should return an HTTP get to the built URL with the view sig" do
51
+ mock_config.stub(:build_url).with(build_url_h) { :the_url }
52
+ RestClient.should_receive(:get).with(:the_url, params) { :expected }
53
+ expect(obj.send(meth, content_type: arg)).to be(:expected)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "#play" do
60
+ let(:meth) { :play }
61
+ let(:mock_config) { mock(Helix::Config, build_url: :the_built_url, signature: :some_sig) }
62
+ subject { obj.method(meth) }
63
+ let(:params) { { params: {signature: :some_sig } } }
64
+ before do
65
+ obj.stub(:config) { mock_config }
66
+ obj.stub(:guid) { :some_guid }
67
+ obj.stub(:plural_media_type) { :media_type }
68
+ RestClient.stub(:get) { '' }
69
+ end
70
+ { '' => '', mp3: :mp3, nil => '' }.each do |arg,actual|
71
+ build_url_h = {action: :play, content_type: actual, guid: :some_guid, media_type: :media_type}
72
+ context "when given {content_type: #{arg}" do
73
+ it "should build_url(#{build_url_h})" do
74
+ mock_config.should_receive(:build_url).with(build_url_h)
75
+ obj.send(meth, content_type: arg)
76
+ end
77
+ it "should get a view signature" do
78
+ mock_config.should_receive(:signature).with(:view) { :some_sig }
79
+ obj.send(meth, content_type: arg)
80
+ end
81
+ it "should return an HTTP get to the built URL with the view sig" do
82
+ mock_config.stub(:build_url).with(build_url_h) { :the_url }
83
+ RestClient.should_receive(:get).with(:the_url, params) { :expected }
84
+ expect(obj.send(meth, content_type: arg)).to be(:expected)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
27
90
  describe "#stillframe" do
28
91
  let(:meth) { :stillframe }
29
92
  let(:mock_config) { mock(Helix::Config) }
30
93
  subject { obj.method(meth) }
31
94
  its(:arity) { should eq(-1) }
32
95
  it "should call self.class.get_stillframe" do
33
- obj.stub!(:guid).and_return :some_guid
96
+ obj.stub(:guid).and_return :some_guid
34
97
  klass.should_receive(:get_stillframe)
35
98
  obj.send(meth)
36
99
  end
37
100
  end
101
+
38
102
  [:destroy, :update].each do |crud_call|
39
103
  it { should respond_to(crud_call) }
40
104
  end
105
+
41
106
  end
42
107
 
43
108
  ### CLASS METHODS
metadata CHANGED
@@ -1,119 +1,118 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: helix
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2.4.pre
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease: 8
5
+ version: 0.0.2.5.pre
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Twistage, Inc
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-07 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-02-14 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: json
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 1.5.4
22
- type: :runtime
23
17
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
29
23
  version: 1.5.4
30
- - !ruby/object:Gem::Dependency
31
- name: rest-client
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - '='
36
- - !ruby/object:Gem::Version
37
- version: 1.6.7
38
24
  type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rest-client
39
28
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
- requirements:
43
- - - '='
44
- - !ruby/object:Gem::Version
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
45
34
  version: 1.6.7
46
- - !ruby/object:Gem::Dependency
47
- name: nori
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - '='
52
- - !ruby/object:Gem::Version
53
- version: 1.1.3
54
35
  type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: nori
55
39
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
59
- - - '='
60
- - !ruby/object:Gem::Version
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
61
45
  version: 1.1.3
46
+ type: :runtime
47
+ version_requirements: *id003
62
48
  description: Provides helper libraries for Ruby access to the Twistage API
63
49
  email: kbaird@twistage.com
64
50
  executables: []
51
+
65
52
  extensions: []
53
+
66
54
  extra_rdoc_files: []
67
- files:
55
+
56
+ files:
68
57
  - lib/helix.rb
69
- - lib/helix/album.rb
70
- - lib/helix/base.rb
71
- - lib/helix/image.rb
58
+ - lib/helix/tag.rb
72
59
  - lib/helix/media.rb
60
+ - lib/helix/statistics.rb
61
+ - lib/helix/library.rb
62
+ - lib/helix/audio_playlist.rb
73
63
  - lib/helix/durationed_media.rb
74
- - lib/helix/exceptions.rb
64
+ - lib/helix/playlist.rb
65
+ - lib/helix/video_playlist.rb
75
66
  - lib/helix/config.rb
76
- - lib/helix/tag.rb
77
67
  - lib/helix/video.rb
78
68
  - lib/helix/track.rb
79
- - lib/helix/statistics.rb
80
- - spec/video_spec.rb
69
+ - lib/helix/base.rb
70
+ - lib/helix/image.rb
71
+ - lib/helix/album.rb
72
+ - lib/helix/exceptions.rb
81
73
  - spec/spec_helper.rb
82
- - spec/statistics_spec.rb
74
+ - spec/audio_playlist_spec.rb
83
75
  - spec/config_spec.rb
84
- - spec/media_spec.rb
85
76
  - spec/image_spec.rb
77
+ - spec/media_spec.rb
78
+ - spec/durationed_media_spec.rb
86
79
  - spec/album_spec.rb
80
+ - spec/statistics_spec.rb
81
+ - spec/tag_spec.rb
82
+ - spec/video_playlist_spec.rb
87
83
  - spec/track_spec.rb
84
+ - spec/video_spec.rb
85
+ - spec/playlist_spec.rb
86
+ - spec/library_spec.rb
88
87
  - spec/base_spec.rb
89
- - spec/durationed_media_spec.rb
90
- - spec/tag_spec.rb
91
88
  - LICENSE
92
89
  - README.md
93
90
  homepage: https://github.com/Twistage/helix/
94
- licenses:
91
+ licenses:
95
92
  - 3-Clause BSD
96
93
  post_install_message:
97
94
  rdoc_options: []
98
- require_paths:
95
+
96
+ require_paths:
99
97
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
98
+ required_ruby_version: !ruby/object:Gem::Requirement
101
99
  none: false
102
- requirements:
103
- - - ! '>='
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
105
  none: false
108
- requirements:
109
- - - ! '>'
110
- - !ruby/object:Gem::Version
106
+ requirements:
107
+ - - ">"
108
+ - !ruby/object:Gem::Version
111
109
  version: 1.3.1
112
110
  requirements: []
111
+
113
112
  rubyforge_project:
114
- rubygems_version: 1.8.24
113
+ rubygems_version: 1.8.11
115
114
  signing_key:
116
115
  specification_version: 3
117
116
  summary: Wrapper library for the video API
118
117
  test_files: []
119
- has_rdoc: yard
118
+