helix 0.0.4.6.pre → 0.0.4.7.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.
- checksums.yaml +8 -8
- data/lib/helix/base.rb +7 -0
- data/lib/helix/config.rb +31 -6
- data/spec/base_spec.rb +10 -0
- data/spec/config_spec.rb +84 -61
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGNmMmI1MWM4NzhjNWM5YjAyOTkzNGJhZjA1YjIzMTUyYThkMDQxNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmM3MWJlYmIwMmI1ZDdlMjQyZjhkNzQ0YmMxMGFhMmZlNjMxNDhkZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDhiM2ZkYTcyZTRlNTVjODkyZWI1NGY3YTY4MGM5ODA5MWUyNmRkNmM3MGEz
|
10
|
+
Mzg0ZjNiOWZlYjkxMjVlMjUxYTY4MTdmZjgzOGMxYjU0OTQxZTkzYWE5N2Nk
|
11
|
+
NWY3MTdiMmMxMGZkODkzYzc5ZmNmZjYwZWJhMjY5MGY2Mjc1MTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDgyMWEzN2QxZDljZGQ2MDViMzNmZWJmZmQ4NDRkZGM1NWFlYzkxOGIyNmRk
|
14
|
+
ODk0MTFlYzhjY2RkN2ZjNzA0MmZmZTcxNjkxMWRlMGNlYWQwN2M4NjM5ZDU1
|
15
|
+
MjkyNGY4MzRiNjk4OGYwYjZjMWQxYjNlMjE1ODYyNjdlZTlmNDE=
|
data/lib/helix/base.rb
CHANGED
@@ -163,6 +163,13 @@ module Helix
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
# Raw response should return the response from the config.
|
167
|
+
#
|
168
|
+
# @return [String] A response from the server in form of JSON or XML
|
169
|
+
def raw_response
|
170
|
+
self.config.response
|
171
|
+
end
|
172
|
+
|
166
173
|
private
|
167
174
|
|
168
175
|
def massage_raw_attrs(raw_attrs)
|
data/lib/helix/config.rb
CHANGED
@@ -24,25 +24,50 @@ module Helix
|
|
24
24
|
attr_reader :response # in Paginates
|
25
25
|
attr_reader :signature_for, :signature_expiration_for # in HasSignatures
|
26
26
|
|
27
|
+
# Creates a singleton of itself, setting the config based on the
|
28
|
+
# provided Hash argument.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# Helix::Config.load_from_hash(
|
32
|
+
# company: 'my-co-nickname',
|
33
|
+
# site: 'http://service-staging.twistage.com'
|
34
|
+
# )
|
35
|
+
# video = Helix::Video.find("8e0701c142ab1") #Uses my_yaml.yml
|
36
|
+
#
|
37
|
+
# @param [Hash] desired_credentials the k/v pairs used for config
|
38
|
+
# @return [Helix::Config] config returns singleton of Helix::Config
|
39
|
+
def self.load_from_hash(desired_credentials)
|
40
|
+
config = self.instance
|
41
|
+
config.instance_variable_set(:@credentials, desired_credentials)
|
42
|
+
RestClient.proxy = config.proxy
|
43
|
+
config
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.from_hash(desired_credentials)
|
47
|
+
load_from_hash(desired_credentials)
|
48
|
+
end
|
49
|
+
|
27
50
|
# Creates a singleton of itself, setting the config
|
28
51
|
# to a specified YAML file. If no file is specified the default
|
29
52
|
# helix.yml file is used.
|
30
53
|
#
|
31
54
|
# @example
|
32
|
-
# Helix::Config.
|
55
|
+
# Helix::Config.load_yaml_file("/some/path/my_yaml.yml")
|
33
56
|
# video = Helix::Video.find("8e0701c142ab1") #Uses my_yaml.yml
|
34
57
|
#
|
35
58
|
# @param [String] yaml_file_location the yaml file used for config
|
36
59
|
# @return [Helix::Config] config returns singleton of Helix::Config
|
37
|
-
def self.
|
38
|
-
|
60
|
+
def self.load_yaml_file(yaml_file_location = DEFAULT_FILENAME)
|
61
|
+
creds = YAML.load(File.open(yaml_file_location)).symbolize_keys
|
62
|
+
config = load_from_hash(creds)
|
39
63
|
config.instance_variable_set(:@filename, yaml_file_location)
|
40
|
-
creds = YAML.load(File.open(yaml_file_location)).symbolize_keys
|
41
|
-
config.instance_variable_set(:@credentials, creds)
|
42
|
-
RestClient.proxy = config.proxy
|
43
64
|
config
|
44
65
|
end
|
45
66
|
|
67
|
+
def self.load(yaml_file_location = DEFAULT_FILENAME)
|
68
|
+
load_yaml_file(yaml_file_location)
|
69
|
+
end
|
70
|
+
|
46
71
|
def proxy
|
47
72
|
if @credentials[:proxy_uri]
|
48
73
|
protocol, uri = @credentials[:proxy_uri].split "://"
|
data/spec/base_spec.rb
CHANGED
@@ -419,6 +419,16 @@ describe Helix::Base do
|
|
419
419
|
end
|
420
420
|
end
|
421
421
|
|
422
|
+
describe "#raw_response" do
|
423
|
+
let(:meth) { :raw_response }
|
424
|
+
subject { obj.method(meth) }
|
425
|
+
its(:arity) { should eq(0) }
|
426
|
+
it "should return the response from config" do
|
427
|
+
obj.config.stub!(:response).and_return :some_response
|
428
|
+
expect(obj.send(meth)).to eq(obj.config.response)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
422
432
|
end
|
423
433
|
|
424
434
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -49,8 +49,29 @@ describe Helix::Config do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
describe ".
|
53
|
-
|
52
|
+
describe ".load_from_hash & from_hash alias" do
|
53
|
+
meths = [ :load_from_hash, :from_hash ]
|
54
|
+
let(:mock_obj) { double(klass, proxy: :stubbed_proxy) }
|
55
|
+
let(:mock_file) { double(File) }
|
56
|
+
let(:mock_cred) { {key1: 'value1', 'key2' => 'value2'} }
|
57
|
+
let(:symbolized_cred) { {key1: 'value1', key2: 'value2'} }
|
58
|
+
before(:each) do
|
59
|
+
klass.stub(:instance) { mock_obj }
|
60
|
+
File.stub(:open) { mock_file }
|
61
|
+
YAML.stub(:load) { mock_cred }
|
62
|
+
end
|
63
|
+
meths.each do |meth|
|
64
|
+
context "when given a Hash" do
|
65
|
+
it "should set the instance's credentials to that Hash arg" do
|
66
|
+
mock_obj.should_receive(:instance_variable_set).with(:@credentials, :the_hash_arg)
|
67
|
+
klass.send(meth, :the_hash_arg)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".load_yaml_file & load alias" do
|
74
|
+
meths = [ :load_yaml_file, :load ]
|
54
75
|
let(:mock_obj) { double(klass, proxy: :stubbed_proxy) }
|
55
76
|
let(:mock_file) { double(File) }
|
56
77
|
let(:mock_cred) { {key1: 'value1', 'key2' => 'value2'} }
|
@@ -61,65 +82,67 @@ describe Helix::Config do
|
|
61
82
|
YAML.stub(:load) { mock_cred }
|
62
83
|
mock_obj.stub(:instance_variable_set).with(:@credentials, anything)
|
63
84
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
File.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
YAML.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
File.
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
YAML.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
85
|
+
meths.each do |meth|
|
86
|
+
context "when given no arg" do
|
87
|
+
before(:each) do mock_obj.stub(:instance_variable_set).with(:@filename, klass::DEFAULT_FILENAME) end
|
88
|
+
it "should get the instance" do
|
89
|
+
klass.should_receive(:instance) { mock_obj }
|
90
|
+
klass.send(meth)
|
91
|
+
end
|
92
|
+
it "should set @filename to DEFAULT_FILENAME" do
|
93
|
+
mock_obj.should_receive(:instance_variable_set).with(:@filename, klass::DEFAULT_FILENAME)
|
94
|
+
klass.send(meth)
|
95
|
+
end
|
96
|
+
it "should File.open(@filename) -> f" do
|
97
|
+
File.should_receive(:open).with(klass::DEFAULT_FILENAME) { mock_file }
|
98
|
+
klass.send(meth)
|
99
|
+
end
|
100
|
+
it "should YAML.load(f) -> cred" do
|
101
|
+
YAML.should_receive(:load).with(mock_file) { mock_cred }
|
102
|
+
klass.send(meth)
|
103
|
+
end
|
104
|
+
it "should set @credentials to cred with symbol keys" do
|
105
|
+
File.stub(:open).with(klass::DEFAULT_FILENAME) { mock_file }
|
106
|
+
YAML.stub(:load).with(mock_file) { mock_cred }
|
107
|
+
mock_obj.should_receive(:instance_variable_set).with(:@credentials, symbolized_cred)
|
108
|
+
klass.send(meth)
|
109
|
+
end
|
110
|
+
it "should set the proxy" do
|
111
|
+
mock_obj.should_receive(:proxy) { :mock_proxy }
|
112
|
+
klass.send(meth)
|
113
|
+
end
|
114
|
+
it "should return the instance" do
|
115
|
+
expect(klass.send(meth)).to be(mock_obj)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context "when given the arg 'some_file.yml'" do
|
119
|
+
let(:yaml_arg) { 'some_file.yml' }
|
120
|
+
before(:each) do mock_obj.stub(:instance_variable_set).with(:@filename, yaml_arg) end
|
121
|
+
it "should get the instance" do
|
122
|
+
klass.should_receive(:instance) { mock_obj }
|
123
|
+
klass.send(meth, yaml_arg)
|
124
|
+
end
|
125
|
+
it "should set @filename to DEFAULT_FILENAME" do
|
126
|
+
mock_obj.should_receive(:instance_variable_set).with(:@filename, yaml_arg)
|
127
|
+
klass.send(meth, yaml_arg)
|
128
|
+
end
|
129
|
+
it "should File.open(@filename) -> f" do
|
130
|
+
File.should_receive(:open).with(yaml_arg) { mock_file }
|
131
|
+
klass.send(meth, yaml_arg)
|
132
|
+
end
|
133
|
+
it "should YAML.load(f) -> cred" do
|
134
|
+
YAML.should_receive(:load).with(mock_file) { mock_cred }
|
135
|
+
klass.send(meth, yaml_arg)
|
136
|
+
end
|
137
|
+
it "should set @credentials to cred with symbol keys" do
|
138
|
+
File.stub(:open).with(klass::DEFAULT_FILENAME) { mock_file }
|
139
|
+
YAML.stub(:load).with(mock_file) { mock_cred }
|
140
|
+
mock_obj.should_receive(:instance_variable_set).with(:@credentials, symbolized_cred)
|
141
|
+
klass.send(meth, yaml_arg)
|
142
|
+
end
|
143
|
+
it "should return the instance" do
|
144
|
+
expect(klass.send(meth, yaml_arg)).to be(mock_obj)
|
145
|
+
end
|
123
146
|
end
|
124
147
|
end
|
125
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: helix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.7.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twistage, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|