Class: Jatai::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jatai/api/client.rb

Defined Under Namespace

Classes: ApiError, AuthenticationError, NotFoundError, ValidationError

Instance Method Summary collapse

Constructor Details

#initialize(token: nil, api_url: nil) ⇒ Client

Returns a new instance of Client.



22
23
24
25
# File 'lib/jatai/api/client.rb', line 22

def initialize(token: nil, api_url: nil)
  @token = token || Config.token
  @api_url = api_url || Config.api_url
end

Instance Method Details

#delete(path) ⇒ Object



43
44
45
# File 'lib/jatai/api/client.rb', line 43

def delete(path)
  request(:delete, path)
end

#get(path, params: {}) ⇒ Object



27
28
29
# File 'lib/jatai/api/client.rb', line 27

def get(path, params: {})
  request(:get, path, params: params)
end

#patch(path, body: {}) ⇒ Object



39
40
41
# File 'lib/jatai/api/client.rb', line 39

def patch(path, body: {})
  request(:patch, path, body: body)
end

#post(path, body: {}) ⇒ Object



31
32
33
# File 'lib/jatai/api/client.rb', line 31

def post(path, body: {})
  request(:post, path, body: body)
end

#put(path, body: {}) ⇒ Object



35
36
37
# File 'lib/jatai/api/client.rb', line 35

def put(path, body: {})
  request(:put, path, body: body)
end

#upload(path, file_path:, params: {}) ⇒ Object



47
48
49
50
51
52
# File 'lib/jatai/api/client.rb', line 47

def upload(path, file_path:, params: {})
  response = upload_connection.post(path) do |req|
    req.body = params.merge(source: Faraday::Multipart::FilePart.new(file_path, "application/gzip"))
  end
  handle_response(response)
end