Class: Parse::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/client/request.rb

Overview

This class represents a Parse request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, uri, body: nil, headers: nil, opts: {}) ⇒ Request

Creates a new request

Parameters:

  • method (String)

    the HTTP method

  • uri (String)

    the API path of the request (without the host)

  • body (Hash)

    the body (or parameters) of this request.

  • headers (Hash)

    additional headers to send in this request.

  • opts (Hash)

    additional optional parameters.


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/parse/client/request.rb', line 37

def initialize(method, uri, body: nil, headers: nil, opts: {})
  @tag = 0
  method = method.downcase.to_sym
  unless method == :get || method == :put || method == :post || method == :delete
    raise ArgumentError, "Invalid method #{method} for request : '#{uri}'"
  end
  self.method = method
  self.path = uri
  self.body = body
  self.headers = headers || {}
  self.opts = opts || {}
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body


# File 'lib/parse/client/request.rb', line 16

#cacheBoolean

Returns:

  • (Boolean)

25
# File 'lib/parse/client/request.rb', line 25

attr_accessor :method, :path, :body, :headers, :opts, :cache

#headersObject

Returns the value of attribute headers


25
26
27
# File 'lib/parse/client/request.rb', line 25

def headers
  @headers
end

#methodObject

Returns the value of attribute method


# File 'lib/parse/client/request.rb', line 10

#optsHash

Returns a set of options for this request.

Returns:

  • (Hash)

    a set of options for this request.


25
# File 'lib/parse/client/request.rb', line 25

attr_accessor :method, :path, :body, :headers, :opts, :cache

#pathObject

Returns the value of attribute path


# File 'lib/parse/client/request.rb', line 13

Instance Method Details

#==(r) ⇒ Boolean

Returns:

  • (Boolean)

62
63
64
65
# File 'lib/parse/client/request.rb', line 62

def ==(r)
  return false unless r.is_a?(Request)
  @method == r.method && @path == r.uri && @body == r.body && @headers == r.headers
end

#as_jsonHash

Returns JSON encoded hash

Returns:

  • (Hash)

    JSON encoded hash


57
58
59
# File 'lib/parse/client/request.rb', line 57

def as_json
  signature.as_json
end

#queryHash

The parameters of this request if the HTTP method is GET.

Returns:


52
53
54
# File 'lib/parse/client/request.rb', line 52

def query
  body if @method == :get
end

#signatureHash

Signature provies a way for us to compare different requests objects. Two requests objects are the same if they have the same signature.

Returns:

  • (Hash)

    A hash representing this request.


70
71
72
# File 'lib/parse/client/request.rb', line 70

def signature
  {method: @method.upcase, path: @path, body: @body}
end

#to_sString

Returns:


80
81
82
# File 'lib/parse/client/request.rb', line 80

def to_s
  "#{@method.to_s.upcase} #{@path}"
end