reddit_bot 0.1.3 → 1.0.0

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: f71731b982933f8e4326cb498f7d9d26192ff106
4
- data.tar.gz: 89fd6b15ed1cb5b6140499eeebaa3700f4e511d4
3
+ metadata.gz: 305bb60aab77793751a1ebd2a999dfc657cb7dfe
4
+ data.tar.gz: 6ca3d8ebf4d31cb980ab6694034a7b2d85197cc0
5
5
  SHA512:
6
- metadata.gz: f50a272953603b3312ae011fb232253b90b32a14089ee05cdcacfbbeee2d2e615bc2c9218cfbc68e54a494489273ac759e8d36c73c9869b5f6778b062b4cd94b
7
- data.tar.gz: 7c87aeff60aa38951ffbeeacde592da865142df88b083e670e9ef9c889a813759dbcdb21d87fd8eaa1081146b7afa67b6227d08d59790bdcf21132769c6b4019
6
+ metadata.gz: 6a02edccecbdb082ac0ef432d4402564931f47ff08c1c472e8370660f492e5fefab1c4eead7c5c3ff758342adaf738d6b394a50a231fa83e07eb3bbb12d0f3ec
7
+ data.tar.gz: 0fd8bbb254327df02bc65b0c2cf77cbefd4280b66542a8c4f35771ab273c0ae657b41ffe811732fb22f6d198eeb2be8c6afec40dcc049c6f1a438fa95929fb0a
@@ -7,9 +7,15 @@ require_relative File.join "../..",
7
7
  "download_with_retry"
8
8
 
9
9
  require "reddit_bot"
10
- # RedditBot.init *File.read(File.join(Dir.pwd, "secrets")).split, ignore_captcha: true
11
- RedditBot.init *File.read("secrets").split, ignore_captcha: true
10
+
11
+ if RedditBot::VERSION <= "0.1.3"
12
+
13
+ RedditBot.init *File.read("secrets").split, ignore_captcha: true
14
+
15
+ end
12
16
 
13
17
  require_relative File.join "../..",
14
18
  *(".." if ENV["LOGNAME"] == "nakilon"),
15
19
  "awsstatus/2.rb"
20
+
21
+ require "yaml"
@@ -8,24 +8,24 @@ require "json"
8
8
 
9
9
 
10
10
  module RedditBot
11
- VERSION = "0.1.3"
11
+ VERSION = "1.0.0"
12
12
 
13
- class << self
13
+ class Bot
14
14
 
15
- attr_accessor :token_cached
16
- attr_accessor :username
17
- attr_accessor :iden_and_captcha
18
- attr_accessor :ignore_captcha
19
- attr_accessor :secrets
20
-
21
- def init *secrets, **kwargs
22
- @secrets = secrets
23
- kwargs
15
+ def initialize secrets, **kwargs
16
+ @secrets = secrets.values_at *%i{ client_id client_secret password login }
24
17
  @ignore_captcha = kwargs[:ignore_captcha]
25
18
  end
26
19
 
27
- def json mtd, url, form = []
28
- response = JSON.parse resp_with_token mtd, url, Hash[form].merge({api_type: "json"})
20
+ # attr_accessor :token_cached
21
+ # attr_accessor :username
22
+ # attr_accessor :iden_and_captcha
23
+ # attr_accessor :ignore_captcha
24
+ # attr_accessor :secrets
25
+
26
+ def json mtd, url, _form = []
27
+ form = Hash[_form]
28
+ response = JSON.parse resp_with_token mtd, url, form.merge({api_type: "json"})
29
29
  if response.is_a?(Hash) && response["json"] # for example, flairlist.json and {"error": 403} do not have it
30
30
  puts "ERROR OCCURED on #{[mtd, url]}" unless response["json"]["errors"].empty?
31
31
  # pp response["json"]
@@ -34,10 +34,10 @@ module RedditBot
34
34
  case error
35
35
  when "ALREADY_SUB" ; puts "was rejected by moderator if you didn't see in dups"
36
36
  when "BAD_CAPTCHA" ; update_captcha
37
- json mtd, url, form.concat([
38
- ["iden", @iden_and_captcha[0]],
39
- ["captcha", @iden_and_captcha[1]],
40
- ]) unless @ignore_captcha
37
+ json mtd, url, form.merger( {
38
+ iden: @iden_and_captcha[0],
39
+ captcha: @iden_and_captcha[1],
40
+ } ) unless @ignore_captcha
41
41
  else ; raise error
42
42
  end
43
43
  end
@@ -48,10 +48,8 @@ module RedditBot
48
48
  def wiki_edit subreddit, page, text
49
49
  json :post,
50
50
  "/r/#{subreddit}/api/wiki/edit",
51
- [
52
- ["page", page],
53
- ["content", text]
54
- ]
51
+ page: page,
52
+ content: text
55
53
  # ["previous", result["data"]["children"].last["id"]],
56
54
  end
57
55
 
@@ -60,13 +58,11 @@ module RedditBot
60
58
  def token
61
59
  return @token_cached if @token_cached
62
60
  response = JSON.parse(reddit_resp(:post,
63
- "https://www.reddit.com/api/v1/access_token",
64
- [
65
- ["grant_type", "password"],
66
- ["username", @username = @secrets[3]],
67
- ["password", @secrets[2]],
68
- ],
69
- {}, # headers
61
+ "https://www.reddit.com/api/v1/access_token", {
62
+ grant_type: "password",
63
+ username: @username = @secrets[3],
64
+ password: @secrets[2],
65
+ }, {}, # headers
70
66
  [@secrets[0], @secrets[1]],
71
67
  ))
72
68
  raise response.inspect unless @token_cached = response["access_token"]
@@ -181,13 +177,13 @@ module RedditBot
181
177
  fail response.to_hash["x-ratelimit-remaining"][0] \
182
178
  if response.to_hash["x-ratelimit-remaining"] &&
183
179
  response.to_hash["x-ratelimit-remaining"][0].size <= 2
184
- # /home/ec2-user/largeimages/bot.rb:126:in `_resp': 288 (RuntimeError)
185
- # File.write File.join(__dir__(), "temp.json"), response.body
186
- # if response.code == "401"
187
- # puts request.path
188
- # puts request.body
189
- # pp request.to_hash
190
- # end
180
+
181
+ # if response.code == "401"
182
+ # puts request.path
183
+ # puts request.body
184
+ # pp request.to_hash
185
+ # end
186
+
191
187
  response
192
188
  end
193
189
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-30 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json