tumblr_draftking 0.7.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +7 -0
  3. data/CHANGELOG.md +80 -0
  4. data/LICENSE +67 -0
  5. data/README.md +293 -0
  6. data/Rakefile +22 -0
  7. data/bin/dk +7 -0
  8. data/lib/draftking/cli/cli_helpers.rb +61 -0
  9. data/lib/draftking/cli/cli_options.rb +31 -0
  10. data/lib/draftking/cli/commands/_template.rb +4 -0
  11. data/lib/draftking/cli/commands/accounts.rb +66 -0
  12. data/lib/draftking/cli/commands/blogs.rb +26 -0
  13. data/lib/draftking/cli/commands/comment.rb +34 -0
  14. data/lib/draftking/cli/commands/console.rb +18 -0
  15. data/lib/draftking/cli/commands/movedrafts.rb +33 -0
  16. data/lib/draftking/cli/commands/status.rb +24 -0
  17. data/lib/draftking/cli/commands/strip.rb +19 -0
  18. data/lib/draftking/cli/commands/tag.rb +21 -0
  19. data/lib/draftking/cli/commands/user_command.rb +45 -0
  20. data/lib/draftking/cli.rb +62 -0
  21. data/lib/draftking/client.rb +80 -0
  22. data/lib/draftking/config/config_setup.rb +56 -0
  23. data/lib/draftking/config.rb +151 -0
  24. data/lib/draftking/constants.rb +25 -0
  25. data/lib/draftking/dependency_patches.rb +2 -0
  26. data/lib/draftking/drafts.rb +53 -0
  27. data/lib/draftking/patches/thor.rb +12 -0
  28. data/lib/draftking/patches/tumblr_client.rb +10 -0
  29. data/lib/draftking/posts/post.rb +150 -0
  30. data/lib/draftking/posts/posts_helpers.rb +55 -0
  31. data/lib/draftking/posts.rb +173 -0
  32. data/lib/draftking/queue.rb +17 -0
  33. data/lib/draftking/reporter.rb +62 -0
  34. data/lib/draftking/tqueue/future_queue_methods.rb +97 -0
  35. data/lib/draftking/version.rb +3 -0
  36. data/lib/tasks/build.rake +33 -0
  37. data/lib/tasks/rubo.rake +36 -0
  38. data/lib/tumblr_draftking.rb +18 -0
  39. metadata +170 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 642bb7d8a6c8739a1af84577e5efd774482dc3cb
4
+ data.tar.gz: afb26f3ddaec14c04e635588ca8d5d85aa14e940
5
+ SHA512:
6
+ metadata.gz: 850cf60e8ac139b4af34705224516e7f86b678a288a6acbce768e9a5bd24ac29f171a21c3d65be36d0019f12b3cbfe829d520950ec3541410def820f9386ae21
7
+ data.tar.gz: 93fb9c629af2ed65f4020264f3ee22790ec8bd9ca54a5ab2aedc6a78022b77313bd71e2d852aea3def2061a1e52ef42778a0290dde552eec674b29f81d1f45cf
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --readme README.md
2
+ --title 'DraftKing for Tumblr API Documentation'
3
+ --charset utf-8
4
+ 'lib/**/*.rb'
5
+ -
6
+ *.md
7
+ LICENSE
data/CHANGELOG.md ADDED
@@ -0,0 +1,80 @@
1
+ # Changelog :: tumblr_draftking
2
+ ## Version 0.7.0
3
+ + New! (CLI) Store [custom commands](#custom-commands) in .dkconfig then view/execute them using DK ($> dk custom)
4
+ + New! (Posts) #post_operation Reporter dependency injected via options[:reporter], allowing custom report formats.
5
+ + New! (CLI) Manually check for updates using `dk update` (no more auto-notifications)
6
+ + New! (CLI) Updated UI
7
+ + New! (Config) Restructured .dkconfig file format and DK::Config to accommodate new functionality.
8
+ + New! (CLI) Use Reporter for all content output
9
+ + Bugfix: 'bin/dk' not found error when no default config file is present
10
+
11
+ ## Version 0.6.0.1
12
+ + Changing text 'tumblr' to 'Tumblr'
13
+
14
+ ## Version 0.6.0
15
+ + New! (Reporter) replaces PostReporter. Reporter is generic and can report on any class.
16
+ + New! (Reporter) Added simulation indication.
17
+ + New! (Reporter) Documentation
18
+ + Fix: (CLI::movedrafts) Show correct # of posts being processed
19
+ + (Reporter) Logic tweaks
20
+ + (Post) Removed named parameters for methods with single parameter (Post) to clean up code
21
+
22
+ ## Version 0.5.2
23
+ + Bugfix: CLI --no-tags option suppresses tag auto-generation (comment, movedrafts, tag)
24
+
25
+ ## Version 0.5.1
26
+ + New! CLI --no-tags option suppresses tag auto-generation (comment, movedrafts, tag)
27
+
28
+ ## Version 0.5.0
29
+ + New! PostReporter - Display summary of modified posts
30
+ + Breaking change: DK::Posts#post_operation now returns both a count of modified posts and the actual posts.
31
+ + Fix: Added accessors for DK::Client.state
32
+ + Fix: Added accessors for DK::Post.blog_url
33
+
34
+ ## Version 0.4.7
35
+ + Bugfix: Handle HTML post comments without getting crazy auto-generated tags
36
+ + Posts now handle logic about their state (changed)
37
+ + Refactored Post Operation threading logic
38
+
39
+ ## Version 0.4.6
40
+ + Bugfix: Automatic determination of movable post limits not being applied when removing old comments
41
+ + Bugfix: Calculation of Queue space adjusted to reflect limit of 300, instead of 301.
42
+
43
+ ## Version 0.4.5
44
+ + Bugfix: movedrafts incorrectly limited by size of queue instead of available space in queue.
45
+
46
+ ## Version 0.4.4
47
+ + CLI now displays a notification when a new version is available
48
+
49
+ ## Version 0.4.3
50
+ + Performance improvement: Faster processing of posts with multi-threading
51
+ + Bugfix: Missing 'console' command
52
+ + Bugfix: Passing a Limit > 50 was only applying to first 50 posts
53
+ + Bugfix: Non-queue related operations were being limited by available queue space
54
+ + Automated injection of change log information into README
55
+
56
+ ## Version 0.4.2
57
+ + Bugfix: Drafts not moving to queue
58
+
59
+ ## Version 0.4.1
60
+ + Bugfix for queued posts. Posts in the queue have a state 'queued'. In order to save them back in the queue state needs to be changed to 'queue'.
61
+
62
+ ## Version 0.4.0
63
+ + Code refactoring: consolidate option processing to simplify code.
64
+ + Updated header image
65
+
66
+ ## Version 0.3.1
67
+ + Update credit tag
68
+
69
+ ## Version 0.3.0
70
+ + New CLI! The Command Line Interface has been redone using [Thor](https://github.com/erikhuda/thor)
71
+ + CLI can now save and switch between multiple [account configurations](./README.md#configured-accounts)
72
+ + Added a [CHANGELOG](./CHANGELOG.md)
73
+ + Added a repository header image
74
+ + Improved test coverage
75
+ + Cleared out [.rubocop_todo.yml](./.rubocop_todo.yml) to reflect true codeclimate
76
+
77
+ ## Version 0.2.2
78
+ + Improved documentation
79
+ + Reduced test suite runtime
80
+ + Code cleanup
data/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
39
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
41
+
42
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
43
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
44
+
45
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
46
+
47
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
48
+
49
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
50
+
51
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
52
+
53
+ END OF TERMS AND CONDITIONS
54
+
55
+ Copyright [2016] [Meissa Dia]
56
+
57
+ Licensed under the Apache License, Version 2.0 (the "License");
58
+ you may not use this file except in compliance with the License.
59
+ You may obtain a copy of the License at
60
+
61
+ http://www.apache.org/licenses/LICENSE-2.0
62
+
63
+ Unless required by applicable law or agreed to in writing, software
64
+ distributed under the License is distributed on an "AS IS" BASIS,
65
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66
+ See the License for the specific language governing permissions and
67
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,293 @@
1
+ <img style='width:100%' src='./readme/logo-draftking.png'/>
2
+ DraftKing is not associated with Tumblr
3
+ [![Gem Version](https://badge.fury.io/rb/tumblr_draftking.svg)](https://badge.fury.io/rb/tumblr_draftking)
4
+ [![Code Climate](https://codeclimate.com/github/meissadia/tumblr_draftking/badges/gpa.svg)](https://codeclimate.com/github/meissadia/tumblr_draftking)
5
+ [![Test Coverage](https://codeclimate.com/github/meissadia/tumblr_draftking/badges/coverage.svg)](https://codeclimate.com/github/meissadia/tumblr_draftking/coverage)
6
+
7
+ DraftKing for Tumblr takes the hassle out of managing your draft queue!
8
+ + **(New!) Save and name your own DK commands!**
9
+ + **Automate the addition of comments and tags.**
10
+ + **Strip away old comments.**
11
+ + **Easily replenish your queue.**
12
+ + **Randomize post order to add variety.**
13
+ + **Manage multiple accounts.**
14
+
15
+ Version 0.7.0
16
+ + New! (CLI) Store [custom commands](#custom-commands) in .dkconfig then view/execute them using DK ($> dk custom)
17
+ + New! (Posts) #post_operation Reporter dependency injected via options[:reporter], allowing custom report formats.
18
+ + New! (CLI) Manually check for updates using `dk update` (no more auto-notifications)
19
+ + New! (CLI) Updated UI
20
+ + New! (Config) Restructured .dkconfig file format and DK::Config to accommodate new functionality.
21
+ + New! (CLI) Use Reporter for all content output
22
+ + Bugfix: 'bin/dk' not found error when no default config file is present
23
+
24
+ + Please report any [issues] you encounter!
25
+ + [Change Log](./CHANGELOG.md)
26
+
27
+ ## Table of Contents
28
+ + [Installation](#installation)
29
+ + [Setup](#setup)
30
+ + [1. Register an app](#1.-register-an-app)
31
+ + [2. Get oauth_token and oauth_token_secret](#2.-get-oauth_token-and-oauth_token_secret)
32
+ + [3. Run setup](#3.-run-setup)
33
+ + [Usage](#usage)
34
+ + [Command Line Interface](#command-line-interface)
35
+ + [Custom Commands](#custom-commands)
36
+ + [My Workflow](#my-workflow)
37
+ + [Examples](#examples)
38
+ + [Configured Accounts](#configured-accounts)
39
+ + [Blog list](#blog-list)
40
+ + [Commenting](#commenting)
41
+ + [Drafts or Queue](#drafts-or-queue)
42
+ + [Stripping Comments](#stripping-comments)
43
+ + [Comment & Move](#comment-&-move)
44
+ + [Testing Console](#testing-console)
45
+ + [API](#api)
46
+ + [Built With](#built-with)
47
+ + [Test Suite](#test-suite)
48
+ + [Contributing](#contributing)
49
+
50
+
51
+ ## Installation
52
+
53
+ $ gem install tumblr_draftking
54
+
55
+ ## Setup
56
+
57
+ ### 1. Register an app
58
+ https://www.tumblr.com/oauth/apps
59
+ + **Application Name:** DraftKing
60
+ + **Application Description:** [anything]
61
+ + **Administrative contact email:** [your email address]
62
+ + **Default callback URL:** [any url]
63
+
64
+ Once registered you should see your Consumer Key and Secret Key:
65
+ ![setup1](./readme/step1.png)
66
+ <br/>
67
+ <br/>
68
+ ### 2. Get oauth_token and oauth_token_secret
69
+ Using your Consumer Key and Secret Key from above, access https://api.tumblr.com/console/calls/user/info
70
+ ![keys](./readme/keys.png)
71
+ <br/>
72
+ <br/>
73
+ ### 3. Run setup
74
+ ```ruby
75
+ $ dk setup
76
+ ```
77
+
78
+ Setup will walk you through saving your configuration for future use.
79
+
80
+ ![setup2](./readme/step3.png)
81
+ <br/>
82
+ <br/>
83
+ ## Usage
84
+
85
+ ### Command Line Interface
86
+
87
+ The CLI will walk you through connecting to your Tumblr account the first time it's run.
88
+
89
+ * See: [Setup]
90
+
91
+ Once you've got that configured, check the help to familiarize yourself with your options.
92
+
93
+ ```ruby
94
+ $ dk -h
95
+ ```
96
+
97
+ #### Custom Commands
98
+ You can store your DK commands in your configuration file's (i.e. ~/.dkconfig) user_commands array.
99
+
100
+ Configuration file with two custom commands: tag_with_cool & show_other_account_status
101
+ ```
102
+ ---
103
+ :config_name: utb
104
+ :api_keys:
105
+ consumer_key: [your_consumer_key]
106
+ consumer_secret: [your_consumer_secret]
107
+ oauth_token: [your_oauth_token]
108
+ oauth_token_secret: [your_oauth_token_secret]
109
+ :user_commands:
110
+ tag_with_cool:
111
+ command: dk tag -t cool -c cool
112
+ description: Add the tag and comment 'cool' to posts
113
+ config_name: utb
114
+ show_other_account_status:
115
+ command: dk status --config account2
116
+ description: Show the status blogs under account2
117
+ config_name: account2
118
+ ```
119
+
120
+ Trigger custom command example:
121
+ ```
122
+ $> dk tag_with_cool
123
+ ```
124
+
125
+
126
+ #### My Workflow
127
+ I manually add comments for posts where I want more detail, using a separator ( / | , \ ) to identify tags.
128
+ + These tags/comment will not be removed by dk.
129
+
130
+ ```
131
+ ~MD~ | architecture | landscape | blue | yams |
132
+ ```
133
+
134
+ Then I'll let DraftKing automatically comment and tag the rest, strip old comments, and move them to my queue.
135
+ ```
136
+ $ dk md -c ~MD~
137
+ ```
138
+ * It will preserve post comments which already contain the string passed via `-c ~MD~`, so I don't need to worry about overwriting my special cases.
139
+ * It will also generate tags from the comment. In the above case you would get: #architecture #landscape #blue #yams (the comment in not added as a tag)
140
+
141
+ And that's it, my queue is loaded with manicured posts!
142
+
143
+ By default dk will act on your primary blog. To target an secondary blog, specify it using `-b <blog name>`
144
+ <br/>
145
+ <br/>
146
+
147
+ #### Examples
148
+
149
+ ##### Configured Accounts
150
+ ```ruby
151
+ $ dk accounts
152
+
153
+ #> * ---- Accounts ---- *
154
+ #> 0. (Default)
155
+ #> 1. ugly-test-blog
156
+ #> 2. nice-test-blog
157
+ ```
158
+
159
+ The default account is the configuration used when calling dk.
160
+ If the default doesn't exists, the first available configuration will be used.
161
+
162
+ To use an alternate account: `$dk accounts -s` . A dialog will help you set it as the default.
163
+ To delete an account configuration: `$dk accounts -d` . A dialog will let you choose which one.
164
+ <br/>
165
+ <br/>
166
+ ##### Blog list
167
+ ```ruby
168
+ $ dk blogs
169
+ #> #-------- Blogs --------#
170
+ #> 1. 'primary-blog-name'
171
+ #> 2. 'second-blog-name'
172
+
173
+ ```
174
+ ##### Commenting
175
+ - Add the comment "dude, where's my car?"
176
+ - Target primary blog
177
+ - Apply to Drafts
178
+ - Keep existing tags (-k)
179
+ - Keep existing comments (-K)
180
+
181
+ ```ruby
182
+ $ dk comment -c "dude, where's my car?" -k -K
183
+
184
+ #> Adding draft comment "dude, where's my car?": 32 / 32 [100%]
185
+
186
+ ```
187
+ ##### Drafts or Queue
188
+ - Add the comment 'where\'s your car, dude?'
189
+ - Target primary blog
190
+ - Apply to Queue (--source q)
191
+ - Limit action to 42 posts (-l 42)
192
+ - Remove old comments
193
+
194
+
195
+ ```ruby
196
+ $ dk comment -c "where's your car, dude?" --source q -l 42
197
+
198
+ #> Adding queue comment "where's your car, dude?": 32 / 32 [100%]
199
+
200
+ ```
201
+ ##### Stripping Comments
202
+ - Remove old comments
203
+ - Apply to Drafts
204
+ - Target 'second-blog-name' (-b second-blog-name)
205
+ - Simulate (-s)
206
+
207
+ ```ruby
208
+ $ dk strip -b second-blog-name -s
209
+
210
+ #> Stripping previous comments: 113 / 113 [100%]
211
+
212
+ ```
213
+ ##### Comment & Move
214
+ - Add the comment "draftking for tumblr"
215
+ - Target primary blog
216
+ - Apply to Drafts
217
+ - Generate tags from comment for posts with a comment already containing 'tumblr_draftking'
218
+ - Keep existing tags (-k)
219
+ - Add tags #new, #tags, #to, #add
220
+ - Remove old comments
221
+ - Move posts to the Queue.
222
+ - Suppress progress message (-m)
223
+
224
+ ```ruby
225
+ $ dk md -c "draftking for tumblr" -k -a new,tags,to,add -m
226
+ ```
227
+ #### Testing Console
228
+ The dk console can act as a sandbox while you explore the api or you can use it to actively manage your account.
229
+ By default it runs in simulation mode so any changes you make will not affect your account.
230
+
231
+ ```ruby
232
+ $ dk console
233
+ irb:> $dk.status
234
+ irb:> $dk.strip_old_comments
235
+
236
+ # Switch to live mode
237
+ irb:> $dk.simulate = false
238
+
239
+ ```
240
+
241
+ ### API
242
+ By default, API Keys are read from ~/\*.dkconfig (See: [Setup]) or you can pass them at the time of Client creation.
243
+
244
+ ```ruby
245
+ require 'tumblr_draftking'
246
+
247
+ # Use default configuration file: ~/.dkconfig
248
+ dk = DK::Client.new()
249
+
250
+ # Specify your own configuration file
251
+ dk = DK::Client.new(config_file: file_path)
252
+
253
+ # Define directly
254
+ dk = DK::Client.new(keys: { consumer_key: 'your value',
255
+ consumer_secret: 'your value',
256
+ oauth_token: 'your value',
257
+ oauth_token_secret: 'your value' })
258
+
259
+ ```
260
+
261
+ Documentation available on [rubydoc.info](http://www.rubydoc.info/gems/tumblr_draftking/0.3.0)
262
+ <br/>
263
+ <br/>
264
+ ## Built With
265
+ + [atom](https://atom.io/)
266
+ + [codeclimate](http://www.codeclimate.com)
267
+ + [minitest](https://github.com/seattlerb/minitest)
268
+ + [rubocop](https://github.com/bbatsov/rubocop)
269
+ + [simplecov](https://github.com/colszowka/simplecov)
270
+ + [Thor]
271
+ + [tumblr](https://github.com/tumblr/tumblr_client)
272
+ + [Lions](http://www.dafont.com/lions.font)
273
+
274
+ ## Test Suite
275
+ 1. Configure your test account configuration using `$ dk setup` and save it as default.
276
+ 1. `$ cp ~/.dkconfig ~/.dkconfig2`
277
+ 1. Update test/test_helper.rb to point to your test blog: $test_blog
278
+ 1. `$ rake`
279
+
280
+ ## Contributing
281
+
282
+ Bug reports and pull requests are welcome on GitHub at https://github.com/meissadia/tumblr_draftking.
283
+
284
+ <br/>
285
+ <br/>
286
+ <br/>
287
+ <br/>
288
+ <br/>
289
+ (c) 2016 Meissa Dia
290
+
291
+ [Setup]: #setup
292
+ [Thor]: https://github.com/erikhuda/thor
293
+ [issues]: https://github.com/meissadia/tumblr_draftking/issues
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ Dir.glob('lib/tasks/*.rake').each { |r| load r }
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc 'Run tests'
10
+ task default: :test
11
+
12
+ desc 'Open documentation'
13
+ task :show_docs do
14
+ files = %w(README.md CHANGELOG.md coverage/index.html rubocop/report.html)
15
+ files.each { |doc| `open #{doc} -a "Google Chrome"` }
16
+ end
17
+
18
+ desc 'Push latest version of gem to remote server'
19
+ task :deploy_gem do
20
+ gemfile = `ls -t1 *.gem | head -n 1`
21
+ puts `gem push #{gemfile}`
22
+ end
data/bin/dk ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require_relative '../lib/tumblr_draftking'
4
+
5
+ # Display 'update available'
6
+ require 'open-uri'
7
+ DK::CLI.start(ARGV)
@@ -0,0 +1,61 @@
1
+ module DK
2
+ # Helpers for Command Line Interface
3
+ module CliHelpers
4
+ VALID_OPTS = [:simulate, :limit, :blog, :key_text, :comment, :add_tags, :mute, :publish, :keep_tags, :keep_comments, :source, :config].freeze
5
+
6
+ private
7
+
8
+ def get_dk_instance(opts)
9
+ DK::Config.setup unless DK::Config.configured?
10
+ DK::Client.new(opts)
11
+ end
12
+
13
+ def configured?
14
+ DK::Config.setup unless DK::Config.configured?
15
+ end
16
+
17
+ def process_source(source)
18
+ source = source.to_s
19
+ return :queue if source.include?('q')
20
+ :draft
21
+ end
22
+
23
+ def process_options(options)
24
+ opts = options.each_with_object({}) { |(k, v), memo| memo[k.to_sym] = v; memo }
25
+ opts[:blog_name] = options[:blog] if options[:blog]
26
+ opts[:keep_tree] = options[:keep_comments] if options[:keep_comments]
27
+ opts[:source] = process_source(options[:source])
28
+ opts[:state] = DK::PUBLISH if options[:publish]
29
+ opts[:state] ||= DK::QUEUE if opts[:source] == :queue
30
+ opts[:state] ||= DK::DRAFT
31
+ process_config(opts)
32
+ opts
33
+ end
34
+
35
+ def process_config(opts)
36
+ return unless input = opts[:config]
37
+ input = DK::Config.available_configs[input.to_i].split('.')[1] if is_num_s?(input)
38
+ filename = DK::Config.home_path_file('.' + input + '.dkconfig')
39
+ opts[:keys] = DK::Config.new(file: filename).config.api_keys
40
+ opts[:config] = filename
41
+ end
42
+
43
+ # Numeric String?
44
+ def is_num_s?(input)
45
+ /^[\d_]+$/.match(input)
46
+ end
47
+
48
+ def config_to_num(input)
49
+ return nil if input.nil? || DK::Config.available_configs.empty?
50
+ case input
51
+ when /^\d+$/.match(input) # Numeric String
52
+ return input
53
+ when String
54
+ DK::Config.available_configs.each_with_index do |file, idx|
55
+ current = DK::Config.new(file: DK::Config.home_path_file(file))
56
+ return idx.to_s if current.filename == input
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,31 @@
1
+ module DK
2
+ # Options helper methods for CLI
3
+ class Options
4
+ # Define option descriptions
5
+ def self.op_strings
6
+ d = {}
7
+ d[:add_tags] = 'Comma separated string of tags to add.'
8
+ d[:blog] = 'Name of blog to use. Excluding this will default to main blog.'
9
+ d[:comment] = 'Comment to add to any posts which do not already contain it.'
10
+ d[:config] = 'Name or # of Config to use (`dk accounts` for list)'
11
+ d[:credit] = 'Give draftking credit with a tag'
12
+ d[:keep_comments] = 'Keep the previous comments on a post.'
13
+ d[:keep_tags] = 'Keep existing tags, in addition to newly generated tags.'
14
+ d[:key_text] = "Only apply command to posts who's comment contains the key_text string."
15
+ d[:limit] = 'Restrict number of posts selected.'
16
+ d[:mute] = 'Suppress progress messages.'
17
+ d[:publish] = 'Indicate that posts should be moved to the Published state.'
18
+ d[:simulate] = 'Simulation mode: Display program output without modifying actual Tumblr data.'
19
+ d[:source] = 'Modify posts from your : d-drafts, q-queue'
20
+ d[:state] = 'Set post state: d-draft, q-queued'
21
+ d[:tags] = 'Auto-Generate tags based on user comment.'
22
+ d
23
+ end
24
+
25
+ # String of operation descriptions
26
+ def self.descriptions(array)
27
+ d = op_strings
28
+ array.map { |opt| d[opt] || "not found #{opt}" }.join("\n\n")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module DK
2
+ class CLI < Thor
3
+ end
4
+ end
@@ -0,0 +1,66 @@
1
+ module DK
2
+ class CLI < Thor
3
+ desc 'accounts', 'Manage configured accounts'
4
+ option :delete, type: :boolean, aliases: :d, desc: 'Delete account configuration'
5
+ option :switch, type: :boolean, aliases: :s, desc: 'Switch default account configuration'
6
+ option :config, type: :string, desc: Options.op_strings[:config]
7
+ def accounts
8
+ files = DK::Config.available_configs
9
+ show_accounts(files)
10
+ return if options.empty? # Empty = no action to take
11
+ puts accounts_input_dialogue(options)
12
+ opts = process_options(options)
13
+ choice = config_to_num(opts[:config]) || DK::Config.get_input
14
+ return if /[^0-9]/ =~ choice
15
+ file = files[choice.to_i]
16
+ return if file.nil?
17
+ msg = accounts_action(file, opts)
18
+ show_accounts(DK::Config.available_configs, msg)
19
+ end
20
+
21
+ private
22
+
23
+ # Show available accounts
24
+ # @param account_list [[String]] List of configuration file names
25
+ def show_accounts(account_list, _msg = nil)
26
+ title = 'Accounts'
27
+ fields = %w(# name default file)
28
+ rows = []
29
+ account_list.each_with_index do |config, idx|
30
+ file = DK::Config.home_path_file(config)
31
+ conf = DK::Config.new(file: file)
32
+ default = ' (X)' if conf.is_default?
33
+ rows << [idx, conf.config_name, default, file]
34
+ end
35
+ Reporter.new(title: title, rows: rows, headers: fields).show
36
+ end
37
+
38
+ def accounts_input_dialogue(options)
39
+ return if options[:config]
40
+ return "\nEnter # to use as DEFAULT ('x' to exit): " if options[:switch]
41
+ return "\nEnter # to DELETE ('x' to exit): " if options[:delete]
42
+ end
43
+
44
+ def accounts_action(filename, options)
45
+ msg = accounts_delete(filename) if options[:delete]
46
+ msg = accounts_switch(filename) if options[:switch]
47
+ puts "#{msg}\n\n" if msg
48
+ msg
49
+ end
50
+
51
+ def accounts_extract_name(filename)
52
+ filename.gsub(/(^\.)|(.dkconfig)/, '')
53
+ end
54
+
55
+ def accounts_delete(file)
56
+ account = accounts_extract_name(file)
57
+ DK::Config.delete_config(file) ? "Deleted account: #{account}." : "Failed to delete account: #{account}!"
58
+ end
59
+
60
+ def accounts_switch(file)
61
+ return 'No change made.' if file == DK::CONFIG_FILENAME
62
+ account = accounts_extract_name(file)
63
+ DK::Config.switch_default_config(file) ? "New default account: #{account}." : 'Unable to change default account!'
64
+ end
65
+ end
66
+ end