Class: Access::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/access/response.rb', line 6

def initialize(response)
  response.each { |key, value| instance_variable_set("@#{key}", value) if self.class.instance_methods.include? key.to_sym }
  @response_status = response.message
  @status ||= response.code
  check_success(response)
  if @success
    @info = Access::Info.new(@info) if @info
    (@links = @links.is_a?(Array) ? Access::Link.process_batch(@links) : Access::Link.new(@links)) if @links
    process_data
  end

end

Instance Attribute Details

#access_tokensObject

Returns the value of attribute access_tokens.



4
5
6
# File 'lib/access/response.rb', line 4

def access_tokens
  @access_tokens
end

#api_calls_over_timeObject

Returns the value of attribute api_calls_over_time.



4
5
6
# File 'lib/access/response.rb', line 4

def api_calls_over_time
  @api_calls_over_time
end

#categoriesObject

Returns the value of attribute categories.



4
5
6
# File 'lib/access/response.rb', line 4

def categories
  @categories
end

#content_typeObject

Returns the value of attribute content_type.



4
5
6
# File 'lib/access/response.rb', line 4

def content_type
  @content_type
end

#detailsObject

Returns the value of attribute details.



4
5
6
# File 'lib/access/response.rb', line 4

def details
  @details
end

#dev_nodeObject

Returns the value of attribute dev_node.



4
5
6
# File 'lib/access/response.rb', line 4

def dev_node
  @dev_node
end

#errorObject

Returns the value of attribute error.



4
5
6
# File 'lib/access/response.rb', line 4

def error
  @error
end

#filtersObject

Returns the value of attribute filters.



4
5
6
# File 'lib/access/response.rb', line 4

def filters
  @filters
end

#infoObject

Returns the value of attribute info.



4
5
6
# File 'lib/access/response.rb', line 4

def info
  @info
end

#intervalObject

Returns the value of attribute interval.



4
5
6
# File 'lib/access/response.rb', line 4

def interval
  @interval
end

Returns the value of attribute links.



4
5
6
# File 'lib/access/response.rb', line 4

def links
  @links
end

#locationsObject

Returns the value of attribute locations.



4
5
6
# File 'lib/access/response.rb', line 4

def locations
  @locations
end

#membersObject

Returns the value of attribute members.



4
5
6
# File 'lib/access/response.rb', line 4

def members
  @members
end

#messageObject

Returns the value of attribute message.



4
5
6
# File 'lib/access/response.rb', line 4

def message
  @message
end

#oauth_access_tokenObject

Returns the value of attribute oauth_access_token.



4
5
6
# File 'lib/access/response.rb', line 4

def oauth_access_token
  @oauth_access_token
end

#oauth_applicationsObject

Returns the value of attribute oauth_applications.



4
5
6
# File 'lib/access/response.rb', line 4

def oauth_applications
  @oauth_applications
end

#oauth_tokenObject

Returns the value of attribute oauth_token.



4
5
6
# File 'lib/access/response.rb', line 4

def oauth_token
  @oauth_token
end

#oauth_tokensObject

Returns the value of attribute oauth_tokens.



4
5
6
# File 'lib/access/response.rb', line 4

def oauth_tokens
  @oauth_tokens
end

#offersObject

Returns the value of attribute offers.



4
5
6
# File 'lib/access/response.rb', line 4

def offers
  @offers
end

#redemption_methodObject

Returns the value of attribute redemption_method.



4
5
6
# File 'lib/access/response.rb', line 4

def redemption_method
  @redemption_method
end

#report_envObject

Returns the value of attribute report_env.



4
5
6
# File 'lib/access/response.rb', line 4

def report_env
  @report_env
end

#reportsObject

Returns the value of attribute reports.



4
5
6
# File 'lib/access/response.rb', line 4

def reports
  @reports
end

#response_statusObject

Returns the value of attribute response_status.



4
5
6
# File 'lib/access/response.rb', line 4

def response_status
  @response_status
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/access/response.rb', line 4

def status
  @status
end

#storesObject

Returns the value of attribute stores.



4
5
6
# File 'lib/access/response.rb', line 4

def stores
  @stores
end

#successObject

Returns the value of attribute success.



4
5
6
# File 'lib/access/response.rb', line 4

def success
  @success
end

#suggestionsObject

Returns the value of attribute suggestions.



4
5
6
# File 'lib/access/response.rb', line 4

def suggestions
  @suggestions
end

#time_periodObject

Returns the value of attribute time_period.



4
5
6
# File 'lib/access/response.rb', line 4

def time_period
  @time_period
end

#total_api_callsObject

Returns the value of attribute total_api_calls.



4
5
6
# File 'lib/access/response.rb', line 4

def total_api_calls
  @total_api_calls
end

#verifyObject

Returns the value of attribute verify.



4
5
6
# File 'lib/access/response.rb', line 4

def verify
  @verify
end

Instance Method Details

#check_success(response) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/access/response.rb', line 19

def check_success(response)
  if response.success?
    @success = true
  else
    create_error
  end
end

#create_errorObject



27
28
29
30
31
32
# File 'lib/access/response.rb', line 27

def create_error
  @success = false
  @error = Access::Error.new(@response_status, @status, @message)
  remove_instance_variable(:@message) if @message
  remove_instance_variable(:@status)
end