lita-amesh 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17fbccb3ed3945b0ab77db117cc3f54bffc907d55b11f0a9bc3846af97590088
4
- data.tar.gz: 774fd4e4204ebeee8f4113d51d640528cf7082a56820a242deca523001590fab
3
+ metadata.gz: e5f6ebaaf147fb5ab813fe809b7ccd24a1775c00aeac7c27b76095c0f1aa515a
4
+ data.tar.gz: 893657fc143c61a696fae224a8f41816a3514bc3e9aede15a9b918a13c3deeb9
5
5
  SHA512:
6
- metadata.gz: 06b58e6d707da3ad2e1607d4a18c133753cd13ad5d05c0a9621b64a47856fd05a6a4a15af5b1d5bb8a44702f6299266952a27a8bbac5b9af989387c875e3625d
7
- data.tar.gz: 35d50a2cdd51e24083c1197a523e4bde0874d623bb0a8eeba1b682be1c3a841c195f42e6889000a06c1b98190721333e7b07fa406b55d83bd2ac038253722a21
6
+ metadata.gz: df71d27dfa21db94163c81b162ab203b158924f749c3d78d83013a68eea0a21c7d313ad0d3b572ab58a41f016e672e1bc4a108d5f8912512daa091bc83029eba
7
+ data.tar.gz: 7ff347b1792aa22a096e565bd17cb0c684fa052df67cee1e2543f3ae8a147555cc782ed8785c97d3e3c6be4d7fe6c1517460814b81b3d08934bb1b591fa6821a
@@ -0,0 +1,40 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ parallelism: 1
5
+ docker:
6
+ - image: circleci/ruby:2.5.1
7
+ environment:
8
+ BUNDLE_JOBS: 3
9
+ BUNDLE_RETRY: 3
10
+ BUNDLE_PATH: vendor/bundle
11
+ - image: circleci/redis
12
+ steps:
13
+ - checkout
14
+ - run:
15
+ name: Which bundler?
16
+ command: bundle -v
17
+ - restore_cache:
18
+ keys:
19
+ - rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
20
+ - rails-demo-bundle-v2-
21
+ - run:
22
+ name: Bundle Install
23
+ command: bundle check || bundle install
24
+ - save_cache:
25
+ key: rails-demo-bundle-v2-{{ checksum "Gemfile.lock" }}
26
+ paths:
27
+ - vendor/bundle
28
+ - run:
29
+ name: Wait for Redis
30
+ command: dockerize -wait tcp://localhost:6379 -timeout 1m
31
+ - run:
32
+ name: Run rspec
33
+ command: |
34
+ bundle exec rspec --profile 10 \
35
+ --format RspecJunitFormatter \
36
+ --out test_results/rspec.xml \
37
+ --format progress \
38
+ $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
39
+ - store_test_results:
40
+ path: test_results
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lita-amesh (0.0.1)
4
+ lita-amesh (0.1.0)
5
5
  lita (>= 4.7)
6
6
  mini_magick
7
7
  slack-ruby-client
@@ -75,6 +75,8 @@ GEM
75
75
  diff-lcs (>= 1.2.0, < 2.0)
76
76
  rspec-support (~> 3.8.0)
77
77
  rspec-support (3.8.0)
78
+ rspec_junit_formatter (0.4.1)
79
+ rspec-core (>= 2, < 4, != 2.12.0)
78
80
  slack-ruby-client (0.12.0)
79
81
  activesupport
80
82
  faraday (>= 0.9)
@@ -102,6 +104,7 @@ DEPENDENCIES
102
104
  rack-test
103
105
  rake
104
106
  rspec (>= 3.0.0)
107
+ rspec_junit_formatter
105
108
 
106
109
  BUNDLED WITH
107
110
  1.16.1
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # lita-amesh
2
2
 
3
+ [![CircleCI Status](https://circleci.com/gh/tatsuyafw/lita-amesh/tree/master.svg?style=svg)](https://circleci.com/gh/tatsuyafw/lita-amesh/tree/master)
4
+
3
5
  lita-amesh is a handler for Lita that displays a Tokyo amesh image in a chart room.
4
6
 
5
7
  ## Installation
@@ -19,7 +21,7 @@ $ convert -version
19
21
 
20
22
  ### Required attributes
21
23
 
22
- NOTE: So far this gem only supports Slack adapter.
24
+ NOTE: As of now, this gem only supports the Slack adapter.
23
25
 
24
26
  - `config.adapters.slack.token` (String)
25
27
 
@@ -8,31 +8,22 @@ module Lita
8
8
  module Amesh
9
9
  class Downloader
10
10
  BASE_URL = 'http://tokyo-ame.jwa.or.jp/'.freeze
11
+ TIME_FORMAT = '%Y%m%d%H%M'
11
12
 
12
13
  def self.fetch_amesh_image
13
14
  new.fetch_amesh_image
14
15
  end
15
16
 
16
17
  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)
18
+ result = MiniMagick::Image.open("#{BASE_URL}/map/map000.jpg")
19
+ image = MiniMagick::Image.open("#{BASE_URL}/map/msk000.png")
20
+ result = result.composite(image) do |c|
21
+ c.compose 'Over'
28
22
  end
29
23
 
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
24
+ rain_gif = fetch_rain_gif
25
+ result = result.composite(rain_gif) do |c|
26
+ c.compose 'Over'
36
27
  end
37
28
 
38
29
  result
@@ -40,16 +31,39 @@ module Lita
40
31
 
41
32
  private
42
33
 
43
- def rain_gif_path
44
- current_time_str = Time.now.strftime("%Y%m%d%H%M")
34
+ def fetch_rain_gif
35
+ image = nil
36
+ time = target_time
37
+ begin
38
+ image = MiniMagick::Image.open("#{BASE_URL}/#{rain_gif_path(time)}")
39
+ rescue OpenURI::HTTPError => e
40
+ Lita.logger.error(e.message)
41
+ # Fetch 5 minutes ago image as a fallback image
42
+ time = five_minutes_ago(time)
43
+ image = MiniMagick::Image.open("#{BASE_URL}/#{rain_gif_path(time)}")
44
+ end
45
+
46
+ image
47
+ end
48
+
49
+ def rain_gif_path(time)
50
+ t = time.strftime(TIME_FORMAT)
51
+ "mesh/000/#{t}.gif"
52
+ end
53
+
54
+ def target_time
55
+ current_time = Time.now
56
+ current_time_str = current_time.strftime(TIME_FORMAT)
45
57
  current_time_i = current_time_str.to_i
46
58
 
47
- if (current_time_i % 5).zero?
48
- return "mesh/000/#{current_time_str}.gif"
49
- end
59
+ return current_time if (current_time_i % 5).zero?
60
+
61
+ t = current_time_i - (current_time_i % 5)
62
+ Time.parse(t.to_s)
63
+ end
50
64
 
51
- current_time_i -= current_time_i % 5
52
- "mesh/000/#{current_time_i}.gif"
65
+ def five_minutes_ago(time)
66
+ time - 5 * 60
53
67
  end
54
68
  end
55
69
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "lita-amesh"
5
- spec.version = "0.0.1"
5
+ spec.version = "0.1.0"
6
6
  spec.authors = ["Tatsuya Hoshino"]
7
7
  spec.email = ["tatsuya7.hoshino7@gmail.com"]
8
8
  spec.description = %q{A Lita handler for displaying an image of Tokyo amesh.}
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rack-test"
27
27
  spec.add_development_dependency "rspec", ">= 3.0.0"
28
+ spec.add_development_dependency "rspec_junit_formatter"
28
29
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Lita::Handlers::Amesh::Downloader do
6
+ describe '#target_time' do
7
+ let(:downloader) { described_class.new }
8
+ subject { downloader.send(:target_time) }
9
+
10
+ before do
11
+ allow(Time).to receive(:now).and_return(current_time)
12
+ end
13
+
14
+ context 'when a current time is divisible by 5' do
15
+ let(:current_time) { Time.new(2018, 1, 1, 0, 0) }
16
+
17
+ it 'returns an url path based on a current time' do
18
+ expect(subject).to eq(current_time)
19
+ end
20
+ end
21
+
22
+ context 'when a current time is not divisible by 5' do
23
+ let(:current_time) { Time.new(2018, 1, 1, 0, 1) }
24
+
25
+ it 'returns an url path based on the time that is divisible by 5 before a current time' do
26
+ expect(subject).to eq(Time.new(2018, 1, 1, 0, 0))
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#five_minutes_ago' do
32
+ let(:downloader) { described_class.new }
33
+
34
+ it 'returns a 5 minutes ago image of given time' do
35
+ time = Time.new(2018, 1, 1, 0, 0)
36
+ actual = downloader.send(:five_minutes_ago, time)
37
+ expect(actual).to eq(Time.new(2017, 12, 31, 23, 55))
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Lita::Handlers::Amesh::Handler, lita_handler: true do
6
+ it { is_expected.to route_command('amesh').to(:amesh) }
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-amesh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Hoshino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
11
+ date: 2018-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.0.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec_junit_formatter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: A Lita handler for displaying an image of Tokyo amesh.
126
140
  email:
127
141
  - tatsuya7.hoshino7@gmail.com
@@ -129,6 +143,7 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
146
+ - ".circleci/config.yml"
132
147
  - ".gitignore"
133
148
  - Gemfile
134
149
  - Gemfile.lock
@@ -142,7 +157,8 @@ files:
142
157
  - lib/lita/handlers/amesh/uploaders/slack_uploader.rb
143
158
  - lita-amesh.gemspec
144
159
  - locales/en.yml
145
- - spec/lita/handlers/amesh_spec.rb
160
+ - spec/lita/handlers/amesh/downloader_spec.rb
161
+ - spec/lita/handlers/amesh/handler_spec.rb
146
162
  - spec/spec_helper.rb
147
163
  homepage: https://github.com/tatsuyafw/lita-amesh
148
164
  licenses:
@@ -170,5 +186,6 @@ signing_key:
170
186
  specification_version: 4
171
187
  summary: A Lita handler for displaying an image of Tokyo amesh.
172
188
  test_files:
173
- - spec/lita/handlers/amesh_spec.rb
189
+ - spec/lita/handlers/amesh/downloader_spec.rb
190
+ - spec/lita/handlers/amesh/handler_spec.rb
174
191
  - spec/spec_helper.rb
@@ -1,4 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Lita::Handlers::Amesh, lita_handler: true do
4
- end