world_time_api 0.1.5 → 0.1.7
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 +18 -8
- data/README.md +13 -5
- data/doc/WorldTimeApi/Request.html +13 -5
- data/doc/WorldTimeApi.html +67 -16
- data/doc/_index.html +4 -4
- data/doc/class_list.html +6 -3
- data/doc/css/full_list.css +3 -3
- data/doc/css/style.css +6 -0
- data/doc/file.README.html +32 -29
- data/doc/file_list.html +5 -2
- data/doc/frames.html +10 -5
- data/doc/index.html +32 -29
- data/doc/js/app.js +294 -264
- data/doc/js/full_list.js +30 -4
- data/doc/method_list.html +5 -2
- data/doc/top-level-namespace.html +3 -3
- data/lib/world_time_api/error.rb +4 -3
- data/lib/world_time_api/request.rb +16 -5
- data/lib/world_time_api/response.rb +5 -4
- data/lib/world_time_api/version.rb +2 -3
- data/lib/world_time_api.rb +12 -7
- metadata +4 -4
data/doc/js/full_list.js
CHANGED
|
@@ -62,8 +62,25 @@ function enableToggles() {
|
|
|
62
62
|
evt.stopPropagation();
|
|
63
63
|
evt.preventDefault();
|
|
64
64
|
$(this).parent().parent().toggleClass('collapsed');
|
|
65
|
+
$(this).attr('aria-expanded', function (i, attr) {
|
|
66
|
+
return attr == 'true' ? 'false' : 'true'
|
|
67
|
+
});
|
|
65
68
|
highlight();
|
|
66
69
|
});
|
|
70
|
+
|
|
71
|
+
// navigation of nested classes using keyboard
|
|
72
|
+
$('#full_list a.toggle').on('keypress',function(evt) {
|
|
73
|
+
// enter key is pressed
|
|
74
|
+
if (evt.which == 13) {
|
|
75
|
+
evt.stopPropagation();
|
|
76
|
+
evt.preventDefault();
|
|
77
|
+
$(this).parent().parent().toggleClass('collapsed');
|
|
78
|
+
$(this).attr('aria-expanded', function (i, attr) {
|
|
79
|
+
return attr == 'true' ? 'false' : 'true'
|
|
80
|
+
});
|
|
81
|
+
highlight();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
function populateSearchCache() {
|
|
@@ -91,7 +108,7 @@ function enableSearch() {
|
|
|
91
108
|
}
|
|
92
109
|
});
|
|
93
110
|
|
|
94
|
-
$('#full_list').after("<div id='noresults' style='display:none'></div>");
|
|
111
|
+
$('#full_list').after("<div id='noresults' role='status' style='display: none'></div>");
|
|
95
112
|
}
|
|
96
113
|
|
|
97
114
|
function ignoredKeyPress(event) {
|
|
@@ -154,11 +171,14 @@ function partialSearch(searchString, offset) {
|
|
|
154
171
|
function searchDone() {
|
|
155
172
|
searchTimeout = null;
|
|
156
173
|
highlight();
|
|
157
|
-
|
|
158
|
-
|
|
174
|
+
var found = $('#full_list li:visible').size();
|
|
175
|
+
if (found === 0) {
|
|
176
|
+
$('#noresults').text('No results were found.');
|
|
159
177
|
} else {
|
|
160
|
-
|
|
178
|
+
// This is read out to screen readers
|
|
179
|
+
$('#noresults').text('There are ' + found + ' results.');
|
|
161
180
|
}
|
|
181
|
+
$('#noresults').show();
|
|
162
182
|
$('#content').removeClass('insearch');
|
|
163
183
|
}
|
|
164
184
|
|
|
@@ -188,6 +208,12 @@ function expandTo(path) {
|
|
|
188
208
|
$target.addClass('clicked');
|
|
189
209
|
$target.removeClass('collapsed');
|
|
190
210
|
$target.parentsUntil('#full_list', 'li').removeClass('collapsed');
|
|
211
|
+
|
|
212
|
+
$target.find('a.toggle').attr('aria-expanded', 'true')
|
|
213
|
+
$target.parentsUntil('#full_list', 'li').each(function(i, el) {
|
|
214
|
+
$(el).find('> div > a.toggle').attr('aria-expanded', 'true');
|
|
215
|
+
});
|
|
216
|
+
|
|
191
217
|
if($target[0]) {
|
|
192
218
|
window.scrollTo(window.scrollX, $target.offset().top - 250);
|
|
193
219
|
highlight();
|
data/doc/method_list.html
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
2
|
+
<html >
|
|
3
3
|
<head>
|
|
4
4
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5
5
|
<meta charset="utf-8" />
|
|
@@ -38,7 +38,10 @@
|
|
|
38
38
|
|
|
39
39
|
</div>
|
|
40
40
|
|
|
41
|
-
<div id="search">
|
|
41
|
+
<div id="search">
|
|
42
|
+
<label for="search-class">Search:</label>
|
|
43
|
+
<input id="search-class" type="text" />
|
|
44
|
+
</div>
|
|
42
45
|
</div>
|
|
43
46
|
|
|
44
47
|
<ul id="full_list" class="method">
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<title>
|
|
7
7
|
Top Level Namespace
|
|
8
8
|
|
|
9
|
-
— Documentation by YARD 0.9.
|
|
9
|
+
— Documentation by YARD 0.9.37
|
|
10
10
|
|
|
11
11
|
</title>
|
|
12
12
|
|
|
@@ -100,9 +100,9 @@
|
|
|
100
100
|
</div>
|
|
101
101
|
|
|
102
102
|
<div id="footer">
|
|
103
|
-
Generated on Thu
|
|
103
|
+
Generated on Thu Nov 20 18:24:43 2025 by
|
|
104
104
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
105
|
-
0.9.
|
|
105
|
+
0.9.37 (ruby-3.2.2).
|
|
106
106
|
</div>
|
|
107
107
|
|
|
108
108
|
</div>
|
data/lib/world_time_api/error.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# A Ruby wrapper for the World Time API.
|
|
4
4
|
module WorldTimeApi
|
|
5
|
-
|
|
6
5
|
# Creates an error object with the specified message.
|
|
7
6
|
#
|
|
8
7
|
# @param message [String] The error message.
|
|
9
8
|
# @return [Hash] A hash with a single key `"error"` containing the error message.
|
|
10
|
-
|
|
9
|
+
# @example
|
|
10
|
+
# WorldTimeApi::Error.call('Invalid timezone')
|
|
11
|
+
Error = ->(message) { { error: message } }
|
|
11
12
|
end
|
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "response"
|
|
4
4
|
require_relative "error"
|
|
5
|
-
require
|
|
5
|
+
require "httparty"
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# A Ruby wrapper for the World Time API.
|
|
8
8
|
module WorldTimeApi
|
|
9
|
-
|
|
10
|
-
# The Request module contains methods for making HTTP requests to the World Time API.
|
|
9
|
+
# A module for making HTTP requests to the World Time API.
|
|
11
10
|
module Request
|
|
12
11
|
include HTTParty
|
|
13
12
|
|
|
14
13
|
base_uri "http://worldtimeapi.org/api"
|
|
15
14
|
|
|
16
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
17
|
#
|
|
18
18
|
# @param url [String] The URL to make the request to.
|
|
19
|
+
# @param max_retries [Integer] Maximum number of retry attempts (default: 3).
|
|
19
20
|
# @return [Hash] A hash representing the response body, or an error hash if there was a problem with the request.
|
|
20
|
-
|
|
21
|
+
# @example
|
|
22
|
+
# WorldTimeApi::Request::Call.call('/timezone/Europe/London')
|
|
23
|
+
Call = lambda { |url, max_retries: 3|
|
|
24
|
+
retries = 0
|
|
25
|
+
|
|
21
26
|
begin
|
|
22
27
|
response = get(url)
|
|
23
28
|
|
|
@@ -25,6 +30,12 @@ module WorldTimeApi
|
|
|
25
30
|
|
|
26
31
|
WorldTimeApi::Response[response]
|
|
27
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
|
|
38
|
+
end
|
|
28
39
|
WorldTimeApi::Error["Connection error"]
|
|
29
40
|
end
|
|
30
41
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "json"
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# A Ruby wrapper for the World Time API.
|
|
6
6
|
module WorldTimeApi
|
|
7
|
-
|
|
8
7
|
# Converts the HTTParty response object into a hash.
|
|
9
8
|
#
|
|
10
9
|
# @param response [HTTParty::Response] The HTTParty response object to convert.
|
|
11
10
|
# @return [Hash] A hash representation of the response body.
|
|
12
|
-
|
|
11
|
+
# @example
|
|
12
|
+
# WorldTimeApi::Response.call(HTTParty.get('http://worldtimeapi.org/api/timezone/Europe/London'))
|
|
13
|
+
Response = ->(response) { JSON.parse(response.body) }
|
|
13
14
|
end
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
3
|
+
# A Ruby wrapper for the World Time API.
|
|
4
4
|
module WorldTimeApi
|
|
5
|
-
|
|
6
5
|
# The current version number of the WorldTimeApi gem.
|
|
7
|
-
VERSION = "0.1.
|
|
6
|
+
VERSION = "0.1.7"
|
|
8
7
|
end
|
data/lib/world_time_api.rb
CHANGED
|
@@ -6,23 +6,28 @@ require_relative "world_time_api/request"
|
|
|
6
6
|
require_relative "world_time_api/response"
|
|
7
7
|
require_relative "world_time_api/error"
|
|
8
8
|
|
|
9
|
-
#
|
|
9
|
+
# A Ruby wrapper for the World Time API.
|
|
10
10
|
module WorldTimeApi
|
|
11
|
-
|
|
12
11
|
# Returns a list of all timezones supported by the World Time API.
|
|
13
12
|
#
|
|
14
|
-
# @return [
|
|
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
|
|
15
16
|
Timezones = -> { Request::Call["/timezone"] }
|
|
16
17
|
|
|
17
18
|
# Returns the current time for the specified timezone.
|
|
18
19
|
#
|
|
19
20
|
# @param timezone [String] The timezone ID.
|
|
20
|
-
# @return [
|
|
21
|
-
|
|
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}"] }
|
|
22
25
|
|
|
23
26
|
# Returns the current time for the client's IP address, or for the specified IP address if provided.
|
|
24
27
|
#
|
|
25
28
|
# @param ip [String] (optional) The IP address to lookup.
|
|
26
|
-
# @return [
|
|
27
|
-
|
|
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}" : ""}"] }
|
|
28
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.7
|
|
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
|
|
@@ -91,7 +91,7 @@ metadata:
|
|
|
91
91
|
homepage_uri: https://github.com/nemuba/world_time_api
|
|
92
92
|
source_code_uri: https://github.com/nemuba/world_time_api
|
|
93
93
|
changelog_uri: https://github.com/nemuba/world_time_api/blob/main/CHANGELOG.md
|
|
94
|
-
documentation_uri: https://rubydoc.info/
|
|
94
|
+
documentation_uri: https://rubydoc.info/gems/world_time_api
|
|
95
95
|
post_install_message:
|
|
96
96
|
rdoc_options: []
|
|
97
97
|
require_paths:
|
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
107
|
- !ruby/object:Gem::Version
|
|
108
108
|
version: '0'
|
|
109
109
|
requirements: []
|
|
110
|
-
rubygems_version: 3.4.
|
|
110
|
+
rubygems_version: 3.4.10
|
|
111
111
|
signing_key:
|
|
112
112
|
specification_version: 4
|
|
113
113
|
summary: Api World Time
|