Class: InstagramBasicDisplay::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Object

Constructor

Parameters:

  • response (String)

    raw JSON repsonse from the Instagram API



25
26
27
28
29
30
# File 'lib/instagram_basic_display/response.rb', line 25

def initialize(response)
  @response = response
  @body = JSON.parse(response.body)
  @status = response.code
  @paging = body['paging']
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



19
20
21
# File 'lib/instagram_basic_display/response.rb', line 19

def body
  @body
end

#pagingObject (readonly)

Returns the value of attribute paging.



19
20
21
# File 'lib/instagram_basic_display/response.rb', line 19

def paging
  @paging
end

#responseObject (readonly)

Returns the value of attribute response.



19
20
21
# File 'lib/instagram_basic_display/response.rb', line 19

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



19
20
21
# File 'lib/instagram_basic_display/response.rb', line 19

def status
  @status
end

Instance Method Details

#errorNil, Struct

If an error is returned from the Instagram API, returns it as a Struct

Returns:

  • (Nil, Struct)


70
71
72
73
74
75
# File 'lib/instagram_basic_display/response.rb', line 70

def error
  return unless body['error'] || body['error_message']

  error_response = normalize_error(body)
  deserialize_json(error_response)
end

#next_page?Boolean

Returns whether or not a next page of results from the Instagram API is available

Returns:

  • (Boolean)


34
35
36
# File 'lib/instagram_basic_display/response.rb', line 34

def next_page?
  !next_page_link.nil?
end

Returns a link to the next page of results from the Instagram API

Returns:

  • (String)


46
47
48
# File 'lib/instagram_basic_display/response.rb', line 46

def next_page_link
  paging['next'] if paging
end

#payloadStruct

Returns the raw payload from Instagram’s API deserialized into a Struct

Returns:

  • (Struct)


64
65
66
# File 'lib/instagram_basic_display/response.rb', line 64

def payload
  deserialize_json(body)
end

#previous_page?Boolean

Returns whether or not a previous page of results from the Instagram API is available

Returns:

  • (Boolean)


40
41
42
# File 'lib/instagram_basic_display/response.rb', line 40

def previous_page?
  !previous_page_link.nil?
end

Returns a link to the previous page of results from the Instagram API

Returns:

  • (String)


52
53
54
# File 'lib/instagram_basic_display/response.rb', line 52

def previous_page_link
  paging['previous'] if paging
end

#success?Boolean

Returns whether the request to the Instagram API was a success

Returns:

  • (Boolean)


58
59
60
# File 'lib/instagram_basic_display/response.rb', line 58

def success?
  response.message == 'OK'
end