helix 0.0.4.0.pre → 0.0.4.1.pre
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/helix/durationed.rb +9 -0
- data/lib/helix/track.rb +25 -0
- data/lib/helix/video.rb +0 -9
- data/spec/statistics_spec.rb +12 -31
- data/spec/track_spec.rb +63 -0
- metadata +73 -81
data/lib/helix/durationed.rb
CHANGED
@@ -2,6 +2,15 @@ module Helix
|
|
2
2
|
|
3
3
|
module Durationed
|
4
4
|
|
5
|
+
def generic_download(opts)
|
6
|
+
content_type = opts[:content_type] || ''
|
7
|
+
url = config.build_url( action: opts[:action],
|
8
|
+
content_type: content_type,
|
9
|
+
guid: guid,
|
10
|
+
resource_label: plural_resource_label )
|
11
|
+
RestClient.get(url, params: {signature: config.signature(:view)})
|
12
|
+
end
|
13
|
+
|
5
14
|
module ClassMethods
|
6
15
|
|
7
16
|
# Used to import tracks from a URL into the Twistage system.
|
data/lib/helix/track.rb
CHANGED
@@ -16,6 +16,31 @@ module Helix
|
|
16
16
|
# @return [Symbol] Name of the class.
|
17
17
|
def self.resource_label_sym; :track; end
|
18
18
|
|
19
|
+
# Used to download data for the given Track.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# track = Helix::Track.find("239c59483d346")
|
23
|
+
# track_data = track.download #=> xDC\xF1?\xE9*?\xFF\xD9
|
24
|
+
# File.open("my_track.mp3", "w") { |f| f.puts track_data }
|
25
|
+
#
|
26
|
+
# @param [Hash] opts a hash of options for building URL
|
27
|
+
# @return [String] Raw track data, save it to a file
|
28
|
+
def download(opts={})
|
29
|
+
generic_download(opts.merge(action: :file))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Used to play the given Track.
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# track = Helix::Track.find("239c59483d346")
|
36
|
+
# track_data = track.play #=> xDC\xF1?\xE9*?\xFF\xD9
|
37
|
+
#
|
38
|
+
# @param [Hash] opts a hash of options for building URL
|
39
|
+
# @return [String] Raw track data
|
40
|
+
def play(opts={})
|
41
|
+
generic_download(opts.merge(action: :play))
|
42
|
+
end
|
43
|
+
|
19
44
|
end
|
20
45
|
|
21
46
|
end
|
data/lib/helix/video.rb
CHANGED
@@ -106,14 +106,5 @@ module Helix
|
|
106
106
|
url << "#{width.to_s}#{height.to_s}.jpg"
|
107
107
|
end
|
108
108
|
|
109
|
-
def generic_download(opts)
|
110
|
-
content_type = opts[:content_type] || ''
|
111
|
-
url = config.build_url( action: opts[:action],
|
112
|
-
content_type: content_type,
|
113
|
-
guid: guid,
|
114
|
-
resource_label: plural_resource_label )
|
115
|
-
RestClient.get(url, params: {signature: config.signature(:view)})
|
116
|
-
end
|
117
|
-
|
118
109
|
end
|
119
110
|
end
|
data/spec/statistics_spec.rb
CHANGED
@@ -51,30 +51,20 @@ describe Helix::Statistics do
|
|
51
51
|
when 'delivery'
|
52
52
|
media_name = MEDIA_NAME_OF[resource_label] || resource_label
|
53
53
|
context "when given opts containing a :#{media_name}_id" do
|
54
|
-
let(:opts) { {group: :daily, "#{media_name}_id"
|
54
|
+
let(:opts) { {group: :daily, :"#{media_name}_id" => :"the_#{media_name}_id"} }
|
55
55
|
it_behaves_like "clones the stats opts arg"
|
56
56
|
it "should refer to the Helix::Config instance" do
|
57
57
|
Helix::Config.should_receive(:instance) { mock_config }
|
58
58
|
mod.send(meth, opts)
|
59
59
|
end
|
60
|
-
it "should delete :content_type from opts" do
|
61
|
-
opts.stub(:delete)
|
62
|
-
opts.should_receive(:delete).with(:content_type) { "the_#{media_name}_id".to_sym }
|
63
|
-
mod.send(meth, opts)
|
64
|
-
end
|
65
|
-
it "should delete :#{media_name}_id from opts" do
|
66
|
-
opts.stub(:delete)
|
67
|
-
opts.should_receive(:delete).with("#{media_name}_id".to_sym) { "the_#{media_name}_id".to_sym }
|
68
|
-
mod.send(meth, opts)
|
69
|
-
end
|
70
60
|
context "when opts contains a :content_type" do
|
71
61
|
before(:each) do opts.merge!(content_type: :the_format) end
|
72
62
|
it "should call config.build_url(guid: the_#{media_name}_id, resource_label: :#{media_name}s, action: :statistics, content_type: :the_format)" do
|
73
63
|
build_opts_url = {
|
74
|
-
guid:
|
75
|
-
resource_label: "#{media_name}s"
|
76
|
-
action:
|
77
|
-
content_type:
|
64
|
+
guid: :"the_#{media_name}_id",
|
65
|
+
resource_label: :"#{media_name}s",
|
66
|
+
action: :statistics,
|
67
|
+
content_type: :the_format
|
78
68
|
}
|
79
69
|
mock_config.should_receive(:build_url).with(build_opts_url) { :built_url }
|
80
70
|
mod.send(meth, opts)
|
@@ -82,7 +72,8 @@ describe Helix::Statistics do
|
|
82
72
|
end
|
83
73
|
context "when opts did NOT contain a :content_type" do
|
84
74
|
it "should call config.build_url(guid: the_#{media_name}_id, resource_label: :#{media_name}s, action: :statistics)" do
|
85
|
-
|
75
|
+
build_url_opts = {guid: :"the_#{media_name}_id", resource_label: :"#{media_name}s", action: :statistics}
|
76
|
+
mock_config.should_receive(:build_url).with(build_url_opts) { :built_url }
|
86
77
|
mod.send(meth, opts)
|
87
78
|
end
|
88
79
|
end
|
@@ -99,27 +90,17 @@ describe Helix::Statistics do
|
|
99
90
|
Helix::Config.should_receive(:instance) { mock_config }
|
100
91
|
mod.send(meth, opts)
|
101
92
|
end
|
102
|
-
it "should delete :content_type from opts" do
|
103
|
-
opts.stub(:delete)
|
104
|
-
opts.should_receive(:delete).with(:content_type) { nil }
|
105
|
-
mod.send(meth, opts)
|
106
|
-
end
|
107
|
-
it "should (fail to) delete :#{media_name}_id from opts" do
|
108
|
-
opts.stub(:delete)
|
109
|
-
opts.should_receive(:delete).with("#{media_name}_id".to_sym) { nil }
|
110
|
-
mod.send(meth, opts)
|
111
|
-
end
|
112
93
|
context "when opts contains a :content_type" do
|
113
94
|
before(:each) do opts.merge!(content_type: :the_format) end
|
114
95
|
it "should call config.build_url(resource_label: :statistics, action: :#{media_name}_delivery, content_type: :the_format)" do
|
115
|
-
build_url_opts = {resource_label: :statistics, action: "#{media_name}_delivery"
|
96
|
+
build_url_opts = {resource_label: :statistics, action: :"#{media_name}_delivery", content_type: :the_format}
|
116
97
|
mock_config.should_receive(:build_url).with(build_url_opts) { :built_url }
|
117
98
|
mod.send(meth, opts)
|
118
99
|
end
|
119
100
|
end
|
120
101
|
context "when opts did NOT contain a :content_type" do
|
121
102
|
it "should call config.build_url(resource_label: :statistics, action: :#{media_name}_delivery)" do
|
122
|
-
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: "#{media_name}_delivery"
|
103
|
+
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: :"#{media_name}_delivery"}) { :built_url }
|
123
104
|
mod.send(meth, opts)
|
124
105
|
end
|
125
106
|
end
|
@@ -141,7 +122,7 @@ describe Helix::Statistics do
|
|
141
122
|
mod.send(meth, opts)
|
142
123
|
end
|
143
124
|
it "should call config.build_url(resource_label: :statistics, action: :#{media_name}_#{publish_name}/brakdown)" do
|
144
|
-
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: "#{media_name}_#{publish_name}/breakdown"
|
125
|
+
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: :"#{media_name}_#{publish_name}/breakdown"}) { :built_url }
|
145
126
|
mod.send(meth, opts)
|
146
127
|
end
|
147
128
|
it "should assign config.get_response(built_url, opts.merge(sig_type: :view) => raw" do
|
@@ -159,7 +140,7 @@ describe Helix::Statistics do
|
|
159
140
|
mod.send(meth, opts)
|
160
141
|
end
|
161
142
|
it "should call config.build_url(resource_label: :statistics, action: :#{media_name}_#{publish_name}/#{act})" do
|
162
|
-
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: "#{media_name}_#{publish_name}/#{act}"
|
143
|
+
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: :"#{media_name}_#{publish_name}/#{act}"}) { :built_url }
|
163
144
|
mod.send(meth, opts)
|
164
145
|
end
|
165
146
|
it "should assign config.get_response(built_url, opts.merge(sig_type: :view) => raw" do
|
@@ -181,7 +162,7 @@ describe Helix::Statistics do
|
|
181
162
|
mod.send(meth, opts)
|
182
163
|
end
|
183
164
|
it "should call config.build_url(resource_label: :statistics, action: :#{media_name}_#{publish_name}/disk_usage)" do
|
184
|
-
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: "#{media_name}_#{publish_name}/disk_usage"
|
165
|
+
mock_config.should_receive(:build_url).with({resource_label: :statistics, action: :"#{media_name}_#{publish_name}/disk_usage"}) { :built_url }
|
185
166
|
mod.send(meth, opts)
|
186
167
|
end
|
187
168
|
it "should assign config.get_response(built_url, opts.merge(sig_type: :view) => raw" do
|
data/spec/track_spec.rb
CHANGED
@@ -25,6 +25,69 @@ describe Helix::Track do
|
|
25
25
|
[:destroy, :update].each do |crud_call|
|
26
26
|
it { should respond_to(crud_call) }
|
27
27
|
end
|
28
|
+
|
29
|
+
describe "#download" do
|
30
|
+
let(:meth) { :download }
|
31
|
+
let(:mock_config) { double(Helix::Config, build_url: :the_built_url, signature: :some_sig) }
|
32
|
+
subject { obj.method(meth) }
|
33
|
+
let(:params) { { params: {signature: :some_sig } } }
|
34
|
+
before do
|
35
|
+
obj.stub(:config) { mock_config }
|
36
|
+
obj.stub(:guid) { :some_guid }
|
37
|
+
obj.stub(:plural_resource_label) { :resource_label }
|
38
|
+
RestClient.stub(:get) { '' }
|
39
|
+
end
|
40
|
+
{ '' => '', mp3: :mp3, nil => '' }.each do |arg,actual|
|
41
|
+
build_url_h = {action: :file, content_type: actual, guid: :some_guid, resource_label: :resource_label}
|
42
|
+
context "when given {content_type: #{arg}" do
|
43
|
+
it "should build_url(#{build_url_h})" do
|
44
|
+
mock_config.should_receive(:build_url).with(build_url_h)
|
45
|
+
obj.send(meth, content_type: arg)
|
46
|
+
end
|
47
|
+
it "should get a view signature" do
|
48
|
+
mock_config.should_receive(:signature).with(:view) { :some_sig }
|
49
|
+
obj.send(meth, content_type: arg)
|
50
|
+
end
|
51
|
+
it "should return an HTTP get to the built URL with the view sig" do
|
52
|
+
mock_config.stub(:build_url).with(build_url_h) { :the_url }
|
53
|
+
RestClient.should_receive(:get).with(:the_url, params) { :expected }
|
54
|
+
expect(obj.send(meth, content_type: arg)).to be(:expected)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#play" do
|
61
|
+
let(:meth) { :play }
|
62
|
+
let(:mock_config) { double(Helix::Config, build_url: :the_built_url, signature: :some_sig) }
|
63
|
+
subject { obj.method(meth) }
|
64
|
+
let(:params) { { params: {signature: :some_sig } } }
|
65
|
+
before do
|
66
|
+
obj.stub(:config) { mock_config }
|
67
|
+
obj.stub(:guid) { :some_guid }
|
68
|
+
obj.stub(:plural_resource_label) { :resource_label }
|
69
|
+
RestClient.stub(:get) { '' }
|
70
|
+
end
|
71
|
+
{ '' => '', mp3: :mp3, nil => '' }.each do |arg,actual|
|
72
|
+
build_url_h = {action: :play, content_type: actual, guid: :some_guid, resource_label: :resource_label}
|
73
|
+
context "when given {content_type: #{arg}" do
|
74
|
+
it "should build_url(#{build_url_h})" do
|
75
|
+
mock_config.should_receive(:build_url).with(build_url_h)
|
76
|
+
obj.send(meth, content_type: arg)
|
77
|
+
end
|
78
|
+
it "should get a view signature" do
|
79
|
+
mock_config.should_receive(:signature).with(:view) { :some_sig }
|
80
|
+
obj.send(meth, content_type: arg)
|
81
|
+
end
|
82
|
+
it "should return an HTTP get to the built URL with the view sig" do
|
83
|
+
mock_config.stub(:build_url).with(build_url_h) { :the_url }
|
84
|
+
RestClient.should_receive(:get).with(:the_url, params) { :expected }
|
85
|
+
expect(obj.send(meth, content_type: arg)).to be(:expected)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
28
91
|
end
|
29
92
|
|
30
93
|
### CLASS METHODS
|
metadata
CHANGED
@@ -1,136 +1,128 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: helix
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.0.pre
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease: 8
|
5
|
+
version: 0.0.4.1.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
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2013-09-04 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
|
-
|
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
|
-
|
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
|
-
|
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: kevin.baird@perceptivesoftware.com, michael.wood@perceptivesoftware.com
|
64
50
|
executables: []
|
51
|
+
|
65
52
|
extensions: []
|
53
|
+
|
66
54
|
extra_rdoc_files: []
|
67
|
-
|
55
|
+
|
56
|
+
files:
|
68
57
|
- lib/helix.rb
|
69
|
-
- lib/helix/base.rb
|
70
|
-
- lib/helix/audio_playlist.rb
|
71
|
-
- lib/helix/image.rb
|
72
|
-
- lib/helix/restful.rb
|
73
|
-
- lib/helix/hash_ext.rb
|
74
|
-
- lib/helix/library.rb
|
75
58
|
- lib/helix/user.rb
|
76
|
-
- lib/helix/uploadable.rb
|
77
|
-
- lib/helix/statistics.rb
|
78
59
|
- lib/helix/document.rb
|
79
|
-
- lib/helix/
|
60
|
+
- lib/helix/tag.rb
|
61
|
+
- lib/helix/media.rb
|
62
|
+
- lib/helix/statistics.rb
|
80
63
|
- lib/helix/object_ext.rb
|
64
|
+
- lib/helix/library.rb
|
65
|
+
- lib/helix/audio_playlist.rb
|
66
|
+
- lib/helix/uploadable.rb
|
67
|
+
- lib/helix/durationed.rb
|
68
|
+
- lib/helix/playlist.rb
|
69
|
+
- lib/helix/restful.rb
|
81
70
|
- lib/helix/video_playlist.rb
|
82
|
-
- lib/helix/
|
71
|
+
- lib/helix/config.rb
|
83
72
|
- lib/helix/video.rb
|
84
|
-
- lib/helix/album.rb
|
85
|
-
- lib/helix/tag.rb
|
86
|
-
- lib/helix/playlist.rb
|
87
73
|
- lib/helix/track.rb
|
74
|
+
- lib/helix/base.rb
|
75
|
+
- lib/helix/image.rb
|
76
|
+
- lib/helix/album.rb
|
88
77
|
- lib/helix/exceptions.rb
|
89
|
-
- lib/helix/
|
90
|
-
- spec/durationed_spec.rb
|
91
|
-
- spec/document_spec.rb
|
92
|
-
- spec/audio_playlist_spec.rb
|
93
|
-
- spec/library_spec.rb
|
78
|
+
- lib/helix/hash_ext.rb
|
94
79
|
- spec/spec_helper.rb
|
80
|
+
- spec/audio_playlist_spec.rb
|
95
81
|
- spec/config_spec.rb
|
96
|
-
- spec/base_spec.rb
|
97
|
-
- spec/playlist_spec.rb
|
98
|
-
- spec/video_spec.rb
|
99
|
-
- spec/tag_spec.rb
|
100
|
-
- spec/user_spec.rb
|
101
|
-
- spec/_integration_spec.rb
|
102
|
-
- spec/album_spec.rb
|
103
82
|
- spec/image_spec.rb
|
83
|
+
- spec/media_spec.rb
|
84
|
+
- spec/durationed_spec.rb
|
104
85
|
- spec/helix_spec.rb
|
86
|
+
- spec/document_spec.rb
|
87
|
+
- spec/album_spec.rb
|
105
88
|
- spec/statistics_spec.rb
|
89
|
+
- spec/_integration_spec.rb
|
90
|
+
- spec/tag_spec.rb
|
106
91
|
- spec/video_playlist_spec.rb
|
107
|
-
- spec/media_spec.rb
|
108
92
|
- spec/track_spec.rb
|
93
|
+
- spec/user_spec.rb
|
94
|
+
- spec/video_spec.rb
|
95
|
+
- spec/playlist_spec.rb
|
96
|
+
- spec/library_spec.rb
|
97
|
+
- spec/base_spec.rb
|
109
98
|
- LICENSE
|
110
99
|
- README.md
|
111
100
|
homepage: https://github.com/Twistage/helix/
|
112
|
-
licenses:
|
101
|
+
licenses:
|
113
102
|
- 3-Clause BSD
|
114
103
|
post_install_message:
|
115
104
|
rdoc_options: []
|
116
|
-
|
105
|
+
|
106
|
+
require_paths:
|
117
107
|
- lib
|
118
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
109
|
none: false
|
120
|
-
requirements:
|
121
|
-
- -
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version:
|
124
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
115
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
116
|
+
requirements:
|
117
|
+
- - ">"
|
118
|
+
- !ruby/object:Gem::Version
|
129
119
|
version: 1.3.1
|
130
120
|
requirements: []
|
121
|
+
|
131
122
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.8.
|
123
|
+
rubygems_version: 1.8.11
|
133
124
|
signing_key:
|
134
125
|
specification_version: 3
|
135
126
|
summary: Wrapper library for the video API
|
136
127
|
test_files: []
|
128
|
+
|