world_time_api 0.1.3 → 0.1.5
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 +9 -1
- data/README.md +10 -6
- data/doc/WorldTimeApi/Request.html +177 -0
- data/doc/WorldTimeApi.html +314 -0
- data/doc/_index.html +122 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +497 -0
- data/doc/file.README.html +125 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +125 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +51 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/world_time_api/error.rb +11 -0
- data/lib/world_time_api/request.rb +32 -0
- data/lib/world_time_api/response.rb +13 -0
- data/lib/world_time_api/version.rb +4 -1
- data/lib/world_time_api.rb +21 -31
- metadata +23 -3
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "response"
|
4
|
+
require_relative "error"
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
# The WorldTimeApi module contains methods for making requests to the World Time API.
|
8
|
+
module WorldTimeApi
|
9
|
+
|
10
|
+
# The Request module contains methods for making HTTP requests to the World Time API.
|
11
|
+
module Request
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
base_uri "http://worldtimeapi.org/api"
|
15
|
+
|
16
|
+
# Makes an HTTP GET request to the specified URL and returns the response as a hash.
|
17
|
+
#
|
18
|
+
# @param url [String] The URL to make the request to.
|
19
|
+
# @return [Hash] A hash representing the response body, or an error hash if there was a problem with the request.
|
20
|
+
Call = ->(url) {
|
21
|
+
begin
|
22
|
+
response = get(url)
|
23
|
+
|
24
|
+
return WorldTimeApi::Error["Invalid timezone"] if response.code != 200
|
25
|
+
|
26
|
+
WorldTimeApi::Response[response]
|
27
|
+
rescue StandardError
|
28
|
+
WorldTimeApi::Error["Connection error"]
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
# The WorldTimeApi module contains methods for making requests to the World Time API.
|
6
|
+
module WorldTimeApi
|
7
|
+
|
8
|
+
# Converts the HTTParty response object into a hash.
|
9
|
+
#
|
10
|
+
# @param response [HTTParty::Response] The HTTParty response object to convert.
|
11
|
+
# @return [Hash] A hash representation of the response body.
|
12
|
+
Response = -> (response) { JSON.parse(response.body) }
|
13
|
+
end
|
data/lib/world_time_api.rb
CHANGED
@@ -1,38 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "world_time_api/version"
|
4
3
|
require "httparty"
|
4
|
+
require_relative "world_time_api/version"
|
5
|
+
require_relative "world_time_api/request"
|
6
|
+
require_relative "world_time_api/response"
|
7
|
+
require_relative "world_time_api/error"
|
5
8
|
|
6
|
-
# module
|
9
|
+
# The WorldTimeApi module contains methods for making requests to the World Time API.
|
7
10
|
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
|
-
|
25
|
-
response.parsed_response
|
26
|
-
rescue StandardError
|
27
|
-
"Error of connection"
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.client_ip(ip = nil)
|
31
|
-
response = ip.nil? ? get("/ip") : get("/ip/#{ip}")
|
32
|
-
return "Invalid IP" if response.code != 200
|
33
11
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
12
|
+
# Returns a list of all timezones supported by the World Time API.
|
13
|
+
#
|
14
|
+
# @return [WorldTimeApi::Response] The API response.
|
15
|
+
Timezones = -> { Request::Call["/timezone"] }
|
16
|
+
|
17
|
+
# Returns the current time for the specified timezone.
|
18
|
+
#
|
19
|
+
# @param timezone [String] The timezone ID.
|
20
|
+
# @return [WorldTimeApi::Response] The API response.
|
21
|
+
Time = -> (timezone) { Request::Call["/timezone/#{timezone}"] }
|
22
|
+
|
23
|
+
# Returns the current time for the client's IP address, or for the specified IP address if provided.
|
24
|
+
#
|
25
|
+
# @param ip [String] (optional) The IP address to lookup.
|
26
|
+
# @return [WorldTimeApi::Response] The API response.
|
27
|
+
ClientIp = -> (ip = nil) { Request::Call["/ip#{ip ? "/#{ip}" : ''}"] }
|
38
28
|
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.5
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -63,7 +63,26 @@ files:
|
|
63
63
|
- CODE_OF_CONDUCT.md
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
|
+
- doc/WorldTimeApi.html
|
67
|
+
- doc/WorldTimeApi/Request.html
|
68
|
+
- doc/_index.html
|
69
|
+
- doc/class_list.html
|
70
|
+
- doc/css/common.css
|
71
|
+
- doc/css/full_list.css
|
72
|
+
- doc/css/style.css
|
73
|
+
- doc/file.README.html
|
74
|
+
- doc/file_list.html
|
75
|
+
- doc/frames.html
|
76
|
+
- doc/index.html
|
77
|
+
- doc/js/app.js
|
78
|
+
- doc/js/full_list.js
|
79
|
+
- doc/js/jquery.js
|
80
|
+
- doc/method_list.html
|
81
|
+
- doc/top-level-namespace.html
|
66
82
|
- lib/world_time_api.rb
|
83
|
+
- lib/world_time_api/error.rb
|
84
|
+
- lib/world_time_api/request.rb
|
85
|
+
- lib/world_time_api/response.rb
|
67
86
|
- lib/world_time_api/version.rb
|
68
87
|
homepage: https://github.com/nemuba/world_time_api
|
69
88
|
licenses:
|
@@ -72,6 +91,7 @@ metadata:
|
|
72
91
|
homepage_uri: https://github.com/nemuba/world_time_api
|
73
92
|
source_code_uri: https://github.com/nemuba/world_time_api
|
74
93
|
changelog_uri: https://github.com/nemuba/world_time_api/blob/main/CHANGELOG.md
|
94
|
+
documentation_uri: https://rubydoc.info/github/nemuba/world_time_api/blob/main/doc/index.html
|
75
95
|
post_install_message:
|
76
96
|
rdoc_options: []
|
77
97
|
require_paths:
|
@@ -87,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
107
|
- !ruby/object:Gem::Version
|
88
108
|
version: '0'
|
89
109
|
requirements: []
|
90
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.4.7
|
91
111
|
signing_key:
|
92
112
|
specification_version: 4
|
93
113
|
summary: Api World Time
|