ellen-syoboi_calendar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 76860f9b7414a8f31229cfcc572588ac51b1a714
4
+ data.tar.gz: 4d3c21a6e8ba0e35f407d69ae66c7f204172eb5e
5
+ SHA512:
6
+ metadata.gz: 37ba08772ec90e7cc41f58264c8f7cf7daa998ed7f0e157dc0d410d4b1107b00978a897810498f5f2cf8cc7929a6b1a2a6a53ec3e26daa521e41f741736fe22b
7
+ data.tar.gz: f8dd18aa078c8d408d330abdad7431fbbda2ae5b0cd67b7bc657c8a1cc7598b5627723b393b9e4a7352607d0b3b68d6fb88dadf84fcb0f3eb6d5bd1d6b35476c
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen-syoboi_calendar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # Ellen::SyoboiCalendar
2
+ Ask today's Japanese anime line-up from [cal.syoboi.jp](http://cal.syoboi.jp/).
3
+
4
+ ## Installation
5
+ ```ruby
6
+ # Gemfile
7
+ gem "ellen-syoboi_calendar"
8
+ ```
9
+
10
+ ## Usage
11
+ ```
12
+ @ellen list anime
13
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ellen/syoboi_calendar/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ellen-syoboi_calendar"
7
+ spec.version = Ellen::SyoboiCalendar::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Ask today's Japanese anime line-up from cal.syoboi.jp."
11
+ spec.homepage = "https://github.com/r7kamura/ellen-syoboi_calendar"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency "activesupport"
20
+ spec.add_dependency "ellen", ">= 0.2.0"
21
+ spec.add_dependency "syoboi_calendar", "0.2.1"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rack"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "2.14.1"
27
+ spec.add_development_dependency "webmock"
28
+ end
@@ -0,0 +1,96 @@
1
+ require "active_support/core_ext/numeric/time"
2
+ require "active_support/core_ext/time"
3
+
4
+ module Ellen
5
+ module Handlers
6
+ class SyoboiCalendar < Base
7
+ on(/list anime\z/, name: "list", description: "List today's anime")
8
+
9
+ def list(message)
10
+ message.reply(descriptions.join("\n"))
11
+ end
12
+
13
+ private
14
+
15
+ def descriptions
16
+ programs_sorted_by_started_at.map do |program|
17
+ "#{program[:started_at].strftime("%Y-%m-%d %H:%M")} #{titles_by_id[program[:title_id]][:title]} #{program[:count]}"
18
+ end
19
+ end
20
+
21
+ def client
22
+ @client ||= ::SyoboiCalendar::Client.new
23
+ end
24
+
25
+ def titles_by_id
26
+ @titles_by_id ||= titles.inject({}) do |table, title|
27
+ table.merge(title[:id] => title)
28
+ end
29
+ end
30
+
31
+ def titles
32
+ [get_titles.TitleLookupResponse.TitleItems.TitleItem].flatten.map do |title|
33
+ {
34
+ id: title.id,
35
+ title: title.Title,
36
+ short_title: title.ShortTitle,
37
+ }
38
+ end
39
+ end
40
+
41
+ def get_titles
42
+ client.titles(title_options)
43
+ end
44
+
45
+ def title_options
46
+ {
47
+ title_id: title_ids_in_programs.join(",")
48
+ }
49
+ end
50
+
51
+ def title_ids_in_programs
52
+ programs.map do |program|
53
+ program[:title_id]
54
+ end
55
+ end
56
+
57
+ def programs_sorted_by_started_at
58
+ programs.sort_by do |program|
59
+ program[:started_at]
60
+ end
61
+ end
62
+
63
+ def programs
64
+ @programs ||= [get_programs.ProgLookupResponse.ProgItems.ProgItem].flatten.map do |program|
65
+ {
66
+ count: program.Count,
67
+ channel_id: program.ChID,
68
+ sub_title: program.STSubTitle,
69
+ title_id: program.TID,
70
+ started_at: Time.parse(program.StTime),
71
+ finished_at: Time.parse(program.EdTime),
72
+ }
73
+ end
74
+ end
75
+
76
+ def get_programs
77
+ client.programs(program_options)
78
+ end
79
+
80
+ def program_options
81
+ {
82
+ played_from: played_from,
83
+ played_to: played_to,
84
+ }
85
+ end
86
+
87
+ def played_from
88
+ Time.now
89
+ end
90
+
91
+ def played_to
92
+ Time.now.end_of_day
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,5 @@
1
+ require "ellen"
2
+ require "syoboi_calendar"
3
+
4
+ require "ellen/handlers/syoboi_calendar"
5
+ require "ellen/syoboi_calendar/version"
@@ -0,0 +1,5 @@
1
+ module Ellen
2
+ module SyoboiCalendar
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,107 @@
1
+ require "spec_helper"
2
+
3
+ describe Ellen::Handlers::SyoboiCalendar do
4
+ let(:instance) do
5
+ described_class.new(robot)
6
+ end
7
+
8
+ let(:robot) do
9
+ Ellen::Robot.new
10
+ end
11
+
12
+ let(:dummy_programs_response) do
13
+ <<-EOS.strip_heredoc
14
+ <?xml version="1.0" encoding="UTF-8"?>
15
+ <ProgLookupResponse>
16
+ <ProgItems>
17
+ <ProgItem id="1">
18
+ <LastUpdate>2000-01-01 00:00:00</LastUpdate>
19
+ <PID>1</PID>
20
+ <TID>2</TID>
21
+ <StTime>2000-01-01 00:00:00</StTime>
22
+ <StOffset>0</StOffset>
23
+ <EdTime>2000-01-01 00:00:00</EdTime>
24
+ <Count>1</Count>
25
+ <SubTitle></SubTitle>
26
+ <ProgComment></ProgComment>
27
+ <Flag>9</Flag>
28
+ <Deleted>0</Deleted>
29
+ <Warn>1</Warn>
30
+ <ChID>3</ChID>
31
+ <Revision>2</Revision>
32
+ <STSubTitle></STSubTitle>
33
+ </ProgItem>
34
+ </ProgItems>
35
+ <Result>
36
+ <Code>200</Code>
37
+ <Message>
38
+ </Message>
39
+ </Result>
40
+ </ProgLookupResponse>
41
+ EOS
42
+ end
43
+
44
+ let(:dummy_titles_response) do
45
+ <<-EOS.strip_heredoc
46
+ <?xml version="1.0" encoding="UTF-8"?>
47
+ <TitleLookupResponse>
48
+ <Result>
49
+ <Code>200</Code>
50
+ <Message>
51
+ </Message>
52
+ </Result>
53
+ <TitleItems>
54
+ <TitleItem id="2">
55
+ <TID>2</TID>
56
+ <LastUpdate>2000-01-01 00:00:00</LastUpdate>
57
+ <Title>DummyTitle</Title>
58
+ <ShortTitle></ShortTitle>
59
+ <TitleYomi>ダミータイトル</TitleYomi>
60
+ <TitleEN></TitleEN>
61
+ <Comment></Comment>
62
+ <Cat>4</Cat>
63
+ <TitleFlag>0</TitleFlag>
64
+ <FirstYear>2000</FirstYear>
65
+ <FirstMonth>1</FirstMonth>
66
+ <FirstEndYear>2000</FirstEndYear>
67
+ <FirstEndMonth>1</FirstEndMonth>
68
+ <FirstCh>DummyChannel</FirstCh>
69
+ <Keywords></Keywords>
70
+ <UserPoint>6</UserPoint>
71
+ <UserPointRank>1</UserPointRank>
72
+ <SubTitles></SubTitles>
73
+ </TitleItem>
74
+ </TitleItems>
75
+ </TitleLookupResponse>
76
+ EOS
77
+ end
78
+
79
+ let(:app) do
80
+ ->(env) do
81
+ if env["QUERY_STRING"] =~ /ProgLookup/
82
+ [200, { "Content-type" => "application/xml" }, [dummy_programs_response]]
83
+ else
84
+ [200, { "Content-type" => "application/xml" }, [dummy_titles_response]]
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "#list" do
90
+ before do
91
+ stub_request(:get, /cal.syoboi.jp/).to_rack(app)
92
+ end
93
+
94
+ let(:message) do
95
+ {
96
+ body: "@ellen list anime",
97
+ from: "test",
98
+ to: "ellen",
99
+ }
100
+ end
101
+
102
+ it "replies today's anime list" do
103
+ Ellen.logger.should_receive(:info).with("2000-01-01 00:00 DummyTitle 1")
104
+ robot.receive(message)
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,10 @@
1
+ require "ellen/syoboi_calendar"
2
+ require "active_support/all"
3
+ require "rack"
4
+ require "webmock/rspec"
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen-syoboi_calendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ellen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.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.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: syoboi_calendar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.1
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.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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
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: rake
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: 2.14.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 2.14.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
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'
139
+ description:
140
+ email:
141
+ - r7kamura@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - ellen-syoboi_calendar.gemspec
152
+ - lib/ellen/handlers/syoboi_calendar.rb
153
+ - lib/ellen/syoboi_calendar.rb
154
+ - lib/ellen/syoboi_calendar/version.rb
155
+ - spec/ellen/handlers/syoboi_calendar_spec.rb
156
+ - spec/spec_helper.rb
157
+ homepage: https://github.com/r7kamura/ellen-syoboi_calendar
158
+ licenses:
159
+ - MIT
160
+ metadata: {}
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 2.2.2
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: Ask today's Japanese anime line-up from cal.syoboi.jp.
181
+ test_files:
182
+ - spec/ellen/handlers/syoboi_calendar_spec.rb
183
+ - spec/spec_helper.rb
184
+ has_rdoc: