helix 0.0.2.3.pre → 0.0.2.4.pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/helix.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'helix/durationed_media'
2
2
  require 'helix/video'
3
3
  require 'helix/track'
4
+ require 'helix/tag'
4
5
  require 'helix/album'
5
6
  require 'helix/image'
6
7
  require 'helix/config'
data/lib/helix/album.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'helix/base'
1
+ require 'helix/media'
2
2
 
3
3
  module Helix
4
4
 
5
- class Album < Base
5
+ class Album < Media
6
6
 
7
7
  # The class name, to be used by supporting classes. Such as Config which uses
8
8
  # this method as a way to build URLs.
data/lib/helix/base.rb CHANGED
@@ -2,6 +2,7 @@ require 'rest-client'
2
2
  require 'json'
3
3
  require 'yaml'
4
4
  require 'nori'
5
+ require 'time'
5
6
 
6
7
  module Helix
7
8
  class Base
@@ -13,38 +14,6 @@ module Helix
13
14
  attr_accessor :attributes
14
15
  attr_writer :config
15
16
 
16
- # Creates a new record via API and then returns an instance of that record.
17
- #
18
- # Example is using Video class since Video inherits from Base. This won't
19
- # normally be called as Helix::Base.create
20
- #
21
- # @example
22
- # Helix::Album.create({title: "My new album"})
23
- #
24
- # @param [Hash] attributes a hash containing the attributes used in the create
25
- # @return [Base] An instance of Helix::Base
26
- def self.create(attributes={})
27
- url = config.build_url(media_type: plural_media_type,
28
- content_type: :xml)
29
- response = RestClient.post(url, attributes.merge(signature: config.signature(:update)))
30
- attrs = Hash.from_xml(response)
31
- self.new(attributes: attrs[media_type_sym.to_s], config: config)
32
- end
33
-
34
- # Finds and returns a record in instance form for a class, through
35
- # guid lookup.
36
- #
37
- # @example
38
- # video_guid = "8e0701c142ab1"
39
- # video = Helix::Video.find(video_guid)
40
- #
41
- # @param [String] guid an id in guid form.
42
- # @return [Base] An instance of Helix::Base
43
- def self.find(guid)
44
- item = self.new(attributes: { guid_name => guid }, config: config)
45
- item.load
46
- end
47
-
48
17
  # Fetches all accessible records, places them into instances, and returns
49
18
  # them as an array.
50
19
  #
@@ -56,9 +25,27 @@ module Helix
56
25
  def self.find_all(opts={})
57
26
  data_sets = get_data_sets(opts)
58
27
  return [] if data_sets.nil?
59
- data_sets.map { |attrs| self.new(attributes: attrs, config: config) }
28
+ data_sets.map { |attrs| self.new( attributes: massage_attrs(attrs),
29
+ config: config) }
60
30
  end
61
31
 
32
+ # (see .find_all)
33
+ def self.where(opts={})
34
+ find_all(opts)
35
+ end
36
+
37
+ # (see .find_all)
38
+ # @note this method takes no query options, unlike find_all
39
+ def self.all
40
+ find_all
41
+ end
42
+
43
+ # Does a GET call to the api and defaults to content_type xml and
44
+ # signature_type view.
45
+ #
46
+ #
47
+ # @param [Hash] opts a hash of options for parameters passed into the HTTP GET
48
+ # @return [Array] The array of attributes (for a model) in hash form.
62
49
  def self.get_data_sets(opts)
63
50
  url = config.build_url(content_type: opts[:content_type] || :xml,
64
51
  media_type: self.plural_media_type)
@@ -96,27 +83,16 @@ module Helix
96
83
  @config = opts[:config]
97
84
  end
98
85
 
86
+ # Returns the singleton instance of the Helix::Config.
99
87
  def self.config
100
88
  Helix::Config.instance
101
89
  end
102
90
 
91
+ # (see .config)
103
92
  def config
104
93
  @config ||= Helix::Config.instance
105
94
  end
106
95
 
107
- # Deletes the record of the Helix::Base instance.
108
- #
109
- # @example
110
- # video = Helix::Video.create({title: "Some Title"})
111
- # video.destroy
112
- #
113
- # @return [String] The response from the HTTP DELETE call.
114
- def destroy
115
- RestClient.log = 'helix.log'
116
- url = config.build_url(content_type: :xml, guid: guid, media_type: plural_media_type)
117
- RestClient.delete(url, params: {signature: config.signature(:update)})
118
- end
119
-
120
96
  # Creates a string that associates to the class id.
121
97
  #
122
98
  # @example
@@ -154,25 +130,6 @@ module Helix
154
130
  end
155
131
  end
156
132
 
157
- # Updates instance and record with attributes passed in.
158
- #
159
- # @example
160
- # video = Helix::Video.find(video_guid)
161
- # video.update({title: "My new title"})
162
- #
163
- # @param [Hash] opts a hash of attributes to update the instance with.
164
- # @return [Base] Returns an instance of the class after update.
165
- def update(opts={})
166
- RestClient.log = 'helix.log' if opts.delete(:log)
167
- memo_cfg = config
168
- url = memo_cfg.build_url(content_type: :xml,
169
- guid: guid,
170
- media_type: plural_media_type)
171
- params = {signature: memo_cfg.signature(:update)}.merge(media_type_sym => opts)
172
- RestClient.put(url, params)
173
- self
174
- end
175
-
176
133
  private
177
134
 
178
135
  def massage_raw_attrs(raw_attrs)
@@ -181,5 +138,35 @@ module Helix
181
138
  proper_hash ? raw_attrs : raw_attrs.first
182
139
  end
183
140
 
141
+ def self.massage_attrs(attrs)
142
+ return attrs unless attrs.is_a?(Hash)
143
+ Hash[massage_custom_field_attrs(massage_time_attrs(attrs)).sort]
144
+ end
145
+
146
+ def self.massage_time_attrs(attrs)
147
+ return attrs unless attrs.is_a?(Hash)
148
+ attrs.each do |key, val|
149
+ begin
150
+ if val.is_a?(String) && val =~ /(\d{4}-\d{2}-\d{2})/
151
+ attrs[key] = Time.parse(val)
152
+ end
153
+ rescue ArgumentError,RangeError;end
154
+ massage_time_attrs(val)
155
+ end
156
+ end
157
+
158
+ def self.massage_custom_field_attrs(attrs)
159
+ return attrs unless attrs.is_a?(Hash)
160
+ return attrs unless attrs["custom_fields"].is_a?(Hash)
161
+ attrs["custom_fields"].delete_if { |key, val| key.to_s =~ /^@/ }
162
+ cfs = []
163
+ attrs["custom_fields"].each do |key, val|
164
+ val.each do |val_val|
165
+ cfs << { "name" => key, "value" => val_val.to_s }
166
+ end
167
+ end
168
+ attrs.merge({'custom_fields' => cfs})
169
+ end
170
+
184
171
  end
185
172
  end
data/lib/helix/config.rb CHANGED
@@ -36,6 +36,7 @@ module Helix
36
36
  config.instance_variable_set(:@filename, yaml_file_location)
37
37
  creds = YAML.load(File.open(yaml_file_location)).symbolize_keys
38
38
  config.instance_variable_set(:@credentials, creds)
39
+ RestClient.proxy = config.proxy
39
40
  config
40
41
  end
41
42
 
@@ -117,6 +118,20 @@ module Helix
117
118
  @signature_for[lk][sig_type] = RestClient.get(url_for(sig_type, opts))
118
119
  end
119
120
 
121
+ def proxy
122
+ if @credentials[:proxy_uri]
123
+ protocol, uri = @credentials[:proxy_uri].split "://"
124
+ user, pass = @credentials[:proxy_username], @credentials[:proxy_password]
125
+ proxy_str = "#{protocol}://"
126
+ proxy_str += "#{user}:" if user
127
+ proxy_str += "#{pass}" if user && pass
128
+ proxy_str += '@' if user
129
+ proxy_str += "#{uri}"
130
+ elsif @credentials[:proxy_used] == true
131
+ ENV['http_proxy']
132
+ end
133
+ end
134
+
120
135
  private
121
136
 
122
137
  def error_message_for(sig_type)
@@ -0,0 +1,4 @@
1
+ require 'helix/base'
2
+ module Helix
3
+ class NoConfigurationLoaded < StandardError ; end
4
+ end
data/lib/helix/image.rb CHANGED
@@ -1,8 +1,8 @@
1
- require 'helix/base'
1
+ require 'helix/media'
2
2
 
3
3
  module Helix
4
4
 
5
- class Image < Base
5
+ class Image < Media
6
6
 
7
7
  # The class name, to be used by supporting classes. Such as Config which uses
8
8
  # this method as a way to build URLs.
@@ -0,0 +1,68 @@
1
+ require 'helix/base'
2
+
3
+ module Helix
4
+ class Media < Base
5
+ # Creates a new record via API and then returns an instance of that record.
6
+ #
7
+ # Example is using Video class since Video inherits from Base. This won't
8
+ # normally be called as Helix::Base.create
9
+ #
10
+ # @example
11
+ # Helix::Album.create({title: "My new album"})
12
+ #
13
+ # @param [Hash] attributes a hash containing the attributes used in the create
14
+ # @return [Base] An instance of Helix::Base
15
+ def self.create(attributes={})
16
+ url = config.build_url(media_type: plural_media_type,
17
+ content_type: :xml)
18
+ response = RestClient.post(url, attributes.merge(signature: config.signature(:update)))
19
+ attrs = Hash.from_xml(response)
20
+ self.new(attributes: attrs[media_type_sym.to_s], config: config)
21
+ end
22
+
23
+ # Finds and returns a record in instance form for a class, through
24
+ # guid lookup.
25
+ #
26
+ # @example
27
+ # video_guid = "8e0701c142ab1"
28
+ # video = Helix::Video.find(video_guid)
29
+ #
30
+ # @param [String] guid an id in guid form.
31
+ # @return [Base] An instance of Helix::Base
32
+ def self.find(guid)
33
+ item = self.new(attributes: { guid_name => guid }, config: config)
34
+ item.load
35
+ end
36
+
37
+ # Deletes the record of the Helix::Base instance.
38
+ #
39
+ # @example
40
+ # video = Helix::Video.create({title: "Some Title"})
41
+ # video.destroy
42
+ #
43
+ # @return [String] The response from the HTTP DELETE call.
44
+ def destroy
45
+ url = config.build_url(content_type: :xml, guid: guid, media_type: plural_media_type)
46
+ RestClient.delete(url, params: {signature: config.signature(:update)})
47
+ end
48
+
49
+ # Updates instance and record with attributes passed in.
50
+ #
51
+ # @example
52
+ # video = Helix::Video.find(video_guid)
53
+ # video.update({title: "My new title"})
54
+ #
55
+ # @param [Hash] opts a hash of attributes to update the instance with.
56
+ # @return [Base] Returns an instance of the class after update.
57
+ def update(opts={})
58
+ RestClient.log = 'helix.log' if opts.delete(:log)
59
+ memo_cfg = config
60
+ url = memo_cfg.build_url(content_type: :xml,
61
+ guid: guid,
62
+ media_type: plural_media_type)
63
+ params = {signature: memo_cfg.signature(:update)}.merge(media_type_sym => opts)
64
+ RestClient.put(url, params)
65
+ self
66
+ end
67
+ end
68
+ end
data/lib/helix/tag.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'nori'
5
+
6
+ module Helix
7
+ class Tag < Base
8
+ # The class name, to be used by supporting classes. Such as Config which uses
9
+ # this method as a way to build URLs.
10
+ #
11
+ #
12
+ # @example
13
+ # Helix::Tag.media_type_sym #=> :tag
14
+ #
15
+ # @return [Symbol] Name of the class.
16
+ def self.media_type_sym; :tag; end
17
+ end
18
+ end
data/lib/helix/track.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require 'helix/media'
2
+
1
3
  module Helix
2
4
 
3
- class Track < Base
5
+ class Track < Media
4
6
 
5
7
  include DurationedMedia
6
8
 
data/lib/helix/video.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'helix/base'
1
+ require 'helix/media'
2
2
  require 'active_support/core_ext'
3
3
 
4
4
  module Helix
5
5
 
6
- class Video < Base
6
+ class Video < Media
7
7
 
8
8
  include DurationedMedia
9
9
 
data/spec/album_spec.rb CHANGED
@@ -9,6 +9,9 @@ describe Helix::Album do
9
9
  its(:guid_name) { should eq('album_id') }
10
10
  its(:media_type_sym) { should be(:album) }
11
11
  its(:plural_media_type) { should eq('albums') }
12
+ [:find, :create, :all, :find_all, :where].each do |crud_call|
13
+ it { should respond_to(crud_call) }
14
+ end
12
15
 
13
16
  describe "Constants"
14
17
 
@@ -22,6 +25,9 @@ describe Helix::Album do
22
25
  expect(lambda { obj.send(meth) }).to raise_error("Albums Update is not currently supported.")
23
26
  end
24
27
  end
28
+ [:destroy, :update].each do |crud_call|
29
+ it { should respond_to(crud_call) }
30
+ end
25
31
  end
26
32
 
27
33
  end
data/spec/base_spec.rb CHANGED
@@ -34,80 +34,16 @@ describe Helix::Base do
34
34
  end
35
35
  end
36
36
 
37
- describe ".create" do
38
- let(:meth) { :create }
39
- let(:mock_config) { mock(Helix::Config) }
37
+ shared_examples_for "a search all with opts" do
38
+ let(:mock_config) { mock(Helix::Config, build_url: :built_url, get_response: {}) }
40
39
  subject { klass.method(meth) }
41
40
  its(:arity) { should eq(-1) }
42
- let(:klass_sym) { :klass }
43
- let(:resp_value) { { klass_sym.to_s => { attribute: :value } } }
44
- let(:resp_json) { "JSON" }
45
- let(:params) { { signature: "some_sig" } }
46
- let(:expected) { { attributes: { attribute: :value }, config: mock_config } }
47
- before(:each) do
48
- klass.stub(:plural_media_type) { :klasses }
49
- klass.stub(:media_type_sym) { klass_sym }
50
- mock_config.stub(:build_url).with(action: :create_many, media_type: :klasses) { :url }
51
- mock_config.stub(:signature).with(:update) { "some_sig" }
52
- Helix::Config.stub(:instance) { mock_config }
53
- end
54
- it "should get an ingest signature" do
55
- mock_config.should_receive(:build_url).with(media_type: :klasses,
56
- content_type: :xml)
57
- RestClient.stub(:post).with(:url, params) { resp_json }
58
- Hash.should_receive(:from_xml).with(resp_json) { resp_value }
59
- klass.stub(:new).with(expected)
60
- mock_config.should_receive(:signature).with(:update) { "some_sig" }
61
- klass.send(meth)
62
- end
63
- it "should do an HTTP post call, parse response and call new" do
64
- mock_config.should_receive(:build_url).with(media_type: :klasses,
65
- content_type: :xml)
66
- RestClient.should_receive(:post).with(:url, params) { resp_json }
67
- Hash.should_receive(:from_xml).with(resp_json) { resp_value }
68
- klass.should_receive(:new).with(expected)
69
- klass.send(meth)
70
- end
71
- end
72
-
73
- describe ".find" do
74
- let(:meth) { :find }
75
- let(:mock_config) { mock(Helix::Config) }
76
- let(:mock_obj) { mock(klass, :load => :output_of_load) }
77
- subject { klass.method(meth) }
78
- its(:arity) { should eq(1) }
79
- before(:each) do Helix::Config.stub(:instance) { mock_config } end
80
- context "when given a Helix::Config instance and a guid" do
81
- let(:guid) { :a_guid }
82
- let(:guid_name) { :the_guid_name }
83
- let(:mock_attrs) { mock(Object, :[]= => :output_of_setting_val) }
84
- before(:each) do
85
- klass.stub(:attributes) { mock_attrs }
86
- klass.stub(:guid_name) { guid_name }
87
- klass.stub(:new) { mock_obj }
88
- end
89
- it "should instantiate with {attributes: guid_name => the_guid, config: config}" do
90
- klass.should_receive(:new).with({attributes: {guid_name => guid}, config: mock_config})
91
- klass.send(meth, guid)
92
- end
93
- it "should load" do
94
- mock_obj.should_receive(:load)
95
- klass.send(meth, guid)
96
- end
97
- end
98
- end
99
-
100
- describe ".find_all" do
101
- let(:meth) { :find_all }
102
- let(:mock_config) { mock(Helix::Config, build_url: :built_url, get_response: {}) }
103
- subject { klass.method(meth) }
104
- its(:arity) { should eq(-1) }
105
41
  before(:each) do Helix::Config.stub(:instance) { mock_config } end
106
42
  context "when given a config instances and an opts Hash" do
107
43
  let(:opts) { {opts_key1: :opts_val1} }
108
44
  let(:plural_media_type) { :videos }
109
45
  before(:each) do klass.stub(:plural_media_type) { plural_media_type } end
110
- it "should build a JSON URL -> the_url" do
46
+ it "should build a XML URL -> the_url" do
111
47
  mock_config.should_receive(:build_url).with(content_type: :xml,
112
48
  media_type: plural_media_type)
113
49
  klass.send(meth, opts)
@@ -138,6 +74,101 @@ describe Helix::Base do
138
74
  end
139
75
  end
140
76
 
77
+ shared_examples_for "a search all without opts" do
78
+ let(:mock_config) { mock(Helix::Config, build_url: :built_url, get_response: {}) }
79
+ subject { klass.method(meth) }
80
+ before(:each) do Helix::Config.stub(:instance) { mock_config } end
81
+ context "when given a config instances and NO opts Hash" do
82
+ let(:plural_media_type) { :videos }
83
+ before(:each) do klass.stub(:plural_media_type) { plural_media_type } end
84
+ it "should build a XML URL -> the_url" do
85
+ mock_config.should_receive(:build_url).with(content_type: :xml,
86
+ media_type: plural_media_type)
87
+ klass.send(meth)
88
+ end
89
+ it "should get_response(the_url, {sig_type: :view} -> raw_response" do
90
+ mock_config.should_receive(:get_response).with(:built_url, {sig_type: :view})
91
+ klass.send(meth)
92
+ end
93
+ it "should read raw_response[plural_media_type] -> data_sets" do
94
+ mock_raw_response = mock(Object)
95
+ mock_config.stub(:get_response) { mock_raw_response }
96
+ mock_raw_response.should_receive(:[]).with(plural_media_type)
97
+ klass.send(meth)
98
+ end
99
+ context "when data_sets is nil" do
100
+ it "should return []" do expect(klass.send(meth)).to eq([]) end
101
+ end
102
+ context "when data_sets is NOT nil" do
103
+ let(:data_set) { (0..2).to_a }
104
+ before(:each) do mock_config.stub(:get_response) { {plural_media_type => data_set } } end
105
+ it "should map instantiation with attributes: each data set element" do
106
+ klass.should_receive(:new).with(attributes: data_set[0], config: mock_config) { :a }
107
+ klass.should_receive(:new).with(attributes: data_set[1], config: mock_config) { :b }
108
+ klass.should_receive(:new).with(attributes: data_set[2], config: mock_config) { :c }
109
+ expect(klass.send(meth)).to eq([:a, :b, :c])
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ describe ".find_all" do
116
+ let(:meth) { :find_all }
117
+ it_behaves_like "a search all with opts"
118
+ it_behaves_like "a search all without opts"
119
+ end
120
+
121
+ describe ".all" do
122
+ let(:meth) { :all }
123
+ subject { klass.method(meth) }
124
+ its(:arity) { should eq(0) }
125
+ it_behaves_like "a search all without opts"
126
+ end
127
+
128
+ describe ".where" do
129
+ let(:meth) { :where }
130
+ it_behaves_like "a search all with opts"
131
+ it_behaves_like "a search all without opts"
132
+ end
133
+
134
+ describe ".massage_attrs" do
135
+ let(:meth) { :massage_attrs }
136
+ subject { klass.method(meth) }
137
+ its(:arity) { should eq(1) }
138
+ let(:attrs) { Hash.new }
139
+ it "should call massage_custom_field_attrs and massage_time_attrs" do
140
+ klass.should_receive(:massage_time_attrs).and_return attrs
141
+ klass.should_receive(:massage_custom_field_attrs).and_return attrs
142
+ klass.send(meth, attrs)
143
+ end
144
+ end
145
+
146
+ describe ".massage_time_attrs" do
147
+ let(:meth) { :massage_time_attrs }
148
+ subject { klass.method(meth) }
149
+ its(:arity) { should eq(1) }
150
+ let(:time) { Time.new(2013) }
151
+ let(:attrs) { { key_one: time.to_s, key_two: { key_three: time, key_four: { key_five: time.to_s } } } }
152
+ let(:expected) { { key_one: time, key_two: { key_three: time, key_four: { key_five: time } } } }
153
+ it "should turn stringified time values into time objects" do
154
+ expect(klass.send(meth, attrs)).to eq(expected)
155
+ end
156
+ end
157
+
158
+ describe ".massage_custom_field_attrs" do
159
+ let(:meth) { :massage_custom_field_attrs }
160
+ subject { klass.method(meth) }
161
+ its(:arity) { should eq(1) }
162
+ let(:custom_hash) { { "custom_fields" => {"boole"=>[nil, nil], "@type"=>"hash"} } }
163
+ let(:expected) { { "custom_fields" => [{"name"=>"boole", "value"=>""}, {"name"=>"boole", "value"=>""}] } }
164
+ it "should turn custom_hash into expected" do
165
+ expect(klass.send(meth, custom_hash)).to eq(expected)
166
+ end
167
+ it "should return the custom_hash in its form" do
168
+ expect(klass.send(meth, expected)).to eq(expected)
169
+ end
170
+ end
171
+
141
172
  describe "an instance" do
142
173
  let(:obj) { klass.new({}) }
143
174
 
@@ -160,33 +191,6 @@ describe Helix::Base do
160
191
  end
161
192
  end
162
193
 
163
- describe "#destroy" do
164
- let(:meth) { :destroy }
165
- let(:mock_config) { mock(Helix::Config, build_url: :the_built_url, signature: :some_sig) }
166
- subject { obj.method(meth) }
167
- let(:params) { { params: {signature: :some_sig } } }
168
- before do
169
- obj.stub(:config) { mock_config }
170
- obj.stub(:guid) { :some_guid }
171
- obj.stub(:plural_media_type) { :media_type }
172
- end
173
- it "should get an update signature" do
174
- url = mock_config.build_url(media_type: :media_type,
175
- guid: :some_guid,
176
- content_type: :xml)
177
- RestClient.stub(:delete).with(url, params)
178
- mock_config.should_receive(:signature).with(:update) { :some_sig }
179
- obj.send(meth)
180
- end
181
- it "should call for an HTTP delete and return nil" do
182
- url = mock_config.build_url(media_type: :media_type,
183
- guid: :some_guid,
184
- content_type: :xml)
185
- RestClient.should_receive(:delete).with(url, params)
186
- expect(obj.send(meth)).to be_nil
187
- end
188
- end
189
-
190
194
  describe "#guid" do
191
195
  let(:meth) { :guid }
192
196
  it "should return @attributes[guid_name]" do
@@ -305,49 +309,6 @@ describe Helix::Base do
305
309
  end
306
310
  end
307
311
 
308
- describe "#update" do
309
- let(:meth) { :update }
310
- let(:mock_config) { mock(Helix::Config) }
311
- subject { obj.method(meth) }
312
- its(:arity) { should eq(-1) }
313
- before(:each) do
314
- obj.stub(:config) { mock_config }
315
- obj.stub(:guid) { :the_guid }
316
- obj.stub(:media_type_sym) { :video }
317
- obj.stub(:plural_media_type) { :the_media_type }
318
- mock_config.stub(:signature).with(:update) { 'some_sig' }
319
- mock_config.stub(:build_url) { :expected_url }
320
- end
321
- shared_examples_for "builds URL for update" do
322
- it "should build_url(content_type: :xml, guid: guid, media_type: plural_media_type)" do
323
- mock_config.should_receive(:build_url).with(content_type: :xml, guid: :the_guid, media_type: :the_media_type)
324
- RestClient.stub(:put)
325
- obj.send(meth)
326
- end
327
- it "should get an update signature" do
328
- mock_config.stub(:build_url)
329
- RestClient.stub(:put)
330
- mock_config.should_receive(:signature).with(:update) { 'some_sig' }
331
- obj.send(meth)
332
- end
333
- end
334
- context "when given no argument" do
335
- it_behaves_like "builds URL for update"
336
- it "should call RestClient.put(output_of_build_url, {signature: the_sig, video: {}}) and return instance of klass" do
337
- RestClient.should_receive(:put).with(:expected_url, {signature: 'some_sig', video: {}})
338
- expect(obj.send(meth)).to be_an_instance_of(klass)
339
- end
340
- end
341
- context "when given an opts argument of {key1: :value1}" do
342
- let(:opts) { {key1: :value1} }
343
- it_behaves_like "builds URL for update"
344
- it "should call RestClient.put(output_of_build_url, {signature: the_sig, video: opts}) and return instance of klass" do
345
- RestClient.should_receive(:put).with(:expected_url, {signature: 'some_sig', video: opts})
346
- expect(obj.send(meth, opts)).to be_an_instance_of(klass)
347
- end
348
- end
349
- end
350
-
351
312
  end
352
313
 
353
314
  end
data/spec/config_spec.rb CHANGED
@@ -34,8 +34,8 @@ describe Helix::Config do
34
34
  end
35
35
 
36
36
  describe ".load" do
37
- let(:meth) { :load }
38
- let(:mock_obj) { mock(klass) }
37
+ let(:meth) { :load }
38
+ let(:mock_obj) { mock(klass, proxy: :stubbed_proxy) }
39
39
  let(:mock_file) { mock(File) }
40
40
  let(:mock_cred) { mock(Hash, symbolize_keys: :symbolized_creds) }
41
41
  before(:each) do
@@ -68,6 +68,10 @@ describe Helix::Config do
68
68
  mock_obj.should_receive(:instance_variable_set).with(:@credentials, mock_cred.symbolize_keys)
69
69
  klass.send(meth)
70
70
  end
71
+ it "should set the proxy" do
72
+ mock_obj.should_receive(:proxy) { :mock_proxy }
73
+ klass.send(meth)
74
+ end
71
75
  it "should return the instance" do
72
76
  expect(klass.send(meth)).to be(mock_obj)
73
77
  end
@@ -359,6 +363,25 @@ describe Helix::Config do
359
363
  end
360
364
  end
361
365
 
366
+ describe "#proxy" do
367
+ let(:meth) { :proxy }
368
+ subject { obj.method(meth) }
369
+ its(:arity) { should eq(0) }
370
+ it "should return the system proxy" do
371
+ ENV['http_proxy'] = 'http://test.proxy'
372
+ obj.credentials[:proxy_used] = true
373
+ expect(obj.send(meth)).to eq(ENV['http_proxy'])
374
+ end
375
+ it "should return the proxy specified in the config" do
376
+ obj.credentials[:proxy_uri] = 'http://test.proxy'
377
+ expect(obj.send(meth)).to eq 'http://test.proxy'
378
+ end
379
+ it "should return just proxy uri if only pass exists" do
380
+ obj.credentials[:proxy_password] = 'fake_pass'
381
+ expect(obj.send(meth)).to eq 'http://test.proxy'
382
+ end
383
+ end
384
+
362
385
  describe "#signature" do
363
386
  let(:meth) { :signature }
364
387
 
data/spec/image_spec.rb CHANGED
@@ -9,6 +9,9 @@ describe Helix::Image do
9
9
  its(:guid_name) { should eq('image_id') }
10
10
  its(:media_type_sym) { should be(:image) }
11
11
  its(:plural_media_type) { should eq('images') }
12
+ [:find, :create, :all, :find_all, :where].each do |crud_call|
13
+ it { should respond_to(crud_call) }
14
+ end
12
15
 
13
16
  describe "Constants"
14
17
 
@@ -16,6 +19,9 @@ describe Helix::Image do
16
19
  let(:obj) { klass.new({'image_id' => 'some_image_guid'}) }
17
20
  subject { obj }
18
21
  its(:media_type_sym) { should be(:image) }
22
+ [:destroy, :update].each do |crud_call|
23
+ it { should respond_to(crud_call) }
24
+ end
19
25
  end
20
26
 
21
27
  end
@@ -0,0 +1,145 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'helix'
3
+
4
+ describe Helix::Media do
5
+
6
+ let(:klass) { Helix::Media }
7
+
8
+ subject { klass }
9
+
10
+ describe ".create" do
11
+ let(:meth) { :create }
12
+ let(:mock_config) { mock(Helix::Config) }
13
+ subject { klass.method(meth) }
14
+ its(:arity) { should eq(-1) }
15
+ let(:klass_sym) { :klass }
16
+ let(:resp_value) { { klass_sym.to_s => { attribute: :value } } }
17
+ let(:resp_json) { "JSON" }
18
+ let(:params) { { signature: "some_sig" } }
19
+ let(:expected) { { attributes: { attribute: :value }, config: mock_config } }
20
+ before(:each) do
21
+ klass.stub(:plural_media_type) { :klasses }
22
+ klass.stub(:media_type_sym) { klass_sym }
23
+ mock_config.stub(:build_url).with(action: :create_many, media_type: :klasses) { :url }
24
+ mock_config.stub(:signature).with(:update) { "some_sig" }
25
+ Helix::Config.stub(:instance) { mock_config }
26
+ end
27
+ it "should get an ingest signature" do
28
+ mock_config.should_receive(:build_url).with(media_type: :klasses,
29
+ content_type: :xml)
30
+ RestClient.stub(:post).with(:url, params) { resp_json }
31
+ Hash.should_receive(:from_xml).with(resp_json) { resp_value }
32
+ klass.stub(:new).with(expected)
33
+ mock_config.should_receive(:signature).with(:update) { "some_sig" }
34
+ klass.send(meth)
35
+ end
36
+ it "should do an HTTP post call, parse response and call new" do
37
+ mock_config.should_receive(:build_url).with(media_type: :klasses,
38
+ content_type: :xml)
39
+ RestClient.should_receive(:post).with(:url, params) { resp_json }
40
+ Hash.should_receive(:from_xml).with(resp_json) { resp_value }
41
+ klass.should_receive(:new).with(expected)
42
+ klass.send(meth)
43
+ end
44
+ end
45
+
46
+ describe ".find" do
47
+ let(:meth) { :find }
48
+ let(:mock_config) { mock(Helix::Config) }
49
+ let(:mock_obj) { mock(klass, :load => :output_of_load) }
50
+ subject { klass.method(meth) }
51
+ its(:arity) { should eq(1) }
52
+ before(:each) do Helix::Config.stub(:instance) { mock_config } end
53
+ context "when given a Helix::Config instance and a guid" do
54
+ let(:guid) { :a_guid }
55
+ let(:guid_name) { :the_guid_name }
56
+ let(:mock_attrs) { mock(Object, :[]= => :output_of_setting_val) }
57
+ before(:each) do
58
+ klass.stub(:attributes) { mock_attrs }
59
+ klass.stub(:guid_name) { guid_name }
60
+ klass.stub(:new) { mock_obj }
61
+ end
62
+ it "should instantiate with {attributes: guid_name => the_guid, config: config}" do
63
+ klass.should_receive(:new).with({attributes: {guid_name => guid}, config: mock_config})
64
+ klass.send(meth, guid)
65
+ end
66
+ it "should load" do
67
+ mock_obj.should_receive(:load)
68
+ klass.send(meth, guid)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "an instance" do
74
+ let(:obj) { klass.new({}) }
75
+
76
+ describe "#destroy" do
77
+ let(:meth) { :destroy }
78
+ let(:mock_config) { mock(Helix::Config, build_url: :the_built_url, signature: :some_sig) }
79
+ subject { obj.method(meth) }
80
+ let(:params) { { params: {signature: :some_sig } } }
81
+ before do
82
+ obj.stub(:config) { mock_config }
83
+ obj.stub(:guid) { :some_guid }
84
+ obj.stub(:plural_media_type) { :media_type }
85
+ end
86
+ it "should get an update signature" do
87
+ url = mock_config.build_url(media_type: :media_type,
88
+ guid: :some_guid,
89
+ content_type: :xml)
90
+ RestClient.stub(:delete).with(url, params)
91
+ mock_config.should_receive(:signature).with(:update) { :some_sig }
92
+ obj.send(meth)
93
+ end
94
+ it "should call for an HTTP delete and return nil" do
95
+ url = mock_config.build_url(media_type: :media_type,
96
+ guid: :some_guid,
97
+ content_type: :xml)
98
+ RestClient.should_receive(:delete).with(url, params)
99
+ expect(obj.send(meth)).to be_nil
100
+ end
101
+ end
102
+ describe "#update" do
103
+ let(:meth) { :update }
104
+ let(:mock_config) { mock(Helix::Config) }
105
+ subject { obj.method(meth) }
106
+ its(:arity) { should eq(-1) }
107
+ before(:each) do
108
+ obj.stub(:config) { mock_config }
109
+ obj.stub(:guid) { :the_guid }
110
+ obj.stub(:media_type_sym) { :video }
111
+ obj.stub(:plural_media_type) { :the_media_type }
112
+ mock_config.stub(:signature).with(:update) { 'some_sig' }
113
+ mock_config.stub(:build_url) { :expected_url }
114
+ end
115
+ shared_examples_for "builds URL for update" do
116
+ it "should build_url(content_type: :xml, guid: guid, media_type: plural_media_type)" do
117
+ mock_config.should_receive(:build_url).with(content_type: :xml, guid: :the_guid, media_type: :the_media_type)
118
+ RestClient.stub(:put)
119
+ obj.send(meth)
120
+ end
121
+ it "should get an update signature" do
122
+ mock_config.stub(:build_url)
123
+ RestClient.stub(:put)
124
+ mock_config.should_receive(:signature).with(:update) { 'some_sig' }
125
+ obj.send(meth)
126
+ end
127
+ end
128
+ context "when given no argument" do
129
+ it_behaves_like "builds URL for update"
130
+ it "should call RestClient.put(output_of_build_url, {signature: the_sig, video: {}}) and return instance of klass" do
131
+ RestClient.should_receive(:put).with(:expected_url, {signature: 'some_sig', video: {}})
132
+ expect(obj.send(meth)).to be_an_instance_of(klass)
133
+ end
134
+ end
135
+ context "when given an opts argument of {key1: :value1}" do
136
+ let(:opts) { {key1: :value1} }
137
+ it_behaves_like "builds URL for update"
138
+ it "should call RestClient.put(output_of_build_url, {signature: the_sig, video: opts}) and return instance of klass" do
139
+ RestClient.should_receive(:put).with(:expected_url, {signature: 'some_sig', video: opts})
140
+ expect(obj.send(meth, opts)).to be_an_instance_of(klass)
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
data/spec/tag_spec.rb ADDED
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'helix'
3
+
4
+ describe Helix::Tag do
5
+
6
+ let(:klass) { Helix::Tag }
7
+ subject { klass }
8
+ its(:media_type_sym) { should be(:tag) }
9
+ its(:plural_media_type) { should eq('tags') }
10
+ it { should_not respond_to(:find) }
11
+ it { should_not respond_to(:create) }
12
+ it { should respond_to(:all)}
13
+ it { should respond_to(:find_all)}
14
+
15
+ describe "Constants"
16
+
17
+ describe "an instance" do
18
+ let(:obj) { klass.new({}) }
19
+ subject { obj }
20
+ its(:media_type_sym) { should be(:tag) }
21
+ it { should_not respond_to(:destroy) }
22
+ it { should_not respond_to(:update) }
23
+ end
24
+ end
data/spec/track_spec.rb CHANGED
@@ -8,6 +8,9 @@ describe Helix::Track do
8
8
  its(:guid_name) { should eq('track_id') }
9
9
  its(:media_type_sym) { should be(:track) }
10
10
  its(:plural_media_type) { should eq('tracks') }
11
+ [:find, :create, :all, :find_all, :where].each do |crud_call|
12
+ it { should respond_to(crud_call) }
13
+ end
11
14
 
12
15
  describe "Constants"
13
16
 
@@ -15,5 +18,8 @@ describe Helix::Track do
15
18
  let(:obj) { klass.new({'track_id' => 'some_track_guid'}) }
16
19
  subject { obj }
17
20
  its(:media_type_sym) { should be(:track) }
21
+ [:destroy, :update].each do |crud_call|
22
+ it { should respond_to(crud_call) }
23
+ end
18
24
  end
19
25
  end
data/spec/video_spec.rb CHANGED
@@ -12,6 +12,9 @@ describe Helix::Video do
12
12
  its(:guid_name) { should eq('video_id') }
13
13
  its(:media_type_sym) { should be(:video) }
14
14
  its(:plural_media_type) { should eq('videos') }
15
+ [:find, :create, :all, :find_all, :where].each do |crud_call|
16
+ it { should respond_to(crud_call) }
17
+ end
15
18
 
16
19
  describe "Constants"
17
20
 
@@ -32,6 +35,9 @@ describe Helix::Video do
32
35
  obj.send(meth)
33
36
  end
34
37
  end
38
+ [:destroy, :update].each do |crud_call|
39
+ it { should respond_to(crud_call) }
40
+ end
35
41
  end
36
42
 
37
43
  ### CLASS METHODS
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.3.pre
4
+ version: 0.0.2.4.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-24 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -69,8 +69,11 @@ files:
69
69
  - lib/helix/album.rb
70
70
  - lib/helix/base.rb
71
71
  - lib/helix/image.rb
72
+ - lib/helix/media.rb
72
73
  - lib/helix/durationed_media.rb
74
+ - lib/helix/exceptions.rb
73
75
  - lib/helix/config.rb
76
+ - lib/helix/tag.rb
74
77
  - lib/helix/video.rb
75
78
  - lib/helix/track.rb
76
79
  - lib/helix/statistics.rb
@@ -78,11 +81,13 @@ files:
78
81
  - spec/spec_helper.rb
79
82
  - spec/statistics_spec.rb
80
83
  - spec/config_spec.rb
84
+ - spec/media_spec.rb
81
85
  - spec/image_spec.rb
82
86
  - spec/album_spec.rb
83
87
  - spec/track_spec.rb
84
88
  - spec/base_spec.rb
85
89
  - spec/durationed_media_spec.rb
90
+ - spec/tag_spec.rb
86
91
  - LICENSE
87
92
  - README.md
88
93
  homepage: https://github.com/Twistage/helix/