Class: Hyperclient::HTTP Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
HTTParty
Defined in:
lib/hyperclient/http.rb

Overview

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

This class wrapps HTTParty and performs the HTTP requests for a resource.

Instance Method Summary collapse

Constructor Details

#initialize(resource, options = {}) ⇒ HTTP

Initializes a HTTP agent.

Parameters:

  • resource

    A Resource instance. A Resource is given instead of the url

  • since

    the resource url could change during its live.



25
26
27
28
# File 'lib/hyperclient/http.rb', line 25

def initialize(resource, options = {})
  @resource = resource
  authenticate(options[:auth]) if options && options.include?(:auth)
end

Instance Method Details

#authenticate(options) ⇒ void (private)

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.

This method returns an undefined value.

Sets the authenitcation method for HTTParty.

Parameters:

  • options

    An options Hash to set the authentication options.

Options Hash (options):

  • :type (Object)

    A String or Symbol to set the authentication type.

  • :credentials (Object)

    An Array of Strings with the user and password.



85
86
87
88
# File 'lib/hyperclient/http.rb', line 85

def authenticate(options)
  auth_method = options[:type].to_s + '_auth'
  self.class.send(auth_method, *options[:credentials])
end

#deleteObject

Sends a DELETE request the the resource url.

Returns:

  • Returns: A HTTParty::Response



72
73
74
# File 'lib/hyperclient/http.rb', line 72

def delete
  self.class.delete(url)
end

#getObject

Sends a GET request the the resource url.

Returns:

  • Returns: The response parsed response.



33
34
35
# File 'lib/hyperclient/http.rb', line 33

def get
  self.class.get(url).parsed_response
end

#headObject

Sends a HEAD request the the resource url.

Returns:

  • Returns: A HTTParty::Response



65
66
67
# File 'lib/hyperclient/http.rb', line 65

def head
  self.class.head(url)
end

#optionsObject

Sends an OPTIONS request the the resource url.

Returns:

  • Returns: A HTTParty::Response



58
59
60
# File 'lib/hyperclient/http.rb', line 58

def options
  self.class.options(url)
end

#post(params) ⇒ Object

Sends a POST request the the resource url.

Parameters:

  • params

    A Hash to send as POST params

Returns:

  • Returns: A HTTParty::Response



42
43
44
# File 'lib/hyperclient/http.rb', line 42

def post(params)
  self.class.post(url, body: params)
end

#put(params) ⇒ Object

Sends a PUT request the the resource url.

Parameters:

  • params

    A Hash to send as PUT params

Returns:

  • Returns: A HTTParty::Response



51
52
53
# File 'lib/hyperclient/http.rb', line 51

def put(params)
  self.class.put(url, body: params)
end