Class: Pcloud::Request
- Inherits:
-
Object
- Object
- Pcloud::Request
- Defined in:
- lib/pcloud/request.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(client, verb, path, params, payload) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(client, verb, path, params, payload) ⇒ Request
3 4 5 |
# File 'lib/pcloud/request.rb', line 3 def initialize(client, verb, path, params, payload) @client, @verb, @path, @params, @payload = client, verb, path, params, payload end |
Instance Method Details
#call ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pcloud/request.rb', line 7 def call params = {params: {}} params[:params].merge!(@params, {auth: @client.auth}) http = @client.http_client res = case @verb when :get begin http[@path].get(params) rescue => e handle_response(e.http_code, e.) end when :post begin http[@path].post(@payload, params) rescue => e handle_response(e.http_code, e.) end else raise "Unsupported verb: #{@verb}" end JSON.parse(res.body, { symbolize_names: true }) end |