helix 0.0.2.2.pre → 0.0.2.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/helix/base.rb +5 -4
- data/lib/helix/config.rb +1 -1
- data/lib/helix/statistics.rb +10 -10
- data/spec/base_spec.rb +10 -10
- data/spec/config_spec.rb +10 -10
- data/spec/statistics_spec.rb +14 -14
- metadata +2 -2
data/lib/helix/base.rb
CHANGED
@@ -60,8 +60,8 @@ module Helix
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.get_data_sets(opts)
|
63
|
-
url = config.build_url(
|
64
|
-
media_type:
|
63
|
+
url = config.build_url(content_type: opts[:content_type] || :xml,
|
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))
|
67
67
|
data_sets = raw_response[plural_media_type]
|
@@ -112,7 +112,8 @@ module Helix
|
|
112
112
|
#
|
113
113
|
# @return [String] The response from the HTTP DELETE call.
|
114
114
|
def destroy
|
115
|
-
|
115
|
+
RestClient.log = 'helix.log'
|
116
|
+
url = config.build_url(content_type: :xml, guid: guid, media_type: plural_media_type)
|
116
117
|
RestClient.delete(url, params: {signature: config.signature(:update)})
|
117
118
|
end
|
118
119
|
|
@@ -133,7 +134,7 @@ module Helix
|
|
133
134
|
# @return [Base] Returns an instance of the class.
|
134
135
|
def load(opts={})
|
135
136
|
memo_cfg = config
|
136
|
-
url = memo_cfg.build_url(
|
137
|
+
url = memo_cfg.build_url(content_type: :json, guid: self.guid, media_type: plural_media_type)
|
137
138
|
# We allow opts[:sig_type] for internal negative testing only.
|
138
139
|
raw_attrs = memo_cfg.get_response(url, {sig_type: :view}.merge(opts))
|
139
140
|
@attributes = massage_raw_attrs(raw_attrs)
|
data/lib/helix/config.rb
CHANGED
@@ -59,7 +59,7 @@ module Helix
|
|
59
59
|
# @param [Hash] opts a hash of options for building URL
|
60
60
|
# @return [String] The full RESTful URL string object
|
61
61
|
def build_url(opts={})
|
62
|
-
opts[:content_type] ||= :
|
62
|
+
opts[:content_type] ||= :xml
|
63
63
|
opts[:media_type] ||= :videos
|
64
64
|
base_url = get_base_url(opts)
|
65
65
|
url = add_sub_urls(base_url, opts)
|
data/lib/helix/statistics.rb
CHANGED
@@ -125,13 +125,13 @@ module Helix
|
|
125
125
|
private
|
126
126
|
|
127
127
|
def self.delivery(media_type, opts)
|
128
|
-
memo_cfg
|
129
|
-
|
130
|
-
guid
|
131
|
-
url_opts
|
128
|
+
memo_cfg = Helix::Config.instance
|
129
|
+
content_type = opts.delete(:content_type)
|
130
|
+
guid = opts.delete("#{media_type}_id".to_sym)
|
131
|
+
url_opts = guid ?
|
132
132
|
{guid: guid, media_type: "#{media_type}s".to_sym, action: :statistics} :
|
133
133
|
{media_type: :statistics, action: "#{media_type}_delivery".to_sym}
|
134
|
-
url_opts.merge!(
|
134
|
+
url_opts.merge!(content_type: content_type) if content_type
|
135
135
|
url = memo_cfg.build_url(url_opts)
|
136
136
|
# We allow opts[:sig_type] for internal negative testing only.
|
137
137
|
memo_cfg.get_response(url, {sig_type: :view}.merge(opts))
|
@@ -144,11 +144,11 @@ module Helix
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def self.storage(media_type, opts)
|
147
|
-
memo_cfg
|
148
|
-
|
149
|
-
action
|
150
|
-
url_opts
|
151
|
-
url_opts.merge!(
|
147
|
+
memo_cfg = Helix::Config.instance
|
148
|
+
content_type = opts.delete(:content_type)
|
149
|
+
action = opts.delete(:action) || storage_action_for(media_type)
|
150
|
+
url_opts = {media_type: :statistics, action: action}
|
151
|
+
url_opts.merge!(content_type: content_type) if content_type
|
152
152
|
url = memo_cfg.build_url(url_opts)
|
153
153
|
# We allow opts[:sig_type] for internal negative testing only.
|
154
154
|
memo_cfg.get_response(url, {sig_type: :view}.merge(opts))
|
data/spec/base_spec.rb
CHANGED
@@ -52,8 +52,8 @@ describe Helix::Base do
|
|
52
52
|
Helix::Config.stub(:instance) { mock_config }
|
53
53
|
end
|
54
54
|
it "should get an ingest signature" do
|
55
|
-
mock_config.should_receive(:build_url).with(media_type:
|
56
|
-
|
55
|
+
mock_config.should_receive(:build_url).with(media_type: :klasses,
|
56
|
+
content_type: :xml)
|
57
57
|
RestClient.stub(:post).with(:url, params) { resp_json }
|
58
58
|
Hash.should_receive(:from_xml).with(resp_json) { resp_value }
|
59
59
|
klass.stub(:new).with(expected)
|
@@ -61,8 +61,8 @@ describe Helix::Base do
|
|
61
61
|
klass.send(meth)
|
62
62
|
end
|
63
63
|
it "should do an HTTP post call, parse response and call new" do
|
64
|
-
mock_config.should_receive(:build_url).with(media_type:
|
65
|
-
|
64
|
+
mock_config.should_receive(:build_url).with(media_type: :klasses,
|
65
|
+
content_type: :xml)
|
66
66
|
RestClient.should_receive(:post).with(:url, params) { resp_json }
|
67
67
|
Hash.should_receive(:from_xml).with(resp_json) { resp_value }
|
68
68
|
klass.should_receive(:new).with(expected)
|
@@ -108,8 +108,8 @@ describe Helix::Base do
|
|
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(
|
112
|
-
media_type:
|
111
|
+
mock_config.should_receive(:build_url).with(content_type: :xml,
|
112
|
+
media_type: plural_media_type)
|
113
113
|
klass.send(meth, opts)
|
114
114
|
end
|
115
115
|
it "should get_response(the_url, {sig_type: :view}.merge(opts) -> raw_response" do
|
@@ -173,7 +173,7 @@ describe Helix::Base do
|
|
173
173
|
it "should get an update signature" do
|
174
174
|
url = mock_config.build_url(media_type: :media_type,
|
175
175
|
guid: :some_guid,
|
176
|
-
|
176
|
+
content_type: :xml)
|
177
177
|
RestClient.stub(:delete).with(url, params)
|
178
178
|
mock_config.should_receive(:signature).with(:update) { :some_sig }
|
179
179
|
obj.send(meth)
|
@@ -181,7 +181,7 @@ describe Helix::Base do
|
|
181
181
|
it "should call for an HTTP delete and return nil" do
|
182
182
|
url = mock_config.build_url(media_type: :media_type,
|
183
183
|
guid: :some_guid,
|
184
|
-
|
184
|
+
content_type: :xml)
|
185
185
|
RestClient.should_receive(:delete).with(url, params)
|
186
186
|
expect(obj.send(meth)).to be_nil
|
187
187
|
end
|
@@ -225,8 +225,8 @@ describe Helix::Base do
|
|
225
225
|
obj.should_receive(:guid) { 'some_guid' }
|
226
226
|
obj.send(meth)
|
227
227
|
end
|
228
|
-
it "should build_url(
|
229
|
-
mock_config.should_receive(:build_url).with(
|
228
|
+
it "should build_url(content_type: :json, guid: the_guid, media_type: 'videos')" do
|
229
|
+
mock_config.should_receive(:build_url).with(content_type: :json, guid: 'some_guid', media_type: 'videos')
|
230
230
|
RestClient.stub(:put)
|
231
231
|
obj.send(meth)
|
232
232
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -161,44 +161,44 @@ describe Helix::Config do
|
|
161
161
|
context "when given 'create_many' as an action" do
|
162
162
|
opts = { action: :create_many }
|
163
163
|
subject { obj.send(meth, opts) }
|
164
|
-
it_behaves_like "reads scope from credentials for build_url", :videos, :
|
164
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :xml, opts
|
165
165
|
end
|
166
166
|
context "when given NO opts" do
|
167
167
|
subject { obj.send(meth) }
|
168
|
-
it_behaves_like "reads scope from credentials for build_url", :videos, :
|
168
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :xml
|
169
169
|
end
|
170
170
|
context "when given opts of {}" do
|
171
171
|
subject { obj.send(meth, {}) }
|
172
|
-
it_behaves_like "reads scope from credentials for build_url", :videos, :
|
172
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :xml
|
173
173
|
end
|
174
174
|
context "when given opts of {guid: :the_guid}" do
|
175
175
|
subject { obj.send(meth, {guid: :the_guid}) }
|
176
|
-
it_behaves_like "reads scope from credentials for build_url", :videos, :
|
176
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :xml, {guid: :the_guid}
|
177
177
|
end
|
178
178
|
context "when given opts of {action: :the_action}" do
|
179
179
|
subject { obj.send(meth, {action: :the_action}) }
|
180
|
-
it_behaves_like "reads scope from credentials for build_url", :videos, :
|
180
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :xml, {action: :the_action}
|
181
181
|
end
|
182
182
|
context "when given opts of {guid: :the_guid, action: :the_action}" do
|
183
183
|
subject { obj.send(meth, {guid: :the_guid, action: :the_action}) }
|
184
|
-
it_behaves_like "reads scope from credentials for build_url", :videos, :
|
184
|
+
it_behaves_like "reads scope from credentials for build_url", :videos, :xml, {guid: :the_guid, action: :the_action}
|
185
185
|
end
|
186
186
|
[ :videos, :tracks ].each do |media_type|
|
187
187
|
context "when given opts[:media_type] of :#{media_type}" do
|
188
188
|
subject { obj.send(meth, media_type: media_type) }
|
189
|
-
it_behaves_like "reads scope from credentials for build_url", media_type, :
|
189
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :xml
|
190
190
|
end
|
191
191
|
context "when given opts[:media_type] of :#{media_type} and opts[:guid] of :the_guid" do
|
192
192
|
subject { obj.send(meth, media_type: media_type, guid: :the_guid) }
|
193
|
-
it_behaves_like "reads scope from credentials for build_url", media_type, :
|
193
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :xml, {guid: :the_guid}
|
194
194
|
end
|
195
195
|
context "when given opts[:media_type] of :#{media_type} and opts[:action] of :the_action" do
|
196
196
|
subject { obj.send(meth, media_type: media_type, action: :the_action) }
|
197
|
-
it_behaves_like "reads scope from credentials for build_url", media_type, :
|
197
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :xml, {action: :the_action}
|
198
198
|
end
|
199
199
|
context "when given opts[:media_type] of :#{media_type}, opts[:guid] of :the_guid, opts[:action] of :the_action" do
|
200
200
|
subject { obj.send(meth, media_type: media_type, guid: :the_guid, action: :the_action) }
|
201
|
-
it_behaves_like "reads scope from credentials for build_url", media_type, :
|
201
|
+
it_behaves_like "reads scope from credentials for build_url", media_type, :xml, {guid: :the_guid, action: :the_action}
|
202
202
|
end
|
203
203
|
end
|
204
204
|
[ :json, :xml ].each do |content_type|
|
data/spec/statistics_spec.rb
CHANGED
@@ -39,9 +39,9 @@ describe Helix::Statistics do
|
|
39
39
|
Helix::Config.should_receive(:instance) { mock_config }
|
40
40
|
mod.send(meth, opts)
|
41
41
|
end
|
42
|
-
it "should delete :
|
42
|
+
it "should delete :content_type from opts" do
|
43
43
|
opts.stub(:delete)
|
44
|
-
opts.should_receive(:delete).with(:
|
44
|
+
opts.should_receive(:delete).with(:content_type) { "the_#{media_name}_id".to_sym }
|
45
45
|
mod.send(meth, opts)
|
46
46
|
end
|
47
47
|
it "should delete :#{media_name}_id from opts" do
|
@@ -49,20 +49,20 @@ describe Helix::Statistics do
|
|
49
49
|
opts.should_receive(:delete).with("#{media_name}_id".to_sym) { "the_#{media_name}_id".to_sym }
|
50
50
|
mod.send(meth, opts)
|
51
51
|
end
|
52
|
-
context "when opts contains a :
|
53
|
-
before(:each) do opts.merge!(
|
54
|
-
it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics,
|
52
|
+
context "when opts contains a :content_type" do
|
53
|
+
before(:each) do opts.merge!(content_type: :the_format) end
|
54
|
+
it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics, content_type: :the_format)" do
|
55
55
|
build_opts_url = {
|
56
56
|
guid: "the_#{media_name}_id".to_sym,
|
57
57
|
media_type: "#{media_name}s".to_sym,
|
58
58
|
action: :statistics,
|
59
|
-
|
59
|
+
content_type: :the_format
|
60
60
|
}
|
61
61
|
mock_config.should_receive(:build_url).with(build_opts_url) { :built_url }
|
62
62
|
mod.send(meth, opts)
|
63
63
|
end
|
64
64
|
end
|
65
|
-
context "when opts did NOT contain a :
|
65
|
+
context "when opts did NOT contain a :content_type" do
|
66
66
|
it "should call config.build_url(guid: the_#{media_name}_id, media_type: :#{media_name}s, action: :statistics)" do
|
67
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
68
|
mod.send(meth, opts)
|
@@ -79,9 +79,9 @@ describe Helix::Statistics do
|
|
79
79
|
Helix::Config.should_receive(:instance) { mock_config }
|
80
80
|
mod.send(meth, opts)
|
81
81
|
end
|
82
|
-
it "should delete :
|
82
|
+
it "should delete :content_type from opts" do
|
83
83
|
opts.stub(:delete)
|
84
|
-
opts.should_receive(:delete).with(:
|
84
|
+
opts.should_receive(:delete).with(:content_type) { nil }
|
85
85
|
mod.send(meth, opts)
|
86
86
|
end
|
87
87
|
it "should (fail to) delete :#{media_name}_id from opts" do
|
@@ -89,15 +89,15 @@ describe Helix::Statistics do
|
|
89
89
|
opts.should_receive(:delete).with("#{media_name}_id".to_sym) { nil }
|
90
90
|
mod.send(meth, opts)
|
91
91
|
end
|
92
|
-
context "when opts contains a :
|
93
|
-
before(:each) do opts.merge!(
|
94
|
-
it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery,
|
95
|
-
build_url_opts = {media_type: :statistics, action: "#{media_name}_delivery".to_sym,
|
92
|
+
context "when opts contains a :content_type" do
|
93
|
+
before(:each) do opts.merge!(content_type: :the_format) end
|
94
|
+
it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery, content_type: :the_format)" do
|
95
|
+
build_url_opts = {media_type: :statistics, action: "#{media_name}_delivery".to_sym, content_type: :the_format}
|
96
96
|
mock_config.should_receive(:build_url).with(build_url_opts) { :built_url }
|
97
97
|
mod.send(meth, opts)
|
98
98
|
end
|
99
99
|
end
|
100
|
-
context "when opts did NOT contain a :
|
100
|
+
context "when opts did NOT contain a :content_type" do
|
101
101
|
it "should call config.build_url(media_type: :statistics, action: :#{media_name}_delivery)" do
|
102
102
|
mock_config.should_receive(:build_url).with({media_type: :statistics, action: "#{media_name}_delivery".to_sym}) { :built_url }
|
103
103
|
mod.send(meth, opts)
|
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.
|
4
|
+
version: 0.0.2.3.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-
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|