immosquare-constants 0.1.10 → 0.1.12
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 +59 -3
- data/lib/immosquare-constants/locale.rb +1 -0
- data/lib/immosquare-constants/version.rb +1 -1
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2801e9a375c22fcb94e0739754e9399630cc8847740bf9013e9514e711aa2455
|
4
|
+
data.tar.gz: 93413f0d1b48010f58fb61d04f322d6291612c2e74308a084c24e86423836919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25c7bf453aef00017391599eaf2bb69f9249663633b304349928f33ccc394e8fc3eabca70fcb7b6d2f3e205f931d4cca633f1cd632fd2ecb05f5230dca26f6f
|
7
|
+
data.tar.gz: 84a347e271bb5d35860fd92d5cb3d14029573ddf76d8c9167a048580df954403732f0bd687bfce5a44d200598953044f483d25e395f0ef1fb88e54254afecc84
|
@@ -1,15 +1,70 @@
|
|
1
1
|
require "socket"
|
2
2
|
require "net/http"
|
3
3
|
require "uri"
|
4
|
+
require "ostruct"
|
4
5
|
|
5
6
|
module ImmosquareConstants
|
6
7
|
module Ip
|
7
8
|
class << self
|
8
9
|
|
9
10
|
##============================================================##
|
10
|
-
##
|
11
|
+
## Méthode pour récupérer l'IP publique : DEPRECATED
|
11
12
|
##============================================================##
|
12
13
|
def get_real_ip
|
14
|
+
get_public_ip_from_aws
|
15
|
+
end
|
16
|
+
|
17
|
+
##============================================================##
|
18
|
+
## Méthode pour récupérer les IPs disponibles
|
19
|
+
##============================================================##
|
20
|
+
def get_ips(request = nil)
|
21
|
+
OpenStruct.new(
|
22
|
+
:local => get_local_ip,
|
23
|
+
:client => defined?(Rails) && Rails.env.development? && !request.nil? ? get_client_ip(request) : get_public_ip_from_aws
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
##============================================================##
|
30
|
+
## On utilise un Socket pour obtenir l'IP locale
|
31
|
+
## en se connectant à au DNS Google
|
32
|
+
##============================================================##
|
33
|
+
def get_local_ip
|
34
|
+
local_ip = nil
|
35
|
+
begin
|
36
|
+
socket = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM)
|
37
|
+
socket.connect(Addrinfo.tcp("8.8.8.8", 53))
|
38
|
+
local_ip = socket.local_address.ip_address
|
39
|
+
socket.close
|
40
|
+
rescue StandardError => e
|
41
|
+
puts("Error getting local IP: #{e.message}")
|
42
|
+
ensure
|
43
|
+
return local_ip
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##============================================================##
|
48
|
+
## On récupère l'IP client avec gestion intelligente des proxies
|
49
|
+
## Hiérarchie de récupération d'IP (du plus fiable au moins fiable) :
|
50
|
+
## 1. HTTP_X_REAL_IP : En-tête personnalisé souvent défini par les load balancers/proxies
|
51
|
+
## 2. request.ip : Méthode Rails intelligente qui analyse X-Forwarded-For, X-Real-IP, etc.
|
52
|
+
## 3. request.remote_ip : IP directe de la connexion (peut être l'IP du proxy)
|
53
|
+
##
|
54
|
+
## Exemple : Client (203.0.113.1) → Proxy (10.0.0.1) → Rails Server
|
55
|
+
## - request.remote_ip retournerait 10.0.0.1 (proxy)
|
56
|
+
## - request.ip retournerait 203.0.113.1 (client réel)
|
57
|
+
## - HTTP_X_REAL_IP pourrait contenir 203.0.113.1 si défini par le proxy
|
58
|
+
##============================================================##
|
59
|
+
def get_client_ip(request)
|
60
|
+
ip = request.env["HTTP_X_REAL_IP"] || request.ip || request.remote_ip
|
61
|
+
ip.nil? ? get_public_ip_from_aws : ip
|
62
|
+
end
|
63
|
+
|
64
|
+
##============================================================##
|
65
|
+
## On récupère l'IP publique avec fallback (pour production)
|
66
|
+
##============================================================##
|
67
|
+
def get_public_ip_from_aws
|
13
68
|
begin
|
14
69
|
begin
|
15
70
|
uri = URI.parse("https://checkip.amazonaws.com/")
|
@@ -19,8 +74,8 @@ module ImmosquareConstants
|
|
19
74
|
response.body.strip
|
20
75
|
rescue StandardError => e
|
21
76
|
s = Socket.ip_address_list.find(&:ipv4_private?)
|
22
|
-
s = Socket.ip_address_list.first if s.
|
23
|
-
raise("No IP found") if s.
|
77
|
+
s = Socket.ip_address_list.first if s.nil?
|
78
|
+
raise("No IP found") if s.nil?
|
24
79
|
|
25
80
|
s.ip_address
|
26
81
|
end
|
@@ -29,6 +84,7 @@ module ImmosquareConstants
|
|
29
84
|
end
|
30
85
|
end
|
31
86
|
|
87
|
+
|
32
88
|
end
|
33
89
|
end
|
34
90
|
end
|
@@ -44,6 +44,7 @@ module ImmosquareConstants
|
|
44
44
|
:"en-ZA" => "English (South Africa)",
|
45
45
|
# Spanish (Spain, Latin America, United States)
|
46
46
|
:es => "Español",
|
47
|
+
:"es-LA" => "Español (Latinoamérica)",
|
47
48
|
:"es-AR" => "Español (Argentina)",
|
48
49
|
:"es-BO" => "Español (Bolivia)",
|
49
50
|
:"es-CL" => "Español (Chile)",
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- immosquare
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: ImmosquareConstants gem provides a robust set of constants to facilitate
|
14
13
|
application development across various domains
|
@@ -28,7 +27,6 @@ homepage: https://github.com/immosquare/immosquare-constants
|
|
28
27
|
licenses:
|
29
28
|
- MIT
|
30
29
|
metadata: {}
|
31
|
-
post_install_message:
|
32
30
|
rdoc_options: []
|
33
31
|
require_paths:
|
34
32
|
- lib
|
@@ -36,15 +34,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
34
|
requirements:
|
37
35
|
- - ">="
|
38
36
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
37
|
+
version: 3.2.6
|
40
38
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
39
|
requirements:
|
42
40
|
- - ">="
|
43
41
|
- !ruby/object:Gem::Version
|
44
42
|
version: '0'
|
45
43
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
44
|
+
rubygems_version: 3.6.9
|
48
45
|
specification_version: 4
|
49
46
|
summary: ImmosquareConstants is a comprehensive collection of constants useful for
|
50
47
|
a variety of applications.
|