lita-tweeta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/tweeta.rb +56 -0
- data/lib/lita-tweeta.rb +7 -0
- data/lita-tweeta.gemspec +25 -0
- data/locales/en.yml +7 -0
- data/spec/lita/handlers/tweeta_spec.rb +39 -0
- data/spec/spec_helper.rb +11 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6b5e93d47fb44bc70ae89d924e340bf3acc9774
|
4
|
+
data.tar.gz: 072c39a3920e2fca7d8d60cfa5b33933f690e123
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 637cebc1da469b89fa92e750138e8523e3a78dfd257fd3c93349b9c47430bd59dc2739c7a255553cd4319f68e92e852565c50acd3daf4de0ebaaaf5fe03f863c
|
7
|
+
data.tar.gz: 018e0420e7772fad3fe86a80b23a996ab5651e500e68c3761a06d1cdaa063e4d2e7366740d9af193a7086206602a510bce56dbca1f0148a89a768b5a3b77b0c0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Tristan Chong
|
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,44 @@
|
|
1
|
+
# lita-tweeta
|
2
|
+
|
3
|
+
**lita-tweeta** is a handler for [Lita](https://github.com/jimmycuadra/lita) that displays a tweet for a given Twitter URL or username.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add lita-tweeta to your Lita instance's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "lita-tweeta"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
Twitter's API requires authentication via OAuth, so you'll need to [register your application with Twitter](https://apps.twitter.com/).
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
Lita.configure do |config|
|
19
|
+
config.handlers.tweeta.consumer_key = "foo"
|
20
|
+
config.handlers.tweeta.consumer_secret = "bar"
|
21
|
+
config.handlers.tweeta.access_token = "baz"
|
22
|
+
config.handlers.tweeta.access_token_secret = "luhrmann"
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
To have Lita display a tweet, simply paste its URL into the chat channel:
|
29
|
+
|
30
|
+
```
|
31
|
+
<me> congratulations jimmy https://twitter.com/tristaneuan/status/463007122087616512
|
32
|
+
<lita> "Congratulations on 400 GitHub stars, @litachatbot and @jimmycuadra! #chatops #ruby https://t.co/mADTTu3M3N" --Tristan Chong, 2014-05-04
|
33
|
+
```
|
34
|
+
|
35
|
+
You can also retrieve a given user's latest tweet:
|
36
|
+
|
37
|
+
```
|
38
|
+
<me> @lita: tweet sfsiren
|
39
|
+
<lita> "This is a test. This is a test of the outdoor warning system. This is only a test." --SFSiren, 2015-05-05
|
40
|
+
```
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "date"
|
2
|
+
require "twitter"
|
3
|
+
|
4
|
+
module Lita
|
5
|
+
module Handlers
|
6
|
+
class Tweeta < Handler
|
7
|
+
config :consumer_key, type: String, required: true
|
8
|
+
config :consumer_secret, type: String, required: true
|
9
|
+
config :access_token, type: String, required: true
|
10
|
+
config :access_token_secret, type: String, required: true
|
11
|
+
|
12
|
+
route(/https:\/\/twitter.com\/\w+\/status\/(\d+)/i, :tweeta,
|
13
|
+
command: false)
|
14
|
+
route(/^tw(?:eet|itter)?\s+(\w+)/i, :user_tweet, command: true,
|
15
|
+
help: {t("help.tweeta_key") => t("tweeta_value")})
|
16
|
+
|
17
|
+
def initialize(robot)
|
18
|
+
super
|
19
|
+
@client = Twitter::REST::Client.new do |config|
|
20
|
+
config.consumer_key = Lita.config.handlers.tweeta.consumer_key
|
21
|
+
config.consumer_secret = Lita.config.handlers.tweeta.consumer_secret
|
22
|
+
config.access_token = Lita.config.handlers.tweeta.access_token
|
23
|
+
config.access_token_secret = Lita.config.handlers.tweeta.access_token_secret
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def tweeta(response)
|
28
|
+
begin
|
29
|
+
tweet = @client.status(response.matches.first.first.to_i)
|
30
|
+
rescue Twitter::Error::NotFound
|
31
|
+
return
|
32
|
+
else
|
33
|
+
response.reply format(tweet)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_tweet(response)
|
38
|
+
username = response.matches.first.first
|
39
|
+
if @client.user?(username)
|
40
|
+
user = @client.user(username)
|
41
|
+
tweets = @client.user_timeline(user, {count: 1, include_rts: false})
|
42
|
+
unless tweets.empty?
|
43
|
+
response.reply format(tweets.first)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def format(tweet)
|
50
|
+
"\"#{tweet.text}\" --#{tweet.user.name}, #{tweet.created_at.strftime('%F')}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Lita.register_handler(Tweeta)
|
55
|
+
end
|
56
|
+
end
|
data/lib/lita-tweeta.rb
ADDED
data/lita-tweeta.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-tweeta"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Tristan Chong"]
|
5
|
+
spec.email = ["ong@tristaneuan.ch"]
|
6
|
+
spec.description = %q{A Lita handler that displays a tweet for a given Twitter URL or username.}
|
7
|
+
spec.summary = %q{A Lita handler that displays a tweet for a given Twitter URL or username.}
|
8
|
+
spec.homepage = "https://github.com/tristaneuan/lita-tweeta"
|
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", ">= 4.0"
|
18
|
+
spec.add_runtime_dependency "twitter", ">= 5.14.0"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
23
|
+
spec.add_development_dependency "simplecov"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Tweeta, lita_handler: true do
|
4
|
+
before do
|
5
|
+
registry.config.handlers.tweeta.consumer_key = ENV["TWITTER_CONSUMER_KEY"]
|
6
|
+
registry.config.handlers.tweeta.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
|
7
|
+
registry.config.handlers.tweeta.access_token = ENV["TWITTER_ACCESS_TOKEN"]
|
8
|
+
registry.config.handlers.tweeta.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it { is_expected.to route("hey jimmy https://twitter.com/tristaneuan/status/463007122087616512 check out this tweet").to(:tweeta) }
|
12
|
+
it { is_expected.to route_command("tw SFSiren").to(:user_tweet) }
|
13
|
+
it { is_expected.to route_command("tweet SFSiren").to(:user_tweet) }
|
14
|
+
it { is_expected.to route_command("twitter SFSiren").to(:user_tweet) }
|
15
|
+
|
16
|
+
describe "#tweeta" do
|
17
|
+
it "returns a linked tweet's text, author, and date" do
|
18
|
+
send_message "hey jimmy https://twitter.com/tristaneuan/status/463007122087616512 check out this tweet"
|
19
|
+
expect(replies.first).to match(/^"Congratulations on 400 GitHub stars, @litachatbot and @jimmycuadra! #chatops #ruby [\S]+" --Tristan Chong, 2014-05-04$/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not send a message in response to a Twitter URL containing an invalid status ID" do
|
23
|
+
send_message "https://twitter.com/tristaneuan/status/1"
|
24
|
+
expect(replies.count).to eq 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#user_tweet" do
|
29
|
+
it "returns a specified user's latest tweet" do
|
30
|
+
send_command "tweet sfsiren"
|
31
|
+
expect(replies.first).to match(/^"This is a test\. This is a test of the outdoor warning system\. This is only a test\." --SFSiren, \d{4}-\d{2}-\d{2}$/)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not send a message in response to an invalid Twitter username" do
|
35
|
+
send_command "tweet abcdefghijklmnop"
|
36
|
+
expect(replies.count).to eq 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
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-tweeta"
|
10
|
+
require "lita/rspec"
|
11
|
+
Lita.version_3_compatibility_mode = false
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-tweeta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tristan Chong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-09 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: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: twitter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.14.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.14.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
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: coveralls
|
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
|
+
description: A Lita handler that displays a tweet for a given Twitter URL or username.
|
112
|
+
email:
|
113
|
+
- ong@tristaneuan.ch
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/lita-tweeta.rb
|
125
|
+
- lib/lita/handlers/tweeta.rb
|
126
|
+
- lita-tweeta.gemspec
|
127
|
+
- locales/en.yml
|
128
|
+
- spec/lita/handlers/tweeta_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
homepage: https://github.com/tristaneuan/lita-tweeta
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata:
|
134
|
+
lita_plugin_type: handler
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.2.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: A Lita handler that displays a tweet for a given Twitter URL or username.
|
155
|
+
test_files:
|
156
|
+
- spec/lita/handlers/tweeta_spec.rb
|
157
|
+
- spec/spec_helper.rb
|