ipgeolocation_sdk 2.0.0 → 2.0.2

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: 2fd714873e10e71a93363b06825cc1320144c23e929c072f102249fb0b8698f4
4
- data.tar.gz: 367f9e3f264fa09ae56f526067d109df98f89bf1abb6bd8209479ed2b548713f
3
+ metadata.gz: 8d423893c8a9578520671ea730d24c1a80716752647682c9a6ad998494c9a517
4
+ data.tar.gz: 219631c7ed033d981c66b905b9bbb729b5cce38d47f732a77b94a155d1b3026c
5
5
  SHA512:
6
- metadata.gz: 227b7fa05d1368be46c949a82b31cf2267f2360e12f6af496bf11552f1371c1eeea5f684cdd0dc4729598d33a32eeab230d403f882430a780ec8c4befd5abd2f
7
- data.tar.gz: cee24a95e0cb12bc1e063bcff1ea6f77d050108476ce767670d649aebc4b2f00b20b0253835e081b0574c4afefc6f250e635509e63164f7f0e85deb300b185f0
6
+ metadata.gz: e2e3c2609a5fed045b6b8181f56803e3691fc3304c09722b605d06956f9b3eddea0a9c3a22fb7a93a874b90b230c1c6b7b767e102e8e14773826193cf2a56e36
7
+ data.tar.gz: 75bee2d56d4067c2cf69132e3c7f35be16514db513b2fb74039671c1beabeeee3c71f3d102ed7de69b4aac0983b19e17f62e6651a939dd95cf4be916a8487bb6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.2
4
+
5
+ - Hide API keys in request errors and typed bulk error messages.
6
+ - Preserve HTTP error types and status codes when error responses are incomplete or invalid.
7
+ - Add Arabic (`ar`) for single and bulk lookups.
8
+
9
+ Existing public methods and Ruby 2.7+ support remain unchanged.
10
+
11
+ ## 2.0.1
12
+
13
+ - Mask API keys in configuration serialization and client/config inspection.
14
+ - Enforce response-size limits while reading HTTP responses.
15
+ - Preserve UTF-8 across response chunks and replace malformed bytes without losing adjacent text.
16
+ - Correct Bundler test dependencies and add Ruby compatibility checks.
17
+
18
+ Existing public methods and Ruby 2.7+ support are unchanged.
19
+
3
20
  ## 2.0.0
4
21
 
5
22
  - Replaced the old generated v1 gem with the new Ruby SDK for the IPGeolocation.io IP Location API.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # IPGeolocation Ruby SDK
1
+ # IPGeolocation.io Ruby SDK
2
2
 
3
- Official Ruby SDK for the IPGeolocation.io IP Location API.
3
+ Official Ruby SDK for the IPGeolocation.io IP Geolocation API.
4
4
 
5
- Look up IPv4, IPv6, and domains with `/v3/ipgeo` and `/v3/ipgeo-bulk`. Get geolocation, company, ASN, timezone, network, hostname, abuse, user-agent, and security data from one API.
5
+ Look up IPv4, IPv6, and domains with `/v3/ipgeo` and `/v3/ipgeo-bulk`. Get geolocation, company, ASN, time zone, network, hostname, abuse, user-agent, and security data from one API.
6
6
 
7
7
  - Ruby 2.7+
8
8
  - Sync client built on `Net::HTTP`
@@ -85,15 +85,15 @@ You can also pass `LookupIpGeolocationRequest` and `BulkLookupIpGeolocationReque
85
85
  | Module | `IpgeolocationSdk` |
86
86
  | Supported Endpoints | `/v3/ipgeo`, `/v3/ipgeo-bulk` |
87
87
  | Supported Inputs | IPv4, IPv6, domain |
88
- | Main Data Returned | Geolocation, company, ASN, timezone, network, hostname, abuse, user-agent, currency, security |
89
- | Authentication | API key, request-origin auth for `/v3/ipgeo` only |
88
+ | Main Data Returned | Geolocation, company, ASN, time zone, network, hostname, abuse, user-agent, currency, security |
89
+ | Authentication | API key |
90
90
  | Response Formats | Structured JSON, raw JSON, raw XML |
91
91
  | Bulk Limit | Up to 50,000 IPs or domains per request |
92
92
  | Transport | `Net::HTTP` |
93
93
 
94
94
  ## Get Your API Key
95
95
 
96
- To use most SDK features, create or access your IPGeolocation account and copy an API key from your dashboard.
96
+ To use most SDK features, create or access your IPGeolocation.io account and copy an API key from your dashboard.
97
97
 
98
98
  1. Sign up: <https://app.ipgeolocation.io/signup>
99
99
  2. Verify your email if prompted
@@ -101,7 +101,7 @@ To use most SDK features, create or access your IPGeolocation account and copy a
101
101
  4. Open your dashboard: <https://app.ipgeolocation.io/dashboard>
102
102
  5. Copy an API key from the `API Keys` section
103
103
 
104
- For server-side code, keep the API key in an environment variable or secret manager. For browser-based single lookups on paid plans, use request-origin auth instead of exposing an API key in frontend code.
104
+ Keep the API key in an environment variable or secret manager.
105
105
 
106
106
  ## Authentication
107
107
 
@@ -113,21 +113,7 @@ client = IpgeolocationSdk::IpGeolocationClient.new(
113
113
  )
114
114
  ```
115
115
 
116
- ### Request-Origin Auth
117
-
118
- ```ruby
119
- client = IpgeolocationSdk::IpGeolocationClient.new(
120
- request_origin: "https://app.example.com"
121
- )
122
- ```
123
-
124
- `request_origin` must be an absolute `http` or `https` origin with no path, query string, fragment, or userinfo.
125
-
126
- > [!IMPORTANT]
127
- > Request-origin auth does not work with `/v3/ipgeo-bulk`. Bulk lookup always requires `api_key`.
128
-
129
- > [!NOTE]
130
- > If you set both `api_key` and `request_origin`, single lookup still uses the API key. The API key is sent as the `apiKey` query parameter, so avoid logging full request URLs.
116
+ The API key is sent as the `apiKey` query parameter, so avoid logging full request URLs.
131
117
 
132
118
  ## Plan Behavior
133
119
 
@@ -139,7 +125,6 @@ Feature availability depends on your plan and request parameters.
139
125
  | Domain lookup | Not supported | Supported |
140
126
  | Bulk lookup | Not supported | Supported |
141
127
  | Non-English `lang` | Not supported | Supported |
142
- | Request-origin auth | Not supported | Supported for `/v3/ipgeo` only |
143
128
  | Optional modules via `include` | Not supported | Supported |
144
129
  | `include: ["*"]` | Base response only | All plan-available modules |
145
130
 
@@ -149,8 +134,7 @@ Paid plans still need `include` for optional modules. `fields` and `excludes` on
149
134
 
150
135
  | Field | Type | Default | Notes |
151
136
  |-------|------|---------|-------|
152
- | `api_key` | `String` | unset | Required for bulk lookup. Optional for single lookup if `request_origin` is set. |
153
- | `request_origin` | `String` | unset | Must be an absolute `http` or `https` origin. |
137
+ | `api_key` | `String` | unset | Your IPGeolocation.io API key. |
154
138
  | `base_url` | `String` | `https://api.ipgeolocation.io` | Override the API base URL. |
155
139
  | `connect_timeout` | `Numeric` | `10.0` | Time to open the connection, in seconds. |
156
140
  | `read_timeout` | `Numeric` | `30.0` | Time to wait while reading the response body, in seconds. |
@@ -176,7 +160,7 @@ The client constructor accepts either an `IpGeolocationClientConfig` or a hash w
176
160
  |-------|------------|-------|
177
161
  | `ip` | Single lookup | IPv4, IPv6, or domain. Omit it for caller IP lookup. |
178
162
  | `ips` | Bulk lookup | Array of 1 to 50,000 IPs or domains. |
179
- | `lang` | Single and bulk | One of `en`, `de`, `ru`, `ja`, `fr`, `cn`, `es`, `cs`, `it`, `ko`, `fa`, `pt`. |
163
+ | `lang` | Single and bulk | One of `en`, `de`, `ru`, `ja`, `fr`, `cn`, `es`, `cs`, `it`, `ko`, `fa`, `pt`, `ar` (Arabic). |
180
164
  | `include` | Single and bulk | Array of module names such as `security`, `abuse`, `user_agent`, `hostname`, `liveHostname`, `hostnameFallbackLive`, `geo_accuracy`, `dma_code`, or `*`. |
181
165
  | `fields` | Single and bulk | Array of field paths to keep, for example `["location.country_name", "security.threat_score"]`. |
182
166
  | `excludes` | Single and bulk | Array of field paths to remove from the response. |
@@ -331,10 +315,12 @@ puts IpgeolocationSdk.to_pretty_json(response.data)
331
315
  puts IpgeolocationSdk.to_pretty_json(response.data, :full)
332
316
  ```
333
317
 
334
- Compact mode omits `nil` fields. Full mode keeps them.
318
+ Compact mode omits `nil` fields. Full mode keeps them. When serializing a client configuration, both modes replace its API key with `[REDACTED]`. The original key remains available through `config.api_key` and is used for authentication.
335
319
 
336
320
  ## Errors
337
321
 
322
+ If a request error includes your configured API key, the SDK replaces it with `[REDACTED]`. This also applies to errors in typed bulk results. SDK error types and HTTP status codes stay the same. Some error details may be shortened to keep the key hidden.
323
+
338
324
  The SDK raises these exception classes:
339
325
 
340
326
  - `IpgeolocationSdk::ValidationError`
@@ -367,10 +353,8 @@ end
367
353
 
368
354
  ## Troubleshooting
369
355
 
370
- - `bulk lookup requires api_key in client config`
371
- Bulk lookup does not support request-origin auth on its own.
372
- - `single lookup requires api_key or request_origin in client config`
373
- Set at least one authentication option before calling the single lookup methods.
356
+ - Missing API key
357
+ Set `api_key` in the client configuration before making a lookup.
374
358
  - `XML output is not supported by typed methods`
375
359
  Use `lookup_ip_geolocation_raw` or `bulk_lookup_ip_geolocation_raw` for XML output.
376
360
  - `client is closed`
@@ -28,62 +28,90 @@ module IpgeolocationSdk
28
28
 
29
29
  attr_reader :config
30
30
 
31
+ def inspect
32
+ "#<#{self.class} config=#{@config.inspect} closed=#{@closed}>"
33
+ end
34
+
31
35
  def lookup_ip_geolocation(request = nil)
36
+ api_key = @config.api_key&.strip
37
+ redactor = ErrorRedactor.new(api_key)
32
38
  ensure_open
33
39
  typed_request = to_lookup_request(request)
34
40
  validate_lookup_request_base
35
41
  Serde.validate_json_output(typed_request.output)
36
42
 
37
- response, duration_ms = execute_with_metrics(build_lookup_http_request(typed_request))
38
- raise Serde.to_api_error(response.status_code, response.body) unless success_status?(response.status_code)
43
+ response, duration_ms = execute_with_metrics(build_lookup_http_request(typed_request, api_key))
44
+ raise Serde.to_api_error(response.status_code, response.body, redactor) unless success_status?(response.status_code)
39
45
 
40
46
  ApiResponse.new(
41
47
  data: Serde.parse_single_lookup(response.body),
42
48
  metadata: Serde.to_metadata(response.status_code, duration_ms, response.headers)
43
49
  )
50
+ rescue StandardError => error
51
+ raise if api_key.nil?
52
+
53
+ raise redactor.copy(error), cause: nil
44
54
  end
45
55
 
46
56
  def lookup_ip_geolocation_raw(request = nil)
57
+ api_key = @config.api_key&.strip
58
+ redactor = ErrorRedactor.new(api_key)
47
59
  ensure_open
48
60
  typed_request = to_lookup_request(request)
49
61
  validate_lookup_request_base
50
62
 
51
- response, duration_ms = execute_with_metrics(build_lookup_http_request(typed_request))
52
- raise Serde.to_api_error(response.status_code, response.body) unless success_status?(response.status_code)
63
+ response, duration_ms = execute_with_metrics(build_lookup_http_request(typed_request, api_key))
64
+ raise Serde.to_api_error(response.status_code, response.body, redactor) unless success_status?(response.status_code)
53
65
 
54
66
  ApiResponse.new(
55
67
  data: response.body,
56
68
  metadata: Serde.to_metadata(response.status_code, duration_ms, response.headers)
57
69
  )
70
+ rescue StandardError => error
71
+ raise if api_key.nil?
72
+
73
+ raise redactor.copy(error), cause: nil
58
74
  end
59
75
 
60
76
  def bulk_lookup_ip_geolocation(request)
77
+ api_key = @config.api_key&.strip
78
+ redactor = ErrorRedactor.new(api_key)
61
79
  ensure_open
62
80
  typed_request = to_bulk_request(request)
63
81
  validate_bulk_request_base
64
82
  Serde.validate_json_output(typed_request.output)
65
83
 
66
- response, duration_ms = execute_with_metrics(build_bulk_http_request(typed_request))
67
- raise Serde.to_api_error(response.status_code, response.body) unless success_status?(response.status_code)
84
+ response, duration_ms = execute_with_metrics(build_bulk_http_request(typed_request, api_key))
85
+ raise Serde.to_api_error(response.status_code, response.body, redactor) unless success_status?(response.status_code)
68
86
 
69
87
  ApiResponse.new(
70
- data: Serde.parse_bulk_lookup(response.body),
88
+ data: Serde.parse_bulk_lookup(response.body, redactor),
71
89
  metadata: Serde.to_metadata(response.status_code, duration_ms, response.headers)
72
90
  )
91
+ rescue StandardError => error
92
+ raise if api_key.nil?
93
+
94
+ raise redactor.copy(error), cause: nil
73
95
  end
74
96
 
75
97
  def bulk_lookup_ip_geolocation_raw(request)
98
+ api_key = @config.api_key&.strip
99
+ redactor = ErrorRedactor.new(api_key)
76
100
  ensure_open
77
101
  typed_request = to_bulk_request(request)
78
102
  validate_bulk_request_base
79
103
 
80
- response, duration_ms = execute_with_metrics(build_bulk_http_request(typed_request))
81
- raise Serde.to_api_error(response.status_code, response.body) unless success_status?(response.status_code)
104
+ response, duration_ms = execute_with_metrics(build_bulk_http_request(typed_request, api_key))
105
+ raise Serde.to_api_error(response.status_code, response.body, redactor) unless success_status?(response.status_code)
82
106
 
83
107
  ApiResponse.new(
84
108
  data: response.body,
85
109
  metadata: Serde.to_metadata(response.status_code, duration_ms, response.headers)
86
110
  )
111
+ rescue StandardError => error
112
+ raise if api_key.nil?
113
+
114
+ raise redactor.copy(error), cause: nil
87
115
  end
88
116
 
89
117
  def close
@@ -136,10 +164,10 @@ module IpgeolocationSdk
136
164
  end
137
165
  end
138
166
 
139
- def build_lookup_http_request(request)
167
+ def build_lookup_http_request(request, api_key)
140
168
  output = request.output || ResponseFormat::JSON
141
169
  query = Serde.build_query(
142
- "apiKey" => @config.api_key,
170
+ "apiKey" => api_key,
143
171
  "ip" => request.ip,
144
172
  "lang" => request.lang,
145
173
  "include" => request.include.empty? ? nil : request.include.join(","),
@@ -171,10 +199,10 @@ module IpgeolocationSdk
171
199
  )
172
200
  end
173
201
 
174
- def build_bulk_http_request(request)
202
+ def build_bulk_http_request(request, api_key)
175
203
  output = request.output || ResponseFormat::JSON
176
204
  query = Serde.build_query(
177
- "apiKey" => @config.api_key,
205
+ "apiKey" => api_key,
178
206
  "lang" => request.lang,
179
207
  "include" => request.include.empty? ? nil : request.include.join(","),
180
208
  "fields" => request.fields.empty? ? nil : request.fields.join(","),
@@ -26,6 +26,10 @@ module IpgeolocationSdk
26
26
  )
27
27
  end
28
28
 
29
+ def inspect
30
+ "#<#{self.class} #{to_h(mode: JsonOutputMode::FULL).inspect}>"
31
+ end
32
+
29
33
  private
30
34
 
31
35
  def normalize_api_key(value)
@@ -14,9 +14,10 @@ module IpgeolocationSdk
14
14
  KO = "ko"
15
15
  FA = "fa"
16
16
  PT = "pt"
17
+ AR = "ar"
17
18
 
18
19
  VALUES = [
19
- EN, DE, RU, JA, FR, CN, ES, CS, IT, KO, FA, PT
20
+ EN, DE, RU, JA, FR, CN, ES, CS, IT, KO, FA, PT, AR
20
21
  ].freeze
21
22
 
22
23
  module_function
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "cgi"
4
+ require "json"
5
+
3
6
  module IpgeolocationSdk
4
7
  class IpGeolocationError < StandardError
5
8
  attr_reader :cause
@@ -35,4 +38,56 @@ module IpgeolocationSdk
35
38
  class RateLimitError < ApiError; end
36
39
  class ClientClosedRequestError < ApiError; end
37
40
  class ServerError < ApiError; end
41
+
42
+ class ErrorRedactor
43
+ def initialize(api_key)
44
+ return if api_key.nil? || api_key.empty?
45
+
46
+ key = api_key.encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
47
+ escaped = CGI.escape(key)
48
+ forms = [key, escaped, escaped.gsub("+", "%20"), CGI.escapeHTML(key),
49
+ JSON.generate(key)[1...-1], JSON.generate(key, ascii_only: true)[1...-1]]
50
+ patterns = forms.uniq.sort_by { |form| -form.length }.map do |form|
51
+ Regexp.escape(form).gsub(/%[0-9A-F]{2}/) { |escape| "(?i:#{escape})" }
52
+ end
53
+ @pattern = Regexp.new(patterns.join("|"))
54
+ end
55
+
56
+ def text(value)
57
+ return value if value.nil? || @pattern.nil?
58
+
59
+ value.encode(Encoding::UTF_8, invalid: :replace, undef: :replace).gsub(@pattern, "[REDACTED]")
60
+ end
61
+
62
+ def copy(error, depth = 0)
63
+ return nil if error.nil? || depth >= 8
64
+
65
+ message = error.is_a?(JSON::ParserError) ? "Invalid JSON response" : text(error.message)
66
+ cause = copy(error.cause, depth + 1)
67
+ sanitized =
68
+ begin
69
+ if error.is_a?(ApiError)
70
+ error.class.new(message, error.status_code, text(error.api_message))
71
+ elsif error.is_a?(IpGeolocationError)
72
+ error.class.new(message, cause: cause)
73
+ else
74
+ error.class.new(message)
75
+ end
76
+ rescue StandardError
77
+ if error.is_a?(ApiError)
78
+ ApiError.new(message, error.status_code, text(error.api_message))
79
+ elsif error.is_a?(IpGeolocationError)
80
+ klass = [RequestTimeoutError, TransportError, ValidationError, SerializationError, IpGeolocationError].find do |type|
81
+ error.is_a?(type)
82
+ end
83
+ klass.new(message, cause: cause)
84
+ else
85
+ StandardError.new(message)
86
+ end
87
+ end
88
+ sanitized.set_backtrace(error.backtrace&.map { |line| text(line) })
89
+ sanitized
90
+ end
91
+ end
92
+ private_constant :ErrorRedactor
38
93
  end
@@ -14,7 +14,7 @@ module IpgeolocationSdk
14
14
  parse_ip_geolocation_response(payload)
15
15
  end
16
16
 
17
- def parse_bulk_lookup(body)
17
+ def parse_bulk_lookup(body, redactor = nil)
18
18
  payload = parse_json(body, "Failed to deserialize bulk lookup response")
19
19
  unless payload.is_a?(Array)
20
20
  raise SerializationError, "Failed to deserialize bulk response: expected an array payload"
@@ -22,8 +22,10 @@ module IpgeolocationSdk
22
22
 
23
23
  payload.map do |item|
24
24
  if bulk_error_item?(item)
25
+ message = string_or_nil(item["message"])
26
+ message = redactor.text(message) unless redactor.nil?
25
27
  BulkLookupError.new(
26
- error: BulkLookupErrorDetails.new(message: string_or_nil(item["message"]))
28
+ error: BulkLookupErrorDetails.new(message: message)
27
29
  )
28
30
  else
29
31
  raise SerializationError, "Failed to deserialize API response" unless item.is_a?(Hash)
@@ -83,8 +85,8 @@ module IpgeolocationSdk
83
85
  raise ValidationError, "XML output is not supported by typed methods. Use ResponseFormat::JSON."
84
86
  end
85
87
 
86
- def to_api_error(status_code, body)
87
- api_message = extract_api_message(body)
88
+ def to_api_error(status_code, body, redactor = nil)
89
+ api_message = extract_api_message(body, redactor)
88
90
  message =
89
91
  if api_message.nil?
90
92
  "API request failed with HTTP status #{status_code}"
@@ -110,22 +112,25 @@ module IpgeolocationSdk
110
112
  klass.new(message, status_code, api_message)
111
113
  end
112
114
 
113
- def extract_api_message(body)
115
+ def extract_api_message(body, redactor = nil)
114
116
  return nil if body.nil?
115
117
 
116
118
  normalized = body.to_s.strip
117
119
  return nil if normalized.empty?
118
120
 
121
+ fallback = (redactor.nil? ? normalized : redactor.text(normalized))[0, 512]
119
122
  payload = JSON.parse(normalized)
120
- return normalized[0, 512] unless payload.is_a?(Hash)
123
+ return fallback unless payload.is_a?(Hash)
121
124
 
122
125
  message = payload["message"]
123
126
  if message.nil? && payload["error"].is_a?(Hash)
124
127
  message = payload["error"]["message"]
125
128
  end
126
- string_or_nil(message) || normalized[0, 512]
129
+ return fallback unless message.is_a?(String)
130
+
131
+ redactor.nil? ? message : redactor.text(message)
127
132
  rescue JSON::ParserError
128
- normalized[0, 512]
133
+ fallback
129
134
  end
130
135
 
131
136
  def parse_int_header(value)
@@ -164,6 +169,7 @@ module IpgeolocationSdk
164
169
  item = value.public_send(name)
165
170
  next if normalized_mode == JsonOutputMode::COMPACT && item.nil?
166
171
 
172
+ item = "[REDACTED]" if value.is_a?(IpGeolocationClientConfig) && name == :api_key && !item.nil?
167
173
  result[name.to_s] = to_plain_data(item, normalized_mode)
168
174
  end
169
175
  when Array
@@ -15,6 +15,16 @@ module IpgeolocationSdk
15
15
 
16
16
  class NetHttpTransport
17
17
  DEFAULT_MAX_RESPONSE_BODY_CHARS = 128 * 1024 * 1024
18
+ INCOMPLETE_UTF8 = /(?:
19
+ [\xC2-\xDF] |
20
+ \xE0[\xA0-\xBF]? |
21
+ [\xE1-\xEC\xEE-\xEF][\x80-\xBF]? |
22
+ \xED[\x80-\x9F]? |
23
+ \xF0(?:[\x90-\xBF][\x80-\xBF]?)? |
24
+ [\xF1-\xF3][\x80-\xBF]{0,2} |
25
+ \xF4(?:[\x80-\x8F][\x80-\xBF]?)?
26
+ )\z/nx.freeze
27
+ private_constant :INCOMPLETE_UTF8
18
28
 
19
29
  def initialize(max_response_body_chars: DEFAULT_MAX_RESPONSE_BODY_CHARS)
20
30
  raise ArgumentError, "max_response_body_chars must be a positive integer" unless max_response_body_chars.is_a?(Integer) && max_response_body_chars.positive?
@@ -29,9 +39,10 @@ module IpgeolocationSdk
29
39
  http.open_timeout = request.connect_timeout
30
40
  http.read_timeout = request.read_timeout
31
41
 
32
- response = http.request(build_net_http_request(uri, request))
33
- body = response.body
34
- body = body.nil? ? read_response_body(response) : normalize_response_text(body.to_s)
42
+ body = nil
43
+ response = http.request(build_net_http_request(uri, request)) do |stream|
44
+ body = read_response_body(stream)
45
+ end
35
46
 
36
47
  HttpResponseData.new(
37
48
  status_code: response.code.to_i,
@@ -78,22 +89,26 @@ module IpgeolocationSdk
78
89
  end
79
90
 
80
91
  def read_response_body(response)
81
- body_parts = []
82
-
83
- response.read_body do |chunk|
84
- body_parts << normalize_response_text(chunk.to_s)
92
+ body = String.new(encoding: Encoding::UTF_8)
93
+ pending = String.new(encoding: Encoding::BINARY)
94
+ size = 0
95
+ append = lambda do |text|
96
+ normalized = text.force_encoding(Encoding::UTF_8).scrub
97
+ size += normalized.length
98
+ if size > @max_response_body_chars
99
+ raise TransportError, "Response body exceeded max size of #{@max_response_body_chars} characters"
100
+ end
101
+ body << normalized
85
102
  end
86
103
 
87
- body_parts.join
88
- end
89
-
90
- def normalize_response_text(text)
91
- normalized = text.encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
92
- if normalized.length > @max_response_body_chars
93
- raise TransportError, "Response body exceeded max size of #{@max_response_body_chars} characters"
104
+ response.read_body do |chunk|
105
+ bytes = pending << chunk.to_s.b
106
+ pending = bytes.slice!(INCOMPLETE_UTF8) || String.new(encoding: Encoding::BINARY)
107
+ append.call(bytes)
94
108
  end
109
+ append.call(pending)
95
110
 
96
- normalized
111
+ body
97
112
  end
98
113
 
99
114
  def normalize_headers(headers)
@@ -1,3 +1,3 @@
1
1
  module IpgeolocationSdk
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipgeolocation_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - IPGeolocation.io
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-04-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -38,6 +37,20 @@ dependencies:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '3.13'
40
+ - !ruby/object:Gem::Dependency
41
+ name: bigdecimal
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.4'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '1.4'
41
54
  description: Ruby SDK for IPGeolocation.io single and bulk IP geolocation lookups
42
55
  with typed and raw responses.
43
56
  email:
@@ -70,7 +83,6 @@ metadata:
70
83
  bug_tracker_uri: https://github.com/IPGeolocation/ip-geolocation-ruby-sdk/issues
71
84
  changelog_uri: https://github.com/IPGeolocation/ip-geolocation-ruby-sdk/blob/main/CHANGELOG.md
72
85
  rubygems_mfa_required: 'true'
73
- post_install_message:
74
86
  rdoc_options: []
75
87
  require_paths:
76
88
  - lib
@@ -85,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
97
  - !ruby/object:Gem::Version
86
98
  version: '0'
87
99
  requirements: []
88
- rubygems_version: 3.4.20
89
- signing_key:
100
+ rubygems_version: 4.0.21
90
101
  specification_version: 4
91
102
  summary: Official Ruby SDK for the IPGeolocation.io IP Location API
92
103
  test_files: []