helix 0.0.1.3.pre → 0.0.1.4.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.
@@ -39,8 +39,12 @@ module Helix
39
39
  # @example
40
40
  # Helix::Statistics.audio_ingest #=> Array of Hashes of stats data
41
41
  #
42
+ # Takes one of :encode, :source, or :breakdown as the :action value. Defaults to :breakdown.
43
+ #
42
44
  # @return [Array of Hashes] Statistics information.
43
45
  def self.audio_ingest(opts={})
46
+ opts[:action] ||= :breakdown
47
+ self.storage(:track, opts.merge(action: :"track_ingest/#{opts[:action]}"))
44
48
  end
45
49
 
46
50
  # @example
@@ -78,6 +82,8 @@ module Helix
78
82
  # @example
79
83
  # Helix::Statistics.track_ingest #=> Array of Hashes of stats data
80
84
  #
85
+ # Takes one of :encode, :source, or :breakdown as the :action value. Defaults to :breakdown.
86
+ #
81
87
  # @return [Array of Hashes] Statistics information.
82
88
  def self.track_ingest(opts={})
83
89
  self.audio_ingest(opts)
@@ -102,9 +108,12 @@ module Helix
102
108
  # @example
103
109
  # Helix::Statistics.video_ingest #=> Array of Hashes of stats data
104
110
  #
111
+ # Takes one of :encode, :source, or :breakdown as the :action value. Defaults to :breakdown.
112
+ #
105
113
  # @return [Array of Hashes] Statistics information.
106
114
  def self.video_ingest(opts={})
107
- # encode, source, or breakdown
115
+ opts[:action] ||= :breakdown
116
+ self.storage(:video, opts.merge(action: :"video_publish/#{opts[:action]}"))
108
117
  end
109
118
 
110
119
  # @example
@@ -133,7 +142,8 @@ module Helix
133
142
  def self.storage(media_type, opts)
134
143
  memo_cfg = Helix::Config.instance
135
144
  format = opts.delete(:format)
136
- url_opts = {media_type: :statistics, action: storage_action_for(media_type)}
145
+ action = opts.delete(:action) || storage_action_for(media_type)
146
+ url_opts = {media_type: :statistics, action: action}
137
147
  url_opts.merge!(format: format) if format
138
148
  url = memo_cfg.build_url(url_opts)
139
149
  # We allow opts[:sig_type] for internal negative testing only.
@@ -30,102 +30,140 @@ describe Helix::Statistics do
30
30
  subject { mod.method(meth) }
31
31
  its(:arity) { should eq(-1) }
32
32
 
33
- if stats_type == 'delivery'
34
- media_name = MEDIA_NAME_OF[media_type] || media_type
35
- context "when given opts containing a :#{media_name}_id" do
36
- let(:opts) { {group: :daily, "#{media_name}_id".to_sym => "the_#{media_name}_id".to_sym} }
37
- it "should refer to the Helix::Config instance" do
38
- Helix::Config.should_receive(:instance) { mock_config }
39
- mod.send(meth, opts)
40
- end
41
- it "should delete :format from opts" do
42
- opts.stub(:delete)
43
- opts.should_receive(:delete).with(:format) { "the_#{media_name}_id".to_sym }
44
- mod.send(meth, opts)
45
- end
46
- it "should delete :#{media_name}_id from opts" do
47
- opts.stub(:delete)
48
- opts.should_receive(:delete).with("#{media_name}_id".to_sym) { "the_#{media_name}_id".to_sym }
49
- mod.send(meth, opts)
50
- end
51
- context "when opts contains a :format" do
52
- before(:each) do opts.merge!(format: :the_format) end
53
- it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics, format: :the_format)" do
54
- build_opts_url = {
55
- guid: "the_#{media_name}_id".to_sym,
56
- media_type: "#{media_name}s".to_sym,
57
- action: :statistics,
58
- format: :the_format
59
- }
60
- mock_config.should_receive(:build_url).with(build_opts_url) { :built_url }
33
+ case stats_type
34
+ when 'delivery'
35
+ media_name = MEDIA_NAME_OF[media_type] || media_type
36
+ context "when given opts containing a :#{media_name}_id" do
37
+ let(:opts) { {group: :daily, "#{media_name}_id".to_sym => "the_#{media_name}_id".to_sym} }
38
+ it "should refer to the Helix::Config instance" do
39
+ Helix::Config.should_receive(:instance) { mock_config }
61
40
  mod.send(meth, opts)
62
41
  end
63
- end
64
- context "when opts did NOT contain a :format" do
65
- it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics)" do
66
- mock_config.should_receive(:build_url).with({guid: "the_#{media_name}_id".to_sym, media_type: "#{media_name}s".to_sym, action: :statistics}) { :built_url }
42
+ it "should delete :format from opts" do
43
+ opts.stub(:delete)
44
+ opts.should_receive(:delete).with(:format) { "the_#{media_name}_id".to_sym }
67
45
  mod.send(meth, opts)
68
46
  end
69
- end
70
- it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
71
- mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
72
- expect(mod.send(meth, opts)).to eq(:response)
73
- end
74
- end
75
- context "when given opts NOT containing a :#{media_name}_id" do
76
- let(:opts) { {group: :daily} }
77
- it "should refer to the Helix::Config instance" do
78
- Helix::Config.should_receive(:instance) { mock_config }
79
- mod.send(meth, opts)
80
- end
81
- it "should delete :format from opts" do
82
- opts.stub(:delete)
83
- opts.should_receive(:delete).with(:format) { nil }
84
- mod.send(meth, opts)
85
- end
86
- it "should (fail to) delete :#{media_name}_id from opts" do
87
- opts.stub(:delete)
88
- opts.should_receive(:delete).with("#{media_name}_id".to_sym) { nil }
89
- mod.send(meth, opts)
90
- end
91
- context "when opts contains a :format" do
92
- before(:each) do opts.merge!(format: :the_format) end
93
- it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery, format: :the_format)" do
94
- build_url_opts = {media_type: :statistics, action: "#{media_name}_delivery".to_sym, format: :the_format}
95
- mock_config.should_receive(:build_url).with(build_url_opts) { :built_url }
47
+ it "should delete :#{media_name}_id from opts" do
48
+ opts.stub(:delete)
49
+ opts.should_receive(:delete).with("#{media_name}_id".to_sym) { "the_#{media_name}_id".to_sym }
96
50
  mod.send(meth, opts)
97
51
  end
52
+ context "when opts contains a :format" do
53
+ before(:each) do opts.merge!(format: :the_format) end
54
+ it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics, format: :the_format)" do
55
+ build_opts_url = {
56
+ guid: "the_#{media_name}_id".to_sym,
57
+ media_type: "#{media_name}s".to_sym,
58
+ action: :statistics,
59
+ format: :the_format
60
+ }
61
+ mock_config.should_receive(:build_url).with(build_opts_url) { :built_url }
62
+ mod.send(meth, opts)
63
+ end
64
+ end
65
+ context "when opts did NOT contain a :format" do
66
+ it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics)" do
67
+ mock_config.should_receive(:build_url).with({guid: "the_#{media_name}_id".to_sym, media_type: "#{media_name}s".to_sym, action: :statistics}) { :built_url }
68
+ mod.send(meth, opts)
69
+ end
70
+ end
71
+ it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
72
+ mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
73
+ expect(mod.send(meth, opts)).to eq(:response)
74
+ end
98
75
  end
99
- context "when opts did NOT contain a :format" do
100
- it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery)" do
101
- mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_delivery".to_sym}) { :built_url }
76
+ context "when given opts NOT containing a :#{media_name}_id" do
77
+ let(:opts) { {group: :daily} }
78
+ it "should refer to the Helix::Config instance" do
79
+ Helix::Config.should_receive(:instance) { mock_config }
102
80
  mod.send(meth, opts)
103
81
  end
82
+ it "should delete :format from opts" do
83
+ opts.stub(:delete)
84
+ opts.should_receive(:delete).with(:format) { nil }
85
+ mod.send(meth, opts)
86
+ end
87
+ it "should (fail to) delete :#{media_name}_id from opts" do
88
+ opts.stub(:delete)
89
+ opts.should_receive(:delete).with("#{media_name}_id".to_sym) { nil }
90
+ mod.send(meth, opts)
91
+ end
92
+ context "when opts contains a :format" do
93
+ before(:each) do opts.merge!(format: :the_format) end
94
+ it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery, format: :the_format)" do
95
+ build_url_opts = {media_type: :statistics, action: "#{media_name}_delivery".to_sym, format: :the_format}
96
+ mock_config.should_receive(:build_url).with(build_url_opts) { :built_url }
97
+ mod.send(meth, opts)
98
+ end
99
+ end
100
+ context "when opts did NOT contain a :format" do
101
+ it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery)" do
102
+ mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_delivery".to_sym}) { :built_url }
103
+ mod.send(meth, opts)
104
+ end
105
+ end
106
+ it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
107
+ mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
108
+ expect(mod.send(meth, opts)).to eq(:response)
109
+ end
104
110
  end
105
- it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
106
- mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
107
- expect(mod.send(meth, opts)).to eq(:response)
108
- end
109
- end
110
- end
111
- if stats_type == 'storage'
112
- media_name = MEDIA_NAME_OF[media_type] || media_type
113
- publish_name = INGEST_NAME_OF[media_type] || 'ingest'
114
- context "when given opts" do
115
- let(:opts) { {group: :daily} }
116
- it "should refer to the Helix::Config instance" do
117
- Helix::Config.should_receive(:instance) { mock_config }
118
- mod.send(meth, opts)
119
- end
120
- it "should call config.build_url(media_type: :statistics, action: :#{media_name}_#{publish_name}/disk_usage)" do
121
- mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_#{publish_name}/disk_usage".to_sym}) { :built_url }
122
- mod.send(meth, opts)
111
+ when 'ingest'
112
+ media_name = MEDIA_NAME_OF[media_type] || media_type
113
+ publish_name = INGEST_NAME_OF[media_type] || 'ingest'
114
+ context "when given opts" do
115
+ context "and opts has no :action key" do
116
+ let(:opts) { {group: :daily} }
117
+ it "should refer to the Helix::Config instance" do
118
+ Helix::Config.should_receive(:instance) { mock_config }
119
+ mod.send(meth, opts)
120
+ end
121
+ it "should call config.build_url(media_type: :statistics, action: :#{media_name}_#{publish_name}/brakdown)" do
122
+ mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_#{publish_name}/breakdown".to_sym}) { :built_url }
123
+ mod.send(meth, opts)
124
+ end
125
+ it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
126
+ mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
127
+ expect(mod.send(meth, opts)).to eq(:response)
128
+ end
129
+ end
130
+ [ :encode, :source, :breakdown ].each do |act|
131
+ context "and opts has an :action value of :#{act}" do
132
+ let(:opts) { {action: act, group: :daily} }
133
+ it "should refer to the Helix::Config instance" do
134
+ Helix::Config.should_receive(:instance) { mock_config }
135
+ mod.send(meth, opts)
136
+ end
137
+ it "should call config.build_url(media_type: :statistics, action: :#{media_name}_#{publish_name}/#{act})" do
138
+ mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_#{publish_name}/#{act}".to_sym}) { :built_url }
139
+ mod.send(meth, opts)
140
+ end
141
+ it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
142
+ mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
143
+ expect(mod.send(meth, opts)).to eq(:response)
144
+ end
145
+ end
146
+ end
123
147
  end
124
- it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
125
- mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
126
- expect(mod.send(meth, opts)).to eq(:response)
148
+ when 'storage'
149
+ media_name = MEDIA_NAME_OF[media_type] || media_type
150
+ publish_name = INGEST_NAME_OF[media_type] || 'ingest'
151
+ context "when given opts" do
152
+ let(:opts) { {group: :daily} }
153
+ it "should refer to the Helix::Config instance" do
154
+ Helix::Config.should_receive(:instance) { mock_config }
155
+ mod.send(meth, opts)
156
+ end
157
+ it "should call config.build_url(media_type: :statistics, action: :#{media_name}_#{publish_name}/disk_usage)" do
158
+ mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_#{publish_name}/disk_usage".to_sym}) { :built_url }
159
+ mod.send(meth, opts)
160
+ end
161
+ it "should return config.get_response(built_url, opts.merge(sig_type: :view)" do
162
+ mock_config.should_receive(:get_response).with(:built_url, {group: :daily, sig_type: :view}) { :response }
163
+ expect(mod.send(meth, opts)).to eq(:response)
164
+ end
127
165
  end
128
- end
166
+ # nested in for case
129
167
  end
130
168
 
131
169
  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.1.3.pre
5
+ version: 0.0.1.4.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: 2012-11-29 00:00:00 Z
13
+ date: 2012-12-03 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json