File tree Expand file tree Collapse file tree 1 file changed +21
-19
lines changed
Expand file tree Collapse file tree 1 file changed +21
-19
lines changed Original file line number Diff line number Diff line change 11require 'square'
22require 'dotenv/load'
3- include Square
43
54client = 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
2120end
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
2830end
2931end
You can’t perform that action at this time.
0 commit comments