Class: FluidCLI::API
- Inherits:
-
Object
show all
- Defined in:
- lib/fluid_cli/api.rb
Defined Under Namespace
Classes: APIRequestClientError, APIRequestError, APIRequestForbiddenError, APIRequestNotFoundError, APIRequestRetriableError, APIRequestServerError, APIRequestThrottledError, APIRequestTimeoutError, APIRequestUnauthorizedError, APIRequestUnexpectedError
Instance Method Summary
collapse
-
#delete(path:, **args, &block) ⇒ Object
-
#get(path:, **args, &block) ⇒ Object
-
#get_company_or_abort ⇒ Object
-
#initialize(ctx) ⇒ API
constructor
-
#multipart_post(path:, **args, &block) ⇒ Object
-
#multipart_put(path:, **args, &block) ⇒ Object
-
#post(path:, **args, &block) ⇒ Object
-
#put(path:, **args, &block) ⇒ Object
-
#rest_request(path:, query: nil, body: nil, method: "GET", token: nil, host: nil) ⇒ Object
Constructor Details
#initialize(ctx) ⇒ API
Returns a new instance of API.
26
27
28
|
# File 'lib/fluid_cli/api.rb', line 26
def initialize(ctx)
@ctx = ctx
end
|
Instance Method Details
#delete(path:, **args, &block) ⇒ Object
42
43
44
|
# File 'lib/fluid_cli/api.rb', line 42
def delete(path:, **args, &block)
rest_request(method: "DELETE", path: path, **args, &block)
end
|
#get(path:, **args, &block) ⇒ Object
30
31
32
|
# File 'lib/fluid_cli/api.rb', line 30
def get(path:, **args, &block)
rest_request(method: "GET", path: path, **args, &block)
end
|
#get_company_or_abort ⇒ Object
#multipart_post(path:, **args, &block) ⇒ Object
50
51
52
|
# File 'lib/fluid_cli/api.rb', line 50
def multipart_post(path:, **args, &block)
rest_request(method: "MULTIPART_POST", path: path, **args, &block)
end
|
#multipart_put(path:, **args, &block) ⇒ Object
46
47
48
|
# File 'lib/fluid_cli/api.rb', line 46
def multipart_put(path:, **args, &block)
rest_request(method: "MULTIPART_PUT", path: path, **args, &block)
end
|
#post(path:, **args, &block) ⇒ Object
38
39
40
|
# File 'lib/fluid_cli/api.rb', line 38
def post(path:, **args, &block)
rest_request(method: "POST", path: path, **args, &block)
end
|
#put(path:, **args, &block) ⇒ Object
34
35
36
|
# File 'lib/fluid_cli/api.rb', line 34
def put(path:, **args, &block)
rest_request(method: "PUT", path: path, **args, &block)
end
|
#rest_request(path:, query: nil, body: nil, method: "GET", token: nil, host: nil) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/fluid_cli/api.rb', line 54
def rest_request(path:, query: nil, body: nil, method: "GET", token: nil, host: nil)
CLI::Kit::Util.begin do
url = URI::HTTPS.build(
host: host || FluidCLI::API_HOST,
path: "/api/#{path}",
query: query,
)
resp = request(url: url.to_s, body: body, headers: , method: method)
resp
end.retry_after(API::APIRequestUnauthorizedError) do
FluidCLI::IdentityAuth.new(ctx: @ctx).reauthenticate unless path == "/me"
end
end
|