timezonedb-client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/lib/timezonedb/client.rb +8 -6
- data/lib/timezonedb/client/version.rb +1 -1
- data/lib/timezonedb_client.rb +1 -1
- data/spec/timezonedb/client_spec.rb +101 -61
- data/timezonedb-client.gemspec +5 -7
- metadata +18 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c1b6a31168ddf8082ab1fd0ef13189b9e726a74
|
4
|
+
data.tar.gz: 3ac5d75d09b02f19d3f4f90098b8831b49f6e8b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96111761f756888769b5747a6723e289182147137544b5009263a5e72cebd13dc2621208fff0a53173c2605d15ade4c84249b49f342ed19271380fbdd434b2dc
|
7
|
+
data.tar.gz: 7176e287393c1c5f2d5b6f3b4facfccc08808b22a8f84cedcec2df9fe2e56cfd750522b80220f899f331b4cd25c1e9e8a18c5223cb54b62782bd37cc902e6e97
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# Timezonedb Client
|
1
|
+
# Timezonedb Client
|
2
|
+
[![Build Status](https://travis-ci.org/Skyscanner/timezonedb-client-ruby.svg?branch=master)](https://travis-ci.org/Skyscanner/timezonedb-client-ruby)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/timezonedb-client.svg)](https://badge.fury.io/rb/timezonedb-client)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/Skyscanner/timezonedb-client-ruby/badges/gpa.svg)](https://codeclimate.com/github/Skyscanner/timezonedb-client-ruby)
|
2
5
|
|
3
6
|
A Ruby client for the [timezonedb.com API](https://timezonedb.com/api)
|
4
7
|
|
@@ -51,6 +54,14 @@ tz.zone_name
|
|
51
54
|
=> "Europe/Madrid"
|
52
55
|
```
|
53
56
|
|
57
|
+
If you have premium API access, add `true` as a parameter when instantiating
|
58
|
+
the Timezonedb client, otherwise it will use the free plan endpoint.
|
59
|
+
|
60
|
+
```
|
61
|
+
# will call vip.timezonedb.com instead of api.timezonedb.com
|
62
|
+
client = Timezonedb::Client.new(api_key, true)
|
63
|
+
```
|
64
|
+
|
54
65
|
## Contributing
|
55
66
|
|
56
67
|
We're glad you want to make a contribution!
|
data/lib/timezonedb/client.rb
CHANGED
@@ -14,24 +14,26 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
require_relative 'client/version'
|
18
|
+
require_relative 'client/response'
|
19
|
+
require_relative 'client/error'
|
20
20
|
|
21
21
|
require 'rest-client'
|
22
22
|
|
23
23
|
module Timezonedb
|
24
24
|
class Client
|
25
|
-
|
25
|
+
FREE_URL = 'http://api.timezonedb.com'
|
26
|
+
PREMIUM_URL = 'http://vip.timezonedb.com'
|
26
27
|
|
27
|
-
def initialize(api_key)
|
28
|
+
def initialize(api_key, premium = false)
|
28
29
|
@api_key = api_key
|
30
|
+
@url = premium ? PREMIUM_URL : FREE_URL
|
29
31
|
end
|
30
32
|
|
31
33
|
def search_by_coords(latitude, longitude)
|
32
34
|
params = { key: @api_key, lat: latitude, lng: longitude, format: 'json' }
|
33
35
|
|
34
|
-
response = RestClient.get
|
36
|
+
response = RestClient.get @url, params: params
|
35
37
|
response_hash = JSON.parse(response)
|
36
38
|
|
37
39
|
if response_hash['status'] == 'OK'
|
data/lib/timezonedb_client.rb
CHANGED
@@ -18,7 +18,6 @@ require_relative '../spec_helper'
|
|
18
18
|
|
19
19
|
describe Timezonedb::Client do
|
20
20
|
describe '#execute' do
|
21
|
-
let(:url) { 'http://api.timezonedb.com' }
|
22
21
|
let(:api_key) { 'api_key_92834' }
|
23
22
|
let(:latitude) { 40.91331 }
|
24
23
|
let(:longitude) { 24.61922 }
|
@@ -52,93 +51,134 @@ describe Timezonedb::Client do
|
|
52
51
|
}
|
53
52
|
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
before(:each) do
|
55
|
+
stub_request(:get, url)
|
56
|
+
.with(query: query)
|
57
|
+
.to_return(status: 200, body: response_body)
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
.with(query: query)
|
63
|
-
.to_return(status: 200,
|
64
|
-
body: response_body)
|
65
|
-
end
|
60
|
+
context 'when free plan' do
|
61
|
+
let(:url) { 'http://api.timezonedb.com' }
|
66
62
|
|
67
|
-
|
68
|
-
expect(subject.message).to eq message
|
69
|
-
end
|
63
|
+
subject { Timezonedb::Client.new(api_key).search_by_coords(latitude, longitude) }
|
70
64
|
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should return response with correct zone_name' do
|
76
|
-
expect(subject.zone_name).to eq zone_name
|
77
|
-
end
|
65
|
+
context 'and successful request' do
|
66
|
+
let(:response_body) { correct_response_body.to_json }
|
78
67
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
it 'should return response with correct gmt_offset' do
|
84
|
-
expect(subject.gmt_offset).to eq gmt_offset
|
85
|
-
end
|
68
|
+
it 'should return response with correct message' do
|
69
|
+
expect(subject.message).to eq message
|
70
|
+
end
|
86
71
|
|
87
|
-
|
88
|
-
|
89
|
-
|
72
|
+
it 'should return response with correct country_code' do
|
73
|
+
expect(subject.country_code).to eq country_code
|
74
|
+
end
|
90
75
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
76
|
+
it 'should return response with correct zone_name' do
|
77
|
+
expect(subject.zone_name).to eq zone_name
|
78
|
+
end
|
95
79
|
|
96
|
-
|
97
|
-
|
98
|
-
it 'raises an Error' do
|
99
|
-
expect { subject }.to raise_error(Timezonedb::Client::Error)
|
80
|
+
it 'should return response with correct abbreviation' do
|
81
|
+
expect(subject.abbreviation).to eq abbreviation
|
100
82
|
end
|
101
|
-
end
|
102
83
|
|
103
|
-
|
104
|
-
|
105
|
-
correct_response_body['status'] = 'NOT_OK'
|
106
|
-
correct_response_body.to_json
|
84
|
+
it 'should return response with correct gmt_offset' do
|
85
|
+
expect(subject.gmt_offset).to eq gmt_offset
|
107
86
|
end
|
108
87
|
|
109
|
-
|
110
|
-
|
111
|
-
.with(query: query)
|
112
|
-
.to_return(status: 200,
|
113
|
-
body: response_body)
|
88
|
+
it 'should return response with correct dst' do
|
89
|
+
expect(subject.dst).to eq dst
|
114
90
|
end
|
115
91
|
|
116
|
-
|
92
|
+
it 'should return response with correct timestamp' do
|
93
|
+
expect(subject.timestamp).to eq timestamp
|
94
|
+
end
|
117
95
|
end
|
118
96
|
|
119
|
-
context '
|
120
|
-
|
97
|
+
context 'and unsuccessful requests' do
|
98
|
+
shared_examples 'an error raiser' do
|
99
|
+
it 'raises an Error' do
|
100
|
+
expect { subject }.to raise_error(Timezonedb::Client::Error)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when successful response code' do
|
105
|
+
let(:response_body) do
|
106
|
+
correct_response_body['status'] = 'NOT_OK'
|
107
|
+
correct_response_body.to_json
|
108
|
+
end
|
121
109
|
|
122
|
-
context 'when 400 responses' do
|
123
110
|
before(:each) do
|
124
111
|
stub_request(:get, url)
|
125
112
|
.with(query: query)
|
126
|
-
.to_return(status:
|
113
|
+
.to_return(status: 200,
|
127
114
|
body: response_body)
|
128
115
|
end
|
129
116
|
|
130
117
|
it_behaves_like 'an error raiser'
|
131
118
|
end
|
132
119
|
|
133
|
-
context 'when
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
120
|
+
context 'when failure response code' do
|
121
|
+
let(:response_body) { 'unsuccessful request body :(' }
|
122
|
+
|
123
|
+
context 'when 400 responses' do
|
124
|
+
before(:each) do
|
125
|
+
stub_request(:get, url)
|
126
|
+
.with(query: query)
|
127
|
+
.to_return(status: 400,
|
128
|
+
body: response_body)
|
129
|
+
end
|
130
|
+
|
131
|
+
it_behaves_like 'an error raiser'
|
139
132
|
end
|
140
133
|
|
141
|
-
|
134
|
+
context 'when 500 responses' do
|
135
|
+
before(:each) do
|
136
|
+
stub_request(:get, url)
|
137
|
+
.with(query: query)
|
138
|
+
.to_return(status: 500,
|
139
|
+
body: response_body)
|
140
|
+
end
|
141
|
+
|
142
|
+
it_behaves_like 'an error raiser'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when premium plan' do
|
149
|
+
let(:url) { 'http://vip.timezonedb.com' }
|
150
|
+
|
151
|
+
subject { Timezonedb::Client.new(api_key, true).search_by_coords(latitude, longitude) }
|
152
|
+
|
153
|
+
context 'and successful request' do
|
154
|
+
let(:response_body) { correct_response_body.to_json }
|
155
|
+
|
156
|
+
it 'should return response with correct message' do
|
157
|
+
expect(subject.message).to eq message
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should return response with correct country_code' do
|
161
|
+
expect(subject.country_code).to eq country_code
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should return response with correct zone_name' do
|
165
|
+
expect(subject.zone_name).to eq zone_name
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should return response with correct abbreviation' do
|
169
|
+
expect(subject.abbreviation).to eq abbreviation
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return response with correct gmt_offset' do
|
173
|
+
expect(subject.gmt_offset).to eq gmt_offset
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should return response with correct dst' do
|
177
|
+
expect(subject.dst).to eq dst
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should return response with correct timestamp' do
|
181
|
+
expect(subject.timestamp).to eq timestamp
|
142
182
|
end
|
143
183
|
end
|
144
184
|
end
|
data/timezonedb-client.gemspec
CHANGED
@@ -21,7 +21,7 @@ require 'timezonedb/client/version'
|
|
21
21
|
Gem::Specification.new do |s|
|
22
22
|
s.name = 'timezonedb-client'
|
23
23
|
s.version = Timezonedb::Client::VERSION
|
24
|
-
s.date = '
|
24
|
+
s.date = '2016-01-29'
|
25
25
|
s.summary = 'Timezonedb Client'
|
26
26
|
s.description = 'A client for accessing the timezonedb.com API'
|
27
27
|
s.authors = ['Kostis Dadamis', 'Emili Parreno']
|
@@ -37,10 +37,8 @@ Gem::Specification.new do |s|
|
|
37
37
|
s.add_runtime_dependency 'rest-client', '~> 1.8.0'
|
38
38
|
s.add_runtime_dependency 'json', '~> 1.8.0'
|
39
39
|
|
40
|
-
s.add_development_dependency 'rake'
|
41
|
-
s.add_development_dependency 'rspec'
|
42
|
-
s.add_development_dependency '
|
43
|
-
s.add_development_dependency '
|
44
|
-
s.add_development_dependency 'rack-test'
|
45
|
-
s.add_development_dependency 'webmock'
|
40
|
+
s.add_development_dependency 'rake', '~> 10.4.2'
|
41
|
+
s.add_development_dependency 'rspec', '~> 3.4.0'
|
42
|
+
s.add_development_dependency 'rack-test', '~> 0.6.3'
|
43
|
+
s.add_development_dependency 'webmock', '~> 1.22.3'
|
46
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timezonedb-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kostis Dadamis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -43,86 +43,58 @@ dependencies:
|
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 10.4.2
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 10.4.2
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: pry-byebug
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: rubocop
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
60
|
+
- - "~>"
|
89
61
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
62
|
+
version: 3.4.0
|
91
63
|
type: :development
|
92
64
|
prerelease: false
|
93
65
|
version_requirements: !ruby/object:Gem::Requirement
|
94
66
|
requirements:
|
95
|
-
- - "
|
67
|
+
- - "~>"
|
96
68
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
69
|
+
version: 3.4.0
|
98
70
|
- !ruby/object:Gem::Dependency
|
99
71
|
name: rack-test
|
100
72
|
requirement: !ruby/object:Gem::Requirement
|
101
73
|
requirements:
|
102
|
-
- - "
|
74
|
+
- - "~>"
|
103
75
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
76
|
+
version: 0.6.3
|
105
77
|
type: :development
|
106
78
|
prerelease: false
|
107
79
|
version_requirements: !ruby/object:Gem::Requirement
|
108
80
|
requirements:
|
109
|
-
- - "
|
81
|
+
- - "~>"
|
110
82
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
83
|
+
version: 0.6.3
|
112
84
|
- !ruby/object:Gem::Dependency
|
113
85
|
name: webmock
|
114
86
|
requirement: !ruby/object:Gem::Requirement
|
115
87
|
requirements:
|
116
|
-
- - "
|
88
|
+
- - "~>"
|
117
89
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
90
|
+
version: 1.22.3
|
119
91
|
type: :development
|
120
92
|
prerelease: false
|
121
93
|
version_requirements: !ruby/object:Gem::Requirement
|
122
94
|
requirements:
|
123
|
-
- - "
|
95
|
+
- - "~>"
|
124
96
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
97
|
+
version: 1.22.3
|
126
98
|
description: A client for accessing the timezonedb.com API
|
127
99
|
email:
|
128
100
|
- kostis.dadamis@skyscanner.net
|