ellen-twitter 0.0.1

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: baca78d2167ab10fb63a787db7d4a4b471c81b96
4
+ data.tar.gz: 72b51dd06971816a50f674524e4e7ad85342b9f3
5
+ SHA512:
6
+ metadata.gz: ebe627fb61957d9f96a835ff7f52fc7d0745adc827c77ee15b994881c6966f308167648481e38bbf21a4f44e42aa8e3db117608a39718fbddeae68ce835116aa
7
+ data.tar.gz: 91b1cff9635ff8471f0bcafc230a974c31ce77460cc99bd0869507447550238da4f689e36859e86474b04c02fc6674bbbb9ea4155c8b3a8ecb2e16d27989bfeb
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen-twitter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Ellen::Twitter
2
+ An [Ellen](https://github.com/r7kamura/ellen) adapter for twitter user-stream API.
3
+
4
+ ## Usage
5
+ ```ruby
6
+ # Gemfile
7
+ gem "ellen-twitter"
8
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ellen/twitter/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ellen-twitter"
7
+ spec.version = Ellen::Twitter::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "An ellen adapter for twitter."
11
+ spec.homepage = "https://github.com/r7kamura/ellen-twitter"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ellen"
20
+ spec.add_dependency "twitter", ">= 5.0.0"
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,58 @@
1
+ require "mem"
2
+ require "twitter"
3
+
4
+ module Ellen
5
+ module Adapters
6
+ class Twitter < Base
7
+ include Mem
8
+
9
+ env :TWITTER_CONSUMER_KEY, "Twitter consumer key (a.k.a. API key)"
10
+ env :TWITTER_CONSUMER_SECRET, "Twitter consumer secret (a.k.a. API secret)"
11
+ env :TWITTER_ACCESS_TOKEN, "Twitter access token"
12
+ env :TWITTER_ACCESS_TOKEN_SECRET, "Twitter access token secret"
13
+
14
+ def run
15
+ abortable
16
+ listen
17
+ end
18
+
19
+ def say(body)
20
+ client.update(body)
21
+ end
22
+
23
+ private
24
+
25
+ def listen
26
+ stream.user do |tweet|
27
+ case tweet
28
+ when ::Twitter::Tweet
29
+ robot.receive(body: tweet.text)
30
+ end
31
+ end
32
+ end
33
+
34
+ def client
35
+ ::Twitter::REST::Client.new do |config|
36
+ config.consumer_key = ENV["TWITTER_CONSUMER_KEY"]
37
+ config.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
38
+ config.access_token = ENV["TWITTER_ACCESS_TOKEN"]
39
+ config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
40
+ end
41
+ end
42
+
43
+ def stream
44
+ ::Twitter::Streaming::Client.new do |config|
45
+ config.consumer_key = ENV["TWITTER_CONSUMER_KEY"]
46
+ config.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
47
+ config.access_token = ENV["TWITTER_ACCESS_TOKEN"]
48
+ config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
49
+ end
50
+ end
51
+ memoize :stream
52
+
53
+ def abortable
54
+ Thread.abort_on_exception = true
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Ellen
2
+ module Twitter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "ellen"
2
+ require "ellen/adapters/twitter"
3
+ require "ellen/twitter/version"
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen-twitter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ellen
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: twitter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.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.0.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.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
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
+ description:
70
+ email:
71
+ - r7kamura@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - ellen-twitter.gemspec
82
+ - lib/ellen/adapters/twitter.rb
83
+ - lib/ellen/twitter.rb
84
+ - lib/ellen/twitter/version.rb
85
+ homepage: https://github.com/r7kamura/ellen-twitter
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.2.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: An ellen adapter for twitter.
109
+ test_files: []