Module: Facy::Facebook
- Included in:
- Facy
- Defined in:
- lib/facy/facebook.rb
Defined Under Namespace
Modules: ConnectionStatus
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#authen_hash ⇒ Object
Returns the value of attribute authen_hash.
3
4
5
|
# File 'lib/facy/facebook.rb', line 3
def authen_hash
@authen_hash
end
|
#rest ⇒ Object
Returns the value of attribute rest.
3
4
5
|
# File 'lib/facy/facebook.rb', line 3
def rest
@rest
end
|
Instance Method Details
#expired_session ⇒ Object
106
107
108
109
110
|
# File 'lib/facy/facebook.rb', line 106
def expired_session
FileUtils.rm(session_file)
instant_output(Item.new(info: :info, content: "Please restart facy to obtain new access token!"))
stop_process
end
|
96
97
98
99
100
101
102
103
104
|
# File 'lib/facy/facebook.rb', line 96
def (post_id, )
@graph.(post_id, )
rescue Koala::Facebook::ServerError
retry_wait
rescue Koala::Facebook::APIError
expired_session
rescue Exception => e
error e
end
|
#facebook_like(post_id) ⇒ Object
63
64
65
66
67
68
69
70
71
|
# 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 ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# 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 ⇒ Object
11
12
13
14
15
16
17
18
19
|
# 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 ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# 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) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# 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) ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# 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 ⇒ Object
#facebook_stream_fetch ⇒ Object
RULE: all facebook method should be prefix with facebook
26
27
28
29
30
31
32
33
34
35
36
37
|
# 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 ⇒ Object
118
119
120
121
122
|
# File 'lib/facy/facebook.rb', line 118
def login
token = config[:access_token]
@graph = Koala::Facebook::API.new(token)
log(:info, "login ok at facebook module: #{@graph}")
end
|
#retry_wait ⇒ Object
112
113
114
115
116
|
# File 'lib/facy/facebook.rb', line 112
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
|