Class: FBScrape::Post

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload, page_id = nil, token = nil) ⇒ Post

Returns a new instance of Post.



7
8
9
10
11
12
13
14
15
# File 'lib/fb_scrape/post.rb', line 7

def initialize payload, page_id=nil, token=nil
  @comments = []
  @page_id = page_id
  @token = token

  if payload
    load_from_payload(payload)
  end
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Returns the value of attribute link.



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

def link
  @link
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

Class Method Details

.load_from_id(id, access_token, page_id = nil) ⇒ Object



17
18
19
20
21
# File 'lib/fb_scrape/post.rb', line 17

def self.load_from_id id, access_token, page_id=nil
  post = FBScrape::Post.new({ 'id' => id }, page_id, access_token)
  post.load_comments
  post
end

Instance Method Details

#has_more_comments?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/fb_scrape/post.rb', line 28

def has_more_comments?
  @page_info && next_cursor
end

#load_all_comments(limit = nil) ⇒ Object



32
33
34
35
36
# File 'lib/fb_scrape/post.rb', line 32

def load_all_comments(limit=nil)
  while has_more_comments? && is_below_limit?(limit) do
    load_more_comments
  end
end

#load_commentsObject



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

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

#to_json(*args) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/fb_scrape/post.rb', line 40

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