Skip to content

Commit 69bd94b

Browse files
authored
Merge pull request #2 from Square-Developers/UpdateToFern
Update to Fern ruby SDK example
2 parents 96518f5 + a52304c commit 69bd94b

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-
includeSquare
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-
ifresult.success?
15-
result.data.locations.eachdo |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+
ifresult.locations
13+
result.locations.eachdo |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-
elsifresult.error?
24-
result.errors.eachdo |error|
25-
warnerror[:category]
26-
warnerror[:code]
27-
warnerror[:detail]
22+
rescue=>e
23+
warn"Error: #{e.message}"
24+
ife.respond_to?(:errors) && e.errors
25+
e.errors.eachdo |error|
26+
warnerror.category
27+
warnerror.code
28+
warnerror.detail
29+
end
2830
end
2931
end

0 commit comments

Comments
(0)