helix 0.0.1.5.pre → 0.0.1.6.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.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'helix/durationed_media'
1
2
  require 'helix/video'
2
3
  require 'helix/track'
3
4
  require 'helix/album'
data/lib/helix/config.rb CHANGED
@@ -19,6 +19,7 @@ module Helix
19
19
  end
20
20
 
21
21
  attr_accessor :credentials
22
+ attr_reader :signature_for, :signature_expiration_for
22
23
 
23
24
  # Creates a singleton of itself, setting the config
24
25
  # to a specified YAML file. If no file is specified the default
@@ -62,6 +63,11 @@ module Helix
62
63
  url = add_sub_urls(base_url, opts)
63
64
  end
64
65
 
66
+ def clear_signatures!
67
+ @signature_for = {}
68
+ @signature_expiration_for = {}
69
+ end
70
+
65
71
  # Creates the base url with information collected from credentials.
66
72
  #
67
73
  # @param [Hash] opts a hash of options for building URL
@@ -0,0 +1,57 @@
1
+ module Helix
2
+
3
+ module DurationedMedia
4
+
5
+ module ClassMethods
6
+
7
+ # Standard hash values used to generate the create_many
8
+ # url.
9
+ #
10
+ # @return [Hash]
11
+ def get_url_opts
12
+ { action: :create_many,
13
+ media_type: plural_media_type,
14
+ format: :xml }
15
+ end
16
+
17
+ private
18
+
19
+ # Gets the hash used in adding the signature to the API
20
+ # call.
21
+ #
22
+ # @return [Hash] Returns a formatted hash for passing in the signature to the API call.
23
+ def get_params(opts={})
24
+ opts = { contributor: :helix, library_id: :development }.merge(opts)
25
+ sig = Helix::Config.instance.signature(:ingest, opts)
26
+ #TODO: Find a better way to handle all the different params needed for a call, such as
27
+ #attributes vs signature params vs process params. :url params is a temp fix.
28
+ url_params = (opts[:url_params].nil? ? {} : opts[:url_params])
29
+ { params: (params = { signature: sig }.merge(url_params)) }
30
+ end
31
+
32
+ # Gets the url used in the create_many import call.
33
+ #
34
+ # @return [String] Returns the valid url used for the API call.
35
+ def get_url
36
+ Helix::Config.instance.build_url(self.get_url_opts)
37
+ end
38
+
39
+ # Method allows for :use_raw_xml to be passed into attributes.
40
+ # Normally attributes would be converted to xml, but use_raw_xml
41
+ # takes raw xml as an argument. Allowing for xml files to be
42
+ # used in place of attributes.
43
+ #
44
+ # @param [Hash] attrs The attributes for creating xml.
45
+ # @return [String] Returns xml either from a raw entry or generated from attributes.
46
+ def get_xml(attrs={})
47
+ return attrs[:use_raw_xml] if attrs[:use_raw_xml].present?
48
+ { list: { entry: attrs } }.to_xml(root: :add)
49
+ end
50
+
51
+ end
52
+
53
+ def self.included(klass); klass.extend(ClassMethods); end
54
+
55
+ end
56
+
57
+ end
data/lib/helix/track.rb CHANGED
@@ -2,6 +2,8 @@ module Helix
2
2
 
3
3
  class Track < Base
4
4
 
5
+ include DurationedMedia
6
+
5
7
  # The class name, to be used by supporting classes. Such as Config which uses
6
8
  # this method as a way to build URLs.
7
9
  #
@@ -11,7 +13,7 @@ module Helix
11
13
  #
12
14
  # @return [Symbol] Name of the class.
13
15
  def self.media_type_sym; :track; end
14
-
16
+
15
17
  # Used to import tracks from a URL into the Twistage system.
16
18
  # Doc reference: /doc/api/track/import
17
19
  #
@@ -25,54 +27,11 @@ module Helix
25
27
  # @return [RestClient] The response object.
26
28
  def self.import(attrs={})
27
29
  #TODO: Pull shared logic (with video) into a shared lib file.
28
- RestClient.post(self.get_url,
29
- self.get_xml(attrs),
30
- self.get_params(attrs))
31
- end
32
-
33
- private
34
-
35
- # Method allows for :use_raw_xml to be passed into attributes.
36
- # Normally attributes would be converted to xml, but use_raw_xml
37
- # takes raw xml as an argument. Allowing for xml files to be
38
- # used in place of attributes.
39
- #
40
- # @param [Hash] attrs The attributes for creating xml.
41
- # @return [String] Returns xml either from a raw entry or generated from attributes.
42
- def self.get_xml(attrs={})
43
- return attrs[:use_raw_xml] if attrs[:use_raw_xml].present?
44
- { list: { entry: attrs } }.to_xml(root: :add)
45
- end
46
-
47
- # Standard hash values used to generate the create_many
48
- # url.
49
- #
50
- # @return [Hash]
51
- def self.get_url_opts
52
- { action: :create_many,
53
- media_type: plural_media_type,
54
- format: :xml }
30
+ RestClient.post(get_url,
31
+ get_xml(attrs),
32
+ get_params(attrs))
55
33
  end
56
34
 
57
- # Gets the url used in the create_many import call.
58
- #
59
- # @return [String] Returns the valid url used for the API call.
60
- def self.get_url
61
- Helix::Config.instance.build_url(self.get_url_opts)
62
- end
63
-
64
- # Gets the hash used in adding the signature to the API
65
- # call.
66
- #
67
- # @return [Hash] Returns a formatted hash for passing in the signature to the API call.
68
- def self.get_params(opts={})
69
- opts = { contributor: :helix, library_id: :development }.merge(opts)
70
- sig = Helix::Config.instance.signature(:ingest, opts)
71
- #TODO: Find a better way to handle all the different params needed for a call, such as
72
- #attributes vs signature params vs process params. :url params is a temp fix.
73
- url_params = (opts[:url_params].nil? ? {} : opts[:url_params])
74
- { params: (params = { signature: sig }.merge(url_params)) }
75
- end
76
35
  end
77
36
 
78
37
  end
data/lib/helix/video.rb CHANGED
@@ -5,6 +5,8 @@ module Helix
5
5
 
6
6
  class Video < Base
7
7
 
8
+ include DurationedMedia
9
+
8
10
  # The class name, to be used by supporting classes. Such as Config which uses
9
11
  # this method as a way to build URLs.
10
12
  #
@@ -27,53 +29,11 @@ module Helix
27
29
  # @param [Hash] attrs The attributes for creating a video.
28
30
  # @return [RestClient] The response object.
29
31
  def self.import(attrs={})
30
- RestClient.post(self.get_url,
31
- self.get_xml(attrs),
32
- self.get_params(attrs))
33
- end
34
-
35
- private
36
-
37
- # Method allows for :use_raw_xml to be passed into attributes.
38
- # Normally attributes would be converted to xml, but use_raw_xml
39
- # takes raw xml as an argument. Allowing for xml files to be
40
- # used in place of attributes.
41
- #
42
- # @param [Hash] attrs The attributes for creating xml.
43
- # @return [String] Returns xml either from a raw entry or generated from attributes.
44
- def self.get_xml(attrs={})
45
- return attrs[:use_raw_xml] if attrs[:use_raw_xml].present?
46
- { list: { entry: attrs } }.to_xml(root: :add)
47
- end
48
-
49
- # Standard hash values used to generate the create_many
50
- # url.
51
- #
52
- # @return [Hash]
53
- def self.get_url_opts
54
- { action: :create_many,
55
- media_type: plural_media_type,
56
- format: :xml }
57
- end
58
-
59
- # Gets the url used in the create_many import call.
60
- #
61
- # @return [String] Returns the valid url used for the API call.
62
- def self.get_url
63
- Helix::Config.instance.build_url(self.get_url_opts)
32
+ RestClient.post(get_url,
33
+ get_xml(attrs),
34
+ get_params(attrs))
64
35
  end
65
36
 
66
- # Gets the hash used in adding the signature to the API
67
- # call.
68
- #
69
- # @return [Hash] Returns a formatted hash for passing in the signature to the API call.
70
- def self.get_params(opts={})
71
- opts = { contributor: :helix, library_id: :development }.merge(opts)
72
- sig = Helix::Config.instance.signature(:ingest, opts)
73
- #TODO: Find a better way to handle all the different params needed for a call, such as
74
- #attributes vs signature params vs process params. :url params is a temp fix.
75
- url_params = (opts[:url_params].nil? ? {} : opts[:url_params])
76
- { params: (params = { signature: sig }.merge(url_params)) }
77
- end
78
37
  end
38
+
79
39
  end
data/spec/config_spec.rb CHANGED
@@ -237,6 +237,24 @@ describe Helix::Config do
237
237
  end
238
238
  end
239
239
 
240
+ describe "#clear_signatures!" do
241
+ let(:meth) { :clear_signatures! }
242
+
243
+ subject { obj.method(meth) }
244
+ its(:arity) { should eq(0) }
245
+
246
+ it "should set @signature_for to {}" do
247
+ obj.send(meth)
248
+ expect(obj.instance_variable_get(:@signature_for)).to eq({})
249
+ end
250
+
251
+ it "should set @signature_expiration_for to {}" do
252
+ obj.send(meth)
253
+ expect(obj.instance_variable_get(:@signature_expiration_for)).to eq({})
254
+ end
255
+
256
+ end
257
+
240
258
  describe "#existing_sig_for" do
241
259
  let(:meth) { :existing_sig_for }
242
260
 
@@ -444,4 +462,13 @@ describe Helix::Config do
444
462
  end
445
463
  end
446
464
  end
465
+
466
+ [ :signature_for, :signature_expiration_for ].each do |meth|
467
+ describe "##{meth}" do
468
+ it "should respond to :#{meth}" do
469
+ expect(obj).to respond_to(meth)
470
+ end
471
+ end
472
+ end
473
+
447
474
  end
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.1.5.pre
4
+ version: 0.0.1.6.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: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - '='
52
52
  - !ruby/object:Gem::Version
53
53
  version: 1.1.3
54
54
  type: :runtime
@@ -56,7 +56,7 @@ dependencies:
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.1.3
62
62
  description: Provides helper libraries for Ruby access to the Twistage API
@@ -69,6 +69,7 @@ files:
69
69
  - lib/helix/album.rb
70
70
  - lib/helix/base.rb
71
71
  - lib/helix/image.rb
72
+ - lib/helix/durationed_media.rb
72
73
  - lib/helix/config.rb
73
74
  - lib/helix/video.rb
74
75
  - lib/helix/track.rb