Class: NetologyGroup::TasksClient::Response

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

Direct Known Subclasses

TaskResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(excon_response) ⇒ Response

Returns a new instance of Response.

Parameters:

  • excon_response (Excon::Response)


9
10
11
12
13
14
15
# File 'lib/netology_group/tasks_client/response.rb', line 9

def initialize(excon_response)
  @excon_response = excon_response
  @status = excon_response.status
  @body = JSON.parse(excon_response.body) rescue {}

  @links = Nitlink::Parser.new.parse(excon_response)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/netology_group/tasks_client/response.rb', line 6

def body
  @body
end

#excon_responseObject (readonly)

Returns the value of attribute excon_response.



6
7
8
# File 'lib/netology_group/tasks_client/response.rb', line 6

def excon_response
  @excon_response
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/netology_group/tasks_client/response.rb', line 6

def status
  @status
end

Instance Method Details

#inspectObject



29
30
31
# File 'lib/netology_group/tasks_client/response.rb', line 29

def inspect
  "#{self} @status=#{status} @body=#{body}"
end

#next_pageObject



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

def next_page
  page_number_from_link('next')
end

#previous_pageObject



25
26
27
# File 'lib/netology_group/tasks_client/response.rb', line 25

def previous_page
  page_number_from_link('previous')
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/netology_group/tasks_client/response.rb', line 17

def success?
  [200, 201].include?(excon_response.status)
end