Class: Translatomatic::HTTP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/translatomatic/http/request.rb

Overview

HTTP request wrapper for Net::HTTP functionality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, options = {}) ⇒ Translatomatic::HTTPRequest

Returns Create a new request.

Parameters:

  • method (Symbol)

    HTTP method

  • url (String, URI)

    URL of the request



25
26
27
28
29
30
31
32
33
# File 'lib/translatomatic/http/request.rb', line 25

def initialize(method, url, options = {})
  @method = method
  @options = options
  @uri = url.respond_to?(:host) ? url.dup : URI.parse(url)
  query = options[:query]
  @uri.query = URI.encode_www_form(query) if query
  @multipart_boundary = generate_multipart_boundary
  @body = @options[:body]
end

Instance Attribute Details

#bodyString

Returns the HTTP body.

Returns:

  • (String)

    the HTTP body



14
15
16
# File 'lib/translatomatic/http/request.rb', line 14

def body
  @body
end

#methodString (readonly)

Returns the HTTP method.

Returns:

  • (String)

    the HTTP method



20
21
22
# File 'lib/translatomatic/http/request.rb', line 20

def method
  @method
end

#multipart_boundaryString

Returns the text to use to denote multipart boundaries. By default, a random hexadecimal string is used.

Returns:

  • (String)

    the text to use to denote multipart boundaries. By default, a random hexadecimal string is used.



11
12
13
# File 'lib/translatomatic/http/request.rb', line 11

def multipart_boundary
  @multipart_boundary
end

#uriURI (readonly)

Returns the URI of the request.

Returns:

  • (URI)

    the URI of the request



17
18
19
# File 'lib/translatomatic/http/request.rb', line 17

def uri
  @uri
end

Instance Method Details

#http_requestObject

Returns The request object for use with Net::HTTP.

Returns:

  • (Object)

    The request object for use with Net::HTTP



36
37
38
# File 'lib/translatomatic/http/request.rb', line 36

def http_request
  @request ||= create_request
end