ruboty-npb_report 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 165797d17829bb1614a8322acd1027896a20c426
4
+ data.tar.gz: 87894eccc6795c2d544e1a41926cac5080298a0e
5
+ SHA512:
6
+ metadata.gz: 683e39af3ce450e3b409296b19ad8afdcb4a92297b54e5db21b03cf6cdffa17f03cc2447ab24fa27dc7bacfe971a56a2e59f031cce336c6e425c6ab13de653bf
7
+ data.tar.gz: 24da5293a324d27d477952e75f2f18eb9e8b7f7fe6e66717a956bacf435ad353b2405ab1086404c00b306ae5c6bbd52743c284b24f0f2d0641094b8c4290b56d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruboty-npb_report.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 nozayasu
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # Ruboty::NpbReport
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem "ruboty-npb_report"
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruboty-npb_report
18
+
19
+ ## Usage
20
+
21
+ ruboty npb report
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
26
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ require "ruboty/npb_report/actions/npb_report"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class NpbReport < Base
6
+ on /npb report\z/, name: "npb_report", description: "show prompt report of npb"
7
+
8
+ def npb_report(message)
9
+ Ruboty::NpbReport::Actions::NpbReport.new(message).call
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require "ruboty/npb_report/version"
2
+ require "ruboty/handlers/npb_report"
3
+
4
+ module Ruboty
5
+ module NpbReport
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,97 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ module Ruboty
6
+ module NpbReport
7
+ module Actions
8
+ class NpbReport < Ruboty::Actions::Base
9
+ NPB_API_ENDPOINT = "http://botch.herokuapp.com/v0/scores/"
10
+
11
+ def call
12
+ date = Date.today
13
+ message.reply(prompt_report(date))
14
+ end
15
+
16
+ def prompt_report(date)
17
+ response = call_api(date)
18
+ body = JSON.parse(response.body)
19
+ if response.code == "200"
20
+ build_report(body["data"])
21
+ else
22
+ body["error"]["message"]
23
+ end
24
+ rescue => e
25
+ "Failed by %s" % e.message
26
+ end
27
+
28
+ def call_api(date)
29
+ uri = URI.parse("#{NPB_API_ENDPOINT}#{date.strftime("%Y%m%d")}")
30
+ http = Net::HTTP.new(uri.host, uri.port)
31
+ http.start do |req|
32
+ req.get(uri.request_uri)
33
+ end
34
+ end
35
+
36
+ def build_report(data)
37
+ ret = "プロ野球速報\n"
38
+ data.each do |game|
39
+ status = status(game["info"]["inning"])
40
+ home_team = team(game["home"]["team"])
41
+ home_score = game["home"]["score"]
42
+ away_team = team(game["away"]["team"])
43
+ away_score = game["away"]["score"]
44
+ ret += "(H)#{home_team} #{home_score} #{status} #{away_score} #{away_team}(A)\n"
45
+ end
46
+ ret
47
+ end
48
+
49
+ def status(value)
50
+ case value
51
+ when "yet"
52
+ "試合前"
53
+ when "end"
54
+ "結果"
55
+ when "stop"
56
+ "中止"
57
+ when /([0-9]{1,2})([t,b])\z/
58
+ "#{$1}回#{$2 == "t" ? "表" : "裏"}"
59
+ else
60
+ ""
61
+ end
62
+ end
63
+
64
+ def team(value)
65
+ case value
66
+ when "G"
67
+ "巨人"
68
+ when "T"
69
+ "阪神"
70
+ when "D"
71
+ "中日"
72
+ when "YS"
73
+ "ヤクルト"
74
+ when "C"
75
+ "広島"
76
+ when "DB"
77
+ "DeNA"
78
+ when "H"
79
+ "ソフトバンク"
80
+ when "F"
81
+ "日本ハム"
82
+ when "BF"
83
+ "オリックス"
84
+ when "M"
85
+ "ロッテ"
86
+ when "E"
87
+ "楽天"
88
+ when "L"
89
+ "西武"
90
+ else
91
+ ""
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module NpbReport
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ruboty/npb_report/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-npb_report"
8
+ spec.version = Ruboty::NpbReport::VERSION
9
+ spec.authors = ["nozayasu"]
10
+ spec.email = ["84norin@gmail.com"]
11
+ spec.summary = "The prompt report of npb via informal api"
12
+ spec.homepage = "https://github.com/nozayasu/ruboty-npb_report"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "ruboty"
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-npb_report
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nozayasu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - 84norin@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ruboty/handlers/npb_report.rb
68
+ - lib/ruboty/npb_report.rb
69
+ - lib/ruboty/npb_report/actions/npb_report.rb
70
+ - lib/ruboty/npb_report/version.rb
71
+ - ruboty-npb_report.gemspec
72
+ homepage: https://github.com/nozayasu/ruboty-npb_report
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.8
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: The prompt report of npb via informal api
96
+ test_files: []