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
-
.name ⇒ String
Returns the name of the plugin.
-
.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.
-
#configured? ⇒ Boolean
Plugin is configured when a token and token secret exist.
-
#run_capture_ready ⇒ Object
Capture ready hook, runs after lolcommits captures a snapshot and image processing has completed.
Class Method Details
.name ⇒ String
Returns the name of the plugin. Identifies the plugin to lolcommits.
16 17 18 |
# File 'lib/lolcommits/plugin/twitter.rb', line 16 def self.name 'twitter' end |
.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).
27 28 29 |
# File 'lib/lolcommits/plugin/twitter.rb', line 27 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lolcommits/plugin/twitter.rb', line 46 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 |
#configured? ⇒ Boolean
Plugin is configured when a token and token secret exist
36 37 38 |
# File 'lib/lolcommits/plugin/twitter.rb', line 36 def configured? !!(configuration['token'] && configuration['token_secret']) 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/lolcommits/plugin/twitter.rb', line 69 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.message}" end end |