ruboty-sanfrecce 0.1.0

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: c1c1ddbd95460fc2dce4b5f529c5b812ba2696cd
4
+ data.tar.gz: 327d9ebbc0725ef90bcc97e3bf85af67cc9e54f9
5
+ SHA512:
6
+ metadata.gz: c11f059be0bafef60328f26e2e3f990bc51b1666ef081c9786edbd9c1dc4ad293a22845d2ca9c165c4c6fd613e720c5a110056619872fa902aafb18e66ccd599
7
+ data.tar.gz: 1462e68728ea13630a2b0c0145e8f07c18d5172d440445cce889ff670bcf7cc6f1cc78e1ffa2e65c86c976db8e263cd3c86c695ffc894754f9a0fb938bd069a4
data/.gitignore ADDED
@@ -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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.4
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'google-api-client', '~> 0.8.6'
6
+ gem 'dotenv'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 gennei
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.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Ruboty::Sanfrecce
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/sanfrecce`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-sanfrecce'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-sanfrecce
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruboty-sanfrecce. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/sanfrecce"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require 'ruboty/sanfrecce/client'
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class Sanfrecce < Base
6
+ on /next game/, name: 'next_game', description: '直近の試合取得する'
7
+ on /last game/, name: 'last_game', description: '直近最後の試合を取得する'
8
+
9
+ def next_game(message)
10
+ message.reply(Ruboty::Sanfrecce::Client.new.next_game)
11
+ end
12
+
13
+ def last_game(message)
14
+ message.reply(Ruboty::Sanfrecce::Client.new.last_game)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require "ruboty/sanfrecce/version"
2
+ require "ruboty/handlers/sanfrecce"
3
+
4
+ module Ruboty
5
+ module Sanfrecce
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,68 @@
1
+ require 'dotenv'
2
+ require 'google/api_client'
3
+ require 'pp'
4
+
5
+ module Ruboty
6
+ module Sanfrecce
7
+ class Client
8
+
9
+ def initialize
10
+ load_env
11
+ @client = Google::APIClient.new(:application_name => '')
12
+ @client.authorization = Signet::OAuth2::Client.new(
13
+ :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
14
+ :audience => 'https://accounts.google.com/o/oauth2/token',
15
+ :scope => 'https://www.googleapis.com/auth/calendar.readonly',
16
+ :issuer => ENV['ISSUER'],
17
+ :signing_key => key)
18
+
19
+ @client.authorization.fetch_access_token!
20
+ end
21
+
22
+ def next_game
23
+ items = request(DateTime.now, DateTime.now + 365)
24
+ return get_game(items.first)
25
+ end
26
+
27
+ def last_game
28
+ items = request(DateTime.now - 365, DateTime.now)
29
+ return get_game(items.last)
30
+ end
31
+
32
+ private
33
+
34
+ def key
35
+ Google::APIClient::KeyUtils.load_from_pkcs12(ENV['FILE_NAME'], ENV['SECRET_KEY'])
36
+ end
37
+
38
+ def request(min, max)
39
+
40
+ # イベント取得
41
+ cal = @client.discovered_api('calendar', 'v3')
42
+ params = {'calendarId' => ENV['CALENDAR_ID'],
43
+ 'orderBy' => 'startTime',
44
+ 'timeMax' => max,
45
+ 'timeMin' => min,
46
+ 'singleEvents' => 'True'}
47
+
48
+ result = @client.execute(:api_method => cal.events.list,
49
+ :parameters => params)
50
+ return result.data.items
51
+ end
52
+
53
+ def load_env
54
+ Dotenv.load
55
+ end
56
+
57
+ def get_game(item)
58
+ title = item.summary
59
+ time = item.start.date
60
+ unless time
61
+ time = item.start.dateTime.strftime("%Y/%m/%d %H:%M")
62
+ end
63
+
64
+ return "#{title}, #{time} KICK OFF"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Sanfrecce
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/sanfrecce/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-sanfrecce"
8
+ spec.version = Ruboty::Sanfrecce::VERSION
9
+ spec.authors = ["gennei"]
10
+ spec.email = ["sai.gennei@gmail.com"]
11
+ spec.summary = %q{Ruboty-Sanfrecce}
12
+ spec.description = %q{Sanfrecce Game Schedule}
13
+ spec.homepage = "https://github.com/gennei/ruboty-sanfrecce"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "ruboty"
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "false"
25
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-sanfrecce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gennei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-23 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
+ - !ruby/object:Gem::Dependency
56
+ name: 'false'
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Sanfrecce Game Schedule
70
+ email:
71
+ - sai.gennei@gmail.com
72
+ executables:
73
+ - console
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/ruboty/handlers/sanfrecce.rb
88
+ - lib/ruboty/sanfrecce.rb
89
+ - lib/ruboty/sanfrecce/client.rb
90
+ - lib/ruboty/sanfrecce/version.rb
91
+ - ruboty-sanfrecce.gemspec
92
+ homepage: https://github.com/gennei/ruboty-sanfrecce
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Ruboty-Sanfrecce
116
+ test_files: []