immosquare-constants 0.1.12 → 0.1.14

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: 4b0e58e67146383f7bb046bc321ac80ae421919e732b8ef6e601db0921a952a3
4
+ data.tar.gz: 86dcdc2878e7ab49df7f3b51741b2061b7114d8256d3bd362bb03084b20ec940
5
5
  SHA512:
6
- metadata.gz: c25c7bf453aef00017391599eaf2bb69f9249663633b304349928f33ccc394e8fc3eabca70fcb7b6d2f3e205f931d4cca633f1cd632fd2ecb05f5230dca26f6f
7
- data.tar.gz: 84a347e271bb5d35860fd92d5cb3d14029573ddf76d8c9167a048580df954403732f0bd687bfce5a44d200598953044f483d25e395f0ef1fb88e54254afecc84
6
+ metadata.gz: 77cb31bd52a176a82bb5909f42e5d45068f6baefdb1f691cbaf147091d53ddbdb17eedfaa086e1d3d026ea59362a81563a70059599045f93012d0c529b174038
7
+ data.tar.gz: 138cf03ab85646ff1c7bea7498c04897f566933bb515e44f731404cd1d69baaded686171e4715b911fa5b4432ae3b406adac1412476bd8cb5b9233f088161020
@@ -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,82 @@
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, :public, :client
14
+
15
+ def initialize(local_ip, public_ip, client_ip)
16
+ @local = local_ip
17
+ @public = public_ip
18
+ @client = client_ip
19
+ end
20
+
21
+ def to_json(*)
22
+ {
23
+ :local => @local,
24
+ :public => @public,
25
+ :client => @client
26
+ }.to_json(*)
27
+ end
28
+
29
+ def to_hash
30
+ {
31
+ :local => @local,
32
+ :public => @public,
33
+ :client => @client
34
+ }
35
+ end
36
+
37
+ def to_s
38
+ "local: #{@local}, public: #{@public}, client: #{@client}"
39
+ end
40
+
41
+ def inspect
42
+ "#<ImmosquareConstants::Ip::IpResult local: #{@local.inspect}, public: #{@public.inspect}, client: #{@client.inspect}>"
43
+ end
44
+
45
+ def to_a
46
+ [@local, @public, @client]
47
+ end
48
+
49
+ def to_h
50
+ to_hash
51
+ end
52
+
53
+ end
54
+
8
55
  class << self
9
56
 
10
57
  ##============================================================##
11
- ## Méthode pour récupérer l'IP publique : DEPRECATED
58
+ ## Method to get the public IP address used to access the internet
12
59
  ##============================================================##
13
- def get_real_ip
60
+ def get_my_ip_from_aws
14
61
  get_public_ip_from_aws
15
62
  end
16
63
 
17
64
  ##============================================================##
18
- ## Méthode pour récupérer les IPs disponibles
65
+ ## Method to get available IP addresses
19
66
  ##============================================================##
20
67
  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
68
+ IpResult.new(
69
+ get_local_ip,
70
+ get_public_ip_from_aws,
71
+ get_client_ip(request)
24
72
  )
25
73
  end
26
74
 
27
75
  private
28
76
 
29
77
  ##============================================================##
30
- ## On utilise un Socket pour obtenir l'IP locale
31
- ## en se connectant à au DNS Google
78
+ ## Use a Socket to get the local IP address
79
+ ## by connecting to Google's DNS server
32
80
  ##============================================================##
33
81
  def get_local_ip
34
82
  local_ip = nil
@@ -45,24 +93,33 @@ module ImmosquareConstants
45
93
  end
46
94
 
47
95
  ##============================================================##
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)
96
+ ## Get client IP with intelligent proxy handling
97
+ ## IP retrieval hierarchy (from most reliable to least reliable):
98
+ ## 1. HTTP_X_REAL_IP : Custom header often set by load balancers/proxies
99
+ ## 2. request.ip : Rails intelligent method that analyzes X-Forwarded-For, X-Real-IP, etc.
100
+ ## 3. request.remote_ip : Direct connection IP (might be proxy IP)
53
101
  ##
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
102
+ ## Example: Client (203.0.113.1) → Proxy (10.0.0.1) → Rails Server
103
+ ## - request.remote_ip would return 10.0.0.1 (proxy)
104
+ ## - request.ip would return 203.0.113.1 (real client)
105
+ ## - HTTP_X_REAL_IP might contain 203.0.113.1 if set by proxy
58
106
  ##============================================================##
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
107
+ def get_client_ip(request = nil)
108
+ begin
109
+ raise("No request provided") if request.nil?
110
+
111
+ ip = request.env["HTTP_X_REAL_IP"] || request.ip || request.remote_ip
112
+ raise("No IP found") if ip.nil?
113
+ raise("IP is localhost (127.0.0.1)") if ip == "127.0.0.1"
114
+
115
+ ip
116
+ rescue StandardError => e
117
+ get_public_ip_from_aws
118
+ end
62
119
  end
63
120
 
64
121
  ##============================================================##
65
- ## On récupère l'IP publique avec fallback (pour production)
122
+ ## Get public IP address with fallback (for production)
66
123
  ##============================================================##
67
124
  def get_public_ip_from_aws
68
125
  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.14".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.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare