numerics 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,18 +12,35 @@ module Numerics
12
12
  PORT = '443'
13
13
  BASE_PATH = '/ts'
14
14
 
15
- attr_reader :access_key, :secret_key
15
+ attr_reader :access_key, :secret_key, :host, :port
16
16
 
17
- def initialize(access_key, secret_key, host=nil, port=nil)
17
+ def initialize(access_key, secret_key, host=nil, port=nil, disabled=nil)
18
18
  @access_key, @secret_key = access_key.to_s, secret_key.to_s
19
19
  @host = (host || HOST).to_s
20
20
  @port = (port || PORT).to_s
21
+ @disabled = !!disabled
21
22
  end
22
23
 
23
24
  def to_s
24
25
  "#<Numerics::Connection @access_key=#{@access_key}>"
25
26
  end
26
27
 
28
+ def disable!
29
+ @disabled = true
30
+ end
31
+
32
+ def enable!
33
+ @disabled = false
34
+ end
35
+
36
+ def enabled?
37
+ !@disabled
38
+ end
39
+
40
+ def disabled?
41
+ @disabled
42
+ end
43
+
27
44
  ## Start Commands ##
28
45
 
29
46
  def list
@@ -162,17 +179,21 @@ module Numerics
162
179
  end
163
180
 
164
181
  def do_request(req)
165
- req['X-Access-Key'] = @access_key
166
- req['X-Secret-Key'] = @secret_key
167
- req['Content-Type'] = 'application/json'
168
- response = self.client.start do |h|
169
- h.request(req)
170
- end
171
- data = Yajl::Parser.parse(response.body)
172
- if data[0]
173
- {:error => data[0]}
182
+ if self.enabled?
183
+ req['X-Access-Key'] = @access_key
184
+ req['X-Secret-Key'] = @secret_key
185
+ req['Content-Type'] = 'application/json'
186
+ response = self.client.start do |h|
187
+ h.request(req)
188
+ end
189
+ data = Yajl::Parser.parse(response.body)
190
+ if data[0]
191
+ {:error => data[0]}
192
+ else
193
+ {:success => true, :data => data[1]}
194
+ end
174
195
  else
175
- {:success => true, :data => data[1]}
196
+ {:disabled => true}
176
197
  end
177
198
  end
178
199
 
data/lib/numerics.rb CHANGED
@@ -8,7 +8,7 @@ require 'numerics/connection'
8
8
 
9
9
  module Numerics
10
10
 
11
- VERSION = '0.2.2'
11
+ VERSION = '0.2.3'
12
12
 
13
13
  def self.connect(arg, env=nil)
14
14
  config = if arg.is_a?(Hash)
@@ -38,12 +38,13 @@ module Numerics
38
38
  secret_key = config[:secret_key] || config['secret_key']
39
39
  host = config[:host] || config['host'] # nil means use the default
40
40
  port = config[:port] || config['port'] # nil means use the default
41
+ disabled = config[:disabled] || config['disabled']
41
42
 
42
43
  if !access_key && !secret_key
43
44
  raise ArgumentError, 'Numerics.connect(config_file, env=nil) or Numerics.connect(:access_key => access_key, :secret_key => :secret_key)'
44
45
  end
45
46
 
46
- Numerics::Connection.new(access_key, secret_key, host, port)
47
+ Numerics::Connection.new(access_key, secret_key, host, port, disabled)
47
48
  end
48
49
 
49
50
  def self.config(arg, env=nil)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: numerics
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben Lund