Class: GlobusClient
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/globus_client.rb,
lib/globus_client/version.rb,
lib/globus_client/endpoint.rb,
lib/globus_client/identity.rb,
lib/globus_client/authenticator.rb,
lib/globus_client/unexpected_response.rb
Overview
Client for interacting with the Globus API
Defined Under Namespace
Classes: Authenticator, Config, Endpoint, Identity, UnexpectedResponse
Constant Summary
collapse
- VERSION =
'0.14.0'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
63
64
65
|
# File 'lib/globus_client.rb', line 63
def config
@config
end
|
Class Method Details
rubocop:disable Metrics/ParameterLists
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/globus_client.rb', line 25
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
58
59
60
|
# File 'lib/globus_client.rb', line 58
def default_auth_url
'https://auth.globus.org'
end
|
.default_transfer_url ⇒ Object
54
55
56
|
# File 'lib/globus_client.rb', line 54
def default_transfer_url
'https://transfer.api.globusonline.org'
end
|
Instance Method Details
#delete(base_url:, path:) ⇒ Object
Send an authenticated DELETE request
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/globus_client.rb', line 128
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
155
156
157
158
159
|
# File 'lib/globus_client.rb', line 155
def delete_access_rule(...)
Endpoint
.new(self, ...)
.delete_access_rule
end
|
#disallow_writes ⇒ Object
149
150
151
152
153
|
# File 'lib/globus_client.rb', line 149
def disallow_writes(...)
Endpoint
.new(self, ...)
.disallow_writes
end
|
#file_count ⇒ Object
170
171
172
173
174
|
# File 'lib/globus_client.rb', line 170
def file_count(...)
Endpoint
.new(self, ...)
.list_files { |files| return files.count }
end
|
#get(base_url:, path:, params: {}, content_type: nil) ⇒ Object
Send an authenticated GET request
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/globus_client.rb', line 69
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
182
183
184
185
186
|
# File 'lib/globus_client.rb', line 182
def get_filenames(...)
Endpoint
.new(self, ...)
.list_files { |files| return files.map(&:name) }
end
|
#has_files? ⇒ Boolean
188
189
190
191
192
|
# File 'lib/globus_client.rb', line 188
def has_files?(...)
Endpoint
.new(self, ...)
.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`
164
165
166
167
168
|
# File 'lib/globus_client.rb', line 164
def list_files(**keywords, &)
Endpoint
.new(self, **keywords)
.list_files(&)
end
|
#mkdir ⇒ Object
142
143
144
145
146
147
|
# File 'lib/globus_client.rb', line 142
def mkdir(...)
Endpoint.new(self, ...).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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/globus_client.rb', line 89
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/globus_client.rb', line 109
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
|
#total_size ⇒ Object
176
177
178
179
180
|
# File 'lib/globus_client.rb', line 176
def total_size(...)
Endpoint
.new(self, ...)
.list_files { |files| return files.sum(&:size) }
end
|
#user_valid? ⇒ Boolean
194
195
196
197
198
|
# File 'lib/globus_client.rb', line 194
def user_valid?(...)
Identity
.new(self)
.valid?(...)
end
|