Module: Pcloud::Request

Defined in:
lib/pcloud/request.rb

Class Method Summary collapse

Class Method Details

.call(client, verb, path, params, payload = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pcloud/request.rb', line 4

def call(client, verb, path, params, payload={})
  params = {params: {}.merge!(params, {auth: client.auth_token})}
  http = client.http_client
  res = case verb
        when :get
          begin
            http[path].get(params)
          rescue => e
            handle_response(e.http_code, e.message)
          end
        when :post
          begin
            http[path].post(payload, params)
          rescue => e
            handle_response(e.http_code, e.message)
          end
        else
          raise "Unsupported verb (get and post available): #{verb}"
        end
  return res.body if params[:params][:raw]
  JSON.parse(res.body, { symbolize_names: true })
end