Class: Lolcommits::Plugin::Tumblr
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Tumblr
- Defined in:
- lib/lolcommits/plugin/tumblr.rb
Constant Summary collapse
- TUMBLR_API_HOST =
"api.tumblr.com".freeze
- TUMBLR_API_ENDPOINT =
"https://www.tumblr.com".freeze
- TUMBLR_CONSUMER_KEY =
"2FtMEDpEPkxjoUdkpHh42h9wqTu9IVS7Ra0QyNZGixdCvhllN2".freeze
- TUMBLR_CONSUMER_SECRET =
"qWuvxgFUR2YyWKtbWOkDTMAiBEbj7ZGaNLaNQPba0PI1N4JpBs".freeze
Instance Method Summary collapse
-
#configure_options! ⇒ Hash
Prompts the user to configure the plugin’s options.
-
#run_capture_ready ⇒ Object
Post-capture hook, runs after lolcommits captures a snapshot.
-
#valid_configuration? ⇒ Boolean
Returns true if the plugin has been configured correctly.
Instance Method Details
#configure_options! ⇒ Hash
Prompts the user to configure the plugin’s options.
If the enabled option is set, Ouath configuration is attempted, if successful additional plugin options are asked for to set both ‘tumblr_name` and `open_url`.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/lolcommits/plugin/tumblr.rb', line 76 def = super # ask user to configure tokens if enabling if [:enabled] auth_config = configure_auth! return unless auth_config = .merge(auth_config).merge(configure_tumblr) end end |
#run_capture_ready ⇒ Object
Post-capture hook, runs after lolcommits captures a snapshot.
Posts the lolcommit main image to Tumblr, printing success or failure message to stdout.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lolcommits/plugin/tumblr.rb', line 27 def run_capture_ready if runner.capture_video && !runner.capture_gif debug "unable to post videos, (Tumblr API only supports images)" return end print "*** Posting to Tumblr ... " response = tumblr_api.post do |req| req.url "v2/blog/#{configuration[:tumblr_name]}/post" req.body = { caption: tumblr_caption, type: "photo", data: Faraday::FilePart.new(lolcommit_path, lolcommit_mime_type) } end post = response.body["response"] || {} if post.key?('id') post_url = tumblr_post_url(post) open_url(post_url) if configuration[:open_url] print "done! #{post_url}\n" else print "Post FAILED! #{response.inspect}" end rescue Faraday::Error => e print "Post FAILED! #{e.}" end |
#valid_configuration? ⇒ Boolean
Returns true if the plugin has been configured correctly
61 62 63 64 65 |
# File 'lib/lolcommits/plugin/tumblr.rb', line 61 def valid_configuration? !!(configuration[:access_token] && configuration[:secret] && configuration[:tumblr_name]) end |