Class: AlPapi::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/al_papi/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http, code, path, params) ⇒ Response

Initializing response object to be returned from API calls, used internally.



10
11
12
13
14
# File 'lib/al_papi/response.rb', line 10

def initialize(http, code, path, params) # @private
  @success, @body, @errors = http.success, http.response, http.errors
  @over_limit, @suspended  = http.over_limit, http.suspended
  @code, @path, @params    = code, path, params
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def errors
  @errors
end

#over_limitObject (readonly)

Returns the value of attribute over_limit.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def over_limit
  @over_limit
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def path
  @path
end

#successObject (readonly)

Returns the value of attribute success.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def success
  @success
end

#suspenededObject (readonly)

Returns the value of attribute suspeneded.



3
4
5
# File 'lib/al_papi/response.rb', line 3

def suspeneded
  @suspeneded
end

Instance Method Details

#over_limit?Boolean

Convenience method to see if you have reached your hourly limit

Returns:

  • (Boolean)


30
31
32
# File 'lib/al_papi/response.rb', line 30

def over_limit?
  @over_limit ? true : false
end

#parsed_bodyHashie::Mash

Parses JSON body of request and returns a Hashie::Mash

Returns:

  • (Hashie::Mash)


48
49
50
51
52
53
# File 'lib/al_papi/response.rb', line 48

def parsed_body
  hash = JSON.parse(@body)
  Hashie::Mash.new hash
rescue
  {}
end

#success?Boolean

Convenience method to determine if request was successfull or not

Returns:

  • (Boolean)


21
22
23
# File 'lib/al_papi/response.rb', line 21

def success?
  @success ? true : false
end

#suspended?Boolean

Convenience method to see if your account is supended

Returns:

  • (Boolean)


39
40
41
# File 'lib/al_papi/response.rb', line 39

def suspended?
  @suspended ? true : false
end