world_time_api 0.1.4 → 0.1.6
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 +20 -6
- data/README.md +15 -5
- data/doc/WorldTimeApi/Request.html +185 -0
- data/doc/WorldTimeApi.html +365 -0
- data/doc/_index.html +122 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +503 -0
- data/doc/file.README.html +128 -0
- data/doc/file_list.html +59 -0
- data/doc/frames.html +22 -0
- data/doc/index.html +128 -0
- data/doc/js/app.js +344 -0
- data/doc/js/full_list.js +242 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +54 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/world_time_api/error.rb +8 -1
- data/lib/world_time_api/request.rb +24 -6
- data/lib/world_time_api/response.rb +9 -2
- data/lib/world_time_api/version.rb +3 -1
- data/lib/world_time_api.rb +23 -6
- metadata +20 -3
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
Top Level Namespace
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.9.37
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div class="nav_wrap">
|
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
32
|
+
<div id="resizer"></div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div id="main" tabindex="-1">
|
|
36
|
+
<div id="header">
|
|
37
|
+
<div id="menu">
|
|
38
|
+
|
|
39
|
+
<a href="_index.html">Index</a> »
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
<span class="title">Top Level Namespace</span>
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div id="search">
|
|
47
|
+
|
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
|
49
|
+
href="class_list.html">
|
|
50
|
+
|
|
51
|
+
<svg width="24" height="24">
|
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
55
|
+
</svg>
|
|
56
|
+
</a>
|
|
57
|
+
|
|
58
|
+
</div>
|
|
59
|
+
<div class="clear"></div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<div id="content"><h1>Top Level Namespace
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
</h1>
|
|
67
|
+
<div class="box_info">
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<h2>Defined Under Namespace</h2>
|
|
82
|
+
<p class="children">
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="WorldTimeApi.html" title="WorldTimeApi (module)">WorldTimeApi</a></span>
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
</p>
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div id="footer">
|
|
103
|
+
Generated on Thu Nov 20 18:24:43 2025 by
|
|
104
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
105
|
+
0.9.37 (ruby-3.2.2).
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
</div>
|
|
109
|
+
</body>
|
|
110
|
+
</html>
|
data/lib/world_time_api/error.rb
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# A Ruby wrapper for the World Time API.
|
|
3
4
|
module WorldTimeApi
|
|
4
|
-
|
|
5
|
+
# Creates an error object with the specified message.
|
|
6
|
+
#
|
|
7
|
+
# @param message [String] The error message.
|
|
8
|
+
# @return [Hash] A hash with a single key `"error"` containing the error message.
|
|
9
|
+
# @example
|
|
10
|
+
# WorldTimeApi::Error.call('Invalid timezone')
|
|
11
|
+
Error = ->(message) { { error: message } }
|
|
5
12
|
end
|
|
@@ -2,24 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "response"
|
|
4
4
|
require_relative "error"
|
|
5
|
-
require
|
|
5
|
+
require "httparty"
|
|
6
6
|
|
|
7
|
+
# A Ruby wrapper for the World Time API.
|
|
7
8
|
module WorldTimeApi
|
|
9
|
+
# A module for making HTTP requests to the World Time API.
|
|
8
10
|
module Request
|
|
9
11
|
include HTTParty
|
|
10
12
|
|
|
11
13
|
base_uri "http://worldtimeapi.org/api"
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
# Makes an HTTP GET request to the specified URL and returns the response as a hash.
|
|
16
|
+
# Retries up to 3 times in case of connection errors.
|
|
17
|
+
#
|
|
18
|
+
# @param url [String] The URL to make the request to.
|
|
19
|
+
# @param max_retries [Integer] Maximum number of retry attempts (default: 3).
|
|
20
|
+
# @return [Hash] A hash representing the response body, or an error hash if there was a problem with the request.
|
|
21
|
+
# @example
|
|
22
|
+
# WorldTimeApi::Request::Call.call('/timezone/Europe/London')
|
|
23
|
+
Call = lambda { |url, max_retries: 3|
|
|
24
|
+
retries = 0
|
|
25
|
+
|
|
14
26
|
begin
|
|
15
27
|
response = get(url)
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
return WorldTimeApi::Error["Invalid timezone"] if response.code != 200
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
WorldTimeApi::Response[response]
|
|
32
|
+
rescue StandardError
|
|
33
|
+
retries += 1
|
|
34
|
+
if retries < max_retries
|
|
35
|
+
sleep(0.5 * retries) # Exponential backoff: 0.5s, 1s, 1.5s
|
|
36
|
+
puts "Retrying request to #{url} (attempt #{retries + 1})..."
|
|
37
|
+
retry
|
|
22
38
|
end
|
|
39
|
+
WorldTimeApi::Error["Connection error"]
|
|
40
|
+
end
|
|
23
41
|
}
|
|
24
42
|
end
|
|
25
43
|
end
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "json"
|
|
4
4
|
|
|
5
|
+
# A Ruby wrapper for the World Time API.
|
|
5
6
|
module WorldTimeApi
|
|
6
|
-
|
|
7
|
+
# Converts the HTTParty response object into a hash.
|
|
8
|
+
#
|
|
9
|
+
# @param response [HTTParty::Response] The HTTParty response object to convert.
|
|
10
|
+
# @return [Hash] A hash representation of the response body.
|
|
11
|
+
# @example
|
|
12
|
+
# WorldTimeApi::Response.call(HTTParty.get('http://worldtimeapi.org/api/timezone/Europe/London'))
|
|
13
|
+
Response = ->(response) { JSON.parse(response.body) }
|
|
7
14
|
end
|
data/lib/world_time_api.rb
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "httparty"
|
|
3
4
|
require_relative "world_time_api/version"
|
|
4
5
|
require_relative "world_time_api/request"
|
|
6
|
+
require_relative "world_time_api/response"
|
|
7
|
+
require_relative "world_time_api/error"
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# module WorldTimeAPi
|
|
9
|
+
# A Ruby wrapper for the World Time API.
|
|
9
10
|
module WorldTimeApi
|
|
10
|
-
|
|
11
|
+
# Returns a list of all timezones supported by the World Time API.
|
|
12
|
+
#
|
|
13
|
+
# @return [Hash] A hash representing the response body, or an error hash if there was a problem with the request.
|
|
14
|
+
# @example
|
|
15
|
+
# WorldTimeApi::Timezones.call
|
|
11
16
|
Timezones = -> { Request::Call["/timezone"] }
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
# Returns the current time for the specified timezone.
|
|
19
|
+
#
|
|
20
|
+
# @param timezone [String] The timezone ID.
|
|
21
|
+
# @return [Hash] A hash representing the response body, or an error hash if there was a problem with the request.
|
|
22
|
+
# @example
|
|
23
|
+
# WorldTimeApi::Time.call('Europe/London')
|
|
24
|
+
Time = ->(timezone) { Request::Call["/timezone/#{timezone}"] }
|
|
14
25
|
|
|
15
|
-
|
|
26
|
+
# Returns the current time for the client's IP address, or for the specified IP address if provided.
|
|
27
|
+
#
|
|
28
|
+
# @param ip [String] (optional) The IP address to lookup.
|
|
29
|
+
# @return [Hash] A hash representing the response body, or an error hash if there was a problem with the request.
|
|
30
|
+
# @example
|
|
31
|
+
# WorldTimeApi::ClientIp.call('127.0.0.1')
|
|
32
|
+
ClientIp = ->(ip = nil) { Request::Call["/ip#{ip ? "/#{ip}" : ""}"] }
|
|
16
33
|
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.6
|
|
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:
|
|
11
|
+
date: 2025-11-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -63,6 +63,22 @@ 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
|
|
67
83
|
- lib/world_time_api/error.rb
|
|
68
84
|
- lib/world_time_api/request.rb
|
|
@@ -75,6 +91,7 @@ metadata:
|
|
|
75
91
|
homepage_uri: https://github.com/nemuba/world_time_api
|
|
76
92
|
source_code_uri: https://github.com/nemuba/world_time_api
|
|
77
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
|
|
78
95
|
post_install_message:
|
|
79
96
|
rdoc_options: []
|
|
80
97
|
require_paths:
|
|
@@ -90,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
107
|
- !ruby/object:Gem::Version
|
|
91
108
|
version: '0'
|
|
92
109
|
requirements: []
|
|
93
|
-
rubygems_version: 3.
|
|
110
|
+
rubygems_version: 3.4.10
|
|
94
111
|
signing_key:
|
|
95
112
|
specification_version: 4
|
|
96
113
|
summary: Api World Time
|