ruboty-rainfall_jp 1.0.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: 3a454d3167304c43d22bc65a84892a1808ec9be0
4
+ data.tar.gz: d0d83a4ea30d504acd7666d5eff2d1d01e7b4610
5
+ SHA512:
6
+ metadata.gz: be04c8a775c9a19fa67a9349aa18ec27e4ad527de17a0642144b0b2ed535f1429abf15de8754ce6601c67a1691bfcaf87c7981d0a7d9623e3e2a608ec9e3cd79
7
+ data.tar.gz: c8ef23894f7d6cc2428dc198bf90e9663cfcae9fdaefba4e89b34698b5632a19ec061214922746dcf8460f4a8b07c8995faa67482d3dd4c09c5e84fc5adbe331
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-rainfall_jp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Shimpei Makimoto
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,50 @@
1
+ # Ruboty::RainfallJp
2
+
3
+ A Ruboty plugin to check rainfall forecast in Japan.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-rainfall_jp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-rainfall_jp
20
+
21
+ ## Usage
22
+
23
+ Use as a ruboty plugin.
24
+ It requires `YAHOO_JAPAN_APP_ID` environment variable.
25
+
26
+ ```
27
+ > ruboty tell rainfall at Kyoto
28
+ Rainfall forecast: Kyoto (135.75141900,35.01042850)
29
+ 07-18 22:15 0.0 mm/h
30
+ 07-18 22:25 0.0 mm/h
31
+ 07-18 22:35 0.0 mm/h
32
+ 07-18 22:45 0.0 mm/h
33
+ 07-18 22:55 0.0 mm/h
34
+ 07-18 23:05 0.0 mm/h
35
+ 07-18 23:15 0.0 mm/h
36
+ ```
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/makimoto/ruboty-rainfall_jp.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/rainfall_jp"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module RainfallJp
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,68 @@
1
+ require 'json'
2
+ require 'cgi'
3
+ require 'open-uri'
4
+
5
+ module Ruboty
6
+ module Handlers
7
+ class RainfallJp < Base
8
+ YAHOO_JAPAN_APP_ID = ENV['YAHOO_JAPAN_APP_ID']
9
+ DEFAULT_LOCATION = 'Ebisu'
10
+
11
+ on(
12
+ /Tell rainfall(?: (?:at|in) (?<query>.+))?/i,
13
+ name: 'rainfall_jp',
14
+ description: 'show rainfall forecast'
15
+ )
16
+
17
+ def rainfall_jp(message)
18
+ if YAHOO_JAPAN_APP_ID.nil?
19
+ raise "ENV['YAHOO_JAPAN_APP_ID'] is required for this command"
20
+ end
21
+
22
+ query = message.match_data['query'] || DEFAULT_LOCATION
23
+ geometry = fetch_coodinated_geometry(query)
24
+
25
+ if geometry.nil?
26
+ message.reply('ಠ_ಠ')
27
+ message.reply("Location '#{query}' is not found.")
28
+ return
29
+ end
30
+
31
+ result = fetch_rainfall(geometry)
32
+ message.reply("Rainfall forecast: #{query} (#{geometry})")
33
+ message.reply(result)
34
+ rescue Exception => e
35
+ message.reply('ಠ_ಠ')
36
+ message.reply(e)
37
+ message.reply(e.backtrace)
38
+ end
39
+
40
+ private
41
+
42
+ def fetch_coodinated_geometry(query)
43
+ url = "http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder?appid=#{YAHOO_JAPAN_APP_ID}&output=json&query=#{CGI.escape(query)}"
44
+ response = JSON.parse(open(url).read)
45
+ feature = response["Feature"]&.first
46
+ if feature.nil?
47
+ return nil
48
+ end
49
+ feature["Geometry"]["Coordinates"]
50
+ end
51
+
52
+ def fetch_rainfall(geometry)
53
+ url = "http://weather.olp.yahooapis.jp/v1/place\?appid\=#{YAHOO_JAPAN_APP_ID}\&output=json&coordinates\=#{geometry}"
54
+ response = JSON.parse(open(url).read)
55
+ feature = response["Feature"]&.first
56
+ if feature.nil?
57
+ return nil
58
+ end
59
+ datapoints = feature["Property"]["WeatherList"]["Weather"]
60
+ result = StringIO.new
61
+ datapoints.each do |data|
62
+ result.puts("#{Time.parse(data["Date"]).strftime("%m-%d %H:%M")} #{data["Rainfall"]} mm/h")
63
+ end
64
+ result.string
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/rainfall_jp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-rainfall_jp"
8
+ spec.version = Ruboty::RainfallJp::VERSION
9
+ spec.authors = ["Shimpei Makimoto"]
10
+ spec.email = ["makimoto@tsuyabu.in"]
11
+
12
+ spec.summary = %q{A Ruboty plugin to check rainfall forecast in Japan}
13
+ spec.homepage = "https://github.com/makimoto/ruboty-rainfall_jp"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ruboty"
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-rainfall_jp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Shimpei Makimoto
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-18 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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
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
+ - makimoto@tsuyabu.in
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/ruboty/rainfall_jp.rb
70
+ - lib/ruboty/rainfall_jp/version.rb
71
+ - ruboty-rainfall-jp.gemspec
72
+ homepage: https://github.com/makimoto/ruboty-rainfall_jp
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.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A Ruboty plugin to check rainfall forecast in Japan
96
+ test_files: []