tumblr_draftking 0.7.0.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5182d265c74140d67669beb53b1e85482eba5f92
4
- data.tar.gz: 7579be0019d2ea2828343ee8c9a7b522268cf97f
3
+ metadata.gz: c93a9633bd0ae2cfd31d6791298f44bffaf345da
4
+ data.tar.gz: 1441e5671dd6325a9bfc7a05669d1bf879b02ad5
5
5
  SHA512:
6
- metadata.gz: a6c03b38f127db39e81670d67502028d968285c081bcdb3a8953802682ee720c07fd364c552d2ad4943138f7666657293060ff5b4963efa7e2261de0ef343c42
7
- data.tar.gz: f82d3a48f36e6d39c8d81d291d522f15360e8b68ea5836b2dbe9d027459d2216c266386b64d1a8400baf899a6213fe8375bec5cf152ab40c4bd7738e17f262c8
6
+ metadata.gz: 80db75ddb4b552d75f8ecbd64055fd8e2655c31a1ce2038908e9642ab55ba715cbb13db040212e6509d27850eda7697c482c3a2f17a7475d026744c37b4e5413
7
+ data.tar.gz: a5569f9c6fc6aa2254792ed5f30c211e16b7d6332bc6a7399d61ad904411652c9a5db95501401618420d497a5308fc7518f33690586ac3311c308b81c7d49e9d
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Changelog :: tumblr_draftking
2
+ ## Version 0.8.0
3
+ + DK#post_operation now returns both modified count and modified posts. Use `post_operation(opts)[0]` for previous behavior.
4
+ + Access all Tumblr Post data via DK::Post. i.e. `DK::Post.new(post_data).photos.first.original_size.url`
5
+ + Post.image (first photo, original size), Post.alt_sizes, Post.photos (array of Photo structs)
6
+
2
7
  ## Version 0.7.0
3
8
  + New! (CLI) Store [custom commands](#custom-commands) in .dkconfig then view/execute them using DK ($> dk custom)
4
9
  + New! (Posts) #post_operation Reporter dependency injected via options[:reporter], allowing custom report formats.
data/README.md CHANGED
@@ -12,15 +12,10 @@ DraftKing for Tumblr takes the hassle out of managing your draft queue!
12
12
  + **Randomize post order to add variety.**
13
13
  + **Manage multiple accounts.**
14
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
- + New! (Posts) Support for dashboard access; opts={source: 'dashboard', limit: 50, offset: 0}
23
- + Bugfix: 'bin/dk' not found error when no default config file is present
15
+ Version 0.8.0
16
+ + DK#post_operation now returns both modified count and modified posts. Use `post_operation(opts)[0]` for previous behavior.
17
+ + Access all Tumblr Post data via DK::Post. i.e. `DK::Post.new(post_data).photos.first.original_size.url`
18
+ + Post.image (first photo, original size), Post.alt_sizes, Post.photos (array of Photo structs)
24
19
 
25
20
  + Please report any [issues] you encounter!
26
21
  + [Change Log](./CHANGELOG.md)
@@ -8,17 +8,21 @@ module DK
8
8
  fields = %w(Blog Drafts Queued Q.Space)
9
9
  opts = process_options(options.dup.merge(blog: blog))
10
10
  dk = get_dk_instance(opts)
11
- rows = begin
12
- dk.user.blogs.map do |b|
13
- next unless blog.nil? || b.name == blog
14
- [b.name, b.drafts, b.queue, 300 - b.queue.to_i]
15
- end.compact
16
- rescue
17
- []
18
- end
11
+ rows = build_rows(dk)
19
12
  report = Reporter.new(title: title, rows: rows, headers: fields)
20
- report.show unless simulate
13
+ report.show unless dk.simulate
21
14
  report
22
15
  end
16
+
17
+ private
18
+
19
+ def build_rows(dk)
20
+ dk.user.blogs.map do |b|
21
+ next unless blog.nil? || b.name == blog
22
+ [b.name, b.drafts, b.queue, 300 - b.queue.to_i]
23
+ end.compact
24
+ rescue
25
+ []
26
+ end
23
27
  end
24
28
  end
@@ -45,6 +45,7 @@ module DK
45
45
  @before_id = options[:before_id] || 0
46
46
  @offset = options[:offset] || 0
47
47
  @limit = options[:limit]
48
+ @type = options[:type]
48
49
  end
49
50
 
50
51
  # Configure tumblr_client gem
@@ -76,6 +77,7 @@ module DK
76
77
  @client && @client.info['status'] != 401
77
78
  end
78
79
 
80
+ # Process options[:source]
79
81
  def process_source(src)
80
82
  return :draft unless src
81
83
  return src if src.is_a? Symbol
@@ -8,18 +8,16 @@ module DK
8
8
  # @return [int] Number of modified posts
9
9
  def strip_old_comments(options = {})
10
10
  options[:message] = 'Stripping previous comments: '
11
- mod_count, _mod_posts = post_operation(options) do |post, _|
11
+ post_operation(options) do |post, _|
12
12
  post.changed = true
13
13
  end
14
- mod_count
15
14
  end
16
15
 
17
16
  def strip_tags(options = {})
18
17
  options[:message] = 'Stripping previous comments: '
19
- mod_count, _mod_posts = post_operation(options) do |post, _|
18
+ post_operation(options) do |post, _|
20
19
  post.clear_tags
21
20
  end
22
- mod_count
23
21
  end
24
22
 
25
23
  # Move Drafts to Queue
@@ -37,17 +35,16 @@ module DK
37
35
  options[:shuffle] = true
38
36
  options[:state] = DK::QUEUE
39
37
  options[:limit] ||= @q_space
40
- mod_count, _mod_posts = post_operation(options) do |post, index|
38
+ post_operation(options) do |post, index|
41
39
  next false unless index_within_limit?(index, @q_space)
42
40
  next false unless post.has_key_text?(@key_text)
43
41
  post.replace_comment_with(@comment)
44
42
  post.change_state(@state)
45
43
  post.generate_tags(keep_tags: @keep_tags,
46
- add_tags: @tags,
47
- exclude: @comment,
48
- credit: @credit) if @auto_tag
44
+ add_tags: @tags,
45
+ exclude: @comment,
46
+ credit: @credit) if @auto_tag
49
47
  end
50
- mod_count
51
48
  end
52
49
  end
53
50
  end
@@ -4,32 +4,30 @@ include DK::Posts
4
4
  module DK
5
5
  # Tumblr Post
6
6
  class Post
7
- attr_accessor :id, :state, :tags, :comment, :summary, :reblog_key
8
- attr_accessor :keep_tree, :changed, :saved, :blog_url
9
- attr_accessor :image
10
- attr_reader :data
11
-
12
7
  # @param hash [Hash] Post Data
13
8
  # @param keep_tree [Bool] Attach Reblog Tree?
14
9
  def initialize(hash, keep_tree: nil)
15
10
  return if hash.nil?
16
- # TODO: remove @data
17
- # TODO add post type
18
- # TODO add photoset images
19
- # TODO add various photo sizes
20
- data = JSON.parse(hash.to_json, object_class: OpenStruct)
21
- @id = data.id
22
- @state = process_state(data.state)
23
- @tags = data.tags
24
- @comment = data.reblog.comment
25
- @summary = data.summary
26
- @blog_url = tumblr_url(data.blog_name)
27
- @reblog_key = data.reblog_key
28
- @image = data.photos.first.original_size.url if data.photos
11
+ @data = JSON.parse(hash.to_json, object_class: OpenStruct)
12
+
13
+ # Translate
14
+ @state = process_state(@data.state)
15
+ @blog_url = tumblr_url(@data.blog_name)
16
+ @image = original_image_url
17
+ @photoset = @data.photoset_layout
29
18
  @keep_tree = keep_tree.nil? ? false : keep_tree
30
19
  @changed = false
31
20
  @saved = 0
32
- data = nil
21
+ @comment = @data.caption
22
+
23
+ # Direct map
24
+ @id = @data.id
25
+ @reblog_key = @data.reblog_key
26
+ @state = @data.state
27
+ @summary = @data.summary
28
+ @tags = @data.tags
29
+
30
+ make_accessors(instance_variables)
33
31
  end
34
32
 
35
33
  # String of post data
@@ -82,7 +80,7 @@ module DK
82
80
  # @param simulate [Bool] Simulate Action?
83
81
  def delete(client:, simulate: nil)
84
82
  return 1 if simulate
85
- res = client.delete @blog_url, @id
83
+ res = client.delete @blog_url, id
86
84
  @changed = true if res['id']
87
85
  res['id'] ? 1 : 0
88
86
  end
@@ -93,7 +91,7 @@ module DK
93
91
  def reblog(client:, simulate: nil)
94
92
  return 1 if simulate
95
93
  client.reblog @blog_url,
96
- id: @id,
94
+ id: id,
97
95
  reblog_key: @reblog_key,
98
96
  comment: @comment
99
97
  end
@@ -105,7 +103,7 @@ module DK
105
103
  return 0 unless @changed
106
104
  return @saved = 1 if simulate
107
105
  res = client.edit @blog_url,
108
- id: @id,
106
+ id: id,
109
107
  reblog_key: @reblog_key,
110
108
  state: @state,
111
109
  attach_reblog_tree: @keep_tree,
@@ -145,6 +143,24 @@ module DK
145
143
 
146
144
  private
147
145
 
146
+ def make_accessors(keys)
147
+ for key in keys
148
+ singleton_class.class_eval { attr_accessor key.to_s.delete('@') }
149
+ end
150
+ end
151
+
152
+ def method_missing(method, *args)
153
+ if @data.respond_to?(method)
154
+ return @data.send(method) unless method.to_s.include?('=')
155
+ @data.send(method, args)
156
+ end
157
+ end
158
+
159
+ def original_image_url
160
+ return nil unless @data.photos
161
+ @data.photos.first.original_size.url unless @data.photos.empty?
162
+ end
163
+
148
164
  def process_state(state)
149
165
  return DK::DRAFT unless state
150
166
  return DK::QUEUE if state == 'queued'
@@ -82,14 +82,13 @@ module DK
82
82
  def comment_posts(options = {})
83
83
  src = source_string(options[:source])
84
84
  options[:message] = "Adding #{src} comment \'#{comment}\': "
85
- mod_count, _mod_posts = post_operation(options) do |post, _|
85
+ post_operation(options) do |post, _|
86
86
  post.replace_comment_with(@comment)
87
87
  post.generate_tags(keep_tags: @keep_tags,
88
88
  add_tags: @tags,
89
89
  exclude: @comment,
90
90
  credit: @credit) if @auto_tag
91
91
  end
92
- mod_count
93
92
  end
94
93
 
95
94
  # @param options[:credit] [Bool] Give dk credit?
@@ -104,13 +103,12 @@ module DK
104
103
  def tag_posts(options)
105
104
  src = source_string(options[:source])
106
105
  options[:message] = "Tagging #{src} with #{options[:add_tags]}: "
107
- mod_count, _mod_posts = post_operation(options) do |post, _|
106
+ post_operation(options) do |post, _|
108
107
  post.generate_tags(keep_tags: @keep_tags,
109
108
  add_tags: @tags,
110
109
  exclude: @comment,
111
110
  credit: @credit) if @auto_tag
112
111
  end
113
- mod_count
114
112
  end
115
113
 
116
114
  # Determine draft data to use.
@@ -139,6 +137,7 @@ module DK
139
137
  options[:since_id] = since_id if since_id
140
138
  options[@source == :draft ? :before_id : :offset] =
141
139
  (@source == :draft ? before_id : offset) unless dashboard?
140
+ options[:type] = @type if @type
142
141
 
143
142
  result = call_source(options)
144
143
  result.is_a?(Integer) ? [] : result
@@ -8,10 +8,9 @@ module DK
8
8
  options[:message] = 'Moving Queue ~> Drafts: '
9
9
  options[:shuffle] = false
10
10
  options[:state] = DK::DRAFT
11
- mod_count, _mod_posts = post_operation(options) do |post, _|
11
+ post_operation(options) do |post, _|
12
12
  post.changed = !post.has_key_text?(@key_text)
13
13
  end
14
- mod_count
15
14
  end
16
15
  end
17
16
  end
@@ -1,3 +1,3 @@
1
1
  module DK
2
- VERSION = '0.7.0.7'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumblr_draftking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.7
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meissa Dia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-08 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tumblr_client
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '11.2'
89
+ version: '10.4'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '11.2'
96
+ version: '10.4'
97
97
  description: "\n Automate a number of tasks for your Tumblr Drafts and Queue such
98
98
  as: tagging, stripping\n previous comments and moving Drafts to your Queue. Visit
99
99
  the homepage for information on\n the latest release or to file a bug report!\n
@@ -167,4 +167,3 @@ signing_key:
167
167
  specification_version: 4
168
168
  summary: Take the hassle out of managing your Tumblr account!
169
169
  test_files: []
170
- has_rdoc: