immosquare-constants 0.1.14 → 0.1.16
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/lib/immosquare-constants/ip.rb +18 -6
- data/lib/immosquare-constants/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97b58fa8bdcd04000abd024afae97165b9b11d0e1e38fcb36bf2233af0926895
|
4
|
+
data.tar.gz: f4e113d541371b985f6c75f58c9bc7964adc75c28880ee24c13347696c6c34c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e69deefa3385c84aeb8b666f08cb5a34fe53c114f382cd18c3dfcc2a139a28059489509ec6b3cfc2a94beb66bb34f9ea97065bc022bede2931f203f542c407f5
|
7
|
+
data.tar.gz: 72cb4e752a34f992c61ce00defa1967b8b0c3efa2092285d38b237e7e1f54a713d088fb1d4801fbab27f0e5a3e1cf8350622b9c1568e9a0433f00fde81237d67
|
@@ -50,6 +50,14 @@ module ImmosquareConstants
|
|
50
50
|
to_hash
|
51
51
|
end
|
52
52
|
|
53
|
+
def each(&)
|
54
|
+
to_hash.each(&)
|
55
|
+
end
|
56
|
+
|
57
|
+
def each_with_index(&)
|
58
|
+
to_hash.each_with_index(&)
|
59
|
+
end
|
60
|
+
|
53
61
|
end
|
54
62
|
|
55
63
|
class << self
|
@@ -113,30 +121,34 @@ module ImmosquareConstants
|
|
113
121
|
raise("IP is localhost (127.0.0.1)") if ip == "127.0.0.1"
|
114
122
|
|
115
123
|
ip
|
116
|
-
rescue StandardError
|
124
|
+
rescue StandardError
|
117
125
|
get_public_ip_from_aws
|
118
126
|
end
|
119
127
|
end
|
120
128
|
|
121
129
|
##============================================================##
|
122
|
-
## Get public IP address with fallback
|
130
|
+
## Get public IP address with fallback
|
123
131
|
##============================================================##
|
124
132
|
def get_public_ip_from_aws
|
125
133
|
begin
|
126
134
|
begin
|
127
|
-
uri
|
128
|
-
|
129
|
-
|
135
|
+
uri = URI.parse("https://checkip.amazonaws.com/")
|
136
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
137
|
+
http.use_ssl = true
|
138
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
139
|
+
response = http.get(uri.request_uri)
|
140
|
+
raise("No IP found") if !response.is_a?(Net::HTTPSuccess)
|
130
141
|
|
131
142
|
response.body.strip
|
132
143
|
rescue StandardError => e
|
144
|
+
puts("Error getting public IP from AWS: #{e.message}")
|
133
145
|
s = Socket.ip_address_list.find(&:ipv4_private?)
|
134
146
|
s = Socket.ip_address_list.first if s.nil?
|
135
147
|
raise("No IP found") if s.nil?
|
136
148
|
|
137
149
|
s.ip_address
|
138
150
|
end
|
139
|
-
rescue StandardError
|
151
|
+
rescue StandardError
|
140
152
|
"0.0.0.0"
|
141
153
|
end
|
142
154
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immosquare-constants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- immosquare
|
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
|
-
rubygems_version: 3.
|
44
|
+
rubygems_version: 3.7.2
|
45
45
|
specification_version: 4
|
46
46
|
summary: ImmosquareConstants is a comprehensive collection of constants useful for
|
47
47
|
a variety of applications.
|