immosquare-constants 0.1.12 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2801e9a375c22fcb94e0739754e9399630cc8847740bf9013e9514e711aa2455
4
- data.tar.gz: 93413f0d1b48010f58fb61d04f322d6291612c2e74308a084c24e86423836919
3
+ metadata.gz: 5073fe427e2b2b4c43e1152815e581dd34e1ad8b212c0fb5331a3d9b17c95c28
4
+ data.tar.gz: 774752277082db562cf31143d55e5df66456148dc261ad820bf4ea25b16a3fd2
5
5
  SHA512:
6
- metadata.gz: c25c7bf453aef00017391599eaf2bb69f9249663633b304349928f33ccc394e8fc3eabca70fcb7b6d2f3e205f931d4cca633f1cd632fd2ecb05f5230dca26f6f
7
- data.tar.gz: 84a347e271bb5d35860fd92d5cb3d14029573ddf76d8c9167a048580df954403732f0bd687bfce5a44d200598953044f483d25e395f0ef1fb88e54254afecc84
6
+ metadata.gz: 0dfa8a292ab75f8ed0f5b18f7360fb6b93eded2aaf2dd9ad01d308e5bcecd8b9ddf7c1f645c702a5310376ae31ec5a82a72808c2d35fe08f97f2c0839e36fc87
7
+ data.tar.gz: 685f991fa70989e6560332590d1d9309ca5b1df1e099751ccb0ec5a76514bbd4c0103b3ad60add4b736249d2db7ce84af60a8890d22d25dd883c77f7092b7573
@@ -154,7 +154,8 @@ module ImmosquareConstants
154
154
  class << self
155
155
 
156
156
  def color_name_to_hex(color_name)
157
- COLORS[color_name.to_sym] || nil
157
+ return nil if color_name.nil?
158
+ COLORS[color_name.to_s.downcase.to_sym] || nil
158
159
  end
159
160
 
160
161
  end
@@ -1,34 +1,78 @@
1
1
  require "socket"
2
2
  require "net/http"
3
3
  require "uri"
4
- require "ostruct"
4
+ require "json"
5
5
 
6
6
  module ImmosquareConstants
7
7
  module Ip
8
+ ##============================================================##
9
+ ## Simple class to provide dot notation access to IP addresses
10
+ ##============================================================##
11
+ class IpResult
12
+
13
+ attr_reader :local, :client
14
+
15
+ def initialize(local_ip, client_ip)
16
+ @local = local_ip
17
+ @client = client_ip
18
+ end
19
+
20
+ def to_json(*)
21
+ {
22
+ :local => @local,
23
+ :client => @client
24
+ }.to_json(*)
25
+ end
26
+
27
+ def to_hash
28
+ {
29
+ :local => @local,
30
+ :client => @client
31
+ }
32
+ end
33
+
34
+ def to_s
35
+ "local: #{@local}, client: #{@client}"
36
+ end
37
+
38
+ def inspect
39
+ "#<ImmosquareConstants::Ip::IpResult local: #{@local.inspect}, client: #{@client.inspect}>"
40
+ end
41
+
42
+ def to_a
43
+ [@local, @client]
44
+ end
45
+
46
+ def to_h
47
+ to_hash
48
+ end
49
+
50
+ end
51
+
8
52
  class << self
9
53
 
10
54
  ##============================================================##
11
- ## Méthode pour récupérer l'IP publique : DEPRECATED
55
+ ## Method to get the public IP address used to access the internet
12
56
  ##============================================================##
13
- def get_real_ip
57
+ def get_my_ip_from_aws
14
58
  get_public_ip_from_aws
15
59
  end
16
60
 
17
61
  ##============================================================##
18
- ## Méthode pour récupérer les IPs disponibles
62
+ ## Method to get available IP addresses
19
63
  ##============================================================##
20
64
  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
65
+ IpResult.new(
66
+ get_local_ip,
67
+ get_client_ip(request)
24
68
  )
25
69
  end
26
70
 
27
71
  private
28
72
 
29
73
  ##============================================================##
30
- ## On utilise un Socket pour obtenir l'IP locale
31
- ## en se connectant à au DNS Google
74
+ ## Use a Socket to get the local IP address
75
+ ## by connecting to Google's DNS server
32
76
  ##============================================================##
33
77
  def get_local_ip
34
78
  local_ip = nil
@@ -45,24 +89,33 @@ module ImmosquareConstants
45
89
  end
46
90
 
47
91
  ##============================================================##
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)
92
+ ## Get client IP with intelligent proxy handling
93
+ ## IP retrieval hierarchy (from most reliable to least reliable):
94
+ ## 1. HTTP_X_REAL_IP : Custom header often set by load balancers/proxies
95
+ ## 2. request.ip : Rails intelligent method that analyzes X-Forwarded-For, X-Real-IP, etc.
96
+ ## 3. request.remote_ip : Direct connection IP (might be proxy IP)
53
97
  ##
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
98
+ ## Example: Client (203.0.113.1) → Proxy (10.0.0.1) → Rails Server
99
+ ## - request.remote_ip would return 10.0.0.1 (proxy)
100
+ ## - request.ip would return 203.0.113.1 (real client)
101
+ ## - HTTP_X_REAL_IP might contain 203.0.113.1 if set by proxy
58
102
  ##============================================================##
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
103
+ def get_client_ip(request = nil)
104
+ begin
105
+ raise("No request provided") if request.nil?
106
+
107
+ ip = request.env["HTTP_X_REAL_IP"] || request.ip || request.remote_ip
108
+ raise("No IP found") if ip.nil?
109
+ raise("IP is localhost (127.0.0.1)") if ip == "127.0.0.1"
110
+
111
+ ip
112
+ rescue StandardError => e
113
+ get_public_ip_from_aws
114
+ end
62
115
  end
63
116
 
64
117
  ##============================================================##
65
- ## On récupère l'IP publique avec fallback (pour production)
118
+ ## Get public IP address with fallback (for production)
66
119
  ##============================================================##
67
120
  def get_public_ip_from_aws
68
121
  begin
@@ -212,6 +212,7 @@ module ImmosquareConstants
212
212
  ##============================================================##
213
213
  def native_name_for_locale(locale)
214
214
  begin
215
+ return nil if locale.nil? || locale.to_s.strip.empty?
215
216
  key = locale.to_s.split("-").map.with_index {|part, index| index == 0 ? part.downcase : part.upcase }.join("-").to_sym
216
217
  LOCALES[key]
217
218
  rescue StandardError
@@ -1,3 +1,3 @@
1
1
  module ImmosquareConstants
2
- VERSION = "0.1.12".freeze
2
+ VERSION = "0.1.13".freeze
3
3
  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.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare