Class: Parse::Request
- Inherits:
- Object
- Object
- Parse::Request
- Defined in:
- lib/parse/client/request.rb
Overview
This class represents a Parse request.
Instance Attribute Summary collapse
- #body ⇒ Object
Returns the value of attribute body.
- #cache ⇒ Boolean
- #headers ⇒ Object
Returns the value of attribute headers.
- #method ⇒ Object
Returns the value of attribute method.
- #opts ⇒ Hash
A set of options for this request.
- #path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #==(r) ⇒ Boolean
- #as_json ⇒ Hash
JSON encoded hash.
- #initialize(method, uri, body: nil, headers: nil, opts: {}) ⇒ Request constructor
Creates a new request.
- #query ⇒ Hash
The parameters of this request if the HTTP method is GET.
- #signature ⇒ Hash
Signature provies a way for us to compare different requests objects.
- #to_s ⇒ String
Constructor Details
#initialize(method, uri, body: nil, headers: nil, opts: {}) ⇒ Request
Creates a new request
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
#cache ⇒ Boolean
25 | # File 'lib/parse/client/request.rb', line 25 attr_accessor :method, :path, :body, :headers, :opts, :cache |
#headers ⇒ Object
Returns the value of attribute headers.
25 26 27 | # File 'lib/parse/client/request.rb', line 25 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
# File 'lib/parse/client/request.rb', line 10
|
#opts ⇒ Hash
Returns a set of options for this request.
25 | # File 'lib/parse/client/request.rb', line 25 attr_accessor :method, :path, :body, :headers, :opts, :cache |
Instance Method Details
#==(r) ⇒ 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_json ⇒ Hash
Returns JSON encoded hash.
57 58 59 | # File 'lib/parse/client/request.rb', line 57 def as_json signature.as_json end |
#query ⇒ Hash
The parameters of this request if the HTTP method is GET.
52 53 54 | # File 'lib/parse/client/request.rb', line 52 def query body if @method == :get end |
#signature ⇒ Hash
Signature provies a way for us to compare different requests objects. Two requests objects are the same if they have the same signature.
70 71 72 | # File 'lib/parse/client/request.rb', line 70 def signature { method: @method.upcase, path: @path, body: @body } end |
#to_s ⇒ String
80 81 82 | # File 'lib/parse/client/request.rb', line 80 def to_s "#{@method.to_s.upcase} #{@path}" end |