helix 0.0.4.1.pre → 0.0.4.2.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,7 +50,7 @@ module Helix
50
50
  # @return [String] The full RESTful URL string object
51
51
  def add_sub_urls(base_url, opts)
52
52
  guid, action, format = [:guid, :action, :formats].map { |sub| opts[sub] }
53
- url = "#{base_url}/#{opts[:resource_label]}"
53
+ url = sub_url_scoping(base_url, opts)
54
54
  url += "/#{guid}" if guid
55
55
  url += "/formats/#{format}" if format
56
56
  url += "/#{action}" if action
@@ -174,6 +174,16 @@ module Helix
174
174
 
175
175
  private
176
176
 
177
+ def sub_url_scoping(base_url, opts)
178
+ resource_label = opts[:resource_label]
179
+ if resource_label == 'libraries'
180
+ co_id = opts[:company] || credentials[:company]
181
+ raise "No company to scope to: #{credentials}" if co_id.nil?
182
+ resource_label = "companies/#{co_id}/libraries"
183
+ end
184
+ "#{base_url}/#{resource_label}"
185
+ end
186
+
177
187
  def error_message_for(sig_type)
178
188
  "I don't understand '#{sig_type}'. Please give me one of :ingest, :update, or :view."
179
189
  end
@@ -183,6 +193,14 @@ module Helix
183
193
  @signature_for[license_key][sig_type]
184
194
  end
185
195
 
196
+ def get_contributor_library_company(opts)
197
+ sig_param_labels = [:contributor, :library, :company]
198
+ scoping_proc = lambda { |key| opts[key] || credentials[key] }
199
+ contributor, library, company = sig_param_labels.map(&scoping_proc)
200
+ contributor ||= 'helix_default_contributor'
201
+ [contributor, library, company]
202
+ end
203
+
186
204
  def license_key
187
205
  @credentials[:license_key]
188
206
  end
@@ -227,12 +245,12 @@ module Helix
227
245
  end
228
246
 
229
247
  def url_for(sig_type, opts={})
230
- contributor, library_id, company_id = [:contributor, :library_id, :company_id].map { |key| opts[key] }
231
- contributor ||= (credentials[:contributor] || 'helix_default_contributor')
232
- url = "#{credentials[:site]}/api/#{sig_type}_key?licenseKey=#{credentials[:license_key]}&duration=#{SIG_DURATION}"
248
+ contributor, library, company = get_contributor_library_company(opts)
249
+ url = "#{credentials[:site]}/api/#{sig_type}_key?"
250
+ url += "licenseKey=#{credentials[:license_key]}&duration=#{SIG_DURATION}"
233
251
  url += "&contributor=#{contributor}" if sig_type == :ingest
234
- url += "&library_id=#{library_id}" if library_id
235
- url += "&company_id=#{company_id}" if company_id
252
+ url += "&library_id=#{library}" if library
253
+ url += "&company_id=#{company}" if company
236
254
  url
237
255
  end
238
256
 
@@ -93,7 +93,7 @@ class Hash
93
93
  # configure your own builder with the <tt>:builder</tt> option. The method also accepts
94
94
  # options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
95
95
  def to_xml(options = {})
96
-
96
+
97
97
  options = options.dup
98
98
  options[:indent] ||= 2
99
99
  options[:root] ||= 'hash'
@@ -9,6 +9,10 @@ module Helix
9
9
  # @return [String] A blank String
10
10
  def self.create(attrs={}); super; end
11
11
 
12
+ def self.find(nickname, opts={})
13
+ Helix::RESTful.find(nickname, opts.merge(content_type: :xml))
14
+ end
15
+
12
16
  # The class name, to be used by supporting classes. Such as Config which uses
13
17
  # this method as a way to build URLs.
14
18
  #
@@ -204,8 +204,8 @@ describe Helix::Config do
204
204
  subject { obj.send(meth, {guid: :the_guid, action: :the_action}) }
205
205
  it_behaves_like "reads scope from credentials for build_url", :videos, :xml, {guid: :the_guid, action: :the_action}
206
206
  end
207
- [ :videos, :tracks ].each do |resource_label|
208
- context "when given opts[:resource_label] of :#{resource_label}" do
207
+ %w[ videos tracks ].each do |resource_label|
208
+ context "when given opts[:resource_label] of '#{resource_label}'" do
209
209
  subject { obj.send(meth, resource_label: resource_label) }
210
210
  it_behaves_like "reads scope from credentials for build_url", resource_label, :xml
211
211
  end
@@ -222,6 +222,23 @@ describe Helix::Config do
222
222
  it_behaves_like "reads scope from credentials for build_url", resource_label, :xml, {guid: :the_guid, action: :the_action}
223
223
  end
224
224
  end
225
+ %w[ libraries ].each do |resource_label|
226
+ context "when there is no company in credentials" do
227
+ context "when given opts[:resource_label] of '#{resource_label}'" do
228
+ it "should raise a no company error" do
229
+ the_proc = lambda { obj.send(meth, resource_label: resource_label) }
230
+ expect(the_proc).to raise_error
231
+ end
232
+ end
233
+ end
234
+ context "when there is a company in credentials" do
235
+ before(:each) do obj.credentials.merge!(company: :the_co_id) end
236
+ context "when given opts[:resource_label] of '#{resource_label}'" do
237
+ subject { obj.send(meth, resource_label: resource_label) }
238
+ it { should eq("http://example.com/companies/the_co_id/companies/the_co_id/libraries.xml") }
239
+ end
240
+ end
241
+ end
225
242
  [ :json, :xml ].each do |content_type|
226
243
  context "when given opts[:content_type] of :#{content_type}" do
227
244
  subject { obj.send(meth, content_type: content_type) }
@@ -549,10 +566,16 @@ describe Helix::Config do
549
566
  obj.instance_variable_set(:@signature_expiration_for, sig_exp_for)
550
567
  RestClient.stub(:get) { :fresh_sig }
551
568
  end
569
+ before(:each) do
570
+ Helix::Config.instance.credentials[:company] = "the_co"
571
+ Helix::Config.instance.credentials[:library] = "default"
572
+ end
552
573
  it "should call RestClient.get(#{url})" do
553
574
  set_stubs(obj)
554
575
  url = "#{obj.credentials[:site]}/api/#{sig_type}_key?licenseKey=#{license_key}&duration=1200"
555
576
  url += "&contributor=helix_default_contributor" if sig_type == :ingest
577
+ url += "&library_id=default"
578
+ url += "&company_id=the_co"
556
579
  RestClient.should_receive(:get).with(url) { :fresh_sig }
557
580
  expect(obj.send(meth, sig_type)).to be(:fresh_sig)
558
581
  end
@@ -30,6 +30,24 @@ describe Helix::Library do
30
30
 
31
31
  describe "Constants"
32
32
 
33
+ describe ".find" do
34
+ let(:meth) { :find }
35
+ subject { klass.method(meth) }
36
+ its(:arity) { should eq(-2) }
37
+ context "when given just a nickname" do
38
+ it "should call super(nickname, {content_type: :xml})" do
39
+ Helix::RESTful.should_receive(:find).with(:a_nickname, {content_type: :xml})
40
+ klass.send(meth, :a_nickname)
41
+ end
42
+ end
43
+ context "when given a nickname and opts" do
44
+ it "should call super(nickname, opts.merge(content_type: :xml))" do
45
+ Helix::RESTful.should_receive(:find).with(:a_nickname, {content_type: :xml, k: :v})
46
+ klass.send(meth, :a_nickname, {k: :v})
47
+ end
48
+ end
49
+ end
50
+
33
51
  describe "an instance" do
34
52
  let(:obj) { klass.new({'library_id' => 'some_library_id'}) }
35
53
  subject { obj }
@@ -38,4 +56,5 @@ describe Helix::Library do
38
56
  it { should respond_to(crud_call) }
39
57
  end
40
58
  end
59
+
41
60
  end
metadata CHANGED
@@ -1,128 +1,137 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: helix
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4.2.pre
4
5
  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
- date: 2013-09-04 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: json
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 1.5.4
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rest-client
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.5.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
32
- - - "="
33
- - !ruby/object:Gem::Version
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
34
37
  version: 1.6.7
35
38
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: nori
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: nori
48
+ requirement: !ruby/object:Gem::Requirement
41
49
  none: false
42
- requirements:
43
- - - "="
44
- - !ruby/object:Gem::Version
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
45
53
  version: 1.1.3
46
54
  type: :runtime
47
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.3
48
62
  description: Provides helper libraries for Ruby access to the Twistage API
49
63
  email: kevin.baird@perceptivesoftware.com, michael.wood@perceptivesoftware.com
50
64
  executables: []
51
-
52
65
  extensions: []
53
-
54
66
  extra_rdoc_files: []
55
-
56
- files:
67
+ files:
57
68
  - lib/helix.rb
58
- - lib/helix/user.rb
69
+ - lib/helix/album.rb
70
+ - lib/helix/audio_playlist.rb
71
+ - lib/helix/base.rb
72
+ - lib/helix/config.rb
59
73
  - lib/helix/document.rb
60
- - lib/helix/tag.rb
74
+ - lib/helix/durationed.rb
75
+ - lib/helix/exceptions.rb
76
+ - lib/helix/hash_ext.rb
77
+ - lib/helix/image.rb
78
+ - lib/helix/library.rb
61
79
  - lib/helix/media.rb
62
- - lib/helix/statistics.rb
63
80
  - 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
81
  - lib/helix/playlist.rb
69
82
  - lib/helix/restful.rb
70
- - lib/helix/video_playlist.rb
71
- - lib/helix/config.rb
72
- - lib/helix/video.rb
83
+ - lib/helix/statistics.rb
84
+ - lib/helix/tag.rb
73
85
  - lib/helix/track.rb
74
- - lib/helix/base.rb
75
- - lib/helix/image.rb
76
- - lib/helix/album.rb
77
- - lib/helix/exceptions.rb
78
- - lib/helix/hash_ext.rb
79
- - spec/spec_helper.rb
86
+ - lib/helix/uploadable.rb
87
+ - lib/helix/user.rb
88
+ - lib/helix/video.rb
89
+ - lib/helix/video_playlist.rb
90
+ - spec/_integration_spec.rb
91
+ - spec/album_spec.rb
80
92
  - spec/audio_playlist_spec.rb
93
+ - spec/base_spec.rb
81
94
  - spec/config_spec.rb
82
- - spec/image_spec.rb
83
- - spec/media_spec.rb
95
+ - spec/document_spec.rb
84
96
  - spec/durationed_spec.rb
85
97
  - spec/helix_spec.rb
86
- - spec/document_spec.rb
87
- - spec/album_spec.rb
98
+ - spec/image_spec.rb
99
+ - spec/library_spec.rb
100
+ - spec/media_spec.rb
101
+ - spec/playlist_spec.rb
102
+ - spec/spec_helper.rb
88
103
  - spec/statistics_spec.rb
89
- - spec/_integration_spec.rb
90
104
  - spec/tag_spec.rb
91
- - spec/video_playlist_spec.rb
92
105
  - spec/track_spec.rb
93
106
  - spec/user_spec.rb
107
+ - spec/video_playlist_spec.rb
94
108
  - spec/video_spec.rb
95
- - spec/playlist_spec.rb
96
- - spec/library_spec.rb
97
- - spec/base_spec.rb
98
109
  - LICENSE
99
110
  - README.md
100
111
  homepage: https://github.com/Twistage/helix/
101
- licenses:
112
+ licenses:
102
113
  - 3-Clause BSD
103
114
  post_install_message:
104
115
  rdoc_options: []
105
-
106
- require_paths:
116
+ require_paths:
107
117
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
118
+ required_ruby_version: !ruby/object:Gem::Requirement
109
119
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
114
- required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
125
  none: false
116
- requirements:
117
- - - ">"
118
- - !ruby/object:Gem::Version
126
+ requirements:
127
+ - - ! '>'
128
+ - !ruby/object:Gem::Version
119
129
  version: 1.3.1
120
130
  requirements: []
121
-
122
131
  rubyforge_project:
123
- rubygems_version: 1.8.11
132
+ rubygems_version: 1.8.25
124
133
  signing_key:
125
134
  specification_version: 3
126
135
  summary: Wrapper library for the video API
127
136
  test_files: []
128
-
137
+ has_rdoc: yard