module Facy::Facebook

Attributes

authen_hash[R]
rest[R]

Public Instance Methods

expired_session() click to toggle source
# File lib/facy/facebook.rb, line 106
def expired_session
  if File.exists?(session_file)
    FileUtils.rm(session_file)
  end
  instant_output(Item.new(info: :info, content: "Please restart facy to obtain new access token!"))
  stop_process
end
facebook_comment(post_id, comment) click to toggle source
# File lib/facy/facebook.rb, line 96
def facebook_comment(post_id, comment)
  @graph.put_comment(post_id, comment)
rescue Koala::Facebook::ServerError
  retry_wait
rescue Koala::Facebook::APIError
  expired_session
rescue Exception => e
  error e
end
facebook_like(post_id) click to toggle source
# File lib/facy/facebook.rb, line 63
def facebook_like(post_id)
  @graph.put_like(post_id)
rescue Koala::Facebook::ServerError
  retry_wait
rescue Koala::Facebook::APIError
  expired_session
rescue Exception => e
  error e
end
facebook_mailbox() click to toggle source
# File lib/facy/facebook.rb, line 84
def facebook_mailbox
  @graph.get_connections("me", "inbox")
rescue Koala::Facebook::ServerError => e
  retry_wait
rescue Koala::Facebook::APIError => e
  error e.message
  expired_session
rescue Exception => e
  error e
end
facebook_me() click to toggle source
# File lib/facy/facebook.rb, line 11
def facebook_me
  @graph.api("/me?fields=id,name")
rescue Koala::Facebook::ServerError
  retry_wait
rescue Koala::Facebook::APIError
  expired_session
rescue Exception => e
  error e
end
facebook_notification_fetch() click to toggle source
# File lib/facy/facebook.rb, line 39
def facebook_notification_fetch
  return unless facebook_status == ConnectionStatus::NORMAL
  notifications = @graph.get_connections("me", "notifications")
  notifications.each { |notifi| notification_print_queue << graph2item(notifi) }
  log(:info, "fetch notification ok")
rescue Koala::Facebook::ServerError
  retry_wait
rescue Koala::Facebook::APIError
  expired_session
rescue Exception => e
  error e
end
facebook_post(text) click to toggle source
# File lib/facy/facebook.rb, line 52
def facebook_post(text)
  @graph.put_wall_post(text)
rescue Koala::Facebook::ServerError
  retry_wait
rescue Koala::Facebook::APIError
  expired_session
rescue Exception => e
  error e
end
facebook_set_seen(notification_id) click to toggle source
# File lib/facy/facebook.rb, line 73
def facebook_set_seen(notification_id)
  @graph.put_connections("#{notification_id}", "unread=false")
rescue Koala::Facebook::ServerError => e
  retry_wait
rescue Koala::Facebook::APIError => e
  error e.message
  expired_session
rescue Exception => e
  error e
end
facebook_status() click to toggle source
# File lib/facy/facebook.rb, line 21
def facebook_status
  @status ||= ConnectionStatus::NORMAL
end
facebook_stream_fetch() click to toggle source

RULE: all facebook method should be prefix with facebook

# File lib/facy/facebook.rb, line 26
def facebook_stream_fetch
  return unless facebook_status == ConnectionStatus::NORMAL
  streams = @graph.get_connections("me", "home")
  streams.each { |post| stream_print_queue << graph2item(post) }
  log(:info, "fetch stream ok")
rescue Koala::Facebook::ServerError
  retry_wait
rescue Koala::Facebook::APIError
  expired_session
rescue Exception => e
  error e
end
login() click to toggle source
# File lib/facy/facebook.rb, line 120
def login
  token = config[:access_token]
  @graph = Koala::Facebook::API.new(token)
  log(:info, "login ok at facebook module: #{@graph}")
end
retry_wait() click to toggle source
# File lib/facy/facebook.rb, line 114
def retry_wait
  log(:error, "facebook server error, need retry")
  instant_output(Item.new(info: :error, content: "facebook server error, retry in #{config[:retry_interval]} seconds"))
  sleep(config[:retry_interval])
end