kynigos 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/kynigos.rb +69 -0
  3. metadata +115 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 18bd7e0760126b565fb769c7d8b45608dae6adf8
4
+ data.tar.gz: 9d6b1c0cf59c3bd4fddfe3dbe9b0cd7018683c41
5
+ SHA512:
6
+ metadata.gz: 2bd5ecd223a755ea191790cee8e3a88f301eccfd8046f040fed7abe6ec26be467b60e47f2173d8b01695abbdb40264194847affda6a6fc3c08508f02ed8566d1
7
+ data.tar.gz: 4462c200e81a17e5d3653d3639c8763059948db30e6028762e08cc83a17e16c57d531f5227a89a51d27a97dc07326b288f0d198613ac9e5a38c8a4fda11569c7
data/lib/kynigos.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'snoo'
2
+ require 'pry'
3
+ class Kynigos
4
+
5
+ attr_reader :username, :password, :client
6
+ def initialize(params)
7
+ @username = params.fetch(:username)
8
+ @password = params.fetch(:password)
9
+ @client = Snoo::Client.new
10
+ client.log_in username, password
11
+ end
12
+
13
+ #send a message to specified reddit user with urls of
14
+ #specific listings that match the specified keywords
15
+ #@params to => reddit user
16
+ #@params keywords => array of words to search for
17
+ #@params sub => subreddit to search in
18
+ def send_prize to, keywords, sub
19
+ client.send_pm to, title, format_body(keywords, sub)
20
+ end
21
+
22
+ def title
23
+ "Hunt from #{Time.now.strftime("%b. %e, %Y %I:%M%p %Z")}"
24
+ end
25
+
26
+ #return the past 100 listings in the subreddit
27
+ #@params sub => subreddit
28
+ def get_listings sub
29
+ client.get_listing({
30
+ subreddit: sub,
31
+ page: 'new',
32
+ limit: 100
33
+ })
34
+ end
35
+
36
+ #return title and url of listings in subreddit
37
+ #@params sub => subreddit
38
+ def clean_up_listings sub
39
+ get_listings(sub)["data"]["children"].map do |listing|
40
+ {
41
+ title: listing["data"]["title"],
42
+ url: listing["data"]["permalink"]
43
+ }
44
+ end
45
+ end
46
+
47
+ #search through listings in subreddit for keywords
48
+ #return listings with keywords
49
+ #@params words => keywords
50
+ #@params sub => subreddit
51
+ def hunt_for words, sub
52
+ clean_up_listings(sub).select do |title|
53
+ title if words.map do |word|
54
+ title[:title].include?(word)
55
+ end.include? true
56
+ end
57
+ end
58
+
59
+ #return urls of listings after search
60
+ #@params keywords => keywords
61
+ #@params sub => subreddit
62
+ def format_body keywords, sub
63
+ words = [keywords.map(&:split)].flatten
64
+ hunt_for(words, sub).map do |prize|
65
+ prize[:url]
66
+ end.join("\n")
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kynigos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vincent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: snoo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Gem for finding specific threads in reddit
84
+ email:
85
+ - vinyoodles@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/kynigos.rb
91
+ homepage:
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Find unique threads and links in reddit
115
+ test_files: []