Class: FBScrape::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_name, token_secret, id = nil, limit = nil, load_on_init = true) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fb_scrape/client.rb', line 7

def initialize(page_name, token_secret, id=nil, limit=nil, load_on_init=true)
  @page_name = page_name
  @token_secret = token_secret
  @id = id
  @posts = []
  @conversations = []
  @loaded_initial = false
  @loaded_initial_conversations = false
  @limit = limit
  @conversations_page_info = nil
  if @id && load_on_init
    load_initial_posts
  elsif !@id
    get_page_id
  end
end

Instance Attribute Details

#conversationsObject

Returns the value of attribute conversations.



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

def conversations
  @conversations
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#page_nameObject

Returns the value of attribute page_name.



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

def page_name
  @page_name
end

#postsObject

Returns the value of attribute posts.



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

def posts
  @posts
end

Instance Method Details

#can_load_more_conversations?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/fb_scrape/client.rb', line 46

def can_load_more_conversations?
  !is_limited? || (@conversations.count < @limit.to_i && has_more_conversations?)
end

#has_more_conversations?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fb_scrape/client.rb', line 50

def has_more_conversations?
  @conversations_page_info && next_conversation_cursor
end

#has_more_posts?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fb_scrape/client.rb', line 42

def has_more_posts?
  @page_info && next_cursor
end

#is_limited?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/fb_scrape/client.rb', line 38

def is_limited?
  !@limit.nil?
end

#is_under_limit?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/fb_scrape/client.rb', line 34

def is_under_limit?
  !is_limited? || @posts.count < @limit.to_i
end

#load(limit = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fb_scrape/client.rb', line 24

def load(limit=nil)
  load_initial_posts
  @limit = limit if limit != @limit

  while has_more_posts? && is_under_limit? do
    # load more posts
    load_more_posts
  end
end

#load_conversations(limit = nil) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/fb_scrape/client.rb', line 54

def load_conversations(limit=nil)
  @limit = limit if limit != @limit
  load_initial_conversations

  while has_more_conversations? && can_load_more_conversations? do
    load_more_conversations
  end
end