redd 0.8.6 → 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9143e5925475c5e0143ac3aacb6c10666986c18f
4
- data.tar.gz: 6c7be0b33836c21aa36765937795cabe6c7aa8e6
3
+ metadata.gz: d4fbf6feb86c64f8456437def7264e516773734c
4
+ data.tar.gz: cd942825bb17e6d1d4c2f2d28085b988e431b19e
5
5
  SHA512:
6
- metadata.gz: 541cffb6f3ad7b15b2d1560b30ae400d7d9db898290c7a252ee9ad2c7bae3d1c8aa9591d202e9f32190f28e0fe37539b33443a0d8f5adccc0c3af8aa84f5def4
7
- data.tar.gz: 707d66c874d7c74fbbe1710d52247f5dbc4e5c5e88fc4ab66b7c739075a30b4cfeb28d59965d762779b61d3bd9ca323432b6e543316f24237f916b694612d12c
6
+ metadata.gz: 80156b77d8cda4722f400638911efb77f181d88d936e0ff1bb4dc759fb3ab1523364b8d2be243cb3ea62405178d0136be244755efdaa1150ee0f7629cc05fb98
7
+ data.tar.gz: 5d40f20d64969486c457457c15d2110e87c4e4adc58da2c05215d55b9a4a73c5901ed23443f9b544b1a684febdd5ce7bffc3a28ba5d7fb51ae0cbadbe02e4e45
@@ -33,6 +33,9 @@ module Redd
33
33
  # @option options [Hash] :body the direct body contents
34
34
  # @return [Response] the response
35
35
  def request(verb, path, options = {})
36
+ # Uncomment if desperate
37
+ # puts "#{verb} #{path}: #{options}"
38
+
36
39
  response = connection.request(verb, path, **options)
37
40
  Response.new(response.status.code, response.headers, response.body.to_s)
38
41
  end
@@ -54,7 +54,8 @@ module Redd
54
54
  # Stream newly submitted posts.
55
55
  def post_stream(**params, &block)
56
56
  params[:limit] ||= 100
57
- stream = Utilities::Stream.new do |before|
57
+ stream = Utilities::Stream.new do |previous|
58
+ before = previous ? previous.first.name : nil
58
59
  listing(:new, params.merge(before: before))
59
60
  end
60
61
  block_given? ? stream.stream(&block) : stream.enum_for(:stream)
@@ -63,7 +64,8 @@ module Redd
63
64
  # Stream newly submitted comments.
64
65
  def comment_stream(**params, &block)
65
66
  params[:limit] ||= 100
66
- stream = Utilities::Stream.new do |before|
67
+ stream = Utilities::Stream.new do |previous|
68
+ before = previous ? previous.first.name : nil
67
69
  listing(:comments, params.merge(before: before))
68
70
  end
69
71
  block_given? ? stream.stream(&block) : stream.enum_for(:stream)
@@ -15,11 +15,13 @@ module Redd
15
15
  @client.post('/api/remove', id: get_attribute(:name), spam: spam)
16
16
  end
17
17
 
18
- # Distinguish a link or comment with a sigil to show that it has
19
- # been created by a moderator.
18
+ # Distinguish a link or comment with a sigil to show that it has been created by a moderator.
20
19
  # @param how [:yes, :no, :admin, :special] how to distinguish the thing
21
- def distinguish(how = :yes)
22
- @client.post('/api/distinguish', id: get_attribute(:name), how: how)
20
+ # @param sticky [Boolean] (for comments) whether to sticky the comment to the top
21
+ def distinguish(how = :yes, sticky: nil)
22
+ params = { id: get_attribute(:name), how: how }
23
+ params[:sticky] = sticky unless sticky.nil?
24
+ @client.post('/api/distinguish', params)
23
25
  end
24
26
 
25
27
  # Remove the sigil that shows a thing was created by a moderator.
@@ -154,7 +154,8 @@ module Redd
154
154
  # Stream newly submitted posts.
155
155
  def post_stream(**params, &block)
156
156
  params[:limit] ||= 100
157
- stream = Utilities::Stream.new do |before|
157
+ stream = Utilities::Stream.new do |previous|
158
+ before = previous ? previous.first.name : nil
158
159
  listing(:new, params.merge(before: before))
159
160
  end
160
161
  block_given? ? stream.stream(&block) : stream.enum_for(:stream)
@@ -163,7 +164,8 @@ module Redd
163
164
  # Stream newly submitted comments.
164
165
  def comment_stream(**params, &block)
165
166
  params[:limit] ||= 100
166
- stream = Utilities::Stream.new do |before|
167
+ stream = Utilities::Stream.new do |previous|
168
+ before = previous ? previous.first.name : nil
167
169
  listing(:comments, params.merge(before: before))
168
170
  end
169
171
  block_given? ? stream.stream(&block) : stream.enum_for(:stream)
@@ -403,6 +405,19 @@ module Redd
403
405
  remove_relationship(type: 'wikibanned', name: user.name)
404
406
  end
405
407
 
408
+ # Upload a subreddit-specific image.
409
+ # @param file [String, IO] the image file to upload
410
+ # @param image_type ['jpg', 'png'] the image type
411
+ # @param upload_type ['img', 'header', 'icon', 'banner'] where to upload the image
412
+ # @param image_name [String] the name of the image (if upload_type is 'img')
413
+ # @return [String] the url of the uploaded file
414
+ def upload_image(file:, image_type:, upload_type:, image_name: nil)
415
+ file_data = HTTP::FormData::File.new(file)
416
+ params = { img_type: image_type, upload_type: upload_type, file: file_data }
417
+ params[:name] = image_name if upload_type.to_s == 'img'
418
+ @client.post("/r/#{display_name}/api/upload_sr_img", params).body[:img_src]
419
+ end
420
+
406
421
  private
407
422
 
408
423
  def default_loader
@@ -55,7 +55,7 @@ module Redd
55
55
 
56
56
  # Deal with those annoying errors that come with perfect 200 status codes.
57
57
  def api_error(res)
58
- return nil unless res.is_a?(Hash) && res.body[:json] && res.body[:json][:errors] &&
58
+ return nil unless res.body.is_a?(Hash) && res.body[:json] && res.body[:json][:errors] &&
59
59
  !res.body[:json][:errors].empty?
60
60
  APIError.new(res)
61
61
  end
@@ -23,30 +23,30 @@ module Redd
23
23
  end
24
24
 
25
25
  # Create a streamer.
26
- # @yield [latest]
27
- # @yieldparam latest [String, nil] the fullname of the latest model requested
28
- # @yieldreturn [Listing] the models after the latest one
26
+ # @yield [Models::Listing]
27
+ # @yieldparam previous [Models::Listing] the result of the last request
28
+ # @yieldreturn [Models::Listing] the models after the latest one
29
29
  def initialize(&block)
30
30
  @loader = block
31
31
  @buffer = RingBuffer.new(100)
32
- @latest = nil
32
+ @previous = nil
33
33
  end
34
34
 
35
35
  # Make another request to reddit, yielding new elements.
36
36
  # @yield [element] an element from the listings returned by the loader
37
37
  def next_request
38
38
  # Get the elements from the loader before the `latest` element
39
- listing = @loader.call(@latest)
39
+ listing = @loader.call(@previous)
40
40
  # If there's nothing new to process, request again.
41
41
  return if listing.empty?
42
- # Set the latest element to the latest one to be processed.
43
- @latest = listing.first.name
44
42
  # Iterate over the new elements, oldest to newest.
45
43
  listing.reverse_each do |el|
46
44
  next if @buffer.include?(el.name)
47
45
  yield el
48
46
  @buffer.add(el.name)
49
47
  end
48
+ # Store the last successful listing
49
+ @previous = listing
50
50
  end
51
51
 
52
52
  # Loop forever, yielding the elements from the loader
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Redd
4
- VERSION = '0.8.6'
4
+ VERSION = '0.8.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http