anywhere_time 0.0.1
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 +7 -0
- data/lib/anywhere_time.rb +39 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 79e9c9ceb7c7ed4bfe754c07427e5187cb3f2019e9b961f59b843639efe59eb5
|
4
|
+
data.tar.gz: a78011c271763e7df2c4ac9097ecc3d270fe7edf8a98a9f3b3d5022993beac06
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b340a8784b7ed3aa634ace3e6b51913cff955121122dc72dadbbd564ae51c8dc59c3b0d630e9a81a43d374383bdb855a2ec36c6c611cc80eff79176250affe6b
|
7
|
+
data.tar.gz: 0b778ba0edd252586852711cbb596698e769fdc4dfd5b4f2ca5e5b08e25249128fb1c6c2dd834e58c7083b63c4f0791481010d810ea30b9e46c815bd5de24142
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
class AnywhereTime
|
6
|
+
API_URL = "http://worldtimeapi.org/api/timezone".freeze
|
7
|
+
|
8
|
+
def self.get_ip_address
|
9
|
+
response = Net::HTTP.get_response(URI('https://api.ipify.org?format=json'))
|
10
|
+
body = JSON.parse(response.body)
|
11
|
+
body["ip"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.current_time
|
15
|
+
ip_address = get_ip_address
|
16
|
+
response = Net::HTTP.get_response(URI("http://worldtimeapi.org/api/ip/#{ip_address}"))
|
17
|
+
body = JSON.parse(response.body)
|
18
|
+
d = DateTime.parse(body["datetime"])
|
19
|
+
d.strftime('%I:%M:%S %p')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.timezones(search: nil)
|
23
|
+
response = Net::HTTP.get_response(URI(API_URL))
|
24
|
+
body = JSON.parse(response.body)
|
25
|
+
if search
|
26
|
+
body.filter {|item| item.include?(search.capitalize)}
|
27
|
+
else
|
28
|
+
body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_area_time(area)
|
33
|
+
area_url = API_URL + "/#{area}"
|
34
|
+
response = Net::HTTP.get_response(URI(area_url))
|
35
|
+
body = JSON.parse(response.body)
|
36
|
+
d = DateTime.parse(body["datetime"])
|
37
|
+
d.strftime('%I:%M:%S %p')
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anywhere_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chirag Saroj
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'Discover AnywhereTimeGem: Instantly access real-time information globally.
|
14
|
+
Effortlessly retrieve current time for any location, enabling seamless global time
|
15
|
+
management across diverse contexts and time zones.'
|
16
|
+
email: chiragsaroj1804@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/anywhere_time.rb
|
22
|
+
homepage: https://github.com/chiragsaroj/anywhere_time
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.5.3
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: 'Discover AnywhereTimeGem: Instantly access real-time information globally.
|
45
|
+
Effortlessly retrieve current time for any location, enabling seamless global time
|
46
|
+
management across diverse contexts and time zones.'
|
47
|
+
test_files: []
|