ruboty-ragoon 0.3.1 → 0.4.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: a20d4b68a5e247bc9c10e729cdbabca486e71803
4
- data.tar.gz: 2a8399ac7603ea269171ad5be7b925bb350924d9
3
+ metadata.gz: b533e41028a40a84be238a9e7afc689f68fabc5c
4
+ data.tar.gz: aa714ff277ee2c8ab6440dfcac6876b7928625c7
5
5
  SHA512:
6
- metadata.gz: 584f736b7169fb1f3a78ee22379dc0ce3b7cee5a2b5a6463c7d1dd9828ac28f3aab90259e236e73cd2989997e4f77cea8e6b45203a52b4e94cce7b804ab324d2
7
- data.tar.gz: 63295f8b0aa264d242a8ba8729e9b5cfd933f1991db56398c1a5fbe14adbcf9ddc13f6048aef3ffa03af7353ef913e285155c2bd7b2be521ed45f3c62ffdcf2f
6
+ metadata.gz: 81d9eb366380ebe52f289cbae5f3465554ab9941d3c9a0d1ac35a99969aff592ad97594581f9aba69a5975288ccac764aaa95bc05bb3cb4a5ed63a5feada28ed
7
+ data.tar.gz: fdc12b1edf2ff7a373e2e622ec0a16b0b8bc9f3cb7d2f2bcc2ed0d862afd647f4ca46f906ded8494f2f0fc42ca5cda63ae5e3bd8519142c59036dd4a0a1de951
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.2.3
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ruboty::Ragoon
2
2
 
3
+ [![Build Status](https://travis-ci.org/kwappa/ruboty-ragoon.svg)](https://travis-ci.org/kwappa/ruboty-ragoon)
4
+
3
5
  [Ragoon](https://github.com/kwappa/ragoon) handler for [Ruboty](https://github.com/r7kamura/ruboty)
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ desc 'Run test_unit based test'
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ t.test_files = Dir['test/**/test_*.rb']
10
+ t.verbose = true
11
+ end
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruboty/ragoon'
5
+
6
+ require 'pry'
7
+ Pry.start
@@ -0,0 +1,29 @@
1
+ module Ruboty::Actions::Ragoon
2
+ class Event < ::Ruboty::Actions::Base
3
+ include ::Ruboty::Actions::Ragoon
4
+
5
+ def call
6
+ target_date = parse_date(message[:date])
7
+ events = ::Ruboty::Ragoon::Event.new(target_date)
8
+ message.reply(events.render(private: private?))
9
+ end
10
+
11
+ private
12
+
13
+ def parse_date(date)
14
+ date = date.strip.downcase
15
+ case date
16
+ when 'today'
17
+ Date.today
18
+ when 'tomorrow'
19
+ Date.today + 1
20
+ when 'yesterday'
21
+ Date.today - 1
22
+ else
23
+ Date.parse(date)
24
+ end
25
+ rescue
26
+ Date.today
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Ruboty::Actions::Ragoon
2
+ class Notification < ::Ruboty::Actions::Base
3
+ include ::Ruboty::Actions::Ragoon
4
+
5
+ def call
6
+ notifications = ::Ruboty::Ragoon::Notification.new(message.robot.brain)
7
+ notifications.retrieve
8
+ unless notifications.empty?
9
+ reply = [":new: #{notifications.unread_count}件の新着通知があります #{notification_url}"]
10
+
11
+ if private?
12
+ reply += notifications.list.find_all(&:unread).map(&:format)
13
+ end
14
+
15
+ message.reply(reply.join("\n"))
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def notification_url
22
+ "#{::Ragoon::garoon_endpoint.gsub(/\?.*\Z/, '')}/notification/index"
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  module Ruboty
2
2
  module Actions
3
- module Helpers
3
+ module Ragoon
4
4
  def private?
5
5
  adapter = message.original[:robot].send(:adapter)
6
6
  return false unless adapter.private_methods.include?(:user_info)
@@ -5,11 +5,11 @@ module Ruboty
5
5
  on(/grn notice/, name: 'notification', description: 'show new notification from garoon')
6
6
 
7
7
  def schedule(message)
8
- ::Ruboty::Actions::Event.new(message).call
8
+ ::Ruboty::Actions::Ragoon::Event.new(message).call
9
9
  end
10
10
 
11
11
  def notification(message)
12
- ::Ruboty::Actions::Notification.new(message).call
12
+ ::Ruboty::Actions::Ragoon::Notification.new(message).call
13
13
  end
14
14
  end
15
15
  end
@@ -1,24 +1,38 @@
1
1
  module Ruboty
2
2
  module Ragoon
3
3
  class Notification
4
- attr_reader :list
4
+ attr_reader :list, :brain
5
5
 
6
- def initialize
7
- retrieve
6
+ def initialize(brain)
7
+ @brain = brain
8
8
  end
9
9
 
10
10
  def retrieve
11
- @list = ::Ragoon::Services::Notification.new.retrieve.map { |data| Item.new(data) }
11
+ new_notifications = ::Ragoon::Services::Notification.new.retrieve
12
+ .map { |data| Item.new(data) }
13
+ .find_all { |item| item.unread }
14
+
15
+ new_notification_ids = new_notifications.map(&:id)
16
+ ids_to_notify = not_notified_ids(new_notification_ids)
17
+
18
+ @list = new_notifications.find_all { |n| ids_to_notify.include?(n.id) }
12
19
  end
13
20
 
14
21
  def unread_count
15
- @list.count { |item| item.unread }
22
+ @list.count
16
23
  end
17
24
 
18
25
  def empty?
19
26
  unread_count == 0
20
27
  end
21
28
 
29
+ def not_notified_ids(new_notification_ids)
30
+ notified_ids = @brain.data['notification_notified_ids'] || []
31
+ notified_ids &= new_notification_ids
32
+ @brain.data['notification_notified_ids'] = notified_ids + new_notification_ids
33
+ new_notification_ids - notified_ids
34
+ end
35
+
22
36
  class Item
23
37
  attr_accessor :id, :module_type, :module_icon, :unread, :recieved_at, :subject, :url
24
38
 
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Ragoon
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
data/lib/ruboty/ragoon.rb CHANGED
@@ -5,9 +5,9 @@ require 'ruboty/ragoon/template'
5
5
  require 'ruboty/ragoon/event'
6
6
  require 'ruboty/ragoon/notification'
7
7
  require 'ruboty/ragoon/version'
8
- require 'ruboty/actions/helpers'
9
- require 'ruboty/actions/event'
10
- require 'ruboty/actions/notification'
8
+ require 'ruboty/actions/ragoon'
9
+ require 'ruboty/actions/ragoon/event'
10
+ require 'ruboty/actions/ragoon/notification'
11
11
  require 'ruboty/handlers/ragoon'
12
12
  require 'tilt'
13
13
  require 'tilt/erb'
@@ -24,4 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.10'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'test-unit'
29
+ spec.add_development_dependency 'test-unit-rr'
27
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-ragoon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIOYA, Hiromu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
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: test-unit
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: test-unit-rr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description: ruboty handlers to use ragoon
84
126
  email:
85
127
  - kwappa.856@gmail.com
@@ -88,13 +130,15 @@ extensions: []
88
130
  extra_rdoc_files: []
89
131
  files:
90
132
  - ".gitignore"
133
+ - ".travis.yml"
91
134
  - Gemfile
92
135
  - LICENSE.txt
93
136
  - README.md
94
137
  - Rakefile
95
- - lib/ruboty/actions/event.rb
96
- - lib/ruboty/actions/helpers.rb
97
- - lib/ruboty/actions/notification.rb
138
+ - bin/console
139
+ - lib/ruboty/actions/ragoon.rb
140
+ - lib/ruboty/actions/ragoon/event.rb
141
+ - lib/ruboty/actions/ragoon/notification.rb
98
142
  - lib/ruboty/handlers/ragoon.rb
99
143
  - lib/ruboty/ragoon.rb
100
144
  - lib/ruboty/ragoon/config.rb
@@ -1,31 +0,0 @@
1
- module Ruboty
2
- module Actions
3
- class Event < ::Ruboty::Actions::Base
4
- include ::Ruboty::Actions::Helpers
5
-
6
- def call
7
- target_date = parse_date(message[:date])
8
- events = ::Ruboty::Ragoon::Event.new(target_date)
9
- message.reply(events.render(private: private?))
10
- end
11
-
12
- private
13
-
14
- def parse_date(date)
15
- date = date.strip.downcase
16
- case date
17
- when 'today'
18
- Date.today
19
- when 'tomorrow'
20
- Date.today + 1
21
- when 'yesterday'
22
- Date.today - 1
23
- else
24
- Date.parse(date)
25
- end
26
- rescue
27
- Date.today
28
- end
29
- end
30
- end
31
- end
@@ -1,26 +0,0 @@
1
- module Ruboty
2
- module Actions
3
- class Notification < ::Ruboty::Actions::Base
4
- include ::Ruboty::Actions::Helpers
5
-
6
- def call
7
- notifications = ::Ruboty::Ragoon::Notification.new
8
- unless notifications.empty?
9
- reply = [":new: #{notifications.unread_count}件の新着通知があります #{notification_url}"]
10
-
11
- if private?
12
- reply += notifications.list.find_all(&:unread).map(&:format)
13
- end
14
-
15
- message.reply(reply.join("\n"))
16
- end
17
- end
18
-
19
- private
20
-
21
- def notification_url
22
- "#{::Ragoon::garoon_endpoint.gsub(/\?.*\Z/, '')}/notification/index"
23
- end
24
- end
25
- end
26
- end