Skip to content

Commit d2dad83

Browse files
oschwaldclaude
andcommitted
Fix syntax errors and improve idiomatic style in code samples
- PHP: Add missing semicolons after require_once, use $camelCase variables - Python: Remove trailing semicolons, fix missing imports and closing quotes - C#/Java: Change # comments to // (correct syntax) - JavaScript/Ruby: Add missing commas in objects/hashes - Python async examples: Fix to use AsyncClient with async with/await 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 5b5bf1d commit d2dad83

File tree

4 files changed

+154
-151
lines changed

4 files changed

+154
-151
lines changed

content/geoip/geolocate-an-ip/databases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ import geoip2.database
161161
# This reader object should be reused across lookups as creation of it is
162162
# expensive.
163163
with geoip2.database.Reader('/path/to/maxmind-database.mmdb') as reader:
164-
response = reader.city('128.101.101.101');
164+
response = reader.city('128.101.101.101')
165165
print(response.country.iso_code)
166166
```
167167

content/geoip/geolocate-an-ip/web-services.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,40 +122,40 @@ const client = new WebServiceClient(accountId, licenseKey, {
122122
```
123123

124124
```php
125-
<?php require_once 'vendor/autoload.php'
125+
<?php
126+
require_once 'vendor/autoload.php';
126127
use GeoIp2\WebService\Client;
127128

128-
$account_id = 10;
129-
$license_key = 'LICENSEKEY';
129+
$accountId = 10;
130+
$licenseKey = 'LICENSEKEY';
130131

131-
$client = new Client($account_id, $license_key);
132+
$client = new Client($accountId, $licenseKey);
132133

133134
// To query the GeoLite web service, you must set the optional `host` argument.
134135
// The third argument specifies the language preferences when using the `->name`
135136
// method on the model classes that this client creates.
136-
$client = new Client($account_id, $license_key, ['en'], ['host' => 'geolite.info']);
137+
$client = new Client($accountId, $licenseKey, ['en'], ['host' => 'geolite.info']);
137138
```
138139

139140
```python
140-
import asyncio # for async requests with AsyncClient
141141
import geoip2.webservice
142142

143143
account_id = 10
144144
license_key = 'LICENSEKEY'
145145

146146
# If you want to use synchronous requests
147-
client = Client(account_id, license_key)
147+
client = geoip2.webservice.Client(account_id, license_key)
148148

149149
# To query the GeoLite web service, you must set the "host" keyword argument
150150
# to "geolite.info"
151-
client = Client(account_id, license_key, host='geolite.info')
151+
client = geoip2.webservice.Client(account_id, license_key, host='geolite.info')
152152

153-
# Or if you want to use asynchronous requests
154-
async_client = AsyncClient(account_id, license_key)
153+
# Or if you want to use asynchronous requests (requires `import asyncio`)
154+
async_client = geoip2.webservice.AsyncClient(account_id, license_key)
155155

156156
# To query the GeoLite web service, you must set the "host" keyword argument
157157
# to "geolite.info"
158-
async_client = AsyncClient(account_id, license_key, host='geolite.info')
158+
async_client = geoip2.webservice.AsyncClient(account_id, license_key, host='geolite.info')
159159
```
160160

161161
```ruby
@@ -247,13 +247,14 @@ client.country('142.1.1.1').then((response) => {
247247
```
248248

249249
```php
250-
<?php require_once 'vendor/autoload.php'
250+
<?php
251+
require_once 'vendor/autoload.php';
251252
use GeoIp2\WebService\Client;
252253

253-
$account_id = 10;
254-
$license_key = 'LICENSEKEY';
254+
$accountId = 10;
255+
$licenseKey = 'LICENSEKEY';
255256

256-
$client = new Client($account_id, $license_key);
257+
$client = new Client($accountId, $licenseKey);
257258

258259
// You can also use `$client->city` or `$client->insights`
259260
// `$client->insights` is not available to GeoLite users
@@ -272,7 +273,7 @@ license_key = 'LICENSEKEY'
272273
with geoip2.webservice.Client(account_id, license_key) as client:
273274
# You can also use `client.city` or `client.insights`
274275
# `client.insights` is not available to GeoLite users
275-
response = client.country('128.101.101.101)
276+
response = client.country('128.101.101.101')
276277

277278
print(response.country.iso_code)
278279

@@ -284,7 +285,7 @@ async def main():
284285
async with geoip2.webservice.AsyncClient(account_id, license_key) as client:
285286
# You can also use `client.city` or `client.insights`
286287
# `client.insights` is not available to GeoLite users
287-
response = await client.country('128.101.101.101)
288+
response = await client.country('128.101.101.101')
288289

289290
print(response.country.iso_code)
290291

content/minfraud/evaluate-a-transaction.md

Lines changed: 125 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ $client = new MinFraud(10, 'LICENSEKEY');
131131
```
132132

133133
```python
134+
from minfraud import Client, AsyncClient
135+
134136
# If you want to use synchronous requests
135-
client = Client(10, 'LICENSEKEY');
137+
client = Client(10, 'LICENSEKEY')
136138

137139
# Or if you want to use asynchronous requests
138-
async_client = AsyncClient(10, 'LICENSEKEY');
140+
async_client = AsyncClient(10, 'LICENSEKEY')
139141
```
140142

141143
```ruby
@@ -418,24 +420,24 @@ Insights, or Factors service.
418420
{{< codeset >}}
419421

420422
```csharp
421-
# minFraud Score
423+
// minFraud Score
422424
var score = await client.ScoreAsync(transaction);
423425

424-
# minFraud Insights
426+
// minFraud Insights
425427
var insights = await client.InsightsAsync(transaction);
426428

427-
# minFraud Factors
429+
// minFraud Factors
428430
var factors = await client.FactorsAsync(transaction);
429431
```
430432

431433
```java
432-
# minFraud Score
434+
// minFraud Score
433435
ScoreResponse score = client.score(transaction);
434436

435-
# minFraud Insights
437+
// minFraud Insights
436438
InsightsResponse insights = client.insights(transaction);
437439

438-
# minFraud Factors
440+
// minFraud Factors
439441
FactorsResponse factors = client.factors(transaction);
440442
```
441443

@@ -451,13 +453,13 @@ client.factors(transaction).then(factorsResponse => ...);
451453
```
452454

453455
```php
454-
# minFraud Score
456+
// minFraud Score
455457
$scoreResponse = $request->score();
456458

457-
# minFraud Insights
459+
// minFraud Insights
458460
$insightsResponse = $request->insights();
459461

460-
# minFraud Factors
462+
// minFraud Factors
461463
$factorsResponse = $request->factors();
462464
```
463465

@@ -989,118 +991,118 @@ foreach ($scoreResponse->warnings as $warning) {
989991
```
990992

991993
```python
992-
import asyncio # Only import asyncio if you are playing to do an asynchronous request
993-
from minfraud import AsyncClient, Client
994-
995-
request = {
996-
'device': {
997-
'ip_address': '1.1.1.1',
998-
'accept_language': 'en-US,en;q=0.8',
999-
'session_age': 3600,
1000-
'session_id': 'a333a4e127f880d8820e56a66f40717c',
1001-
'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36'
1002-
},
1003-
'event': {
1004-
'shop_id': 's2123',
1005-
'type': 'purchase',
1006-
'transaction_id': 'txn3134133',
1007-
'time': '2014-04-12T23:20:50.052+00:00'
1008-
},
1009-
'account': {
1010-
'user_id': '3132',
1011-
'username_md5': '570a90bfbf8c7eab5dc5d4e26832d5b1'
1012-
},
1013-
'email': {
1014-
'address': '977577b140bfb7c516e4746204fbdb01',
1015-
'domain': 'maxmind.com'
1016-
},
1017-
'billing': {
1018-
'first_name': 'First',
1019-
'last_name': 'Last',
1020-
'company': 'Company, Inc.',
1021-
'address': '1 Billing Address St.',
1022-
'address_2': 'Unit 1',
1023-
'city': 'Waltham',
1024-
'region': 'MA',
1025-
'country': 'US',
1026-
'postal': '02451',
1027-
'phone_country_code': '1',
1028-
'phone_number': '555-555-5555',
1029-
},
1030-
'shipping': {
1031-
'first_name': 'First',
1032-
'last_name': 'Last',
1033-
'company': 'Company, Inc.',
1034-
'address': '1 Shipping Address St.',
1035-
'address_2': 'Unit 1',
1036-
'city': 'Waltham',
1037-
'region': 'MA',
1038-
'country': 'US',
1039-
'postal': '02451',
1040-
'phone_country_code': '1',
1041-
'phone_number': '555-555-5555',
1042-
'delivery_speed': 'same_day',
1043-
},
1044-
'credit_card': {
1045-
'bank_phone_country_code': '1',
1046-
'avs_result': 'Y',
1047-
'bank_phone_number': '555-555-5555',
1048-
'last_digits': '1234',
1049-
'cvv_result': 'N',
1050-
'bank_name': 'Test Bank',
1051-
'issuer_id_number': '411111'
1052-
},
1053-
'payment': {
1054-
'decline_code': 'invalid number',
1055-
'was_authorized': False,
1056-
'processor': 'stripe'
1057-
},
1058-
'shopping_cart': [{
1059-
'category': 'pets',
1060-
'quantity': 2,
1061-
'price': 20.43,
1062-
'item_id': 'lsh12'
1063-
}, {
1064-
'category': 'beauty',
1065-
'quantity': 1,
1066-
'price': 100.0,
1067-
'item_id': 'ms12'
1068-
}],
1069-
'order': {
1070-
'affiliate_id': 'af12',
1071-
'referrer_uri': 'http://www.amazon.com/',
1072-
'subaffiliate_id': 'saf42',
1073-
'discount_code': 'FIRST',
1074-
'currency': 'USD',
1075-
'amount': 323.21
1076-
},
1077-
'custom_inputs': {
1078-
'section': 'news',
1079-
'num_of_previous_purchases': 19,
1080-
'discount': 3.2,
1081-
'previous_user': True
1082-
}
1083-
}
1084-
1085-
# This example function uses a synchronous Client object. The object
1086-
# can be used across multiple requests.
1087-
def client(account_id, license_key):
1088-
with Client(account_id, license_key) as client:
1089-
print(client.score(request))
1090-
print(client.insights(request))
1091-
print(client.factors(request))
1092-
1093-
client(42, 'license_key')
1094-
1095-
# This example function uses an asynchronous AsyncClient object. The
1096-
# object can be used across multiple requests.
1097-
async def async_client(account_id, license_key):
1098-
with Client(account_id, license_key) as client:
1099-
print(client.score(request))
1100-
print(client.insights(request))
1101-
print(client.factors(request))
1102-
1103-
asyncio.run(async_client(42, 'license_key'))
994+
import asyncio # Only needed for asynchronous requests
995+
from minfraud import AsyncClient, Client
996+
997+
request = {
998+
'device': {
999+
'ip_address': '1.1.1.1',
1000+
'accept_language': 'en-US,en;q=0.8',
1001+
'session_age': 3600,
1002+
'session_id': 'a333a4e127f880d8820e56a66f40717c',
1003+
'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36'
1004+
},
1005+
'event': {
1006+
'shop_id': 's2123',
1007+
'type': 'purchase',
1008+
'transaction_id': 'txn3134133',
1009+
'time': '2014-04-12T23:20:50.052+00:00'
1010+
},
1011+
'account': {
1012+
'user_id': '3132',
1013+
'username_md5': '570a90bfbf8c7eab5dc5d4e26832d5b1'
1014+
},
1015+
'email': {
1016+
'address': '977577b140bfb7c516e4746204fbdb01',
1017+
'domain': 'maxmind.com'
1018+
},
1019+
'billing': {
1020+
'first_name': 'First',
1021+
'last_name': 'Last',
1022+
'company': 'Company, Inc.',
1023+
'address': '1 Billing Address St.',
1024+
'address_2': 'Unit 1',
1025+
'city': 'Waltham',
1026+
'region': 'MA',
1027+
'country': 'US',
1028+
'postal': '02451',
1029+
'phone_country_code': '1',
1030+
'phone_number': '555-555-5555',
1031+
},
1032+
'shipping': {
1033+
'first_name': 'First',
1034+
'last_name': 'Last',
1035+
'company': 'Company, Inc.',
1036+
'address': '1 Shipping Address St.',
1037+
'address_2': 'Unit 1',
1038+
'city': 'Waltham',
1039+
'region': 'MA',
1040+
'country': 'US',
1041+
'postal': '02451',
1042+
'phone_country_code': '1',
1043+
'phone_number': '555-555-5555',
1044+
'delivery_speed': 'same_day',
1045+
},
1046+
'credit_card': {
1047+
'bank_phone_country_code': '1',
1048+
'avs_result': 'Y',
1049+
'bank_phone_number': '555-555-5555',
1050+
'last_digits': '1234',
1051+
'cvv_result': 'N',
1052+
'bank_name': 'Test Bank',
1053+
'issuer_id_number': '411111'
1054+
},
1055+
'payment': {
1056+
'decline_code': 'invalid number',
1057+
'was_authorized': False,
1058+
'processor': 'stripe'
1059+
},
1060+
'shopping_cart': [{
1061+
'category': 'pets',
1062+
'quantity': 2,
1063+
'price': 20.43,
1064+
'item_id': 'lsh12'
1065+
}, {
1066+
'category': 'beauty',
1067+
'quantity': 1,
1068+
'price': 100.0,
1069+
'item_id': 'ms12'
1070+
}],
1071+
'order': {
1072+
'affiliate_id': 'af12',
1073+
'referrer_uri': 'http://www.amazon.com/',
1074+
'subaffiliate_id': 'saf42',
1075+
'discount_code': 'FIRST',
1076+
'currency': 'USD',
1077+
'amount': 323.21
1078+
},
1079+
'custom_inputs': {
1080+
'section': 'news',
1081+
'num_of_previous_purchases': 19,
1082+
'discount': 3.2,
1083+
'previous_user': True
1084+
}
1085+
}
1086+
1087+
# This example function uses a synchronous Client object. The object
1088+
# can be used across multiple requests.
1089+
def sync_example(account_id, license_key):
1090+
with Client(account_id, license_key) as client:
1091+
print(client.score(request))
1092+
print(client.insights(request))
1093+
print(client.factors(request))
1094+
1095+
sync_example(42, 'license_key')
1096+
1097+
# This example function uses an asynchronous AsyncClient object. The
1098+
# object can be used across multiple requests.
1099+
async def async_example(account_id, license_key):
1100+
async with AsyncClient(account_id, license_key) as client:
1101+
print(await client.score(request))
1102+
print(await client.insights(request))
1103+
print(await client.factors(request))
1104+
1105+
asyncio.run(async_example(42, 'license_key'))
11041106
```
11051107

11061108
```ruby

0 commit comments

Comments
 (0)