worldtimeengine 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/worldtimeengine/client.rb +3 -2
- data/lib/worldtimeengine/configurable.rb +4 -1
- data/spec/worldtimeengine_spec.rb +19 -5
- data/worldtimeengine.gemspec +1 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -27,13 +27,14 @@ module WorldTimeEngine
|
|
27
27
|
def api(ip)
|
28
28
|
endpoint = WorldTimeEngine.instance_variable_get(:@endpoint)
|
29
29
|
api_key = WorldTimeEngine.instance_variable_get(:@api_key)
|
30
|
+
timeout = WorldTimeEngine.instance_variable_get(:@timeout)
|
30
31
|
|
31
32
|
raise ArgumentError.new(":api_key wasn't set in configuration block") if api_key.nil?
|
32
33
|
|
33
|
-
hash = HTTParty.get("#{endpoint}/api/ip/#{api_key}/#{ip}", :format => :xml).to_hash
|
34
|
+
hash = HTTParty.get("#{endpoint}/api/ip/#{api_key}/#{ip}", :format => :xml, :timeout => timeout.to_i).to_hash
|
34
35
|
|
35
36
|
if hash.keys.include?('error')
|
36
|
-
raise "Invalid or Expired API Key used; Error code: 10001"
|
37
|
+
raise "[WorldTimeEngine] Invalid or Expired API Key used; Error code: 10001"
|
37
38
|
end
|
38
39
|
|
39
40
|
timezone_hash = hash['timezone']
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module WorldTimeEngine
|
2
2
|
module Configurable
|
3
3
|
attr_writer :api_key
|
4
|
+
attr_writer :timeout
|
4
5
|
attr_accessor :endpoint
|
5
6
|
|
6
7
|
class << self
|
@@ -8,6 +9,7 @@ module WorldTimeEngine
|
|
8
9
|
def keys
|
9
10
|
@keys ||= [
|
10
11
|
:api_key,
|
12
|
+
:timeout,
|
11
13
|
:endpoint
|
12
14
|
]
|
13
15
|
end
|
@@ -28,6 +30,7 @@ module WorldTimeEngine
|
|
28
30
|
def reset!
|
29
31
|
@api_key = nil
|
30
32
|
@endpoint = 'http://worldtimeengine.com'
|
33
|
+
@timeout = 10 # seconds
|
31
34
|
self
|
32
35
|
end
|
33
36
|
alias setup reset!
|
@@ -36,7 +39,7 @@ module WorldTimeEngine
|
|
36
39
|
|
37
40
|
# @return [Hash]
|
38
41
|
def credentials
|
39
|
-
{ :api_key => @api_key }
|
42
|
+
{ :api_key => @api_key, :timeout => @timeout }
|
40
43
|
end
|
41
44
|
|
42
45
|
# @return [Hash]
|
@@ -35,7 +35,7 @@ describe WorldTimeEngine do
|
|
35
35
|
it "returns raises an exception" do
|
36
36
|
lambda {
|
37
37
|
WorldTimeEngine.api('212.154.168.243')
|
38
|
-
}.should raise_error(RuntimeError, 'Invalid or Expired API Key used; Error code: 10001')
|
38
|
+
}.should raise_error(RuntimeError, '[WorldTimeEngine] Invalid or Expired API Key used; Error code: 10001')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -125,11 +125,25 @@ describe WorldTimeEngine do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
describe ".configure" do
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
describe "api_key" do
|
129
|
+
it "sets an api_key" do
|
130
|
+
WorldTimeEngine.configure do |config|
|
131
|
+
config.api_key = 'abc'
|
132
|
+
end
|
133
|
+
WorldTimeEngine.instance_variable_get(:@api_key).should eq 'abc'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "timeout" do
|
138
|
+
it "detaults to 10 secs default timeout" do
|
139
|
+
WorldTimeEngine.instance_variable_get(:@timeout).should eq 10
|
140
|
+
end
|
141
|
+
it "sets a timeout" do
|
142
|
+
WorldTimeEngine.configure do |config|
|
143
|
+
config.timeout = 20
|
144
|
+
end
|
145
|
+
WorldTimeEngine.instance_variable_get(:@timeout).should eq 20
|
131
146
|
end
|
132
|
-
WorldTimeEngine.instance_variable_get(:@api_key).should eq 'abc'
|
133
147
|
end
|
134
148
|
end
|
135
149
|
|
data/worldtimeengine.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worldtimeengine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
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:
|
12
|
+
date: 2013-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: 2897061304423457029
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|