lita-amesh 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17fbccb3ed3945b0ab77db117cc3f54bffc907d55b11f0a9bc3846af97590088
4
+ data.tar.gz: 774fd4e4204ebeee8f4113d51d640528cf7082a56820a242deca523001590fab
5
+ SHA512:
6
+ metadata.gz: 06b58e6d707da3ad2e1607d4a18c133753cd13ad5d05c0a9621b64a47856fd05a6a4a15af5b1d5bb8a44702f6299266952a27a8bbac5b9af989387c875e3625d
7
+ data.tar.gz: 35d50a2cdd51e24083c1197a523e4bde0874d623bb0a8eeba1b682be1c3a841c195f42e6889000a06c1b98190721333e7b07fa406b55d83bd2ac038253722a21
@@ -0,0 +1,50 @@
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
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lita-amesh (0.0.1)
5
+ lita (>= 4.7)
6
+ mini_magick
7
+ slack-ruby-client
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ byebug (10.0.2)
18
+ coderay (1.1.2)
19
+ concurrent-ruby (1.0.5)
20
+ diff-lcs (1.3)
21
+ faraday (0.15.2)
22
+ multipart-post (>= 1.2, < 3)
23
+ faraday_middleware (0.12.2)
24
+ faraday (>= 0.7.4, < 1.0)
25
+ gli (2.17.2)
26
+ hashie (3.6.0)
27
+ http_router (0.11.2)
28
+ rack (>= 1.0.0)
29
+ url_mount (~> 0.2.1)
30
+ i18n (1.1.0)
31
+ concurrent-ruby (~> 1.0)
32
+ ice_nine (0.11.2)
33
+ lita (4.7.1)
34
+ bundler (>= 1.3)
35
+ faraday (>= 0.8.7)
36
+ http_router (>= 0.11.2)
37
+ i18n (>= 0.6.9)
38
+ ice_nine (>= 0.11.0)
39
+ multi_json (>= 1.7.7)
40
+ puma (>= 2.7.1)
41
+ rack (>= 1.5.2, < 2.0.0)
42
+ rb-readline (>= 0.5.1)
43
+ redis-namespace (>= 1.3.0)
44
+ thor (>= 0.18.1)
45
+ method_source (0.9.0)
46
+ mini_magick (4.8.0)
47
+ minitest (5.11.3)
48
+ multi_json (1.13.1)
49
+ multipart-post (2.0.0)
50
+ pry (0.11.3)
51
+ coderay (~> 1.1.0)
52
+ method_source (~> 0.9.0)
53
+ pry-byebug (3.6.0)
54
+ byebug (~> 10.0)
55
+ pry (~> 0.10)
56
+ puma (3.12.0)
57
+ rack (1.6.10)
58
+ rack-test (1.1.0)
59
+ rack (>= 1.0, < 3)
60
+ rake (12.3.1)
61
+ rb-readline (0.5.5)
62
+ redis (4.0.2)
63
+ redis-namespace (1.6.0)
64
+ redis (>= 3.0.4)
65
+ rspec (3.8.0)
66
+ rspec-core (~> 3.8.0)
67
+ rspec-expectations (~> 3.8.0)
68
+ rspec-mocks (~> 3.8.0)
69
+ rspec-core (3.8.0)
70
+ rspec-support (~> 3.8.0)
71
+ rspec-expectations (3.8.1)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.8.0)
74
+ rspec-mocks (3.8.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.8.0)
77
+ rspec-support (3.8.0)
78
+ slack-ruby-client (0.12.0)
79
+ activesupport
80
+ faraday (>= 0.9)
81
+ faraday_middleware
82
+ gli
83
+ hashie
84
+ websocket-driver
85
+ thor (0.20.0)
86
+ thread_safe (0.3.6)
87
+ tzinfo (1.2.5)
88
+ thread_safe (~> 0.1)
89
+ url_mount (0.2.1)
90
+ rack
91
+ websocket-driver (0.7.0)
92
+ websocket-extensions (>= 0.1.0)
93
+ websocket-extensions (0.1.3)
94
+
95
+ PLATFORMS
96
+ ruby
97
+
98
+ DEPENDENCIES
99
+ bundler (~> 1.3)
100
+ lita-amesh!
101
+ pry-byebug
102
+ rack-test
103
+ rake
104
+ rspec (>= 3.0.0)
105
+
106
+ BUNDLED WITH
107
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Tatsuya Hoshino
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.
@@ -0,0 +1,40 @@
1
+ # lita-amesh
2
+
3
+ lita-amesh is a handler for Lita that displays a Tokyo amesh image in a chart room.
4
+
5
+ ## Installation
6
+ Add lita-amesh to your Lita instance's Gemfile:
7
+
8
+ ``` ruby
9
+ gem "lita-amesh"
10
+ ```
11
+
12
+ And this gem requires ImageMagick or GraphicsMagick command-line tool. You can check if you have it installed by running.
13
+
14
+ ```console
15
+ $ convert -version
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ ### Required attributes
21
+
22
+ NOTE: So far this gem only supports Slack adapter.
23
+
24
+ - `config.adapters.slack.token` (String)
25
+
26
+ A token for Slack API
27
+
28
+ ## Usage
29
+
30
+ ```
31
+ Lita: amesh
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tatsuyafw/lita-amesh.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lita'
4
+
5
+ Lita.load_locales Dir[File.expand_path(
6
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
7
+ )]
8
+
9
+ require 'lita/handlers/amesh/handler.rb'
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'mini_magick'
5
+
6
+ module Lita
7
+ module Handlers
8
+ module Amesh
9
+ class Downloader
10
+ BASE_URL = 'http://tokyo-ame.jwa.or.jp/'.freeze
11
+
12
+ def self.fetch_amesh_image
13
+ new.fetch_amesh_image
14
+ end
15
+
16
+ def fetch_amesh_image
17
+ paths = [
18
+ 'map/map000.jpg',
19
+ 'map/msk000.png',
20
+ rain_gif_path
21
+ ]
22
+
23
+ # TODO: Deal with an error when an amesh image is not found.
24
+ begin
25
+ result = MiniMagick::Image.open("#{BASE_URL}/#{paths[0]}")
26
+ rescue => e
27
+ Lita.logger.error(e.message)
28
+ end
29
+
30
+ paths[1..-1].each do |path|
31
+ url = "#{BASE_URL}/#{path}"
32
+ image = MiniMagick::Image.open(url)
33
+ result = result.composite(image) do |c|
34
+ c.compose 'Over'
35
+ end
36
+ end
37
+
38
+ result
39
+ end
40
+
41
+ private
42
+
43
+ def rain_gif_path
44
+ current_time_str = Time.now.strftime("%Y%m%d%H%M")
45
+ current_time_i = current_time_str.to_i
46
+
47
+ if (current_time_i % 5).zero?
48
+ return "mesh/000/#{current_time_str}.gif"
49
+ end
50
+
51
+ current_time_i -= current_time_i % 5
52
+ "mesh/000/#{current_time_i}.gif"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lita
4
+ module Handlers
5
+ module Amesh
6
+ class Error < StandardError
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lita/handlers/amesh/downloader'
4
+ require 'lita/handlers/amesh/error'
5
+ require 'lita/handlers/amesh/uploaders/slack_uploader'
6
+
7
+ module Lita
8
+ module Handlers
9
+ module Amesh
10
+ class Handler < Lita::Handler
11
+
12
+ route(/^amesh\s*/, :amesh, command: true, help: {
13
+ "amesh" => "Display a tokyo amesh image"
14
+ })
15
+
16
+ def amesh(response)
17
+ uploader = nil
18
+
19
+ case robot.config.robot.adapter
20
+ when :slack
21
+ token = robot.config.adapters.slack.token
22
+ uploader = Uploaders::SlackUploader.new(token: token)
23
+ else
24
+ msg = "Not supported: #{robot.config.robot.adapter}"
25
+ Lita.logger.error(msg)
26
+ raise Error, msg
27
+ end
28
+
29
+ image = Downloader.fetch_amesh_image
30
+ uploader.upload_image(image.path)
31
+ end
32
+
33
+ Lita.register_handler(self)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'slack-ruby-client'
4
+ require 'time'
5
+
6
+ module Lita
7
+ module Handlers
8
+ module Amesh
9
+ module Uploaders
10
+ class SlackUploader
11
+ def initialize(token:)
12
+ Slack.configure do |config|
13
+ config.token = token
14
+ end
15
+ @client = Slack::Web::Client.new
16
+ end
17
+
18
+ def upload_image(image_path)
19
+ filename = "#{Time.now.strftime("%Y%m%d%H%M")}.jpg"
20
+
21
+ client.files_upload(
22
+ channels: '#general',
23
+ as_user: false,
24
+ file: Faraday::UploadIO.new(image_path, 'image/jpeg'),
25
+ title: 'アメッシュ',
26
+ filename: filename
27
+ )
28
+ end
29
+
30
+ private
31
+
32
+ def client
33
+ @client
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "lita-amesh"
5
+ spec.version = "0.0.1"
6
+ spec.authors = ["Tatsuya Hoshino"]
7
+ spec.email = ["tatsuya7.hoshino7@gmail.com"]
8
+ spec.description = %q{A Lita handler for displaying an image of Tokyo amesh.}
9
+ spec.summary = %q{A Lita handler for displaying an image of Tokyo amesh.}
10
+ spec.homepage = "https://github.com/tatsuyafw/lita-amesh"
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.7"
20
+ spec.add_runtime_dependency "slack-ruby-client"
21
+ spec.add_runtime_dependency "mini_magick"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "pry-byebug"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rack-test"
27
+ spec.add_development_dependency "rspec", ">= 3.0.0"
28
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ amesh:
@@ -0,0 +1,4 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Amesh, lita_handler: true do
4
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-amesh"
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
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-amesh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuya Hoshino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-04 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.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-ruby-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: mini_magick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
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: rake
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: rack-test
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.0
125
+ description: A Lita handler for displaying an image of Tokyo amesh.
126
+ email:
127
+ - tatsuya7.hoshino7@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - Gemfile.lock
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - lib/lita-amesh.rb
139
+ - lib/lita/handlers/amesh/downloader.rb
140
+ - lib/lita/handlers/amesh/error.rb
141
+ - lib/lita/handlers/amesh/handler.rb
142
+ - lib/lita/handlers/amesh/uploaders/slack_uploader.rb
143
+ - lita-amesh.gemspec
144
+ - locales/en.yml
145
+ - spec/lita/handlers/amesh_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: https://github.com/tatsuyafw/lita-amesh
148
+ licenses:
149
+ - MIT
150
+ metadata:
151
+ lita_plugin_type: handler
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.7.6
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: A Lita handler for displaying an image of Tokyo amesh.
172
+ test_files:
173
+ - spec/lita/handlers/amesh_spec.rb
174
+ - spec/spec_helper.rb