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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTJhYjFjMGM1MDlhMzM2MjlkOThhYjg1ZWZjM2NlYzE4YThiNGZhMg==
4
+ OGNmMmI1MWM4NzhjNWM5YjAyOTkzNGJhZjA1YjIzMTUyYThkMDQxNA==
5
5
  data.tar.gz: !binary |-
6
- YzhiYTFkNmFlMDNjZTBlODEyOWJmMTA3MDNmZjJlMDhiY2M3ZGM4NA==
6
+ YmM3MWJlYmIwMmI1ZDdlMjQyZjhkNzQ0YmMxMGFhMmZlNjMxNDhkZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTk4NjJlZGI5OGVjMzYwMzY1MGY0NWQ2NjkzYzE1NjU4MTgxZjc2ZGY3NDI5
10
- YTY3NzFmMTgzYTgxZmZiNmM1OWI4MGE0NWQxNjU1NTcwZWE4MmU0ZDFiYTEy
11
- OTQ0YjY2MTA4YzhlZTU5YWEwOTQ3NjliM2E3OGM0NTYyOGYyNGU=
9
+ MDhiM2ZkYTcyZTRlNTVjODkyZWI1NGY3YTY4MGM5ODA5MWUyNmRkNmM3MGEz
10
+ Mzg0ZjNiOWZlYjkxMjVlMjUxYTY4MTdmZjgzOGMxYjU0OTQxZTkzYWE5N2Nk
11
+ NWY3MTdiMmMxMGZkODkzYzc5ZmNmZjYwZWJhMjY5MGY2Mjc1MTc=
12
12
  data.tar.gz: !binary |-
13
- ZTBjZTIzN2RjMjgzN2JkYzE4ODI4MzBmNjM1ZDBjMmQ0MjkwYTk1OWE3YWFl
14
- ODcxYWFjYTAyZGM3Y2JiOGU5NGIxNGZkMzNiNjFhNWFhNzk3NTMwMWE5YzM5
15
- YzA0YjliYzhkODkzZTdhZDdmYzJhMDQwYzZhNjgxYjU5NDcwMjQ=
13
+ MDgyMWEzN2QxZDljZGQ2MDViMzNmZWJmZmQ4NDRkZGM1NWFlYzkxOGIyNmRk
14
+ ODk0MTFlYzhjY2RkN2ZjNzA0MmZmZTcxNjkxMWRlMGNlYWQwN2M4NjM5ZDU1
15
+ MjkyNGY4MzRiNjk4OGYwYjZjMWQxYjNlMjE1ODYyNjdlZTlmNDE=
@@ -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)
@@ -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.load("/some/path/my_yaml.yml")
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.load(yaml_file_location = DEFAULT_FILENAME)
38
- config = self.instance
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 "://"
@@ -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
@@ -49,8 +49,29 @@ describe Helix::Config do
49
49
  end
50
50
  end
51
51
 
52
- describe ".load" do
53
- let(:meth) { :load }
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
- context "when given no arg" do
65
- before(:each) do mock_obj.stub(:instance_variable_set).with(:@filename, klass::DEFAULT_FILENAME) end
66
- it "should get the instance" do
67
- klass.should_receive(:instance) { mock_obj }
68
- klass.send(meth)
69
- end
70
- it "should set @filename to DEFAULT_FILENAME" do
71
- mock_obj.should_receive(:instance_variable_set).with(:@filename, klass::DEFAULT_FILENAME)
72
- klass.send(meth)
73
- end
74
- it "should File.open(@filename) -> f" do
75
- File.should_receive(:open).with(klass::DEFAULT_FILENAME) { mock_file }
76
- klass.send(meth)
77
- end
78
- it "should YAML.load(f) -> cred" do
79
- YAML.should_receive(:load).with(mock_file) { mock_cred }
80
- klass.send(meth)
81
- end
82
- it "should set @credentials to cred with symbol keys" do
83
- File.stub(:open).with(klass::DEFAULT_FILENAME) { mock_file }
84
- YAML.stub(:load).with(mock_file) { mock_cred }
85
- mock_obj.should_receive(:instance_variable_set).with(:@credentials, symbolized_cred)
86
- klass.send(meth)
87
- end
88
- it "should set the proxy" do
89
- mock_obj.should_receive(:proxy) { :mock_proxy }
90
- klass.send(meth)
91
- end
92
- it "should return the instance" do
93
- expect(klass.send(meth)).to be(mock_obj)
94
- end
95
- end
96
- context "when given the arg 'some_file.yml'" do
97
- let(:yaml_arg) { 'some_file.yml' }
98
- before(:each) do mock_obj.stub(:instance_variable_set).with(:@filename, yaml_arg) end
99
- it "should get the instance" do
100
- klass.should_receive(:instance) { mock_obj }
101
- klass.send(meth, yaml_arg)
102
- end
103
- it "should set @filename to DEFAULT_FILENAME" do
104
- mock_obj.should_receive(:instance_variable_set).with(:@filename, yaml_arg)
105
- klass.send(meth, yaml_arg)
106
- end
107
- it "should File.open(@filename) -> f" do
108
- File.should_receive(:open).with(yaml_arg) { mock_file }
109
- klass.send(meth, yaml_arg)
110
- end
111
- it "should YAML.load(f) -> cred" do
112
- YAML.should_receive(:load).with(mock_file) { mock_cred }
113
- klass.send(meth, yaml_arg)
114
- end
115
- it "should set @credentials to cred with symbol keys" do
116
- File.stub(:open).with(klass::DEFAULT_FILENAME) { mock_file }
117
- YAML.stub(:load).with(mock_file) { mock_cred }
118
- mock_obj.should_receive(:instance_variable_set).with(:@credentials, symbolized_cred)
119
- klass.send(meth, yaml_arg)
120
- end
121
- it "should return the instance" do
122
- expect(klass.send(meth, yaml_arg)).to be(mock_obj)
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.6.pre
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-04 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json