facebook-cli 1.6.5 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 72a03921f7c2402bbbd1d00b355af91ea0ff73c1
4
- data.tar.gz: 6bd6a91404c78fda14e0c279de752707ccd8c88c
2
+ SHA256:
3
+ metadata.gz: 6e453ec054ccf4ef2a901ca0c570ce758b3cfcaf64ef7cb5cc42c0e4944919d0
4
+ data.tar.gz: 6bbbf180804564a3d7a2e7a8b263b91a6d2ca67ab8151266f1345859c0d1edc6
5
5
  SHA512:
6
- metadata.gz: a621ff5e7aff3d16b1fba6ef61124a0087ecac1590390da666651e3b562e4cfad473bd6b3d4927553102b9e2fc191d8e9347772142f2251329d430cd371202f7
7
- data.tar.gz: 8f30408b9453d17fc192df93abe02c9d72ffc49b4a26a5453cfeddfe545447871508b11774890886240a3bd8c9fa948865c9d7da5365b96f0cf04bfcce1c8621
6
+ metadata.gz: 87cb74cf0854847d6f3dffbb0cde58ac16b999b041542e61c6f7b0433b1872e2c7b27adecacb030cdb2057596cad3b00702776c4ae8824f7f49be3b3f60eec73
7
+ data.tar.gz: 16cdb09af9a35b37b0b3a6d7a170927a6fb19de7e3467f502fb9a4139e63314e3162d8bda4d62467d217f0b7068d4250fceeb0a1f12add92fad638113e12482e
@@ -42,7 +42,7 @@ def save_config
42
42
  end
43
43
 
44
44
  pre do |global_options, command|
45
- # Make options officially global
45
+ # Make global options officially global
46
46
  $global_options = global_options
47
47
 
48
48
  # Exit gracefully when terminating due to a broken pipe
@@ -71,6 +71,7 @@ Run `#{APP_NAME} config` for setup instructions.
71
71
  true
72
72
  end
73
73
 
74
+ # Trap exceptions bubbling up from GLI and provide an alternative handler
74
75
  on_error do |exception|
75
76
  puts exception.message
76
77
 
@@ -202,37 +203,42 @@ command :logout do |c|
202
203
  end
203
204
  end
204
205
 
205
- desc "Make a Facebook API request"
206
+ desc "Make a direct Facebook API request"
206
207
  arg_name "request"
207
208
  long_desc %(
208
- This is similar to the online tool:
209
-
210
- https://developers.facebook.com/tools/explorer
211
-
212
209
  For example, try:
213
210
 
214
- #{APP_NAME} api "165795193558366?fields=name,about,website"
215
-
216
- To view the list of valid fields you can request, ask for the metadata:
211
+ #{APP_NAME} api "me?fields=name,email,birthday"
217
212
 
218
- #{APP_NAME} api "165795193558366?metadata=1"
213
+ To view the list of fields that can be queried:
219
214
 
220
- Moreover, you can extract a value from the response using --get. For example:
215
+ #{APP_NAME} api "me?metadata=1"
221
216
 
222
- #{APP_NAME} api --get name 165795193558366
217
+ Retrieve a specific value using --get:
223
218
 
224
- Use JsonPath language to retrieve nested values. For example:
219
+ #{APP_NAME} api --get name me
225
220
 
226
- #{APP_NAME} api --get "metadata.fields..name" "165795193558366?metadata=1"
221
+ Retrieve nested values using the JsonPath query language:
227
222
 
228
- Some valid requests may not be honored or return incomplete results due to
229
- insufficient permissions, which were established during the authentication
230
- process.
223
+ #{APP_NAME} api --get "metadata.fields..name" "me?metadata=1"
231
224
  )
232
225
  command :api do |c|
233
- c.flag [:get], :desc => "Extract a particular value from the JSON response"
226
+ c.flag [:get], :desc => "Extract a value from the JSON response by means of a JsonPath query"
234
227
  c.switch [:raw], :desc => 'Output unformatted JSON', :negatable => false
235
228
  c.action do |global_options, options, args|
229
+ # If no query provided, offer guidance
230
+ if args[0].nil? || args[0].empty?
231
+ # TODO: Show usage instructions
232
+ #
233
+ # GLI provides a function help_now! which normally prints usage instructions and exits,
234
+ # however the way it triggers that eventuality is by raising an option parser exception,
235
+ # which in turn results in the default handler printing usage instructions. Unfortunately,
236
+ # since facebook-cli provides an alternative exception handler and breaks that functionality,
237
+ # it will take further engineering to effect the desired behavior.
238
+
239
+ exit_now! "See documentation: #{APP_NAME} help api"
240
+ end
241
+
236
242
  res = FBCLI::raw_request args[0]
237
243
 
238
244
  # Extract value(s) using JsonPath
@@ -246,7 +252,7 @@ command :api do |c|
246
252
  end
247
253
  end
248
254
 
249
- # Nicely format JSON result if not --raw
255
+ # Nicely format JSON result if --raw flag is not set
250
256
  unless options['raw']
251
257
  # It appears that Hash and Koala::Facebook::API::GraphCollection objects
252
258
  # are JSON, while Array results are not.
@@ -299,75 +305,6 @@ command :links do |c|
299
305
  end
300
306
  end
301
307
 
302
- TO_FLAG_DESC = 'ID or alias of page or group to post to (use "me" for timeline)'
303
- TO_COMMAND_DESC = 'to your timeline, a page or a group'
304
-
305
- desc "Post a message or image " + TO_COMMAND_DESC
306
- arg_name "message"
307
- long_desc %(
308
- Facebook recommends: photos should be less than 4 MB and saved as JPG, PNG, GIF or TIFF files.
309
- )
310
- command :post do |c|
311
- c.flag [:to], :desc => TO_FLAG_DESC, :default_value => 'me'
312
- c.flag [:i, :image], :desc => 'File or URL of image to post'
313
- c.action do |global_options, options, args|
314
- if not options['image'].nil?
315
- full_post_id = FBCLI::publish_image options['to'], args[0], options['image']
316
- else
317
- full_post_id = FBCLI::publish_post options['to'], args[0]
318
- end
319
-
320
- puts "Your post: #{link_to_post full_post_id}"
321
- end
322
- end
323
-
324
- desc "Post a video " + TO_COMMAND_DESC
325
- arg_name "message"
326
- long_desc %(
327
- Facebook recommends: aspect ratio must be between 9x16 and 16x9. The following formats are
328
- supported:
329
-
330
- 3g2, 3gp, 3gpp, asf, avi, dat, divx, dv, f4v, flv, m2ts, m4v,
331
- mkv, mod, mov, mp4, mpe, mpeg, mpeg4, mpg, mts, nsv, ogm, ogv, qt, tod,
332
- ts, vob, and wmv
333
- )
334
- command :postvideo do |c|
335
- c.flag [:to], :desc => TO_FLAG_DESC, :default_value => 'me'
336
- c.flag [:v, :video], :desc => 'File or URL of video'
337
- c.flag [:t, :title], :desc => 'Title'
338
- c.action do |global_options, options, args|
339
- video_id = FBCLI::publish_video options['to'], args[0], options['video'], options['title']
340
- puts "Your post: #{link video_id}"
341
- puts "Edit your video: #{link "video/edit/?v=#{video_id}"}"
342
- puts
343
- puts "It might take a few minutes for your video to become available."
344
- end
345
- end
346
-
347
- desc "Post a link " + TO_COMMAND_DESC
348
- arg_name "url"
349
- command :postlink do |c|
350
- c.flag [:to], :desc => TO_FLAG_DESC, :default_value => 'me'
351
- c.flag [:m, :message], :desc => 'Main message'
352
- c.flag [:n, :name], :desc => 'Link name'
353
- c.flag [:d, :description], :desc => 'Link description'
354
- c.flag [:c, :caption], :desc => 'Link caption'
355
- c.flag [:i, :image], :desc => 'Link image URL'
356
- c.action do |global_options, options, args|
357
- link_metadata = {
358
- "name" => options['name'],
359
- "link" => args[0],
360
- "caption" => options['caption'],
361
- "description" => options['description'],
362
- "picture" => options['image']
363
- }
364
-
365
- full_post_id = FBCLI::publish_post options['to'], options['message'], link_metadata
366
-
367
- puts "Your post: #{link_to_post full_post_id}"
368
- end
369
- end
370
-
371
308
  desc "List pages you have 'Liked'"
372
309
  command :likes do |c|
373
310
  c.action do
@@ -378,23 +315,7 @@ command :likes do |c|
378
315
  end
379
316
  end
380
317
 
381
- desc "List people you are friends with (some limitations)"
382
- long_desc %(
383
- As of Graph API v2.0 Facebook no longer provides access to your full friends list.
384
- As an alternative, we now request 'taggable_friends' which only includes friends
385
- you are allowed to tag.
386
-
387
- See: https://developers.facebook.com/docs/apps/faq#faq_1694316010830088
388
- )
389
- command :friends do |c|
390
- c.action do
391
- FBCLI::page_items 'taggable_friends' do |item|
392
- puts item['name']
393
- end
394
- end
395
- end
396
-
397
- desc "List posts on your profile"
318
+ desc "List posts on your timeline"
398
319
  command :feed do |c|
399
320
  c.action do
400
321
  FBCLI::page_items "feed", '- - -' do |item|
@@ -406,23 +327,6 @@ command :feed do |c|
406
327
  end
407
328
  end
408
329
 
409
- desc "List stories you are tagged in"
410
- command :tagged do |c|
411
- c.switch [:date], :desc => 'Include date you were tagged on'
412
- c.action do |global_options, options|
413
- FBCLI::page_items 'tagged', '- - -' do |item|
414
- if item["story"]
415
- puts "### #{item["story"]}"
416
- puts
417
- end
418
- puts item["message"] if item.has_key?("message")
419
- puts
420
- puts link_to_post item["id"]
421
- puts "Tagged on: #{date_str(item["tagged_time"])}" if options['date']
422
- end
423
- end
424
- end
425
-
426
330
  handlePhoto = Proc.new do |item|
427
331
  puts "#{item["name"]}\n\n" unless not item.key?("name")
428
332
  puts link "#{item["id"]}"
@@ -463,86 +367,4 @@ command :videosof do |c|
463
367
  end
464
368
  end
465
369
 
466
- def list_events(past = false)
467
- now = Time.new
468
-
469
- filter = lambda { |item|
470
- starts = Time.parse(item['start_time'])
471
- not ((past and starts < now) ^ (not past and starts > now))
472
- }
473
-
474
- FBCLI::page_items "events", '- - -', filter do |item|
475
- starts = Time.parse(item['start_time'])
476
-
477
- unless item['end_time'].nil?
478
- ends = Time.parse(item['end_time'])
479
- duration = ends - starts
480
- end
481
-
482
- puts "#{item['name']} (#{item['id']})"
483
- puts
484
- puts "Location: #{item['place']['name']}" unless item['place'].nil?
485
- puts "Date: #{date_str(item['start_time'])}"
486
- puts "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil?
487
- puts "RSVP: #{item['rsvp_status'].sub(/unsure/, 'maybe')}"
488
- puts
489
- puts link "events/#{item['id']}"
490
- end
491
- end
492
-
493
- desc "List your upcoming events"
494
- command :events do |c|
495
- c.action do
496
- list_events
497
- end
498
- end
499
-
500
- desc "List your past events"
501
- command :pastevents do |c|
502
- c.action do
503
- list_events true
504
- end
505
- end
506
-
507
- desc "Show event details"
508
- arg_name "[ids...]"
509
- command :event do |c|
510
- c.action do |global_options, options, args|
511
- args.each_with_index do |id, index|
512
- FBCLI::request_object(
513
- id,
514
- :fields => 'name,description,place,owner,start_time,end_time,attending_count,declined_count,maybe_count,is_canceled'
515
- ) do |item|
516
- starts = Time.parse(item['start_time'])
517
-
518
- unless item['end_time'].nil?
519
- ends = Time.parse(item['end_time'])
520
- duration = ends - starts
521
- end
522
-
523
- puts "#{item['name']} (#{item['id']})"
524
-
525
- puts
526
- puts "Location: #{item['place']['name']}" unless item['place'].nil?
527
- puts "Date: #{date_str(item['start_time'])}" + (item['is_canceled'] ? " [CANCELED]" : "")
528
- puts "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil?
529
- puts "Created by: #{item['owner']['name']}"
530
- puts
531
- puts "Attending: #{item['attending_count']}"
532
- puts "Maybe: #{item['maybe_count']}"
533
- puts "Declined: #{item['declined_count']}"
534
- puts
535
- puts link "events/#{item['id']}"
536
-
537
- if not (item['description'].nil? || item['description'].empty?)
538
- puts
539
- puts item['description']
540
- end
541
-
542
- puts "- - -" unless index == args.size - 1
543
- end
544
- end
545
- end
546
- end
547
-
548
370
  exit run(ARGV)
@@ -93,28 +93,4 @@ Run: #{APP_NAME} login
93
93
  items = items.next_page
94
94
  end
95
95
  end
96
-
97
- def self.publish_post(target, msg, link_metadata = {})
98
- result = api_call lambda { |api|
99
- api.put_wall_post(msg, link_metadata, target)
100
- }
101
-
102
- result['id']
103
- end
104
-
105
- def self.publish_image(target, msg, image_file_or_url)
106
- result = api_call lambda { |api|
107
- api.put_picture(image_file_or_url, {:message => msg}, target)
108
- }
109
-
110
- result['post_id']
111
- end
112
-
113
- def self.publish_video(target, msg, video_file_or_url, title = nil)
114
- result = api_call lambda { |api|
115
- api.put_video(video_file_or_url, {:title => title, :description => msg}, target)
116
- }
117
-
118
- result['id']
119
- end
120
96
  end
@@ -1,17 +1,18 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
3
  require 'webrick'
4
+ require 'webrick/https'
4
5
  require 'json'
5
6
 
6
7
  module FBCLI
7
- API_VERSION = "2.10"
8
+ API_VERSION = "3.1"
8
9
 
9
10
  def self.login(app_id, app_secret, local_host, local_port)
10
- redirect_uri = "http://#{local_host}:#{local_port}/"
11
+ redirect_uri = "https://#{local_host}:#{local_port}/"
11
12
 
12
13
  uri = "https://www.facebook.com/dialog/oauth?client_id=#{app_id}" +
13
14
  "&redirect_uri=#{redirect_uri}" +
14
- "&scope=user_likes,user_friends,user_posts,user_photos,user_videos,user_events,publish_actions"
15
+ "&scope=user_likes,user_posts,user_photos,user_videos"
15
16
 
16
17
  puts <<-EOM
17
18
  Open this URL in a web browser and allow access to the Facebook Graph on behalf of your user account:
@@ -24,11 +25,21 @@ Waiting to receive authorization code on port #{local_port}...
24
25
 
25
26
  server = WEBrick::HTTPServer.new(
26
27
  :Port => local_port,
27
- :SSLEnable => false,
28
+ :SSLEnable => true,
29
+ :SSLCertName => [ %w[CN localhost] ],
28
30
  :Logger => WEBrick::Log.new(File.open(File::NULL, 'w')),
29
31
  :AccessLog => []
30
32
  )
31
33
 
34
+ # TODO: WEBrick generates a self-signed SSL certificate with serial number 1, which
35
+ # causes Firefox to complain with SEC_ERROR_REUSED_ISSUER_AND_SERIAL on the
36
+ # second authentication attempt.
37
+ #
38
+ # See: https://github.com/ruby/webrick/blob/6e9081b/lib/webrick/ssl.rb#L112
39
+ #
40
+ # Providing a self-signed certificate to WEBrick during instantiation is one
41
+ # way to surmount this inconvenience.
42
+
32
43
  access_token = nil
33
44
 
34
45
  server.mount_proc '/' do |req, res|
@@ -1,3 +1,3 @@
1
1
  module FBCLI
2
- VERSION = '1.6.5'
2
+ VERSION = '1.7.1'
3
3
  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.6.5
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ildar Sagdejev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-31 00:00:00.000000000 Z
11
+ date: 2018-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: koala
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.6.11
101
+ rubygems_version: 2.7.6
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Facebook command line utility