Class: Phishin::Api::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, response_data) ⇒ Response



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/phishin/api/response.rb', line 11

def initialize(url, response_data)
  @url = url
  @success = response_data['success']

  if success?
    @total_entries = response_data['total_entries']
    @total_pages = response_data['total_pages']
    @page = response_data['page']
    @data = response_data['data']
    @data = @data.is_a?(Hash) ? Hashie::Mash.new(@data) : @data.map{ |d| d.is_a?(Hash) ? Hashie::Mash.new(d) : d }
  else
    @message = response_data['message']
    raise Phishin::Client::UnsuccessfulResponseError.new(url, @message)
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/phishin/api/response.rb', line 8

def data
  @data
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



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

def http_status
  @http_status
end

#pageObject (readonly)

Returns the value of attribute page.



7
8
9
# File 'lib/phishin/api/response.rb', line 7

def page
  @page
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



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

def total_entries
  @total_entries
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



6
7
8
# File 'lib/phishin/api/response.rb', line 6

def total_pages
  @total_pages
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/phishin/api/response.rb', line 9

def url
  @url
end

Instance Method Details

#success?Boolean



27
28
29
# File 'lib/phishin/api/response.rb', line 27

def success?
  return @success == true
end