world_time_api 0.1.3 → 0.1.4
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +8 -6
- data/lib/world_time_api/error.rb +5 -0
- data/lib/world_time_api/request.rb +25 -0
- data/lib/world_time_api/response.rb +7 -0
- data/lib/world_time_api/version.rb +1 -1
- data/lib/world_time_api.rb +5 -27
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a07c38ca8b3c1b3f90de1eb502924a65c1430eee681ff040ae9bf7e4135f168
|
4
|
+
data.tar.gz: 69f7536f3483dd8e0a25a2e4a5db82c686eb095db380dd98a8d8a7f3cb6689cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f87097a455ed233f09c273bb5ab726e10ce663ada0bdafa199d64e484e53033ae8aac3808d38ff85c204251463143d1e8c1ce489302c75f364475ccd6125297e
|
7
|
+
data.tar.gz: 9653883401724d52ae46c673d1b5a620bc1606280fdc1b6999fc21c9b2d6cc570eb63a1964105b82d0aa277ccea3a31b257dc0e93ef37a71b4ec80837fab2b75
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -12,24 +12,26 @@ gem 'world_time_api'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
```
|
16
|
-
|
15
|
+
```bash
|
16
|
+
bundle install
|
17
17
|
```
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
```
|
22
|
-
|
21
|
+
```bash
|
22
|
+
gem install world_time_api
|
23
23
|
```
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
WorldTimeApi.
|
28
|
+
WorldTimeApi::Timezones.call # list timezones
|
29
29
|
|
30
|
-
WorldTimeApi.
|
30
|
+
WorldTimeApi::Time.call(time_zone) # get datetime of the timezone
|
31
31
|
|
32
|
+
WorldTimeApi::ClientIp.call # get datetime by your client ip
|
32
33
|
|
34
|
+
WorldTimeApi::ClientIp.call(ip_address) # get datatime by ip address
|
33
35
|
```
|
34
36
|
|
35
37
|
## Development
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "response"
|
4
|
+
require_relative "error"
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
module WorldTimeApi
|
8
|
+
module Request
|
9
|
+
include HTTParty
|
10
|
+
|
11
|
+
base_uri "http://worldtimeapi.org/api"
|
12
|
+
|
13
|
+
Call = ->(url) {
|
14
|
+
begin
|
15
|
+
response = get(url)
|
16
|
+
|
17
|
+
return WorldTimeApi::Error["Invalid timezone"] if response.code != 200
|
18
|
+
|
19
|
+
WorldTimeApi::Response[response]
|
20
|
+
rescue StandardError
|
21
|
+
WorldTimeApi::Error["Connection error"]
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
data/lib/world_time_api.rb
CHANGED
@@ -1,38 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "world_time_api/version"
|
4
|
+
require_relative "world_time_api/request"
|
5
|
+
|
4
6
|
require "httparty"
|
5
7
|
|
6
8
|
# module WorldTimeAPi
|
7
9
|
module WorldTimeApi
|
8
|
-
include HTTParty
|
9
|
-
|
10
|
-
base_uri "http://worldtimeapi.org/api"
|
11
|
-
|
12
|
-
def self.timezones
|
13
|
-
response = get("/timezone")
|
14
|
-
return "Consult Error" if response.code != 200
|
15
|
-
|
16
|
-
response.parsed_response
|
17
|
-
rescue StandardError
|
18
|
-
"Error of connection"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.time(zone_name)
|
22
|
-
response = get("/timezone/#{zone_name}")
|
23
|
-
return "Invalid Zone Name" if response.code != 200
|
24
10
|
|
25
|
-
|
26
|
-
rescue StandardError
|
27
|
-
"Error of connection"
|
28
|
-
end
|
11
|
+
Timezones = -> { Request::Call["/timezone"] }
|
29
12
|
|
30
|
-
|
31
|
-
response = ip.nil? ? get("/ip") : get("/ip/#{ip}")
|
32
|
-
return "Invalid IP" if response.code != 200
|
13
|
+
Time = -> (timezone) { Request::Call["/timezone/#{timezone}"] }
|
33
14
|
|
34
|
-
|
35
|
-
rescue StandardError
|
36
|
-
"Error of connection"
|
37
|
-
end
|
15
|
+
ClientIp = -> (ip = nil) { Request::Call["/ip#{ip ? "/#{ip}" : ''}"] }
|
38
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: world_time_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alef Ojeda de Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -64,6 +64,9 @@ files:
|
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- lib/world_time_api.rb
|
67
|
+
- lib/world_time_api/error.rb
|
68
|
+
- lib/world_time_api/request.rb
|
69
|
+
- lib/world_time_api/response.rb
|
67
70
|
- lib/world_time_api/version.rb
|
68
71
|
homepage: https://github.com/nemuba/world_time_api
|
69
72
|
licenses:
|