Top Level Namespace
- Includes:
- GLI::App
Defined Under Namespace
Modules: FBCLI
Constant Summary collapse
- APP_NAME =
File.basename($0, File.extname($0))
- CONFIG_FILE =
File.join(ENV['HOME'], ".#{APP_NAME}rc")
- SETUP_INSTRUCTIONS =
Update instructions in README.md when these change
<<-EOM You must create and configure a Facebook application to interact with the Graph API. - Create a new application at: https://developers.facebook.com/apps - Under "PRODUCTS" in the left sidebar: - Click "+ Add Product" - Choose "Facebook Login" by clicking its "Set Up" button - Don't bother choosing a platform, instead click "Settings" under "Facebook Login" in the side bar - Under "Client OAuth Settings", switch "Use Strict Mode for Redirect URIs" to "No" - Under "Valid OAuth redirect URIs", add: "http://localhost:3333/" - Click "Save Changes" - In the "App Review" tab: - Flip the switch to make your app live - Choose a category (any one will do) - Click "Confirm" - In the "Dashboard" tab: - Click "Show" to reveal your app secret - Save the App ID and App Secret by running: #{APP_NAME} config --appid=<app-id> --appsecret=<app-secret> Obtain an access token by running: #{APP_NAME} login EOM
- TO_FLAG_DESC =
'ID or alias of page or group to post to (use "me" for timeline)'
- TO_COMMAND_DESC =
'to your timeline, a page or a group'
Instance Method Summary collapse
-
#date_str(date) ⇒ Object
Facebook returns dates in ISO 8601 or unix timestamp format.
- #link(path) ⇒ Object
- #link_to_post(full_post_id) ⇒ Object
- #list_events(past = false) ⇒ Object
- #save_config ⇒ Object
Instance Method Details
#date_str(date) ⇒ Object
Facebook returns dates in ISO 8601 or unix timestamp format
31 32 33 34 35 36 |
# File 'lib/fbcli.rb', line 31 def date_str(date) t = (date.is_a? Integer) ? Time.at(date) : Time.parse(date).localtime # Convert to human friendly representation in user's time zone (almost RFC 2822) t.strftime('%a, %-d %b %Y %H:%M:%S %Z') end |
#link(path) ⇒ Object
21 22 23 |
# File 'lib/fbcli.rb', line 21 def link(path) "https://www.facebook.com/#{path}" end |
#link_to_post(full_post_id) ⇒ Object
25 26 27 28 |
# File 'lib/fbcli.rb', line 25 def link_to_post(full_post_id) profile_id, post_id = full_post_id.split '_', 2 link "#{profile_id}/posts/#{post_id}" end |
#list_events(past = false) ⇒ Object
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/fbcli.rb', line 455 def list_events(past = false) now = Time.new filter = lambda { |item| starts = Time.parse(item['start_time']) not ((past and starts < now) ^ (not past and starts > now)) } FBCLI::page_items "events", '- - -', filter do |item| starts = Time.parse(item['start_time']) unless item['end_time'].nil? ends = Time.parse(item['end_time']) duration = ends - starts end puts "#{item['name']} (#{item['id']})" puts puts "Location: #{item['place']['name']}" unless item['place'].nil? puts "Date: #{date_str(item['start_time'])}" puts "Duration: #{duration / 3600} hours" if defined?(duration) and not duration.nil? puts "RSVP: #{item['rsvp_status'].sub(/unsure/, 'maybe')}" puts puts link "events/#{item['id']}" end end |
#save_config ⇒ Object
38 39 40 41 42 |
# File 'lib/fbcli.rb', line 38 def save_config File.open(CONFIG_FILE, 'w') do |f| f.write $config.to_yaml end end |