Class: Lolcommits::Plugin::Twitter
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Twitter
- Defined in:
- lib/lolcommits/plugin/twitter.rb
Constant Summary collapse
- DEFAULT_SUFFIX =
'#lolcommits'.freeze
Class Method Summary collapse
-
.runner_order ⇒ Array
Returns position(s) of when this plugin should run during the capture process.
Instance Method Summary collapse
-
#configure_options! ⇒ Hash
Prompts the user to configure plugin options.
-
#run_capture_ready ⇒ Object
Capture ready hook, runs after lolcommits captures a snapshot and image processing has completed.
-
#valid_configuration? ⇒ Boolean
Indicate if the plugin is configured correctly.
Class Method Details
.runner_order ⇒ Array
Returns position(s) of when this plugin should run during the capture process. We want to post to Twitter when the capture is ready (after all image processing is complete).
18 19 20 |
# File 'lib/lolcommits/plugin/twitter.rb', line 18 def self.runner_order [:capture_ready] end |
Instance Method Details
#configure_options! ⇒ Hash
Prompts the user to configure plugin options. Options are enabled (true/false), Twitter auth, and prefix/suffix text.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lolcommits/plugin/twitter.rb', line 37 def = super # ask user to configure all options (if enabling) if [:enabled] auth_config = configure_auth! return unless auth_config = .merge(auth_config). merge(configure_prefix_suffix). merge(configure_open_tweet_url) else # retain config when disabling = configuration.merge() end end |
#run_capture_ready ⇒ Object
Capture ready hook, runs after lolcommits captures a snapshot and image processing has completed.
Posts the lolcommit to Twitter, first uploading the capture media, then posting a new Tweet with the media_id attached.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lolcommits/plugin/twitter.rb', line 60 def run_capture_ready status = build_tweet(runner.) file = File.open(runner.main_image, 'rb') print "Tweeting ... " begin client = twitter_client.new( configuration[:token], configuration[:token_secret] ) debug "--> Uploading media (#{file.size} bytes)" media_id = client.upload_media(file) debug "--> Posting status update (#{status.length} chars, media_id: #{media_id})" status_response = client.update_status(status, media_ids: [media_id]) tweet_url = status_response['entities']['media'][0]['url'] print "#{tweet_url}\n" open_url(tweet_url) if configuration[:open_tweet_url] rescue StandardError => e puts "ERROR: Tweeting FAILED! - #{e.}" end end |
#valid_configuration? ⇒ Boolean
Indicate if the plugin is configured correctly.
27 28 29 |
# File 'lib/lolcommits/plugin/twitter.rb', line 27 def valid_configuration? !!(configuration[:token] && configuration[:token_secret]) end |