helix 0.0.0.pre → 0.0.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/README.md CHANGED
@@ -1,6 +1,3 @@
1
- http://nestacms.com/docs/creating-content/markdown-cheat-sheet
2
- http://support.mashery.com/docs/customizing_your_portal/Markdown_Cheat_Sheet
3
-
4
1
  # Helix
5
2
 
6
3
  The Helix gem allows developers to easily connect to and manipulate the Twistage API.
@@ -60,7 +57,7 @@ Supported Ruby versions
60
57
 
61
58
  How To
62
59
  ------
63
-
60
+ Warning: How To is not currently finished, it may be inaccurate.
64
61
  ###Setup YAML
65
62
  ```yaml
66
63
  site: 'http://service.twistage.com'
@@ -159,11 +156,11 @@ Credits
159
156
 
160
157
  Helix was written by Kevin Baird and Michael Wood.
161
158
 
162
- Helix is maintained and funded by [Twistage, inc](http://twistage.com)
159
+ Helix is maintained and funded by [Twistage, Inc](http://twistage.com)
163
160
 
164
- The names and logos for twistage are trademarks of twistage, inc.
161
+ The names and logos for twistage are trademarks of Twistage, Inc.
165
162
 
166
163
  License
167
164
  -------
168
165
 
169
- Helix is Copyright © 2008-2012 Twistage, inc.
166
+ Helix is Copyright © 2008-2012 Twistage, Inc.
@@ -1,7 +1,7 @@
1
1
  require 'rest_client'
2
2
  require 'json'
3
3
  require 'yaml'
4
- require 'crack'
4
+ require 'active_support/core_ext'
5
5
 
6
6
  module Helix
7
7
  class Base
@@ -18,26 +18,16 @@ module Helix
18
18
  # normally be called as Helix::Base.create
19
19
  #
20
20
  # @example
21
- # Helix::Video.create({title: "My new video"})
21
+ # Helix::Album.create({title: "My new album"})
22
22
  #
23
23
  # @param [Hash] attributes a hash containing the attributes used in the create
24
24
  # @return [Base] An instance of Helix::Base
25
25
  def self.create(attributes={})
26
26
  config = Helix::Config.instance
27
- #xml = '<?xml version="1.0" encoding="UTF-8"?>
28
- # <add>
29
- # <list>
30
- # <entry>
31
- # <src>http://www.minhreigen.com/videos/play.mp4</src>
32
- # <title>Summer camp dance</title>
33
- # <description>This one is the best</description>
34
- # </entry>
35
- # </list>
36
- # </add>'.gsub!(/\s{2,}|\n/, "")
37
27
  url = config.build_url(media_type: plural_media_type,
38
28
  format: :xml)
39
29
  response = RestClient.post(url, attributes.merge(signature: config.signature(:update)))
40
- attrs = Crack::XML.parse(response)
30
+ attrs = Hash.from_xml(response)
41
31
  self.new(attributes: attrs[media_type_sym.to_s], config: config)
42
32
  end
43
33
 
@@ -1,4 +1,5 @@
1
1
  require 'helix/base'
2
+ require 'active_support/core_ext'
2
3
 
3
4
  module Helix
4
5
 
@@ -14,6 +15,61 @@ module Helix
14
15
  # @return [Symbol] Name of the class.
15
16
  def self.media_type_sym; :video; end
16
17
 
17
- end
18
+ # Used to import videos from a URL into the Twistage system.
19
+ #
20
+ # @example
21
+ # video = Helix::Video.import(src: "www.google.com/video.mp4",
22
+ # title: "Some Title,
23
+ # description: "A random video.")
24
+ # new_video.video_id # => dd891b83ba39e
25
+ #
26
+ # @param [Hash] attrs The attributes for creating a video
27
+ # @return [RestClient] The response object.
28
+ def self.import(attrs={})
29
+ RestClient.post(self.get_url, self.get_xml(attrs), self.get_params)
30
+ end
31
+
32
+ private
33
+
34
+ # Method allows for :use_raw_xml to be passed into attributes.
35
+ # Normally attributes would be converted to xml, but use_raw_xml
36
+ # takes raw xml as an argument. Allowing for xml files to be
37
+ # used in place of attributes.
38
+ #
39
+ #
40
+ # @return [String] Returns xml either from a raw entry or generated from attributes.
41
+ def self.get_xml(attrs={})
42
+ return attrs[:use_raw_xml] if attrs[:use_raw_xml].present?
43
+ { list: { entry: attrs } }.to_xml(root: :add)
44
+ end
18
45
 
46
+ # Standard hash values used to generate the create_many
47
+ # url.
48
+ #
49
+ #
50
+ # @return [Hash]
51
+ def self.get_url_opts
52
+ { action: :create_many,
53
+ media_type: plural_media_type,
54
+ format: :xml }
55
+ end
56
+
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
69
+ opts = { contributor: :helix, library_id: :development }
70
+ sig = Helix::Config.instance.signature(:ingest, opts)
71
+ { params: { signature: sig } }
72
+ end
73
+
74
+ end
19
75
  end
@@ -45,7 +45,7 @@ describe Helix::Base do
45
45
  mock_config.should_receive(:build_url).with(media_type: :klasses,
46
46
  format: :xml)
47
47
  RestClient.stub(:post).with(:url, params) { resp_json }
48
- Crack::XML.should_receive(:parse).with(resp_json) { resp_value }
48
+ Hash.should_receive(:from_xml).with(resp_json) { resp_value }
49
49
  klass.stub(:new).with(expected)
50
50
  mock_config.should_receive(:signature).with(:update) { "some_sig" }
51
51
  klass.send(meth)
@@ -54,7 +54,7 @@ describe Helix::Base do
54
54
  mock_config.should_receive(:build_url).with(media_type: :klasses,
55
55
  format: :xml)
56
56
  RestClient.should_receive(:post).with(:url, params) { resp_json }
57
- Crack::XML.should_receive(:parse).with(resp_json) { resp_value }
57
+ Hash.should_receive(:from_xml).with(resp_json) { resp_value }
58
58
  klass.should_receive(:new).with(expected)
59
59
  klass.send(meth)
60
60
  end
@@ -2,20 +2,100 @@ require File.expand_path('../spec_helper', __FILE__)
2
2
  require 'helix'
3
3
 
4
4
  describe Helix::Video do
5
+
6
+ def import_xml(values={})
7
+ { list: { entry: values } }.to_xml(root: :add)
8
+ end
9
+
5
10
  let(:klass) { Helix::Video }
6
11
 
7
- subject { klass }
8
- its(:ancestors) { should include(Helix::Base) }
9
- its(:guid_name) { should eq('video_id') }
12
+ subject { klass }
13
+ its(:ancestors) { should include(Helix::Base) }
14
+ its(:guid_name) { should eq('video_id') }
10
15
  its(:media_type_sym) { should be(:video) }
11
16
  its(:plural_media_type) { should eq('videos') }
12
17
 
13
18
  describe "Constants"
14
19
 
20
+ let(:sig_opts) { { contributor: :helix,
21
+ library_id: :development } }
22
+ let(:url_opts) { { action: :create_many,
23
+ media_type: "videos",
24
+ format: :xml } }
25
+
15
26
  describe "an instance" do
16
- let(:obj) { klass.new({'video_id' => 'some_video_guid'}) }
17
- subject { obj }
18
- its(:media_type_sym) { should be(:video) }
27
+ let(:obj) { klass.new({'video_id' => 'some_video_guid'}) }
28
+ subject { obj }
29
+ its(:media_type_sym) { should be(:video) }
30
+ end
31
+
32
+ describe ".import" do
33
+ let(:meth) { :import }
34
+ let(:mock_config) { mock(Helix::Config) }
35
+ subject { klass.method(meth) }
36
+ its(:arity) { should eq(-1) }
37
+ let(:params) { { params: { signature: :some_sig } } }
38
+ before { Helix::Config.stub(:instance) { mock_config } }
39
+
40
+ it "should get an ingest signature" do
41
+ mock_config.should_receive(:build_url).with(url_opts)
42
+ mock_config.should_receive(:signature).with(:ingest, sig_opts) { :some_sig }
43
+ RestClient.should_receive(:post).with(nil, import_xml, params)
44
+ klass.send(meth)
45
+ end
46
+ end
47
+
48
+ describe ".get_xml" do
49
+ let(:meth) { :get_xml }
50
+ subject { klass.method(meth) }
51
+ its(:arity) { should eq(-1) }
52
+ context "when :use_raw_xml is present in attrs" do
53
+ let(:use_raw_xml) { { use_raw_xml: :xml } }
54
+ it "should return the value of attrs[:use_raw_xml]" do
55
+ expect(klass.send(meth, use_raw_xml)).to eq(:xml)
56
+ end
57
+ end
58
+ context "when hash is passed without :use_raw_xml" do
59
+ let(:attrs) { { attribute: :value } }
60
+ it "should convert attrs into xml" do
61
+ expect(klass.send(meth, attrs)).to eq(import_xml(attrs))
62
+ end
63
+ end
64
+ context "when nothing in passed in" do
65
+ it "should return valid xml" do
66
+ expect(klass.send(meth)).to eq(import_xml)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe ".get_url_opts" do
72
+ let(:meth) { :get_url_opts }
73
+ subject { klass.method(meth) }
74
+ its(:arity) { should eq(0) }
75
+ it "should return a valid hash url options for Helix::Config#build_url" do
76
+ expect(klass.send(meth)).to eq(url_opts)
77
+ end
78
+ end
79
+
80
+ describe ".get_url" do
81
+ let(:meth) { :get_url }
82
+ subject { klass.method(meth) }
83
+ its(:arity) { should eq(0) }
84
+ it "should call Helix::Config#build_url with url opts" do
85
+ Helix::Config.instance.should_receive(:build_url).with(klass.send(:get_url_opts))
86
+ klass.send(meth)
87
+ end
88
+ end
89
+
90
+ describe ".get_params" do
91
+ let(:meth) { :get_params }
92
+ subject { klass.method(meth) }
93
+ its(:arity) { should eq(0) }
94
+ it "should call Helix::Config#signature and return a hash of params" do
95
+ Helix::Config.instance.should_receive(:signature).with(:ingest, sig_opts) { :sig }
96
+ expect(klass.send(meth)).to eq({ params: { signature: :sig } })
97
+ end
19
98
  end
20
99
 
100
+
21
101
  end
metadata CHANGED
@@ -1,104 +1,112 @@
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.1.pre
4
5
  prerelease: 6
5
- version: 0.0.0.pre
6
6
  platform: ruby
7
- authors:
8
- - Twistage
7
+ authors:
8
+ - Twistage, Inc
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-11-19 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-11-21 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
30
25
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
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
33
+ none: false
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: crack
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: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
41
49
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 0.3.1
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.9
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: 3.0.9
48
62
  description: Provides helper libraries for Ruby access to the Twistage API
49
63
  email: kbaird@twistage.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/album.rb
59
69
  - lib/helix/track.rb
60
- - lib/helix/base.rb
61
- - lib/helix/statistics.rb
62
70
  - lib/helix/video.rb
63
- - lib/helix/config.rb
71
+ - lib/helix/statistics.rb
64
72
  - lib/helix/image.rb
73
+ - lib/helix/album.rb
74
+ - lib/helix/config.rb
75
+ - lib/helix/base.rb
76
+ - spec/video_spec.rb
77
+ - spec/album_spec.rb
78
+ - spec/config_spec.rb
65
79
  - spec/base_spec.rb
66
80
  - spec/statistics_spec.rb
67
- - spec/config_spec.rb
81
+ - spec/spec_helper.rb
68
82
  - spec/track_spec.rb
69
83
  - spec/image_spec.rb
70
- - spec/spec_helper.rb
71
- - spec/video_spec.rb
72
- - spec/album_spec.rb
73
84
  - LICENSE
74
85
  - README.md
75
86
  homepage: https://github.com/Twistage/helix/
76
- licenses:
87
+ licenses:
77
88
  - 3-Clause BSD
78
89
  post_install_message:
79
90
  rdoc_options: []
80
-
81
- require_paths:
91
+ require_paths:
82
92
  - lib
83
- required_ruby_version: !ruby/object:Gem::Requirement
93
+ required_ruby_version: !ruby/object:Gem::Requirement
84
94
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
89
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
100
  none: false
91
- requirements:
92
- - - ">"
93
- - !ruby/object:Gem::Version
101
+ requirements:
102
+ - - ! '>'
103
+ - !ruby/object:Gem::Version
94
104
  version: 1.3.1
95
105
  requirements: []
96
-
97
106
  rubyforge_project:
98
107
  rubygems_version: 1.8.24
99
108
  signing_key:
100
109
  specification_version: 3
101
110
  summary: Wrapper library for the video API
102
111
  test_files: []
103
-
104
112
  has_rdoc: true