facebook-cli 1.3.16 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fbcli.rb +47 -42
- data/lib/fbcli/facebook.rb +24 -74
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e825bc8b6a218bd1cb559e8e4061b733d0ce3eb
|
4
|
+
data.tar.gz: 45cc917afd6dc9dcc6ec529a267c665760374bcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1971e9c34e24970570284fbcb6303388e53699f54ca7f8292fdaf650ae13399138e901db8b0e249524d957faaf41a53b45ab788c14739a4a0fe4bfdad435e204
|
7
|
+
data.tar.gz: b372d6298015575340ac147c374a02fc912c1383c2be24c220f6a437c488e9b58d100155c57fc69f469089ee268a2680e4f7c86a743c5cf93c1b14ec7048d2d2
|
data/lib/fbcli.rb
CHANGED
@@ -10,16 +10,17 @@ include GLI::App
|
|
10
10
|
|
11
11
|
program_desc "Facebook command line interface"
|
12
12
|
|
13
|
-
version '1.
|
13
|
+
version '1.4.0'
|
14
14
|
|
15
15
|
flag [:token], :desc => 'Provide Facebook access token', :required => false
|
16
|
-
flag [:pages, :p], :desc => 'Max pages', :required => false, :default_value => -1
|
16
|
+
flag [:pages, :p], :desc => 'Max pages', :required => false, :type => Integer, :default_value => -1
|
17
17
|
|
18
18
|
def link(path)
|
19
19
|
"https://www.facebook.com/#{path}"
|
20
20
|
end
|
21
21
|
|
22
|
-
def link_to_post(
|
22
|
+
def link_to_post(full_post_id)
|
23
|
+
profile_id, post_id = full_post_id.split '_', 2
|
23
24
|
link "#{profile_id}/posts/#{post_id}"
|
24
25
|
end
|
25
26
|
|
@@ -34,7 +35,9 @@ def save_config
|
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
pre do |global_options,command|
|
38
|
+
pre do |global_options, command|
|
39
|
+
$global_options = global_options # They're supposed to be global, right?
|
40
|
+
|
38
41
|
if command.name == :config
|
39
42
|
$config = {}
|
40
43
|
else
|
@@ -61,6 +64,11 @@ pre do |global_options,command|
|
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
67
|
+
# Let access token passed from the command line take precedence
|
68
|
+
if not global_options[:token].nil?
|
69
|
+
$config['access_token'] = global_options[:token]
|
70
|
+
end
|
71
|
+
|
64
72
|
# Success
|
65
73
|
true
|
66
74
|
end
|
@@ -76,7 +84,7 @@ desc "Save Facebook application ID and secret"
|
|
76
84
|
command :config do |c|
|
77
85
|
c.flag [:appid], :desc => 'Facebook application ID', :required => true
|
78
86
|
c.flag [:appsecret], :desc => 'Facebook application secret', :required => true
|
79
|
-
c.action do |global_options,options
|
87
|
+
c.action do |global_options, options|
|
80
88
|
$config['app_id'] = options['appid'].to_i
|
81
89
|
$config['app_secret'] = options['appsecret']
|
82
90
|
|
@@ -91,7 +99,7 @@ end
|
|
91
99
|
desc "Log into Facebook and receive an access token"
|
92
100
|
command :login do |c|
|
93
101
|
c.flag [:port], :desc => 'Local TCP port to serve Facebook login redirect page', :default_value => '3333'
|
94
|
-
c.action do |global_options,options
|
102
|
+
c.action do |global_options, options|
|
95
103
|
token, expiration = FBCLI::listen_for_auth_code(options['port'], $config['app_id'], $config['app_secret'])
|
96
104
|
|
97
105
|
if not token.nil?
|
@@ -110,16 +118,16 @@ end
|
|
110
118
|
|
111
119
|
desc "Deauthorize your access token"
|
112
120
|
command :logout do |c|
|
113
|
-
c.action do
|
114
|
-
FBCLI::logout
|
121
|
+
c.action do
|
122
|
+
FBCLI::logout
|
115
123
|
puts "You are now logged out."
|
116
124
|
end
|
117
125
|
end
|
118
126
|
|
119
127
|
desc "Show your name and profile ID"
|
120
128
|
command :me do |c|
|
121
|
-
c.action do
|
122
|
-
FBCLI::request_object
|
129
|
+
c.action do
|
130
|
+
FBCLI::request_object "me" do |data|
|
123
131
|
puts "Name: #{data["name"]}"
|
124
132
|
puts "ID: #{data["id"]}"
|
125
133
|
end
|
@@ -130,14 +138,14 @@ desc "Post a message or image to your timeline"
|
|
130
138
|
arg_name "message"
|
131
139
|
command :post do |c|
|
132
140
|
c.flag [:i, :image], :desc => 'File or URL of image to post'
|
133
|
-
c.action do |global_options,options,args|
|
141
|
+
c.action do |global_options, options, args|
|
134
142
|
if options['image'].nil?
|
135
|
-
|
143
|
+
full_post_id = FBCLI::publish_post args[0]
|
136
144
|
else
|
137
|
-
|
145
|
+
full_post_id = FBCLI::publish_image args[0], options['image']
|
138
146
|
end
|
139
147
|
|
140
|
-
puts "Your post: #{link_to_post
|
148
|
+
puts "Your post: #{link_to_post full_post_id}"
|
141
149
|
end
|
142
150
|
end
|
143
151
|
|
@@ -149,7 +157,7 @@ command :postlink do |c|
|
|
149
157
|
c.flag [:d, :description], :desc => 'Link description'
|
150
158
|
c.flag [:c, :caption], :desc => 'Link caption'
|
151
159
|
c.flag [:i, :image], :desc => 'Link image URL'
|
152
|
-
c.action do |global_options,options,args|
|
160
|
+
c.action do |global_options, options, args|
|
153
161
|
link_metadata = {
|
154
162
|
"name" => options['name'],
|
155
163
|
"link" => args[0],
|
@@ -158,16 +166,16 @@ command :postlink do |c|
|
|
158
166
|
"picture" => options['image']
|
159
167
|
}
|
160
168
|
|
161
|
-
|
169
|
+
full_post_id = FBCLI::publish_post options['message'], link_metadata
|
162
170
|
|
163
|
-
puts "Your post: #{link_to_post
|
171
|
+
puts "Your post: #{link_to_post full_post_id}"
|
164
172
|
end
|
165
173
|
end
|
166
174
|
|
167
175
|
desc "List the pages you have 'Liked'"
|
168
176
|
command :likes do |c|
|
169
|
-
c.action do
|
170
|
-
FBCLI::page_items
|
177
|
+
c.action do
|
178
|
+
FBCLI::page_items 'likes', '' do |item|
|
171
179
|
puts item["name"]
|
172
180
|
puts link item["id"]
|
173
181
|
end
|
@@ -183,8 +191,8 @@ long_desc %(
|
|
183
191
|
See: https://developers.facebook.com/docs/apps/faq#faq_1694316010830088
|
184
192
|
)
|
185
193
|
command :friends do |c|
|
186
|
-
c.action do
|
187
|
-
FBCLI::page_items
|
194
|
+
c.action do
|
195
|
+
FBCLI::page_items 'taggable_friends' do |item|
|
188
196
|
puts item['name']
|
189
197
|
end
|
190
198
|
end
|
@@ -192,12 +200,10 @@ end
|
|
192
200
|
|
193
201
|
desc "List the posts on your profile"
|
194
202
|
command :feed do |c|
|
195
|
-
c.action do
|
196
|
-
FBCLI::page_items
|
197
|
-
profile_id, post_id = item["id"].split '_', 2
|
198
|
-
|
203
|
+
c.action do
|
204
|
+
FBCLI::page_items "feed", '- - -' do |item|
|
199
205
|
puts item["message"] if item.has_key?("message")
|
200
|
-
puts link_to_post
|
206
|
+
puts link_to_post item["id"]
|
201
207
|
puts "Created: #{date_str(item["created_time"])}"
|
202
208
|
end
|
203
209
|
end
|
@@ -211,15 +217,15 @@ end
|
|
211
217
|
|
212
218
|
desc "List photos you have uploaded"
|
213
219
|
command :photos do |c|
|
214
|
-
c.action do
|
215
|
-
FBCLI::page_items
|
220
|
+
c.action do
|
221
|
+
FBCLI::page_items "photos?type=uploaded", '- - -', &handlePhoto
|
216
222
|
end
|
217
223
|
end
|
218
224
|
|
219
225
|
desc "List photos you are tagged in"
|
220
226
|
command :photosof do |c|
|
221
|
-
c.action do
|
222
|
-
FBCLI::page_items
|
227
|
+
c.action do
|
228
|
+
FBCLI::page_items "photos", '- - -', &handlePhoto
|
223
229
|
end
|
224
230
|
end
|
225
231
|
|
@@ -231,19 +237,19 @@ end
|
|
231
237
|
|
232
238
|
desc "List videos you have uploaded"
|
233
239
|
command :videos do |c|
|
234
|
-
c.action do
|
235
|
-
FBCLI::page_items
|
240
|
+
c.action do
|
241
|
+
FBCLI::page_items "videos?type=uploaded", '- - -', &handleVideo
|
236
242
|
end
|
237
243
|
end
|
238
244
|
|
239
245
|
desc "List videos you are tagged in"
|
240
246
|
command :videosof do |c|
|
241
|
-
c.action do
|
242
|
-
FBCLI::page_items
|
247
|
+
c.action do
|
248
|
+
FBCLI::page_items "videos", '- - -', &handleVideo
|
243
249
|
end
|
244
250
|
end
|
245
251
|
|
246
|
-
def list_events(
|
252
|
+
def list_events(past = false)
|
247
253
|
now = Time.new
|
248
254
|
|
249
255
|
filter = lambda { |item|
|
@@ -251,7 +257,7 @@ def list_events(global_options, past = false)
|
|
251
257
|
not ((past and starts < now) ^ (not past and starts > now))
|
252
258
|
}
|
253
259
|
|
254
|
-
FBCLI::page_items
|
260
|
+
FBCLI::page_items "events", '- - -', filter do |item|
|
255
261
|
starts = Time.parse(item['start_time'])
|
256
262
|
|
257
263
|
unless item['end_time'].nil?
|
@@ -272,25 +278,24 @@ end
|
|
272
278
|
|
273
279
|
desc "List your upcoming events"
|
274
280
|
command :events do |c|
|
275
|
-
c.action do
|
276
|
-
list_events
|
281
|
+
c.action do
|
282
|
+
list_events
|
277
283
|
end
|
278
284
|
end
|
279
285
|
|
280
286
|
desc "List your past events"
|
281
287
|
command :pastevents do |c|
|
282
|
-
c.action do
|
283
|
-
list_events
|
288
|
+
c.action do
|
289
|
+
list_events true
|
284
290
|
end
|
285
291
|
end
|
286
292
|
|
287
293
|
desc "Show event details"
|
288
294
|
arg_name "[ids...]"
|
289
295
|
command :event do |c|
|
290
|
-
c.action do |global_options,options,args|
|
296
|
+
c.action do |global_options, options, args|
|
291
297
|
args.each_with_index do |id, index|
|
292
298
|
FBCLI::request_object(
|
293
|
-
global_options,
|
294
299
|
id,
|
295
300
|
:fields => 'name,description,place,owner,start_time,end_time,attending_count,declined_count,maybe_count,is_canceled'
|
296
301
|
) do |item|
|
data/lib/fbcli/facebook.rb
CHANGED
@@ -3,12 +3,7 @@ require 'koala'
|
|
3
3
|
module FBCLI
|
4
4
|
@@api = nil
|
5
5
|
|
6
|
-
def self.init_api
|
7
|
-
# Access token passed from the command line takes precedence
|
8
|
-
if not global_options[:token].nil?
|
9
|
-
$config['access_token'] = global_options[:token]
|
10
|
-
end
|
11
|
-
|
6
|
+
def self.init_api
|
12
7
|
if $config['access_token'].nil? or $config['access_token'].empty?
|
13
8
|
exit_now! "You must first acquire an access token; run: #{APP_NAME} login"
|
14
9
|
end
|
@@ -27,53 +22,41 @@ module FBCLI
|
|
27
22
|
str
|
28
23
|
end
|
29
24
|
|
30
|
-
def self.
|
31
|
-
if @@api.nil?
|
32
|
-
@@api = init_api(global_options)
|
33
|
-
end
|
25
|
+
def self.api_call(lambda)
|
26
|
+
@@api = init_api if @@api.nil?
|
34
27
|
|
35
28
|
begin
|
36
|
-
@@api
|
29
|
+
lambda.call(@@api)
|
37
30
|
rescue Koala::Facebook::APIError => e
|
38
31
|
exit_now! koala_error_str e
|
39
32
|
end
|
40
33
|
end
|
41
34
|
|
42
|
-
def self.
|
43
|
-
|
44
|
-
|
45
|
-
end
|
35
|
+
def self.logout
|
36
|
+
api_call lambda { |api| api.delete_object("me/permissions") }
|
37
|
+
end
|
46
38
|
|
47
|
-
|
48
|
-
|
39
|
+
def self.request_object(id, options = {})
|
40
|
+
api_call lambda { |api|
|
41
|
+
api.get_object(id, options) do |data|
|
49
42
|
yield data
|
50
43
|
end
|
51
|
-
|
52
|
-
exit_now! koala_error_str e
|
53
|
-
end
|
44
|
+
}
|
54
45
|
end
|
55
46
|
|
56
|
-
def self.request_personal_connections(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
begin
|
62
|
-
data = @@api.get_connections("me", cmd)
|
63
|
-
rescue Koala::Facebook::APIError => e
|
64
|
-
exit_now! koala_error_str e
|
65
|
-
end
|
66
|
-
|
67
|
-
data
|
47
|
+
def self.request_personal_connections(cmd)
|
48
|
+
api_call lambda { |api|
|
49
|
+
api.get_connections("me", cmd)
|
50
|
+
}
|
68
51
|
end
|
69
52
|
|
70
|
-
def self.page_items(
|
71
|
-
items = request_personal_connections(
|
53
|
+
def self.page_items(cmd, separator = nil, filter = nil)
|
54
|
+
items = request_personal_connections(cmd)
|
72
55
|
|
73
56
|
virgin = true
|
74
57
|
count = 0
|
75
58
|
|
76
|
-
while not (items.nil? or count == global_options['pages']
|
59
|
+
while not (items.nil? or count == $global_options['pages']) do
|
77
60
|
items.each_with_index { |item, idx|
|
78
61
|
if filter.nil? or not filter.call(item)
|
79
62
|
unless separator.nil? or virgin
|
@@ -91,46 +74,13 @@ module FBCLI
|
|
91
74
|
end
|
92
75
|
end
|
93
76
|
|
94
|
-
def self.publish_post(
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
begin
|
100
|
-
profile_id, post_id = @@api.put_wall_post(msg)['id'].split '_', 2
|
101
|
-
rescue Koala::Facebook::APIError => e
|
102
|
-
exit_now! koala_error_str e
|
103
|
-
end
|
104
|
-
|
105
|
-
[profile_id, post_id]
|
77
|
+
def self.publish_post(msg, link_metadata = {})
|
78
|
+
result = api_call lambda { |api| api.put_wall_post(msg, link_metadata) }
|
79
|
+
result['id']
|
106
80
|
end
|
107
81
|
|
108
|
-
def self.
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
begin
|
114
|
-
profile_id, post_id = @@api.put_wall_post(msg, link_metadata)['id'].split '_', 2
|
115
|
-
rescue Koala::Facebook::APIError => e
|
116
|
-
exit_now! koala_error_str e
|
117
|
-
end
|
118
|
-
|
119
|
-
[profile_id, post_id]
|
120
|
-
end
|
121
|
-
|
122
|
-
def self.publish_photo(global_options, msg, image_file_or_url)
|
123
|
-
if @@api.nil?
|
124
|
-
@@api = init_api(global_options)
|
125
|
-
end
|
126
|
-
|
127
|
-
begin
|
128
|
-
result = @@api.put_picture(image_file_or_url, {:message => msg})
|
129
|
-
profile_id, post_id = result['post_id'].split '_', 2
|
130
|
-
rescue Koala::Facebook::APIError => e
|
131
|
-
exit_now! koala_error_str e
|
132
|
-
end
|
133
|
-
|
134
|
-
[profile_id, post_id]
|
82
|
+
def self.publish_image(msg, image_file_or_url)
|
83
|
+
result = api_call lambda { |api| api.put_picture(image_file_or_url, {:message => msg}) }
|
84
|
+
result['post_id']
|
135
85
|
end
|
136
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ildar Sagdejev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A limited command line interface to Facebook
|
14
14
|
email: specious@gmail.com
|