Class: Xdelivery::API::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/xdelivery/api/response/base.rb

Direct Known Subclasses

Orders, Ping, Products, Shops

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
# File 'lib/xdelivery/api/response/base.rb', line 7

def initialize(response)
  self.response = response
  handle_error!

  self.data = begin
    JSON.parse(response.body)
  rescue JSON::ParserError
    raise Client::UnknownResponse, "#{code}, Response is not json."
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/xdelivery/api/response/base.rb', line 5

def data
  @data
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/xdelivery/api/response/base.rb', line 5

def response
  @response
end

Instance Method Details

#auth?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/xdelivery/api/response/base.rb', line 22

def auth?
  code == 200
end

#codeObject



18
19
20
# File 'lib/xdelivery/api/response/base.rb', line 18

def code
  response.code
end

#status?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/xdelivery/api/response/base.rb', line 26

def status?
  data['status'] == true
end