helix 0.0.3.3.pre → 0.0.3.4.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/helix.rb +18 -0
- data/lib/helix/library.rb +3 -0
- data/lib/helix/restful.rb +7 -2
- data/lib/helix/user.rb +38 -0
- data/spec/helix_spec.rb +54 -0
- data/spec/media_spec.rb +60 -25
- data/spec/user_spec.rb +34 -0
- metadata +5 -2
data/lib/helix.rb
CHANGED
@@ -10,7 +10,25 @@ require 'helix/document'
|
|
10
10
|
require 'helix/config'
|
11
11
|
require 'helix/statistics'
|
12
12
|
require 'helix/library'
|
13
|
+
require 'helix/user'
|
13
14
|
require 'active_support/core_ext'
|
14
15
|
|
15
16
|
module Helix
|
17
|
+
|
18
|
+
# @param [String] The name of the Company to scope to.
|
19
|
+
def self.scope_to_company(co_id)
|
20
|
+
Helix::Config.instance.credentials.delete(:library)
|
21
|
+
Helix::Config.instance.credentials[:company] = co_id
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [String] The name of the Library to scope to.
|
25
|
+
def self.scope_to_library(lib_id)
|
26
|
+
Helix::Config.instance.credentials[:library] = lib_id
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [String] The license key to use.
|
30
|
+
def self.set_license_key(license_key)
|
31
|
+
Helix::Config.instance.credentials[:license_key] = license_key
|
32
|
+
end
|
33
|
+
|
16
34
|
end
|
data/lib/helix/library.rb
CHANGED
data/lib/helix/restful.rb
CHANGED
@@ -56,8 +56,13 @@ module Helix
|
|
56
56
|
raise Helix::NoConfigurationLoaded.new if config.nil?
|
57
57
|
url = config.build_url(build_url_opts)
|
58
58
|
response = RestClient.post(url, attributes.merge(signature: config.signature(:update)))
|
59
|
-
|
60
|
-
|
59
|
+
return if response == ''
|
60
|
+
begin
|
61
|
+
attrs = Hash.from_xml(response)
|
62
|
+
self.new(attributes: attrs[resource_label_sym.to_s], config: config)
|
63
|
+
rescue REXML::ParseException
|
64
|
+
response
|
65
|
+
end
|
61
66
|
end
|
62
67
|
|
63
68
|
# Finds and returns a record in instance form for a class, through
|
data/lib/helix/user.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helix/media'
|
2
|
+
|
3
|
+
module Helix
|
4
|
+
|
5
|
+
class User < Base
|
6
|
+
|
7
|
+
include RESTful
|
8
|
+
|
9
|
+
# @return [String] the license_key associated with newly-created API User
|
10
|
+
def self.create(attrs={}); super; end
|
11
|
+
|
12
|
+
# The class name, to be used by supporting classes. Such as Config which uses
|
13
|
+
# this method as a way to build URLs.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# Helix::User.resource_label_sym #=> :user
|
18
|
+
#
|
19
|
+
# @return [Symbol] Name of the class.
|
20
|
+
def self.resource_label_sym; :user; end
|
21
|
+
|
22
|
+
# Creates a string associated with a class name pluralized
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# Helix::User.plural_resource_label #=> "users"
|
26
|
+
#
|
27
|
+
# @return [String] The class name pluralized
|
28
|
+
def self.plural_resource_label
|
29
|
+
"users"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.known_attributes
|
33
|
+
[]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/helix_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
describe Helix do
|
5
|
+
let(:klass) { Helix }
|
6
|
+
|
7
|
+
describe "Constants"
|
8
|
+
|
9
|
+
describe "scope_to_company" do
|
10
|
+
let(:meth) { :scope_to_company }
|
11
|
+
let(:the_co_id) { :the_co_id }
|
12
|
+
describe "arity" do
|
13
|
+
subject { klass.method(meth) }
|
14
|
+
its(:arity) { should eq(1) }
|
15
|
+
end
|
16
|
+
it "should add the company arg to credentials" do
|
17
|
+
klass.send(meth, the_co_id)
|
18
|
+
expect(Helix::Config.instance.credentials).to include(company: the_co_id)
|
19
|
+
end
|
20
|
+
it "should clear any pre-exisiting library from credentials" do
|
21
|
+
klass.send(:scope_to_library, :the_lib_name)
|
22
|
+
expect(Helix::Config.instance.credentials).to include(library: :the_lib_name)
|
23
|
+
klass.send(meth, the_co_id)
|
24
|
+
expect(Helix::Config.instance.credentials.keys).not_to include(:library)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "scope_to_library" do
|
29
|
+
let(:meth) { :scope_to_library }
|
30
|
+
let(:the_lib_name) { :the_lib_name }
|
31
|
+
describe "arity" do
|
32
|
+
subject { klass.method(meth) }
|
33
|
+
its(:arity) { should eq(1) }
|
34
|
+
end
|
35
|
+
it "should add the library arg to credentials" do
|
36
|
+
klass.send(meth, the_lib_name)
|
37
|
+
expect(Helix::Config.instance.credentials).to include(library: the_lib_name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "set_license_key" do
|
42
|
+
let(:meth) { :set_license_key }
|
43
|
+
let(:the_key) { :alicense_key }
|
44
|
+
describe "arity" do
|
45
|
+
subject { klass.method(meth) }
|
46
|
+
its(:arity) { should eq(1) }
|
47
|
+
end
|
48
|
+
it "should add the license_key arg to credentials" do
|
49
|
+
klass.send(meth, the_key)
|
50
|
+
Helix::Config.instance.credentials.should include(license_key: the_key)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/media_spec.rb
CHANGED
@@ -17,55 +17,90 @@ describe Helix::Media do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
klasses = [ Helix::Album, Helix::Image, Helix::Track, Helix::Video ]
|
20
|
+
klasses = [ Helix::Album, Helix::Document, Helix::Image, Helix::Track, Helix::User, Helix::Video ]
|
21
21
|
klasses.each do |klass|
|
22
22
|
|
23
23
|
subject { klass }
|
24
|
+
klass_sym = {
|
25
|
+
Helix::Album => :album,
|
26
|
+
Helix::Document => :document,
|
27
|
+
Helix::Image => :image,
|
28
|
+
Helix::Library => :library,
|
29
|
+
Helix::Track => :track,
|
30
|
+
Helix::User => :user,
|
31
|
+
Helix::Video => :video,
|
32
|
+
}
|
24
33
|
|
25
34
|
mods = [ Helix::RESTful, Helix::Uploadable ]
|
26
35
|
mods.each { |mod| its(:ancestors) { should include(mod) } }
|
27
36
|
|
28
37
|
describe ".create" do
|
29
|
-
let(:meth)
|
30
|
-
let(:mock_config)
|
31
|
-
subject
|
32
|
-
its(:arity)
|
33
|
-
let(:
|
34
|
-
let(:
|
35
|
-
let(:
|
36
|
-
let(:
|
37
|
-
|
38
|
-
context "when a Helix:Config instance is absent" do
|
38
|
+
let(:meth) { :create }
|
39
|
+
let(:mock_config) { mock(Helix::Config) }
|
40
|
+
subject { klass.method(meth) }
|
41
|
+
its(:arity) { should eq(-1) }
|
42
|
+
let(:hash_from_xml) { { klass_sym.to_s => { attribute: :value } } }
|
43
|
+
let(:resp_xml) { "Fake XML" }
|
44
|
+
let(:params) { { signature: "some_sig" } }
|
45
|
+
let(:expected) { { attributes: { attribute: :value }, config: mock_config } }
|
46
|
+
context "when a Helix:Config instance is nil" do
|
39
47
|
before(:each) do Helix::Config.stub(:instance) { nil } end
|
40
48
|
it "should raise a NoConfigurationLoaded exception" do
|
41
49
|
lambda { klass.send(meth) }.should raise_error(Helix::NoConfigurationLoaded)
|
42
50
|
end
|
43
51
|
end
|
44
|
-
context "when a Helix:Config instance is
|
52
|
+
context "when a Helix:Config instance is NOT nil" do
|
45
53
|
before(:each) do
|
46
54
|
klass.stub(:plural_resource_label) { :klasses }
|
47
55
|
klass.stub(:resource_label_sym) { klass_sym }
|
48
56
|
mock_config.stub(:build_url).with(content_type: :xml, resource_label: :klasses) { :url }
|
49
57
|
mock_config.stub(:signature).with(:update) { "some_sig" }
|
50
58
|
Helix::Config.stub(:instance) { mock_config }
|
59
|
+
RestClient.stub(:post) { resp_xml }
|
60
|
+
Hash.stub(:from_xml).with(resp_xml) { hash_from_xml }
|
51
61
|
end
|
52
|
-
it "should
|
53
|
-
|
54
|
-
|
55
|
-
RestClient.stub(:post).with(:url, params) { resp_json }
|
56
|
-
Hash.should_receive(:from_xml).with(resp_json) { resp_value }
|
57
|
-
klass.stub(:new).with(expected)
|
58
|
-
mock_config.should_receive(:signature).with(:update) { "some_sig" }
|
62
|
+
it "should build a POST url" do
|
63
|
+
build_url_opts = {resource_label: :klasses, content_type: :xml}
|
64
|
+
mock_config.should_receive(:build_url).with(build_url_opts)
|
59
65
|
klass.send(meth)
|
60
66
|
end
|
61
|
-
it "should
|
62
|
-
|
63
|
-
content_type: :xml)
|
64
|
-
RestClient.should_receive(:post).with(:url, params) { resp_json }
|
65
|
-
Hash.should_receive(:from_xml).with(resp_json) { resp_value }
|
66
|
-
klass.should_receive(:new).with(expected)
|
67
|
+
it "should POST to the created URL" do
|
68
|
+
RestClient.should_receive(:post).with(:url, params) { resp_xml }
|
67
69
|
klass.send(meth)
|
68
70
|
end
|
71
|
+
context "when the POST response is ''" do
|
72
|
+
before(:each) do RestClient.stub(:post) { '' } end
|
73
|
+
it "should return nil"
|
74
|
+
it "should NOT create a Hash from XML" do
|
75
|
+
Hash.should_not_receive(:from_xml)
|
76
|
+
klass.send(meth)
|
77
|
+
end
|
78
|
+
it "should NOT instantiate an instance based on that Hash" do
|
79
|
+
klass.should_not_receive(:new)
|
80
|
+
klass.send(meth)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
context "when the POST response is NOT ''" do
|
84
|
+
before(:each) do RestClient.stub(:post) { resp_xml } end
|
85
|
+
it "should create a Hash from XML" do
|
86
|
+
Hash.should_receive(:from_xml).with(resp_xml) { hash_from_xml }
|
87
|
+
klass.send(meth)
|
88
|
+
end
|
89
|
+
it "should instantiate an instance based on that Hash" do
|
90
|
+
klass.should_receive(:new).with(expected)
|
91
|
+
klass.send(meth)
|
92
|
+
end
|
93
|
+
context "and the response is not parseable as XML" do
|
94
|
+
before(:each) do Hash.should_receive(:from_xml).with(resp_xml) { raise(REXML::ParseException.new(:some_arg)) } end
|
95
|
+
it "should NOT instantiate an instance based on that Hash" do
|
96
|
+
klass.should_not_receive(:new)
|
97
|
+
klass.send(meth)
|
98
|
+
end
|
99
|
+
it "should return the unparseable response" do
|
100
|
+
expect(klass.send(meth)).to be(resp_xml)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
69
104
|
end
|
70
105
|
end
|
71
106
|
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
require 'helix'
|
3
|
+
|
4
|
+
describe Helix::User do
|
5
|
+
|
6
|
+
let(:klass) { Helix::User }
|
7
|
+
subject { klass }
|
8
|
+
|
9
|
+
mods = [ Helix::Base, Helix::RESTful ]
|
10
|
+
mods.each { |mod| its(:ancestors) { should include(mod) } }
|
11
|
+
its(:ancestors) { should_not include(Helix::Media) }
|
12
|
+
|
13
|
+
its(:guid_name) { should eq('user_id') }
|
14
|
+
its(:resource_label_sym) { should be(:user) }
|
15
|
+
its(:plural_resource_label) { should eq('users') }
|
16
|
+
[:find, :create, :all, :find_all, :where].each do |crud_call|
|
17
|
+
it { should respond_to(crud_call) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".known_attributes" do
|
21
|
+
its(:known_attributes) { should eq([]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Constants"
|
25
|
+
|
26
|
+
describe "an instance" do
|
27
|
+
let(:obj) { klass.new({}) }
|
28
|
+
subject { obj }
|
29
|
+
its(:resource_label_sym) { should be(:user) }
|
30
|
+
[:destroy, :update].each do |crud_call|
|
31
|
+
it { should respond_to(crud_call) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: helix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 8
|
5
|
-
version: 0.0.3.
|
5
|
+
version: 0.0.3.4.pre
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Twistage, Inc
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-05-
|
13
|
+
date: 2013-05-21 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/helix/image.rb
|
83
83
|
- lib/helix/restful.rb
|
84
84
|
- lib/helix/library.rb
|
85
|
+
- lib/helix/user.rb
|
85
86
|
- lib/helix/uploadable.rb
|
86
87
|
- lib/helix/statistics.rb
|
87
88
|
- lib/helix/document.rb
|
@@ -104,9 +105,11 @@ files:
|
|
104
105
|
- spec/playlist_spec.rb
|
105
106
|
- spec/video_spec.rb
|
106
107
|
- spec/tag_spec.rb
|
108
|
+
- spec/user_spec.rb
|
107
109
|
- spec/durationed_media_spec.rb
|
108
110
|
- spec/album_spec.rb
|
109
111
|
- spec/image_spec.rb
|
112
|
+
- spec/helix_spec.rb
|
110
113
|
- spec/statistics_spec.rb
|
111
114
|
- spec/video_playlist_spec.rb
|
112
115
|
- spec/media_spec.rb
|