twitter4j4r 0.1.0-java
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +87 -0
- data/Rakefile +2 -0
- data/lib/jar/twitter4j-async-2.2.6.jar +0 -0
- data/lib/jar/twitter4j-core-2.2.6.jar +0 -0
- data/lib/jar/twitter4j-stream-2.2.6.jar +0 -0
- data/lib/twitter4j4r/client.rb +56 -0
- data/lib/twitter4j4r/listener.rb +31 -0
- data/lib/twitter4j4r/version.rb +3 -0
- data/lib/twitter4j4r.rb +3 -0
- data/twitter4j4r.gemspec +18 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tobias Crawley
|
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,87 @@
|
|
1
|
+
# Twitter4j4r
|
2
|
+
|
3
|
+
A thin, woefully inadequate wrapper around [twitter4j](http://twitter4j.org/)
|
4
|
+
that currently only supports the stream api with keywords. It will only work
|
5
|
+
under JRuby.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'twitter4j4r'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install twitter4j4r
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The api is inspired by [tweetstream](https://github.com/intridea/tweetstream/):
|
24
|
+
|
25
|
+
@client = Twitter4j4r::Client.new(:consumer_key => 'ABC123',
|
26
|
+
:consumer_secret => 'ABC234',
|
27
|
+
:access_token => 'ABC345',
|
28
|
+
:access_secret => 'ABC456')
|
29
|
+
|
30
|
+
@client.on_exception do |exception|
|
31
|
+
puts "An error occurred - #{exception.message}"
|
32
|
+
end
|
33
|
+
|
34
|
+
@client.track('bieber') do |tweet|
|
35
|
+
puts "#{tweet.user.screen_name} says #{tweet.text}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# some time later
|
39
|
+
@client.stop
|
40
|
+
|
41
|
+
Blocks passed to `track` and `on_exception` can accept optionally accept
|
42
|
+
a second argument that will be the client instance (similar to tweetstream):
|
43
|
+
|
44
|
+
@client.track('bieber') do |tweet, client|
|
45
|
+
if tweet.text =~ /marry me/
|
46
|
+
puts "grody"
|
47
|
+
client.stop
|
48
|
+
else
|
49
|
+
puts "#{tweet.user.screen_name} says #{tweet.text}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
## Why?
|
54
|
+
|
55
|
+
Because tweetstream uses EventMachine, and EM doesn't support TLS
|
56
|
+
under JRuby, so is unusable.
|
57
|
+
|
58
|
+
Thanks to [Marek Jelen](https://github.com/marekjelen) for the inspiration.
|
59
|
+
|
60
|
+
## Isn't twitter4j4r a crappy name?
|
61
|
+
|
62
|
+
Yes! But I was a hair away from naming it `twitter4j4r4u-and-me`, so take
|
63
|
+
what you're given.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
Copyright 2012 Tobias Crawley
|
76
|
+
|
77
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
78
|
+
you may not use this file except in compliance with the License.
|
79
|
+
You may obtain a copy of the License at
|
80
|
+
|
81
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
82
|
+
|
83
|
+
Unless required by applicable law or agreed to in writing, software
|
84
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
85
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
86
|
+
See the License for the specific language governing permissions and
|
87
|
+
limitations under the License.
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'jar/twitter4j-core-2.2.6.jar'
|
2
|
+
require 'jar/twitter4j-stream-2.2.6.jar'
|
3
|
+
require 'jar/twitter4j-async-2.2.6.jar'
|
4
|
+
|
5
|
+
require 'twitter4j4r/listener'
|
6
|
+
|
7
|
+
module Twitter4j4r
|
8
|
+
class Client
|
9
|
+
def initialize(auth_map)
|
10
|
+
@stream = Java::Twitter4j::TwitterStreamFactory.new(config(auth_map)).instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_exception(&block)
|
14
|
+
@exception_block = block
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_limitation(&block)
|
19
|
+
@limitation_block = block
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_status(&block)
|
24
|
+
@status_block = block
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def track(*terms, &block)
|
29
|
+
on_status(&block)
|
30
|
+
start(terms)
|
31
|
+
end
|
32
|
+
|
33
|
+
def start(search_terms)
|
34
|
+
@stream.addListener(Listener.new(self, @status_block, @exception_block, @limitation_block))
|
35
|
+
@stream.filter(Java::Twitter4j::FilterQuery.new(0, nil, search_terms.to_java(:string)))
|
36
|
+
end
|
37
|
+
|
38
|
+
def stop
|
39
|
+
@stream.cleanUp
|
40
|
+
@stream.shutdown
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def config(auth_map)
|
46
|
+
config = Java::Twitter4jConf::ConfigurationBuilder.new
|
47
|
+
config.setDebugEnabled(true)
|
48
|
+
config.setOAuthConsumerKey(auth_map[:consumer_key])
|
49
|
+
config.setOAuthConsumerSecret(auth_map[:consumer_secret])
|
50
|
+
config.setOAuthAccessToken(auth_map[:access_token])
|
51
|
+
config.setOAuthAccessTokenSecret(auth_map[:access_secret])
|
52
|
+
config.build
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'jar/twitter4j-stream-2.2.6.jar'
|
2
|
+
|
3
|
+
module Twitter4j4r
|
4
|
+
class Listener
|
5
|
+
include Java::Twitter4j::StatusListener
|
6
|
+
|
7
|
+
def initialize(client, status_block, exception_block, limitation_block)
|
8
|
+
@client = client
|
9
|
+
@status_block = status_block
|
10
|
+
@exception_block = exception_block
|
11
|
+
@limitation_block = limitation_block
|
12
|
+
end
|
13
|
+
|
14
|
+
def onStatus(status)
|
15
|
+
call_block_with_client(@status_block, status)
|
16
|
+
end
|
17
|
+
|
18
|
+
def onException(exception)
|
19
|
+
call_block_with_client(@exception_block, exception)
|
20
|
+
end
|
21
|
+
|
22
|
+
def onTrackLimitationNotice(limited_count)
|
23
|
+
call_block_with_client(@limitation_block, limited_count)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def call_block_with_client(block, *args)
|
28
|
+
block.call(*((args + [@client])[0, block.arity])) if block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/twitter4j4r.rb
ADDED
data/twitter4j4r.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/twitter4j4r/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Tobias Crawley", "Marek Jelen"]
|
6
|
+
gem.email = ["toby@tcrawley.org"]
|
7
|
+
gem.description = %q{A thin, woefully inadequate wrapper around http://twitter4j.org/}
|
8
|
+
gem.summary = %q{A thin, woefully inadequate wrapper around http://twitter4j.org/ that only supports the stream api with keywords.}
|
9
|
+
gem.homepage = "https://github.com/tobias/twitter4j4r"
|
10
|
+
|
11
|
+
gem.platform = "java"
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "twitter4j4r"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Twitter4j4r::VERSION
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twitter4j4r
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Tobias Crawley
|
9
|
+
- Marek Jelen
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2012-07-20 00:00:00 Z
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: A thin, woefully inadequate wrapper around http://twitter4j.org/
|
18
|
+
email:
|
19
|
+
- toby@tcrawley.org
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- LICENSE
|
30
|
+
- README.md
|
31
|
+
- Rakefile
|
32
|
+
- lib/jar/twitter4j-async-2.2.6.jar
|
33
|
+
- lib/jar/twitter4j-core-2.2.6.jar
|
34
|
+
- lib/jar/twitter4j-stream-2.2.6.jar
|
35
|
+
- lib/twitter4j4r.rb
|
36
|
+
- lib/twitter4j4r/client.rb
|
37
|
+
- lib/twitter4j4r/listener.rb
|
38
|
+
- lib/twitter4j4r/version.rb
|
39
|
+
- twitter4j4r.gemspec
|
40
|
+
homepage: https://github.com/tobias/twitter4j4r
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.24
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A thin, woefully inadequate wrapper around http://twitter4j.org/ that only supports the stream api with keywords.
|
67
|
+
test_files: []
|
68
|
+
|