Skip to content

Commit a52304c

Browse files
committed
Update to Fern ruby SDK example
1 parent 96518f5 commit a52304c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

quickstart/lib/sdk_validation.rb

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
require 'square'
22
require 'dotenv/load'
3-
include Square
43

54
client = Square::Client.new(
6-
bearer_auth_credentials: BearerAuthCredentials.new(
7-
access_token: ENV['SQUARE_ACCESS_TOKEN']
8-
),
9-
environment: 'sandbox',
10-
timeout: 1
5+
token: ENV['SQUARE_ACCESS_TOKEN'],
6+
base_url: Square::Environment::SANDBOX
117
)
12-
result = client.locations.list_locations
138

14-
if result.success?
15-
result.data.locations.each do |location|
16-
printf("%s: %s, %s, %s\n",
17-
location[:id],
18-
location[:name],
19-
location[:address][:address_line_1],
20-
location[:address][:locality])
9+
begin
10+
result = client.locations.list
11+
12+
if result.locations
13+
result.locations.each do |location|
14+
printf("%s: %s, %s, %s\n",
15+
location.id,
16+
location.name,
17+
location.address&.address_line_1,
18+
location.address&.locality)
19+
end
2120
end
2221

23-
elsif result.error?
24-
result.errors.each do |error|
25-
warn error[:category]
26-
warn error[:code]
27-
warn error[:detail]
22+
rescue => e
23+
warn "Error: #{e.message}"
24+
if e.respond_to?(:errors) && e.errors
25+
e.errors.each do |error|
26+
warn error.category
27+
warn error.code
28+
warn error.detail
29+
end
2830
end
2931
end

0 commit comments

Comments
 (0)