Class: Panda::HttpClient::Faraday

Inherits:
Object
  • Object
show all
Defined in:
lib/panda/faraday.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_url) ⇒ Faraday

Returns a new instance of Faraday.



8
9
10
# File 'lib/panda/faraday.rb', line 8

def initialize(api_url)
  @api_url = api_url
end

Instance Method Details

#delete(request_uri, params) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/panda/faraday.rb', line 41

def delete(request_uri, params)
  rescue_json_parsing do
    connection.delete do |req|
      req.url File.join(connection.path_prefix, request_uri), params
    end.body
  end
end

#get(request_uri, params) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/panda/faraday.rb', line 12

def get(request_uri, params)
  rescue_json_parsing do
    connection.get do |req|
      req.url File.join(connection.path_prefix, request_uri), params
    end.body
  end
end

#post(request_uri, params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/panda/faraday.rb', line 20

def post(request_uri, params)
  # multipart upload
  params['file'] = ::Faraday::UploadIO.new(params['file'], 'multipart/form-data') if params['file']

  rescue_json_parsing do
    connection.post do |req|
      req.url File.join(connection.path_prefix, request_uri)
      req.body = params
    end.body
  end
end

#put(request_uri, params) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/panda/faraday.rb', line 32

def put(request_uri, params)
  rescue_json_parsing do
    connection.put do |req|
      req.url File.join(connection.path_prefix, request_uri)
      req.body = params
    end.body
  end
end