lita-reddit-image 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 44021ae429198786e877dfb842264593cf14370871aa8b783e4f34c9ea9444da
4
+ data.tar.gz: 3beba85ced69c47d9d969c05db6e3c57f582571e94948f3a112db47fb2c20c28
5
+ SHA512:
6
+ metadata.gz: bc0164958fa0b524252efe9f600728b44bfdf0d1ad522da35f2857f235f6ff413e88eac720bd974d76890b139b51eade978c5ffb9e4ebd3232642ce48fe17134
7
+ data.tar.gz: 79745eae1e7140f3437df3cfbced982013016b4127e2bec97562aec0413cc79e0e9378a84cd7ae792f30ae3ccc54995ee293a7159e2c3af05dd0ce12bdeb197d
data/.gitignore ADDED
@@ -0,0 +1,71 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ Gemfile.lock
49
+ .ruby-version
50
+ .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
57
+ .bundle
58
+ .config
59
+ .yardoc
60
+ Gemfile.lock
61
+ InstalledFiles
62
+ _yardoc
63
+ coverage
64
+ doc/
65
+ lib/bundler/man
66
+ pkg
67
+ rdoc
68
+ spec/reports
69
+ test/tmp
70
+ test/version_tmp
71
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Maxime Gauthier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # lita-reddit-image
2
+
3
+ Lita handler for querying images from Reddit
4
+
5
+ TODO: Add a description of the plugin.
6
+
7
+ ## Installation
8
+
9
+ Add lita-reddit-image to your Lita instance's Gemfile:
10
+
11
+ ``` ruby
12
+ gem "lita-reddit-image"
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ TODO: Describe any configuration attributes the plugin exposes.
18
+
19
+ ## Usage
20
+
21
+ TODO: Describe the plugin's features and how to use them.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/reddit_image"
8
+
9
+ Lita::Handlers::RedditImage.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,80 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require 'uri'
4
+ require 'open-uri'
5
+
6
+ module Lita
7
+ module Handlers
8
+ class RedditImage < Handler
9
+
10
+ config :app_id, type: String, required: true
11
+ config :username, type: String, required: true
12
+
13
+ route(/\/r\/(?<subreddit>.+)\s(?<query>(.+))/i, :fetch, command: true, help: {
14
+ "/r/[subreddit] QUERY" => "Displays a random image from [subreddit]."
15
+ })
16
+
17
+ def fetch(response)
18
+ (subreddit, query) = response.matches.to_a.flatten
19
+
20
+ subreddit.strip!
21
+ query.strip!
22
+
23
+ json = JSON.parse(RestClient.get(reddit_url(subreddit, query), user_agent: reddit_user_agent))
24
+
25
+ json['data']['children'].each do |post|
26
+
27
+ post_title = post['data']['title']
28
+ post_url = post['data']['url']
29
+
30
+ # return if image was found
31
+ if (/[\w:]+\.(jpe?g|png|gif)/i =~ post_url)
32
+ filename = $~
33
+ return response.reply([post_title, post_url].join(": "))
34
+ end
35
+
36
+ # keep searching, but wait half a second between requests
37
+ sleep 0.5
38
+ rescue StandardError => e
39
+ Lita.logger.warn("Couldn't fetch image from Reddit: " + e.message)
40
+ end
41
+ end
42
+
43
+ protected
44
+
45
+ def reddit_url(subreddit, query)
46
+ URI.parse('https://www.reddit.com/r/' + subreddit + '/search.json?q=' + query + '&restrict_sr=on').to_s
47
+ end
48
+
49
+ def reddit_user_agent
50
+ "#{platform}:#{config.app_id}:#{version} (by /u/#{config.username})"
51
+ end
52
+
53
+ def platform
54
+ 'ruby'
55
+ end
56
+
57
+ def version
58
+ VERSION
59
+ end
60
+
61
+ private
62
+
63
+ def content_type(filename)
64
+ case filename
65
+ when /[\w:]+\.jpe?g/i
66
+ 'image/jpeg'
67
+ when /[\w:]+\.png/i
68
+ 'image/png'
69
+ when /[\w:]+\.gif/i
70
+ 'image/gif'
71
+ else
72
+ 'image/jpeg'
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ Lita.register_handler(RedditImage)
79
+ end
80
+ end
@@ -0,0 +1,9 @@
1
+ require 'lita'
2
+
3
+ module Lita
4
+ module Handlers
5
+ class RedditImage < Handler
6
+ VERSION = '0.1.0'.freeze
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require "./lib/lita/handlers/reddit_image/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "lita-reddit-image"
5
+ spec.version = Lita::Handlers::RedditImage::VERSION
6
+ spec.authors = ["Maxime 'biximilien' Gauthier"]
7
+ spec.email = ["maxime.gauthier88@gmail.com"]
8
+ spec.description = "Lita handler to fetch images from reddit."
9
+ spec.summary = "Fetch reddit images."
10
+ spec.homepage = "https://github.com/biximilien/lita-reddit-image"
11
+ spec.license = "MIT"
12
+ spec.metadata = { "lita_plugin_type" => "handler" }
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "lita", ">= 4.8"
20
+ spec.add_runtime_dependency "rest-client"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "pry-byebug"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rack-test"
26
+ spec.add_development_dependency "rspec", ">= 3.0.0"
27
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ reddit_image:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::RedditImage, lita_handler: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-reddit-image"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-reddit-image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maxime 'biximilien' Gauthier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ description: Lita handler to fetch images from reddit.
112
+ email:
113
+ - maxime.gauthier88@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-reddit-image.rb
124
+ - lib/lita/handlers/reddit_image.rb
125
+ - lib/lita/handlers/reddit_image/version.rb
126
+ - lita-reddit-image.gemspec
127
+ - locales/en.yml
128
+ - spec/lita/handlers/reddit_image_spec.rb
129
+ - spec/spec_helper.rb
130
+ - templates/.gitkeep
131
+ homepage: https://github.com/biximilien/lita-reddit-image
132
+ licenses:
133
+ - MIT
134
+ metadata:
135
+ lita_plugin_type: handler
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.2.3
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Fetch reddit images.
155
+ test_files:
156
+ - spec/lita/handlers/reddit_image_spec.rb
157
+ - spec/spec_helper.rb