lolcommits-tumblr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c34bf23f1dd00883a2f8d7b6a5a24873be1f5d4
4
+ data.tar.gz: 21958ad78a48c88a191d40d19c82734be000974d
5
+ SHA512:
6
+ metadata.gz: 6b5905a6ba7c404150a5d03bfbc656b1c35e1e107f2b5c9aa51017a042ebf3ebd8a5dca0a8f2be9367b9bdaaa0ae890b937454331e7d9f1ba44d8751afc292ce
7
+ data.tar.gz: 214687925f1e3e2e75b05a0204e008447216315cc15bf41be63356ede121f73336829d3df3548c8513b2b053122ef6d9977aed373964a0b73aeac627fcf741d9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.simplecov ADDED
@@ -0,0 +1,9 @@
1
+ SimpleCov.start do
2
+ add_filter '/test/'
3
+ add_filter '/vendor/'
4
+ end
5
+
6
+ SimpleCov.at_exit do
7
+ SimpleCov.result.format!
8
+ `open ./coverage/index.html` if RUBY_PLATFORM =~ /darwin/
9
+ end
data/.travis.yml ADDED
@@ -0,0 +1,35 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.10
7
+ - 2.2.8
8
+ - 2.3.5
9
+ - 2.4.2
10
+ - ruby-head
11
+
12
+ before_install:
13
+ - gem install bundler -v 1.13.7
14
+ - git --version
15
+ - git config --global user.email "lol@commits.org"
16
+ - git config --global user.name "Lolcommits"
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+
22
+ branches:
23
+ except:
24
+ - gh-pages
25
+
26
+ env:
27
+ global:
28
+ - CC_TEST_REPORTER_ID=912a7346d8a46cba51845e16bbc5582a4af4d884830f83b64ab462eee55a0cd7
29
+ - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
30
+ before_script:
31
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
32
+ - chmod +x ./cc-test-reporter
33
+ - ./cc-test-reporter before-build - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
34
+ after_script:
35
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,50 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer via [GitHub][maintainer]. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [maintainer]: https://github.com/matthutchinson
49
+ [homepage]: http://contributor-covenant.org
50
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,37 @@
1
+ ### Contributing
2
+
3
+ Pull Requests are welcome! To start helping out:
4
+
5
+ [Fork](https://guides.github.com/activities/forking) then clone the repository:
6
+
7
+ git clone git@github.com:your-username/lolcommits-tumblr.git
8
+
9
+ Create your feature branch:
10
+
11
+ git checkout -b my-new-feature
12
+
13
+ When you are happy with your change, run the full test suite:
14
+
15
+ bundle exec rake
16
+
17
+ With a passing test suite, commit your changes, push and submit a new [Pull
18
+ Request](https://github.com/lolcommits/lolcommits-tumblr/compare):
19
+
20
+ git commit -am 'Added some feature'
21
+ git push origin my-new-feature
22
+
23
+ At this point you'll be waiting for one of our maintainers to review it. We will
24
+ try to reply to new Pull Requests within a few days. We might suggest some
25
+ changes, improvements or alternatives. To increase the chance that your pull
26
+ request gets accepted:
27
+
28
+ * Explain what your are doing (and why) in your Pull Request description.
29
+ * If you are fixing an
30
+ [issue](https://github.com/lolcommits/lolcommits-tumblr/issues), link to
31
+ it in your description and [mention
32
+ it](https://help.github.com/articles/closing-issues-via-commit-messages) in
33
+ the commit message.
34
+ * Write a good [commit
35
+ message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
36
+ * Write tests.
37
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # Lolcommits Tumblr
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/lolcommits-tumblr.svg?style=flat)](http://rubygems.org/gems/lolcommits-tumblr)
4
+ [![Travis Build Status](https://travis-ci.org/lolcommits/lolcommits-tumblr.svg?branch=master)](https://travis-ci.org/lolcommits/lolcommits-tumblr)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/0c289196d8504223c31a/test_coverage)](https://codeclimate.com/github/lolcommits/lolcommits-tumblr/test_coverage)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/0c289196d8504223c31a/maintainability)](https://codeclimate.com/github/lolcommits/lolcommits-tumblr/maintainability)
7
+ [![Gem Dependency Status](https://gemnasium.com/badges/github.com/lolcommits/lolcommits-tumblr.svg)](https://gemnasium.com/github.com/lolcommits/lolcommits-tumblr)
8
+
9
+ [lolcommits](https://lolcommits.github.io/) takes a snapshot with your webcam
10
+ every time you git commit code, and archives a lolcat style image with it. Git
11
+ blame has never been so much fun!
12
+
13
+ This is a simple plugin to post lolcommits to your Tumblr. Configure it with a
14
+ Tumblr access token and secret (the plugin will guide you through this process).
15
+
16
+ ## Requirements
17
+
18
+ * Ruby >= 2.0.0
19
+ * A webcam
20
+ * [ImageMagick](http://www.imagemagick.org)
21
+ * [ffmpeg](https://www.ffmpeg.org) (optional) for animated gif capturing
22
+
23
+ ## Installation
24
+
25
+ After installing the lolcommits gem, install this plugin with:
26
+
27
+ $ gem install lolcommits-tumblr
28
+
29
+ Then configure to enable. If this is your first time setting up, you'll be asked
30
+ to visit Tumblr to authenticate and allow access.
31
+
32
+ $ lolcommits --config -p tumblr
33
+ # set enabled to `true`
34
+ # You'll be asked to confirm access for this plugin at tumblr.com
35
+ # Click 'allow' then return to the console to set your Tumblr name
36
+ # Optionally set the plugin to auto-open each created Tumblr post
37
+
38
+ That's it! Your next lolcommit will automatically be posted to your Tumblr blog.
39
+ To disable use:
40
+
41
+ $ lolcommits --config -p tumblr
42
+ # and set enabled to `false`
43
+
44
+ ## Development
45
+
46
+ Check out this repo and run `bin/setup`, this will install all dependencies and
47
+ generate docs. Use `bundle exec rake` to run all tests and generate a coverage
48
+ report.
49
+
50
+ You can also run `bin/console` for an interactive prompt that will allow you to
51
+ experiment with the gem code.
52
+
53
+ This plugin uses the [tumblr-client](https://github.com/tumblr/tumblr_client)
54
+ and [OAuth](https://rubygems.org/gems/oauth/versions/0.5.3) gems. A
55
+ [Webrick](https://rubygems.org/gems/webrick) server is started during
56
+ configuration, to provide a responding `return_uri` for the OAuth flow to
57
+ complete.
58
+
59
+ ## Tests
60
+
61
+ MiniTest is used for testing. Run the test suite with:
62
+
63
+ $ rake test
64
+
65
+ ## Docs
66
+
67
+ Generate docs for this gem with:
68
+
69
+ $ rake rdoc
70
+
71
+ ## Troubles?
72
+
73
+ If you think something is broken or missing, please raise a new
74
+ [issue](https://github.com/lolcommits/lolcommits-tumblr/issues). Take
75
+ a moment to check it hasn't been raised in the past (and possibly closed).
76
+
77
+ ## Contributing
78
+
79
+ Bug [reports](https://github.com/lolcommits/lolcommits-tumblr/issues) and [pull
80
+ requests](https://github.com/lolcommits/lolcommits-tumblr/pulls) are welcome on
81
+ GitHub.
82
+
83
+ When submitting pull requests, remember to add tests covering any new behaviour,
84
+ and ensure all tests are passing on [Travis
85
+ CI](https://travis-ci.org/lolcommits/lolcommits-tumblr). Read the
86
+ [contributing
87
+ guidelines](https://github.com/lolcommits/lolcommits-tumblr/blob/master/CONTRIBUTING.md)
88
+ for more details.
89
+
90
+ This project is intended to be a safe, welcoming space for collaboration, and
91
+ contributors are expected to adhere to the [Contributor
92
+ Covenant](http://contributor-covenant.org) code of conduct. See
93
+ [here](https://github.com/lolcommits/lolcommits-tumblr/blob/master/CODE_OF_CONDUCT.md)
94
+ for more details.
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of
99
+ [LGPL-3](https://opensource.org/licenses/LGPL-3.0).
100
+
101
+ ## Links
102
+
103
+ * [Travis CI](https://travis-ci.org/lolcommits/lolcommits-tumblr)
104
+ * [Code Climate](https://codeclimate.com/github/lolcommits/lolcommits-tumblr)
105
+ * [Test Coverage](https://codeclimate.com/github/lolcommits/lolcommits-tumblr/coverage)
106
+ * [RDoc](http://rdoc.info/projects/lolcommits/lolcommits-tumblr)
107
+ * [Issues](http://github.com/lolcommits/lolcommits-tumblr/issues)
108
+ * [Report a bug](http://github.com/lolcommits/lolcommits-tumblr/issues/new)
109
+ * [Gem](http://rubygems.org/gems/lolcommits-tumblr)
110
+ * [GitHub](https://github.com/lolcommits/lolcommits-tumblr)
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rdoc/task"
4
+
5
+ # generate docs
6
+ RDoc::Task.new do |rd|
7
+ rd.main = "README.md"
8
+ rd.title = "Lolcommits Tumblr"
9
+ rd.rdoc_dir = "doc"
10
+ rd.options << "--all"
11
+ rd.rdoc_files.include("README.md", "LICENSE", "lib/**/*.rb")
12
+ end
13
+
14
+ # run tests
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << "test"
17
+ t.libs << "lib"
18
+ t.test_files = FileList["test/**/*_test.rb"]
19
+ end
20
+
21
+ # run tests with code coverage (default)
22
+ namespace :test do
23
+ desc "Run all tests and features and generate a code coverage report"
24
+ task :coverage do
25
+ ENV['COVERAGE'] = 'true'
26
+ Rake::Task['test'].execute
27
+ end
28
+ end
29
+
30
+
31
+ task :default => ['test:coverage']
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lolcommits/tumblr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ # install deps
7
+ bundle install
8
+
9
+ # generate docs
10
+ bundle exec rake rdoc
@@ -0,0 +1,251 @@
1
+ require 'lolcommits/plugin/base'
2
+ require 'lolcommits/cli/launcher'
3
+ require 'oauth'
4
+ require 'webrick'
5
+ require 'cgi'
6
+ require 'tumblr_client'
7
+
8
+ module Lolcommits
9
+ module Plugin
10
+ class Tumblr < Base
11
+
12
+ TUMBLR_API_ENDPOINT = 'https://www.tumblr.com'.freeze
13
+ TUMBLR_CONSUMER_KEY = '2FtMEDpEPkxjoUdkpHh42h9wqTu9IVS7Ra0QyNZGixdCvhllN2'.freeze
14
+ TUMBLR_CONSUMER_SECRET = 'qWuvxgFUR2YyWKtbWOkDTMAiBEbj7ZGaNLaNQPba0PI1N4JpBs'.freeze
15
+
16
+ ##
17
+ # Returns the name of the plugin to identify the plugin to lolcommits.
18
+ #
19
+ # @return [String] the plugin name
20
+ #
21
+ def self.name
22
+ 'tumblr'
23
+ end
24
+
25
+ ##
26
+ # Returns position(s) of when this plugin should run during the capture
27
+ # process. Uploading happens when a new capture is ready.
28
+ #
29
+ # @return [Array] the position(s) (:capture_ready)
30
+ #
31
+ def self.runner_order
32
+ [:capture_ready]
33
+ end
34
+
35
+ ##
36
+ # Post-capture hook, runs after lolcommits captures a snapshot. Uploads
37
+ # the lolcommit image to the remote server with an optional Authorization
38
+ # header and the following request params.
39
+ #
40
+ # `file` - captured lolcommit image file
41
+ # `message` - the commit message
42
+ # `repo` - repository name e.g. mroth/lolcommits
43
+ # `sha` - commit SHA
44
+ # `key` - key (string) from plugin configuration (optional)
45
+ # `author_name` - the commit author name
46
+ # `author_email` - the commit author email address
47
+ #
48
+ # @return [RestClient::Response] response object from POST request
49
+ # @return [Nil] if any error occurs
50
+ #
51
+ def run_capture_ready
52
+ print "*** Posting to Tumblr ... "
53
+ post = client.photo(configuration['tumblr_name'], data: runner.main_image)
54
+
55
+ if post.key?('id')
56
+ post_url = tumblr_post_url(post)
57
+ open_url(post_url) if configuration['open_url']
58
+ print "done! #{post_url}\n"
59
+ else
60
+ print "Post FAILED! #{post.inspect}"
61
+ end
62
+ rescue Faraday::Error => e
63
+ print "Post FAILED! #{e.message}"
64
+ end
65
+
66
+ ##
67
+ # Returns true if the plugin has been configured.
68
+ #
69
+ # @return [Boolean] true/false indicating if plugin is configured
70
+ #
71
+ def configured?
72
+ !!(configuration['enabled'] &&
73
+ configuration['access_token'] &&
74
+ configuration['secret'] &&
75
+ configuration['tumblr_name'])
76
+ end
77
+
78
+ ##
79
+ # Prompts the user to configure the plugin's options.
80
+ #
81
+ # If the enabled option is set, Ouath configuration is attempted, if
82
+ # successful additional plugin options are asked for to set both
83
+ # `tumblr_name` and `open_url`.
84
+ #
85
+ # @return [Hash] a hash of configured plugin options
86
+ #
87
+ def configure_options!
88
+ options = super
89
+ # ask user to configure tokens if enabling
90
+ if options['enabled']
91
+ auth_config = configure_auth!
92
+ return unless auth_config
93
+ options = options.merge(auth_config).merge(configure_tumblr)
94
+ end
95
+ options
96
+ end
97
+
98
+
99
+ private
100
+
101
+ def configure_auth!
102
+ puts ''
103
+ puts '----------------------------------------'
104
+ puts ' Need to grab Tumblr Oauth token '
105
+ puts '----------------------------------------'
106
+
107
+ request_token = oauth_consumer.get_request_token(exclude_callback: true)
108
+ puts "\nOpening this url to authorize lolcommits:"
109
+ puts request_token.authorize_url
110
+ open_url(request_token.authorize_url)
111
+ puts "\nLaunching local webbrick server to complete the OAuth process ...\n"
112
+ begin
113
+ trap('INT') { local_server.shutdown }
114
+ trap('SIGTERM') { local_server.shutdown }
115
+ local_server.mount_proc '/', server_callback
116
+ local_server.start
117
+ debug "Requesting Tumblr OAuth Token with verifier: #{@verifier}"
118
+ access_token = request_token.get_access_token(oauth_verifier: @verifier)
119
+ rescue OAuth::Unauthorized
120
+ puts "ERROR: Tumblr OAuth verification failed!"
121
+ return
122
+ rescue WEBrick::HTTPServerError
123
+ puts "Do you have something running on port 3000? Please turn it off to complete the authorization process"
124
+ return
125
+ end
126
+ return unless access_token.token && access_token.secret
127
+
128
+ puts ''
129
+ puts '----------------------------------------'
130
+ puts 'Thanks! Lolcommits Tumblr Auth Succeeded'
131
+ puts '----------------------------------------'
132
+
133
+ {
134
+ 'access_token' => access_token.token,
135
+ 'secret' => access_token.secret
136
+ }
137
+ end
138
+
139
+ def configure_tumblr
140
+ print "\n* What's your Tumblr name? (i.e. 'http://[THIS PART HERE].tumblr.com'): "
141
+ tumblr_name = parse_user_input(gets.strip)
142
+ print "\n* Automatically open Tumblr URL after posting (y/N): "
143
+ open_url = ask_yes_or_no?
144
+ { 'tumblr_name' => tumblr_name, 'open_url' => open_url }
145
+ end
146
+
147
+ def client
148
+ @client ||= ::Tumblr.new(
149
+ consumer_key: TUMBLR_CONSUMER_KEY,
150
+ consumer_secret: TUMBLR_CONSUMER_SECRET,
151
+ oauth_token: configuration['access_token'],
152
+ oauth_token_secret: configuration['secret']
153
+ )
154
+ end
155
+
156
+ def oauth_consumer
157
+ @oauth_consumer ||= OAuth::Consumer.new(
158
+ TUMBLR_CONSUMER_KEY,
159
+ TUMBLR_CONSUMER_SECRET,
160
+ site: TUMBLR_API_ENDPOINT,
161
+ request_endpoint: TUMBLR_API_ENDPOINT,
162
+ http_method: :get
163
+ )
164
+ end
165
+
166
+ def ask_yes_or_no?(default: false)
167
+ yes_or_no = parse_user_input(gets.strip)
168
+ return default if yes_or_no.nil?
169
+ !!(yes_or_no =~ /^y/i)
170
+ end
171
+
172
+ def tumblr_post_url(post)
173
+ "https://#{configuration['tumblr_name']}.tumblr.com/post/#{post['id']}"
174
+ end
175
+
176
+ def open_url(url)
177
+ Lolcommits::CLI::Launcher.open_url(url)
178
+ end
179
+
180
+ def local_server
181
+ @local_server ||= WEBrick::HTTPServer.new(Port: 3000)
182
+ end
183
+
184
+ def oauth_response(heading, message)
185
+ <<-RESPONSE
186
+ <html>
187
+ <head>
188
+ <style>
189
+ body {
190
+ background-color: #36465D;
191
+ text-align: center;
192
+ }
193
+
194
+ a { color: #529ecc; text-decoration: none; }
195
+ a img { border: none; }
196
+
197
+ img {
198
+ width: 100px;
199
+ margin-top: 100px;
200
+ }
201
+
202
+ div {
203
+ margin: 20px auto;
204
+ font: normal 16px "Helvetica Neue", "HelveticaNeue", Helvetica, Arial, sans-serif;
205
+ padding: 20px 40px;
206
+ background: #FEFEFE;
207
+ width: 50%;
208
+ border-radius: 10px;
209
+ color: #757575;
210
+ }
211
+
212
+ h1 {
213
+ font-size: 18px;
214
+ }
215
+ </style>
216
+ </head>
217
+ <body>
218
+ <a href="https://lolcommits.github.io">
219
+ <img src="https://lolcommits.github.io/assets/img/logo/lolcommits_logo_400px.png" alt="lolcommits" width="100px" />
220
+ </a>
221
+ <div>
222
+ <h1>#{heading}</h1>
223
+ <p>#{message}</p>
224
+ </div>
225
+ </body>
226
+ </html>
227
+ RESPONSE
228
+ end
229
+
230
+ def server_callback
231
+ proc do |req, res|
232
+ local_server.stop
233
+ local_server.shutdown
234
+
235
+ query = req.request_uri.query
236
+ query = CGI.parse(req.request_uri.query) if query
237
+
238
+ if query && query['oauth_verifier']
239
+ @verifier = query['oauth_verifier'][0]
240
+ res.body = oauth_response(
241
+ "Lolcommits Authorization Complete",
242
+ "Please return to your console to complete the <a href=\"https://github.com/lolcommits/lolcommits-tumblr\">lolcommits-tumblr</a> plugin setup"
243
+ )
244
+ else
245
+ res.body = oauth_response("Lolcommits Authorization Cancelled", ":( Oh well, it was fun to ask")
246
+ end
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,2 @@
1
+ require 'lolcommits/tumblr/version'
2
+ require 'lolcommits/plugin/tumblr'
@@ -0,0 +1,5 @@
1
+ module Lolcommits
2
+ module Tumblr
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lolcommits/tumblr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lolcommits-tumblr"
8
+ spec.version = Lolcommits::Tumblr::VERSION
9
+ spec.authors = ["Matthew Hutchinson"]
10
+ spec.email = ["matt@hiddenloop.com"]
11
+ spec.summary = %q{Post lolcommits to Tumblr}
12
+ spec.homepage = "https://github.com/lolcommits/lolcommits-tumblr"
13
+ spec.license = "LGPL-3"
14
+
15
+ spec.description = <<-EOF
16
+ A simple plugin to post lolcommits to your Tumblr. Configure it with a Tumblr
17
+ access token and secret.
18
+ EOF
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(assets|test|features)/}) }
30
+ spec.test_files = `git ls-files -- {test,features}/*`.split("\n")
31
+ spec.bindir = "bin"
32
+ spec.executables = []
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.required_ruby_version = ">= 2.0.0"
36
+
37
+ spec.add_runtime_dependency('tumblr_client')
38
+ spec.add_runtime_dependency('webrick')
39
+ spec.add_runtime_dependency('oauth')
40
+
41
+ spec.add_development_dependency "lolcommits", ">= 0.9.5"
42
+ spec.add_development_dependency "bundler"
43
+ spec.add_development_dependency "webmock"
44
+ spec.add_development_dependency "pry"
45
+ spec.add_development_dependency "rake"
46
+ spec.add_development_dependency "minitest"
47
+ spec.add_development_dependency "simplecov"
48
+ end
@@ -0,0 +1,155 @@
1
+ require "json"
2
+ require 'net/http'
3
+ require "test_helper"
4
+ require "webmock/minitest"
5
+
6
+ describe Lolcommits::Plugin::Tumblr do
7
+
8
+ include Lolcommits::TestHelpers::GitRepo
9
+ include Lolcommits::TestHelpers::FakeIO
10
+
11
+ def plugin_name
12
+ "tumblr"
13
+ end
14
+
15
+ it "should have a name" do
16
+ ::Lolcommits::Plugin::Tumblr.name.must_equal plugin_name
17
+ end
18
+
19
+ it "should run on capture ready" do
20
+ ::Lolcommits::Plugin::Tumblr.runner_order.must_equal [:capture_ready]
21
+ end
22
+
23
+ describe "with a runner" do
24
+ def runner
25
+ # a simple lolcommits runner with an empty configuration Hash
26
+ @runner ||= Lolcommits::Runner.new(
27
+ main_image: Tempfile.new("main_image.jpg"),
28
+ config: OpenStruct.new(
29
+ read_configuration: {},
30
+ loldir: File.expand_path("#{__dir__}../../../images")
31
+ )
32
+ )
33
+ end
34
+
35
+ def plugin
36
+ @plugin ||= Lolcommits::Plugin::Tumblr.new(runner: runner)
37
+ end
38
+
39
+ def valid_enabled_config
40
+ @config ||= OpenStruct.new(
41
+ read_configuration: {
42
+ plugin_name => {
43
+ "enabled" => true,
44
+ "access_token" => "tumblr-access-token",
45
+ "secret" => "tumblr-secret",
46
+ "tumblr_name" => "my-tumblr",
47
+ "open_url" => false
48
+ }
49
+ }
50
+ )
51
+ end
52
+
53
+ describe "#enabled?" do
54
+ it "is false by default" do
55
+ plugin.enabled?.must_equal false
56
+ end
57
+
58
+ it "is true when configured" do
59
+ plugin.config = valid_enabled_config
60
+ plugin.enabled?.must_equal true
61
+ end
62
+ end
63
+
64
+ describe "run_capture_ready" do
65
+ before { commit_repo_with_message("first commit!") }
66
+ after { teardown_repo }
67
+
68
+ it "posts lolcommit image to tumblr showing link to new photo post" do
69
+ in_repo do
70
+ plugin.config = valid_enabled_config
71
+
72
+ stub_request(:post, "https://api.tumblr.com/v2/blog/my-tumblr.tumblr.com/post").to_return(
73
+ body: {
74
+ "meta" => { "status" => 201, "msg" => "Created"},
75
+ "response" => { "id" => 123456789 }
76
+ }.to_json,
77
+ headers: { "Content-Type" => "application/json" },
78
+ status: 201
79
+ )
80
+
81
+ output = fake_io_capture { plugin.run_capture_ready }
82
+ output.must_match "done! https://my-tumblr.tumblr.com/post/123456789"
83
+
84
+ assert_requested :post, "https://api.tumblr.com/v2/blog/my-tumblr.tumblr.com/post", times: 1,
85
+ headers: {"Content-Type" => /multipart\/form-data/, "Accept" => "application/json" } do |req|
86
+ req.body.must_match 'filename="main_image.jpg'
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ describe "configuration" do
93
+ it "returns false when not configured" do
94
+ plugin.configured?.must_equal false
95
+ end
96
+
97
+ it "returns false when partially configured" do
98
+ plugin.config = OpenStruct.new(read_configuration: {
99
+ plugin_name => { "enabled" => true, "tumblr_name" => "fire" }
100
+ })
101
+ plugin.configured?.must_equal false
102
+ end
103
+
104
+ it "returns true when configured" do
105
+ plugin.config = valid_enabled_config
106
+ plugin.configured?.must_equal true
107
+ end
108
+
109
+ it "allows plugin options to be configured" do
110
+ # allow requests to localhost for this test
111
+ WebMock.disable_net_connect!(allow_localhost: true)
112
+
113
+ # enabled tumblr_name open_url
114
+ inputs = %w(true my-tumblr Y)
115
+ configured_plugin_options = {}
116
+
117
+ # stub Oauth token request flow
118
+ stub_request(:get, "https://www.tumblr.com/oauth/request_token").to_return(
119
+ status: 200,
120
+ body: "oauth_token=mytoken&oauth_token_secret=mytokensercet&oauth_callback_confirmed=true"
121
+ )
122
+
123
+ stub_request(:get, "https://www.tumblr.com/oauth/access_token").to_return(
124
+ status: 200,
125
+ body: "oauth_token=tumblr-access-token&oauth_token_secret=tumblr-secret"
126
+ )
127
+
128
+ # fake clicking authorize app in Tumblr by hitting local webrick server
129
+ # this will loop and request until the server responds 200 OK
130
+ fork do
131
+ res = nil
132
+ while !res || res.code != "200"
133
+ uri = URI('http://localhost:3000/?oauth_verifier[]=my-verifier')
134
+ res = Net::HTTP.get_response(uri) rescue nil
135
+ sleep 0.1
136
+ end
137
+ end
138
+
139
+ fake_io_capture(inputs: inputs) do
140
+ configured_plugin_options = plugin.configure_options!
141
+ end
142
+
143
+ configured_plugin_options.must_equal({
144
+ "enabled" => true,
145
+ "access_token" => "tumblr-access-token",
146
+ "secret" => "tumblr-secret",
147
+ "tumblr_name" => "my-tumblr",
148
+ "open_url" => true
149
+ })
150
+
151
+ WebMock.disable_net_connect!
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # necessary libs from lolcommits (allowing plugin to run)
4
+ require 'git'
5
+ require 'lolcommits/runner'
6
+ require 'lolcommits/vcs_info'
7
+ require 'lolcommits/backends/git_info'
8
+
9
+ # lolcommit test helpers
10
+ require 'lolcommits/test_helpers/git_repo'
11
+ require 'lolcommits/test_helpers/fake_io'
12
+
13
+ if ENV['COVERAGE']
14
+ require 'simplecov'
15
+ end
16
+
17
+ # plugin gem test libs
18
+ require 'lolcommits/tumblr'
19
+ require 'minitest/autorun'
20
+
21
+ # swallow all debug output during test runs
22
+ def debug(msg); end
23
+
24
+ # do not launch URLs
25
+ class Lolcommits::CLI::Launcher
26
+ def self.open_url(url); end
27
+ end
Binary file
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolcommits-tumblr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Hutchinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tumblr_client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webrick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: lolcommits
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: |2
154
+ A simple plugin to post lolcommits to your Tumblr. Configure it with a Tumblr
155
+ access token and secret.
156
+ email:
157
+ - matt@hiddenloop.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - ".gitignore"
163
+ - ".simplecov"
164
+ - ".travis.yml"
165
+ - CODE_OF_CONDUCT.md
166
+ - CONTRIBUTING.md
167
+ - Gemfile
168
+ - LICENSE
169
+ - README.md
170
+ - Rakefile
171
+ - bin/console
172
+ - bin/setup
173
+ - lib/lolcommits/plugin/tumblr.rb
174
+ - lib/lolcommits/tumblr.rb
175
+ - lib/lolcommits/tumblr/version.rb
176
+ - lolcommits-tumblr.gemspec
177
+ - test/lolcommits/plugin/tumblr_test.rb
178
+ - test/test_helper.rb
179
+ - vendor/fonts/Impact.ttf
180
+ homepage: https://github.com/lolcommits/lolcommits-tumblr
181
+ licenses:
182
+ - LGPL-3
183
+ metadata:
184
+ allowed_push_host: https://rubygems.org
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: 2.0.0
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubyforge_project:
201
+ rubygems_version: 2.6.13
202
+ signing_key:
203
+ specification_version: 4
204
+ summary: Post lolcommits to Tumblr
205
+ test_files:
206
+ - test/lolcommits/plugin/tumblr_test.rb
207
+ - test/test_helper.rb