Class: FBScrape::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/fb_scrape/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload, access_token = nil, page_id = nil) ⇒ Comment

Returns a new instance of Comment.



7
8
9
10
11
12
# File 'lib/fb_scrape/comment.rb', line 7

def initialize(payload, access_token=nil, page_id=nil)
  @replies = []
  @access_token = access_token
  @page_id = page_id
  load_from_payload payload
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def created_at
  @created_at
end

#from_idObject

Returns the value of attribute from_id.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def from_id
  @from_id
end

#from_nameObject

Returns the value of attribute from_name.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def from_name
  @from_name
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def id
  @id
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def message
  @message
end

#page_idObject

Returns the value of attribute page_id.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def page_id
  @page_id
end

#repliesObject

Returns the value of attribute replies.



5
6
7
# File 'lib/fb_scrape/comment.rb', line 5

def replies
  @replies
end

Instance Method Details

#has_more_replies?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/fb_scrape/comment.rb', line 24

def has_more_replies?
  @page_info && next_cursor
end

#is_page_response?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/fb_scrape/comment.rb', line 14

def is_page_response?
  @page_id == @from_id
end

#load_all_replies(limit = nil) ⇒ Object



28
29
30
31
32
# File 'lib/fb_scrape/comment.rb', line 28

def load_all_replies(limit=nil)
  while has_more_replies? && is_below_limit?(limit) do
    load_more_replies
  end
end

#load_replies(access_token = nil) ⇒ Object



18
19
20
21
22
# File 'lib/fb_scrape/comment.rb', line 18

def load_replies access_token=nil
  @access_token = access_token if access_token
  url = "https://graph.facebook.com/v#{FBScrape::GRAPH_VERSION}/#{@id}/comments?access_token=#{@access_token}"
  load_from_url url
end

#to_json(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/fb_scrape/comment.rb', line 34

def to_json(*args)
  JSON.pretty_generate({
    id: @id,
    created_at: @created_at,
    from_name: @from_name,
    from_id: @from_id,
    page_id: @page_id,
    message: @message
  })
end