greet_locally 0.1.0
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/greet_locally.rb +13 -0
- data/lib/greet_locally/translator.rb +45 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 71a2cf58392a5ee61d3bf6a91fd9a9b14063014291a07c332ca2b94476f919f4
|
4
|
+
data.tar.gz: 27a86e6bc08f82f2edd5d2a766e33b39ff6f644cdf6a7419f5a22f5b46ea6d3e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e96427d86b871cc6ee950a157e882ca9fde9bbf2102f0bda99137d4987afcbbaf8693264313013dd409cebc4730b5c7f56cbc52eff47ed48125a1aa1431e6e56
|
7
|
+
data.tar.gz: c5f9ceaa0167a2e3a730c801417b29b10db1f82f6e48b922ab7464c9c05818c487b9e2c98890b365aeab1aa3d6211dde5863846d4c84f19a3d42d3adcb28ddb6
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GreetLocally::Translator
|
4
|
+
def initialize(ip_address)
|
5
|
+
@geolocation_url = "https://ipinfo.io/#{ip_address}" #Gets IP for user
|
6
|
+
@language_url = "https://restcountries.eu/rest/v2/alpha"
|
7
|
+
end
|
8
|
+
|
9
|
+
def process
|
10
|
+
say_hi(language)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :geolocation_url, :language_url
|
16
|
+
|
17
|
+
def say_hi(language = "english")
|
18
|
+
case language.downcase
|
19
|
+
when "spanish"
|
20
|
+
"Hola Mundo!"
|
21
|
+
when "chinese"
|
22
|
+
"你好,世界!"
|
23
|
+
when "japanese"
|
24
|
+
"こんにちは世界!"
|
25
|
+
when "german"
|
26
|
+
"Hallo Welt!"
|
27
|
+
when "hindi"
|
28
|
+
"नमस्ते दुनिया!"
|
29
|
+
when "russian"
|
30
|
+
"Привет мир!"
|
31
|
+
else
|
32
|
+
"Hello world!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def location
|
37
|
+
response = Net::HTTP.get(URI.parse(geolocation_url))
|
38
|
+
JSON.parse(response)["country"].downcase
|
39
|
+
end
|
40
|
+
|
41
|
+
def language
|
42
|
+
response = Net::HTTP.get(URI.parse("#{language_url}/#{location}"))
|
43
|
+
JSON.parse(response)["languages"][0]["name"].downcase
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: greet_locally
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Srijan Kapoor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: srijan.kpr@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/greet_locally.rb
|
20
|
+
- lib/greet_locally/translator.rb
|
21
|
+
homepage: https://rubygems.org/greet_locally
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A ruby gem which greets user based on their geolocation.
|
44
|
+
test_files: []
|