timezonedb-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/CONTRIBUTING.md +37 -0
- data/Gemfile +19 -0
- data/LICENSE.md +14 -0
- data/README.md +106 -0
- data/Rakefile +8 -0
- data/lib/timezonedb/client.rb +46 -0
- data/lib/timezonedb/client/error.rb +22 -0
- data/lib/timezonedb/client/response.rb +34 -0
- data/lib/timezonedb/client/version.rb +21 -0
- data/lib/timezonedb_client.rb +17 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/timezonedb/client/response_spec.rb +72 -0
- data/spec/timezonedb/client_spec.rb +146 -0
- data/timezonedb-client.gemspec +46 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3691fbe6ff2c623df360127f642aeed3e3000ae1
|
4
|
+
data.tar.gz: 4e5bd1dd05afcb09730ec9565f32104b539619ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8c45cc575c323ef5dc507f2102589f49e8912f108e8871c94030f798972571bb386ed61bd3d394d836446be46aae876a1415611a7e2a09dfeed3e4ed4859500
|
7
|
+
data.tar.gz: 363b38412c21fc2470d25b03f7c163841756d5694a0cf09a861bff05bfad716321b724cd2b5b83df56364287d8c69e8b6ca10dfc3aa624bff774fc0638ef6f06
|
data/.gitignore
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
Gemfile.lock
|
29
|
+
.ruby-version
|
30
|
+
.ruby-gemset
|
31
|
+
|
32
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
33
|
+
.rvmrc
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Contributing to Timezonedb Client
|
2
|
+
|
3
|
+
We're glad you want to make a contribution!
|
4
|
+
|
5
|
+
Fork this repository and send in a pull request when you're finished with your
|
6
|
+
changes. Link any relevant issues in too.
|
7
|
+
|
8
|
+
Take note of the build status of your pull request, only builds that pass will
|
9
|
+
be accepted. Please also keep to our conventions and style so we can keep this
|
10
|
+
repository as clean as possible.
|
11
|
+
|
12
|
+
## License
|
13
|
+
|
14
|
+
By contributing your code, you agree to license your contribution under the
|
15
|
+
terms of the APLv2: http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
|
17
|
+
All files are released with the Apache 2.0 license.
|
18
|
+
|
19
|
+
If you are adding a new file it should have a header like this:
|
20
|
+
|
21
|
+
```
|
22
|
+
# Copyright 2015 Skyscanner Limited.
|
23
|
+
#
|
24
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
25
|
+
#
|
26
|
+
# you may not use this file except in compliance with the License.
|
27
|
+
#
|
28
|
+
# You may obtain a copy of the License at
|
29
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
30
|
+
#
|
31
|
+
# Unless required by applicable law or agreed to in writing, software
|
32
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
33
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
34
|
+
#
|
35
|
+
# See the License for the specific language governing permissions and
|
36
|
+
# limitations under the License.
|
37
|
+
```
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
source 'https://rubygems.org'
|
18
|
+
|
19
|
+
gemspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# License
|
2
|
+
|
3
|
+
Copyright 2015 Skyscanner Ltd
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
6
|
+
this software except in compliance with the License. You may obtain a copy of the
|
7
|
+
License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
12
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
13
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
14
|
+
specific language governing permissions and limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Timezonedb Client [![Build Status](https://travis-ci.org/Skyscanner/timezonedb-client-ruby.svg?branch=master)](https://travis-ci.org/Skyscanner/timezonedb-client-ruby)
|
2
|
+
|
3
|
+
A Ruby client for the [timezonedb.com API](https://timezonedb.com/api)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'timezonedb-client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install timezonedb-client
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Instantiate a new client object providing a Timezonedb API key.
|
28
|
+
[Register](https://timezonedb.com/register) to get your API key
|
29
|
+
|
30
|
+
```
|
31
|
+
client = Timezonedb::Client.new(api_key)
|
32
|
+
```
|
33
|
+
|
34
|
+
Search for the timezone providing latitude and longitude
|
35
|
+
|
36
|
+
```
|
37
|
+
tz = client.search_by_coords("41.3833", "2.1833")
|
38
|
+
tz.abbreviation
|
39
|
+
=> "CET"
|
40
|
+
tz.country_code
|
41
|
+
=> "ES"
|
42
|
+
tz.dst
|
43
|
+
=> "0"
|
44
|
+
tz.gmt_offset
|
45
|
+
=> "3600"
|
46
|
+
tz.message
|
47
|
+
=> ""
|
48
|
+
tz.timestamp
|
49
|
+
=> 1447847197
|
50
|
+
tz.zone_name
|
51
|
+
=> "Europe/Madrid"
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
We're glad you want to make a contribution!
|
57
|
+
|
58
|
+
Fork this repository and send in a pull request when you're finished with your
|
59
|
+
changes. Link any relevant issues in too.
|
60
|
+
|
61
|
+
Take note of the build status of your pull request, only builds that pass will
|
62
|
+
be accepted. Please also keep to our conventions and style so we can keep this
|
63
|
+
repository as clean as possible.
|
64
|
+
|
65
|
+
By contributing your code, you agree to license your contribution under the
|
66
|
+
terms of the APLv2: http://www.apache.org/licenses/LICENSE-2.0
|
67
|
+
|
68
|
+
All files are released with the Apache 2.0 license.
|
69
|
+
|
70
|
+
If you are adding a new file it should have a header like this:
|
71
|
+
|
72
|
+
```
|
73
|
+
# Copyright 2015 Skyscanner Limited.
|
74
|
+
#
|
75
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
76
|
+
#
|
77
|
+
# you may not use this file except in compliance with the License.
|
78
|
+
#
|
79
|
+
# You may obtain a copy of the License at
|
80
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
81
|
+
#
|
82
|
+
# Unless required by applicable law or agreed to in writing, software
|
83
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
84
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
85
|
+
#
|
86
|
+
# See the License for the specific language governing permissions and
|
87
|
+
# limitations under the License.
|
88
|
+
```
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
Copyright 2015 Skyscanner Limited.
|
93
|
+
|
94
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
95
|
+
|
96
|
+
you may not use this software except in compliance with the License.
|
97
|
+
|
98
|
+
You may obtain a copy of the License at
|
99
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
100
|
+
|
101
|
+
Unless required by applicable law or agreed to in writing, software
|
102
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
103
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
104
|
+
|
105
|
+
See the License for the specific language governing permissions and
|
106
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'timezonedb/client/version'
|
18
|
+
require 'timezonedb/client/response'
|
19
|
+
require 'timezonedb/client/error'
|
20
|
+
|
21
|
+
require 'rest-client'
|
22
|
+
|
23
|
+
module Timezonedb
|
24
|
+
class Client
|
25
|
+
URL = 'http://api.timezonedb.com'
|
26
|
+
|
27
|
+
def initialize(api_key)
|
28
|
+
@api_key = api_key
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_by_coords(latitude, longitude)
|
32
|
+
params = { key: @api_key, lat: latitude, lng: longitude, format: 'json' }
|
33
|
+
|
34
|
+
response = RestClient.get URL, params: params
|
35
|
+
response_hash = JSON.parse(response)
|
36
|
+
|
37
|
+
if response_hash['status'] == 'OK'
|
38
|
+
Response.new(response_hash)
|
39
|
+
else
|
40
|
+
fail Timezonedb::Client::Error.new(response_hash['message'])
|
41
|
+
end
|
42
|
+
rescue RestClient::Exception => e
|
43
|
+
raise Timezonedb::Client::Error.new(e.inspect)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Timezonedb
|
18
|
+
class Client
|
19
|
+
class Error < StandardError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Timezonedb
|
18
|
+
class Client
|
19
|
+
class Response
|
20
|
+
attr_reader :status, :message, :country_code, :zone_name,
|
21
|
+
:abbreviation, :gmt_offset, :dst, :timestamp
|
22
|
+
|
23
|
+
def initialize(response_hash)
|
24
|
+
@message = response_hash['message']
|
25
|
+
@country_code = response_hash['countryCode']
|
26
|
+
@zone_name = response_hash['zoneName']
|
27
|
+
@abbreviation = response_hash['abbreviation']
|
28
|
+
@gmt_offset = response_hash['gmtOffset']
|
29
|
+
@dst = response_hash['dst']
|
30
|
+
@timestamp = response_hash['timestamp']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Timezonedb
|
18
|
+
class Client
|
19
|
+
VERSION = '0.1.0'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'timezonedb/client'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'rack/test'
|
18
|
+
require 'rspec'
|
19
|
+
require 'webmock/rspec'
|
20
|
+
|
21
|
+
require_relative '../lib/timezonedb_client.rb'
|
22
|
+
|
23
|
+
RSpec.configure do |conf|
|
24
|
+
conf.include Rack::Test::Methods
|
25
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require_relative '../../spec_helper'
|
18
|
+
|
19
|
+
describe Timezonedb::Client::Response do
|
20
|
+
describe '#initialize' do
|
21
|
+
let(:message) { 'a message' }
|
22
|
+
let(:country_code) { 'GR' }
|
23
|
+
let(:zone_name) { 'Europe\/Athens' }
|
24
|
+
let(:abbreviation) { 'EEST' }
|
25
|
+
let(:gmt_offset) { '10800' }
|
26
|
+
let(:dst) { '1' }
|
27
|
+
let(:timestamp) { 1_429_107_488 }
|
28
|
+
|
29
|
+
let(:response_hash) do
|
30
|
+
{
|
31
|
+
'status' => 'OK',
|
32
|
+
'message' => message,
|
33
|
+
'countryCode' => country_code,
|
34
|
+
'zoneName' => zone_name,
|
35
|
+
'abbreviation' => abbreviation,
|
36
|
+
'gmtOffset' => gmt_offset,
|
37
|
+
'dst' => dst,
|
38
|
+
'timestamp' => timestamp
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { Timezonedb::Client::Response.new(response_hash) }
|
43
|
+
|
44
|
+
it 'sets the correct message' do
|
45
|
+
expect(subject.message).to eq message
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'sets the correct country_code' do
|
49
|
+
expect(subject.country_code).to eq country_code
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sets the correct zone_name' do
|
53
|
+
expect(subject.zone_name).to eq zone_name
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'sets the correct abbreviation' do
|
57
|
+
expect(subject.abbreviation).to eq abbreviation
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'sets the correct gmt_offset' do
|
61
|
+
expect(subject.gmt_offset).to eq gmt_offset
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'sets the correct dst' do
|
65
|
+
expect(subject.dst).to eq dst
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'sets the correct timestamp' do
|
69
|
+
expect(subject.timestamp).to eq timestamp
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require_relative '../spec_helper'
|
18
|
+
|
19
|
+
describe Timezonedb::Client do
|
20
|
+
describe '#execute' do
|
21
|
+
let(:url) { 'http://api.timezonedb.com' }
|
22
|
+
let(:api_key) { 'api_key_92834' }
|
23
|
+
let(:latitude) { 40.91331 }
|
24
|
+
let(:longitude) { 24.61922 }
|
25
|
+
let(:query) do
|
26
|
+
{
|
27
|
+
key: api_key,
|
28
|
+
lat: latitude,
|
29
|
+
lng: longitude,
|
30
|
+
format: 'json'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:status) { 'OK' }
|
35
|
+
let(:message) { 'an OK message' }
|
36
|
+
let(:country_code) { 'GR' }
|
37
|
+
let(:zone_name) { 'Europe\/Athens' }
|
38
|
+
let(:abbreviation) { 'EEST' }
|
39
|
+
let(:gmt_offset) { '10800' }
|
40
|
+
let(:dst) { '1' }
|
41
|
+
let(:timestamp) { 1_429_107_488 }
|
42
|
+
let(:correct_response_body) do
|
43
|
+
{
|
44
|
+
'status' => status,
|
45
|
+
'message' => message,
|
46
|
+
'countryCode' => country_code,
|
47
|
+
'zoneName' => zone_name,
|
48
|
+
'abbreviation' => abbreviation,
|
49
|
+
'gmtOffset' => gmt_offset,
|
50
|
+
'dst' => dst,
|
51
|
+
'timestamp' => timestamp
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
subject { Timezonedb::Client.new(api_key).search_by_coords(latitude, longitude) }
|
56
|
+
|
57
|
+
context 'when successful request' do
|
58
|
+
let(:response_body) { correct_response_body.to_json }
|
59
|
+
|
60
|
+
before(:each) do
|
61
|
+
stub_request(:get, url)
|
62
|
+
.with(query: query)
|
63
|
+
.to_return(status: 200,
|
64
|
+
body: response_body)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return response with correct message' do
|
68
|
+
expect(subject.message).to eq message
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return response with correct country_code' do
|
72
|
+
expect(subject.country_code).to eq country_code
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should return response with correct zone_name' do
|
76
|
+
expect(subject.zone_name).to eq zone_name
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return response with correct abbreviation' do
|
80
|
+
expect(subject.abbreviation).to eq abbreviation
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should return response with correct gmt_offset' do
|
84
|
+
expect(subject.gmt_offset).to eq gmt_offset
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should return response with correct dst' do
|
88
|
+
expect(subject.dst).to eq dst
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return response with correct timestamp' do
|
92
|
+
expect(subject.timestamp).to eq timestamp
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when unsuccessful requests' do
|
97
|
+
shared_examples 'an error raiser' do
|
98
|
+
it 'raises an Error' do
|
99
|
+
expect { subject }.to raise_error(Timezonedb::Client::Error)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when successful response code' do
|
104
|
+
let(:response_body) do
|
105
|
+
correct_response_body['status'] = 'NOT_OK'
|
106
|
+
correct_response_body.to_json
|
107
|
+
end
|
108
|
+
|
109
|
+
before(:each) do
|
110
|
+
stub_request(:get, url)
|
111
|
+
.with(query: query)
|
112
|
+
.to_return(status: 200,
|
113
|
+
body: response_body)
|
114
|
+
end
|
115
|
+
|
116
|
+
it_behaves_like 'an error raiser'
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when failure response code' do
|
120
|
+
let(:response_body) { 'unsuccessful request body :(' }
|
121
|
+
|
122
|
+
context 'when 400 responses' do
|
123
|
+
before(:each) do
|
124
|
+
stub_request(:get, url)
|
125
|
+
.with(query: query)
|
126
|
+
.to_return(status: 400,
|
127
|
+
body: response_body)
|
128
|
+
end
|
129
|
+
|
130
|
+
it_behaves_like 'an error raiser'
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when 500 responses' do
|
134
|
+
before(:each) do
|
135
|
+
stub_request(:get, url)
|
136
|
+
.with(query: query)
|
137
|
+
.to_return(status: 500,
|
138
|
+
body: response_body)
|
139
|
+
end
|
140
|
+
|
141
|
+
it_behaves_like 'an error raiser'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright 2015 Skyscanner Limited.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
#
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
#
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
#
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
lib = File.expand_path('../lib', __FILE__)
|
18
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
19
|
+
require 'timezonedb/client/version'
|
20
|
+
|
21
|
+
Gem::Specification.new do |s|
|
22
|
+
s.name = 'timezonedb-client'
|
23
|
+
s.version = Timezonedb::Client::VERSION
|
24
|
+
s.date = '2015-11-18'
|
25
|
+
s.summary = 'Timezonedb Client'
|
26
|
+
s.description = 'A client for accessing the timezonedb.com API'
|
27
|
+
s.authors = ['Kostis Dadamis', 'Emili Parreno']
|
28
|
+
s.email = ['kostis.dadamis@skyscanner.net', 'emili.parreno@skysacnenr.net']
|
29
|
+
s.homepage = 'https://github.com/Skyscanner/timezonedb-client-ruby'
|
30
|
+
s.license = 'Apache License, Version 2.0'
|
31
|
+
|
32
|
+
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
33
|
+
s.test_files = s.files.grep(%r{^spec/})
|
34
|
+
s.require_paths = ['lib']
|
35
|
+
s.required_ruby_version = '>= 2.0.0'
|
36
|
+
|
37
|
+
s.add_runtime_dependency 'rest-client', '~> 1.8.0'
|
38
|
+
s.add_runtime_dependency 'json', '~> 1.8.0'
|
39
|
+
|
40
|
+
s.add_development_dependency 'rake'
|
41
|
+
s.add_development_dependency 'rspec'
|
42
|
+
s.add_development_dependency 'pry-byebug'
|
43
|
+
s.add_development_dependency 'rubocop'
|
44
|
+
s.add_development_dependency 'rack-test'
|
45
|
+
s.add_development_dependency 'webmock'
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timezonedb-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kostis Dadamis
|
8
|
+
- Emili Parreno
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.8.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.8.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.8.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.8.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
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
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rack-test
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: A client for accessing the timezonedb.com API
|
127
|
+
email:
|
128
|
+
- kostis.dadamis@skyscanner.net
|
129
|
+
- emili.parreno@skysacnenr.net
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rspec"
|
136
|
+
- ".travis.yml"
|
137
|
+
- CONTRIBUTING.md
|
138
|
+
- Gemfile
|
139
|
+
- LICENSE.md
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- lib/timezonedb/client.rb
|
143
|
+
- lib/timezonedb/client/error.rb
|
144
|
+
- lib/timezonedb/client/response.rb
|
145
|
+
- lib/timezonedb/client/version.rb
|
146
|
+
- lib/timezonedb_client.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/timezonedb/client/response_spec.rb
|
149
|
+
- spec/timezonedb/client_spec.rb
|
150
|
+
- timezonedb-client.gemspec
|
151
|
+
homepage: https://github.com/Skyscanner/timezonedb-client-ruby
|
152
|
+
licenses:
|
153
|
+
- Apache License, Version 2.0
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 2.0.0
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.4.5
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Timezonedb Client
|
175
|
+
test_files:
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- spec/timezonedb/client/response_spec.rb
|
178
|
+
- spec/timezonedb/client_spec.rb
|