Class: GlobusClient
- Inherits:
-
Object
show all
- Includes:
- Errors, Singleton
- Defined in:
- lib/globus_client.rb,
lib/globus_client/errors.rb,
lib/globus_client/version.rb,
lib/globus_client/endpoint.rb,
lib/globus_client/identity.rb,
lib/globus_client/authenticator.rb,
lib/globus_client/endpoint_manager.rb,
lib/globus_client/unexpected_response.rb
Overview
Client for interacting with the Globus API
Defined Under Namespace
Modules: Errors
Classes: Authenticator, Config, Endpoint, EndpointManager, Identity, UnexpectedResponse
Constant Summary
collapse
- VERSION =
'0.18.0'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#allow_writes ⇒ Object
-
#delete(base_url:, path:) ⇒ Object
Send an authenticated DELETE request.
-
#delete_access_rule ⇒ Object
-
#disallow_writes ⇒ Object
-
#exists? ⇒ Boolean
-
#file_count ⇒ Object
-
#get(base_url:, path:, params: {}, content_type: nil) ⇒ Object
Send an authenticated GET request.
-
#get_filenames ⇒ Object
-
#has_files? ⇒ Boolean
-
#list_files(**keywords) ⇒ Object
NOTE: Can’t use the ‘…` (argument forwarding) operator here because we want to route the keyword args to `Endpoint#new` and the block arg to `Endpoint#list_files`.
-
#mkdir ⇒ Object
-
#post(base_url:, path:, body:, expected_response: ->(_resp) { false }) ⇒ Object
Send an authenticated POST request.
-
#put(base_url:, path:, body:) ⇒ Object
Send an authenticated PUT request.
-
#rename(new_path:, **args) ⇒ Object
-
#task_list ⇒ Object
-
#tasks_in_progress? ⇒ Boolean
-
#total_size ⇒ Object
-
#user_valid? ⇒ Boolean
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
65
66
67
|
# File 'lib/globus_client.rb', line 65
def config
@config
end
|
Class Method Details
rubocop:disable Metrics/ParameterLists
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/globus_client.rb', line 26
def configure(client_id:, client_secret:, uploads_directory:, transfer_endpoint_id:,
transfer_url: default_transfer_url, auth_url: default_auth_url)
instance.config = Config.new(
token: 'a temporary dummy token to avoid hitting the API before it is needed',
client_id:,
client_secret:,
uploads_directory:,
transfer_endpoint_id:,
transfer_url:,
auth_url:
)
self
end
|
.default_auth_url ⇒ Object
60
61
62
|
# File 'lib/globus_client.rb', line 60
def default_auth_url
'https://auth.globus.org'
end
|
.default_transfer_url ⇒ Object
56
57
58
|
# File 'lib/globus_client.rb', line 56
def default_transfer_url
'https://transfer.api.globusonline.org'
end
|
Instance Method Details
#allow_writes ⇒ Object
157
158
159
160
161
|
# File 'lib/globus_client.rb', line 157
def allow_writes(...)
Endpoint
.new(...)
.allow_writes
end
|
#delete(base_url:, path:) ⇒ Object
Send an authenticated DELETE request
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/globus_client.rb', line 130
def delete(base_url:, path:)
response = with_token_refresh_when_unauthorized do
connection(base_url).delete(path) do |request|
request.['Authorization'] = "Bearer #{config.token}"
end
end
UnexpectedResponse.call(response) unless response.success?
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#delete_access_rule ⇒ Object
163
164
165
166
167
|
# File 'lib/globus_client.rb', line 163
def delete_access_rule(...)
Endpoint
.new(...)
.delete_access_rule
end
|
#disallow_writes ⇒ Object
151
152
153
154
155
|
# File 'lib/globus_client.rb', line 151
def disallow_writes(...)
Endpoint
.new(...)
.disallow_writes
end
|
#exists? ⇒ Boolean
208
209
210
211
212
|
# File 'lib/globus_client.rb', line 208
def exists?(...)
Endpoint
.new(...)
.exists?
end
|
#file_count ⇒ Object
184
185
186
187
188
|
# File 'lib/globus_client.rb', line 184
def file_count(...)
Endpoint
.new(...)
.list_files { |files| return files.count }
end
|
#get(base_url:, path:, params: {}, content_type: nil) ⇒ Object
Send an authenticated GET request
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/globus_client.rb', line 71
def get(base_url:, path:, params: {}, content_type: nil)
response = with_token_refresh_when_unauthorized do
connection(base_url).get(path, params) do |request|
request.['Authorization'] = "Bearer #{config.token}"
request.['Content-Type'] = content_type if content_type
end
end
UnexpectedResponse.call(response) unless response.success?
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#get_filenames ⇒ Object
196
197
198
199
200
|
# File 'lib/globus_client.rb', line 196
def get_filenames(...)
Endpoint
.new(...)
.list_files { |files| return files.map(&:name) }
end
|
#has_files? ⇒ Boolean
202
203
204
205
206
|
# File 'lib/globus_client.rb', line 202
def has_files?(...)
Endpoint
.new(...)
.has_files?
end
|
#list_files(**keywords) ⇒ Object
NOTE: Can’t use the ‘…` (argument forwarding) operator here because we
want to route the keyword args to `Endpoint#new` and the block arg to
`Endpoint#list_files`
178
179
180
181
182
|
# File 'lib/globus_client.rb', line 178
def list_files(**keywords, &)
Endpoint
.new(**keywords)
.list_files(&)
end
|
#mkdir ⇒ Object
144
145
146
147
148
149
|
# File 'lib/globus_client.rb', line 144
def mkdir(...)
Endpoint.new(...).tap do |endpoint|
endpoint.mkdir
endpoint.allow_writes
end
end
|
#post(base_url:, path:, body:, expected_response: ->(_resp) { false }) ⇒ Object
Send an authenticated POST request
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/globus_client.rb', line 91
def post(base_url:, path:, body:, expected_response: ->(_resp) { false })
response = with_token_refresh_when_unauthorized do
connection(base_url).post(path) do |request|
request.['Authorization'] = "Bearer #{config.token}"
request.['Content-Type'] = 'application/json'
request.body = body.to_json
end
end
UnexpectedResponse.call(response) unless response.success? || expected_response.call(response)
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#put(base_url:, path:, body:) ⇒ Object
Send an authenticated PUT request
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/globus_client.rb', line 111
def put(base_url:, path:, body:)
response = with_token_refresh_when_unauthorized do
connection(base_url).put(path) do |request|
request.['Authorization'] = "Bearer #{config.token}"
request.['Content-Type'] = 'application/json'
request.body = body.to_json
end
end
UnexpectedResponse.call(response) unless response.success?
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#rename(new_path:, **args) ⇒ Object
169
170
171
172
173
|
# File 'lib/globus_client.rb', line 169
def rename(new_path:, **args)
Endpoint
.new(**args)
.rename(new_path:)
end
|
#task_list ⇒ Object
220
221
222
223
224
|
# File 'lib/globus_client.rb', line 220
def task_list(...)
EndpointManager
.new
.task_list(...)
end
|
#tasks_in_progress? ⇒ Boolean
226
227
228
229
230
|
# File 'lib/globus_client.rb', line 226
def tasks_in_progress?(...)
EndpointManager
.new
.tasks_in_progress?(...)
end
|
#total_size ⇒ Object
190
191
192
193
194
|
# File 'lib/globus_client.rb', line 190
def total_size(...)
Endpoint
.new(...)
.list_files { |files| return files.sum(&:size) }
end
|
#user_valid? ⇒ Boolean
214
215
216
217
218
|
# File 'lib/globus_client.rb', line 214
def user_valid?(...)
Identity
.new
.valid?(...)
end
|