lita-time 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/lib/lita-time.rb +7 -0
- data/lib/lita/handlers/time.rb +41 -0
- data/lita-time.gemspec +24 -0
- data/locales/en.yml +10 -0
- data/spec/lita/handlers/time_spec.rb +68 -0
- data/spec/spec_helper.rb +10 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 252406cf4e6a50a894aec18cb7fe2607bb31ebd3
|
4
|
+
data.tar.gz: 059f6482e0111d4eb244c0c45b43bd5300867bce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b0d395ff0ee752e86a6485ca71ac03ebfa7739753eeb9bc6e9a209529fb56ec8a29645cfb5a11353aae2e0b760e29695b6d50aa1dc7510f6a4ee8cd0a34942b
|
7
|
+
data.tar.gz: 0f5939a86cf6bdf066885fc4512f506e0d41113319e4e9b3ec80ca47b1d215063b944017bb5caea5d98aaff1021a5510f4f213673b47ae014ecf8b7bf959cdf0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Harlan Barnes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# lita-time
|
2
|
+
|
3
|
+
[](https://travis-ci.org/harlanbarnes/lita-time)
|
4
|
+
[](https://coveralls.io/r/harlanbarnes/lita-time)
|
5
|
+
|
6
|
+
**lita-time** is a handler for [Lita](https://github.com/jimmycuadra/lita) that uses the [World Weather Online](http://www.worldweatheronline.com) Time Zone API to look up local time in a given location.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add lita-time to your Lita instance's Gemfile:
|
11
|
+
|
12
|
+
``` ruby
|
13
|
+
gem "lita-time"
|
14
|
+
```
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
### Required attributes
|
19
|
+
|
20
|
+
* `apikey` - (String) - An key to access the free API. Sign up at [World Weather Online](https://developer.worldweatheronline.com/auth/register)
|
21
|
+
|
22
|
+
### Example
|
23
|
+
|
24
|
+
```
|
25
|
+
Lita.configure do |config|
|
26
|
+
config.handlers.time.apikey = "abcdef1234567890fedcba0987654321"
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
You can look up the locale lime of a location using many diferent forms:
|
33
|
+
|
34
|
+
```
|
35
|
+
Lita: time Mableton, GA
|
36
|
+
Lita: time in Mableton, GA
|
37
|
+
Lita: what time in Mableton, GA
|
38
|
+
Lita: what time is it in Mableton, GA
|
39
|
+
```
|
40
|
+
|
41
|
+
The location names that supported by the API are:
|
42
|
+
|
43
|
+
* City and Town Names
|
44
|
+
* IP Address
|
45
|
+
* UK Postcode
|
46
|
+
* Canada Postal Code
|
47
|
+
* US Zipcode
|
48
|
+
* Aiport code (IATA)
|
49
|
+
* Latitude and Longitude (in decimal)
|
50
|
+
|
51
|
+
## Acknowledgements
|
52
|
+
|
53
|
+
* Mostly ~~stolen~~ inspired by the [Hubot time plugin](https://github.com/github/hubot-scripts/blob/master/src/scripts/time.coffee).
|
54
|
+
* Used the [Lita Google Images](https://github.com/jimmycuadra/lita-google-images) plugin as a template.
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/lib/lita-time.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Lita
|
2
|
+
module Handlers
|
3
|
+
class Time < Handler
|
4
|
+
URL = "http://api.worldweatheronline.com/free/v1/tz.ashx"
|
5
|
+
|
6
|
+
route(/(?:what\s)?time(?:\sis\sit)?(?:\sin)?\s([^\?]+)(?:\?)?/, :fetch, command: true, help: {
|
7
|
+
t("help.time_key") => t("help.time_value")
|
8
|
+
})
|
9
|
+
|
10
|
+
def self.default_config(handler_config)
|
11
|
+
handler_config.apikey = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(response)
|
15
|
+
location = response.matches[0][0]
|
16
|
+
|
17
|
+
apikey = Lita.config.handlers.time.apikey
|
18
|
+
|
19
|
+
http_response = http.get(
|
20
|
+
URL,
|
21
|
+
q: location,
|
22
|
+
key: apikey,
|
23
|
+
format: 'json'
|
24
|
+
)
|
25
|
+
|
26
|
+
data = MultiJson.load(http_response.body)["data"]
|
27
|
+
|
28
|
+
begin
|
29
|
+
type = data['request'][0]['type']
|
30
|
+
query = data['request'][0]['query']
|
31
|
+
time = data['time_zone'][0]['localtime'].split(/ /)[1]
|
32
|
+
response.reply t("response.success", :type => type, :query => query, :time => time)
|
33
|
+
rescue
|
34
|
+
response.reply t("response.failure", :location => location)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Lita.register_handler(Time)
|
40
|
+
end
|
41
|
+
end
|
data/lita-time.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-time"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Harlan Barnes"]
|
5
|
+
spec.email = ["hbarnes@pobox.com"]
|
6
|
+
spec.description = %q{A Lita handler for getting the curent time for a given location}
|
7
|
+
spec.summary = %q{A Lita handler for getting the curent time for a given location}
|
8
|
+
spec.homepage = "https://github.com/harlanbarnes/lita-time"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", ">= 3.3"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
22
|
+
spec.add_development_dependency "simplecov"
|
23
|
+
spec.add_development_dependency "coveralls"
|
24
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Time, lita_handler: true do
|
4
|
+
|
5
|
+
it { routes_command("time Mableton, GA").to(:fetch) }
|
6
|
+
it { routes_command("time Mableton, GA?").to(:fetch) }
|
7
|
+
it { routes_command("time in Mableton, GA").to(:fetch) }
|
8
|
+
it { routes_command("time in Mableton, GA?").to(:fetch) }
|
9
|
+
it { routes_command("what time in Mableton, GA").to(:fetch) }
|
10
|
+
it { routes_command("what time in Mableton, GA?").to(:fetch) }
|
11
|
+
it { routes_command("what time is it in Mableton, GA").to(:fetch) }
|
12
|
+
it { routes_command("what time is it in Mableton, GA?").to(:fetch) }
|
13
|
+
|
14
|
+
describe "#fetch" do
|
15
|
+
let(:response) { double("Faraday::Response") }
|
16
|
+
|
17
|
+
before do
|
18
|
+
allow_any_instance_of(
|
19
|
+
Faraday::Connection
|
20
|
+
).to receive(:get).and_return(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "replies with the current time of the given location" do
|
24
|
+
allow(response).to receive(:body).and_return(<<-JSON.chomp
|
25
|
+
{
|
26
|
+
"data" : {
|
27
|
+
"request" : [
|
28
|
+
{
|
29
|
+
"query" : "Mableton, United States Of America",
|
30
|
+
"type" : "City"
|
31
|
+
}
|
32
|
+
],
|
33
|
+
"time_zone" : [
|
34
|
+
{
|
35
|
+
"localtime" : "2014-07-26 03:59",
|
36
|
+
"utcOffset" : "-4.0"
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
JSON
|
42
|
+
)
|
43
|
+
send_command("time Mableton, GA")
|
44
|
+
expect(replies.last).to eq(
|
45
|
+
"The current time for the City of Mableton, United States Of America is 03:59"
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "replies with the current time of the given location" do
|
50
|
+
allow(response).to receive(:body).and_return(<<-JSON.chomp
|
51
|
+
{
|
52
|
+
"data" : {
|
53
|
+
"error" : [
|
54
|
+
{
|
55
|
+
"msg" : "Unable to find any matching weather location to the query submitted!"
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
}
|
60
|
+
JSON
|
61
|
+
)
|
62
|
+
send_command("time not a real place")
|
63
|
+
expect(replies.last).to eq(
|
64
|
+
"Sorry, couldn't find not a real place"
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
require "coveralls"
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter "/spec/" }
|
8
|
+
|
9
|
+
require "lita-time"
|
10
|
+
require "lita/rspec"
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harlan Barnes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
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: coveralls
|
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
|
+
description: A Lita handler for getting the curent time for a given location
|
98
|
+
email:
|
99
|
+
- hbarnes@pobox.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/lita-time.rb
|
111
|
+
- lib/lita/handlers/time.rb
|
112
|
+
- lita-time.gemspec
|
113
|
+
- locales/en.yml
|
114
|
+
- spec/lita/handlers/time_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
homepage: https://github.com/harlanbarnes/lita-time
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata:
|
120
|
+
lita_plugin_type: handler
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.0.14
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A Lita handler for getting the curent time for a given location
|
141
|
+
test_files:
|
142
|
+
- spec/lita/handlers/time_spec.rb
|
143
|
+
- spec/spec_helper.rb
|