Class: Sendicate::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sendicate/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Request

Returns a new instance of Request.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sendicate/request.rb', line 30

def initialize(response)
  @response = response
  unless success?
    case response.code
    when 400
      raise BadRequest
    when 401
      raise Unauthorized
    when 404
      raise ResourceNotFound
    end
  end
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



8
9
10
# File 'lib/sendicate/request.rb', line 8

def response
  @response
end

Class Method Details

.delete(path, options = {}, &block) ⇒ Object



26
27
28
# File 'lib/sendicate/request.rb', line 26

def self.delete(path, options={}, &block)
  new(super)
end

.get(path, options = {}, &block) ⇒ Object



10
11
12
# File 'lib/sendicate/request.rb', line 10

def self.get(path, options={}, &block)
  new(super)
end

.patch(path, options = {}, &block) ⇒ Object



18
19
20
# File 'lib/sendicate/request.rb', line 18

def self.patch(path, options={}, &block)
  new(super)
end

.post(path, options = {}, &block) ⇒ Object



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

def self.post(path, options={}, &block)
  new(super)
end

.put(path, options = {}, &block) ⇒ Object



22
23
24
# File 'lib/sendicate/request.rb', line 22

def self.put(path, options={}, &block)
  new(super)
end

Instance Method Details

#parsed_responseObject



44
45
46
# File 'lib/sendicate/request.rb', line 44

def parsed_response
  response.parsed_response
end

#success?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/sendicate/request.rb', line 48

def success?
  [200, 201].include?(response.code)
end