Module: ContextIO::Request Private

Included in:
Resource, Resource
Defined in:
lib/context-io/request.rb,
lib/context-io/request/oauth.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Methods for sending HTTP requests

Defined Under Namespace

Classes: ContextIOOAuth

Instance Method Summary collapse

Instance Method Details

#delete(path, params = {}) ⇒ Hash, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform an HTTP DELETE request

Parameters:

  • path (String)

    The path to request.

  • params (Hash) (defaults to: {})

    Parameters to put in the query part of the URL

Returns:

  • (Hash, Array, Object)

    The parsed JSON response.



12
13
14
# File 'lib/context-io/request.rb', line 12

def delete(path, params={})
  request(:delete, path, params)
end

#get(path, params = {}) ⇒ Hash, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform an HTTP GET request

Parameters:

  • path (String)

    The path to request.

  • params (Hash) (defaults to: {})

    The parameters to put in the query part of the URL.

Returns:

  • (Hash, Array, Object)

    The parsed JSON response.



22
23
24
# File 'lib/context-io/request.rb', line 22

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

#post(path, params = {}) ⇒ Hash, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform an HTTP POST request

Parameters:

  • path (String)

    The path to request.

  • params (Hash) (defaults to: {})

    The parameters to put in the body of the request.

Returns:

  • (Hash, Array, Object)

    The parsed JSON response.



32
33
34
# File 'lib/context-io/request.rb', line 32

def post(path, params={})
  request(:post, path, params)
end

#put(path, params = {}) ⇒ Hash, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform an HTTP PUT request

Parameters:

  • path (String)

    The path to request.

  • The (Hash)

    parameters to put in the body of the request.

Returns:

  • (Hash, Array, Object)

    The parsed JSON response.



42
43
44
# File 'lib/context-io/request.rb', line 42

def put(path, params={})
  request(:put, path, params)
end

#request(method, path, params) ⇒ Hash, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Perform an HTTP request

Parameters:

  • method (:delete, :get, :put, :post)

    The HTTP method to send.

  • path (String)

    The path to request.

  • The (Hash)

    parameters to put in the query part of the URL (for DELETE and GET requests) or in the body of the request (for POST and PUT requests).

Returns:

  • (Hash, Array, Object)

    The parsed JSON response.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/context-io/request.rb', line 55

def request(method, path, params)
  response = connection(params.delete(:raw)).send(method) do |request|
    case method.to_sym
    when :delete, :get, :put
      request.url(path, params)
    when :post
      request.path = path
      request.body = params unless params.empty?
    end
  end

  response.body
end