incomplete-twitter4j4r 0.3.4-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/README.md +62 -66
- data/lib/jar/twitter4j-async-3.0.3.jar +0 -0
- data/lib/jar/twitter4j-core-3.0.3.jar +0 -0
- data/lib/jar/twitter4j-stream-3.0.3.jar +0 -0
- data/lib/twitter4j4r.rb +1 -1
- data/lib/twitter4j4r/client.rb +34 -63
- data/lib/twitter4j4r/config.rb +3 -3
- data/lib/twitter4j4r/stream.rb +58 -0
- data/lib/twitter4j4r/stream/listener.rb +14 -0
- data/lib/twitter4j4r/stream/public-listener.rb +23 -0
- data/lib/twitter4j4r/stream/user-listener.rb +36 -0
- data/lib/twitter4j4r/version.rb +3 -3
- metadata +16 -15
- 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/listener.rb +0 -39
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,66 +1,62 @@
|
|
1
|
-
# Twitter4j4r
|
2
|
-
|
3
|
-
A thin, woefully inadequate wrapper around [twitter4j](http://twitter4j.org/)
|
4
|
-
forked from [tobias](https://github.com/tobias/twitter4j4r). It will only work
|
5
|
-
under JRuby.
|
6
|
-
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
gem 'incomplete-twitter4j4r'
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
19
|
-
|
20
|
-
$ gem install incomplete-twitter4j4r
|
21
|
-
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
Create a configuration object:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
Thanks to [Tobias Crawley](https://github.com/tobias) for the original codebase.
|
1
|
+
# Twitter4j4r
|
2
|
+
|
3
|
+
A thin, woefully inadequate wrapper around [twitter4j](http://twitter4j.org/)
|
4
|
+
forked from [tobias](https://github.com/tobias/twitter4j4r). It will only work
|
5
|
+
under JRuby.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'incomplete-twitter4j4r'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install incomplete-twitter4j4r
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Create a configuration object and a client:
|
26
|
+
|
27
|
+
config = Twitter4j4r::Config.new
|
28
|
+
config.consumer_key = 'ABC456'
|
29
|
+
config.consumer_secret = 'ABC456'
|
30
|
+
config.access_token = 'ABC456'
|
31
|
+
config.access_token_secret = 'ABC456'
|
32
|
+
|
33
|
+
client = Twitter4j4r::Client.new config
|
34
|
+
|
35
|
+
To access the sample stream:
|
36
|
+
|
37
|
+
stream = client.add_stream :insert_stream_name_here
|
38
|
+
|
39
|
+
stream.sample do |tweet|
|
40
|
+
puts "#{tweet.user.screen_name} says \"#{tweet.text}\""
|
41
|
+
end
|
42
|
+
|
43
|
+
Tracking a keyword:
|
44
|
+
|
45
|
+
stream = client.add_stream :insert_stream_name_here
|
46
|
+
|
47
|
+
stream.track('bieber') do |tweet|
|
48
|
+
puts "#{tweet.user.screen_name} says #{tweet.text}"
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
Thanks to [Tobias Crawley](https://github.com/tobias) for the original codebase.
|
Binary file
|
Binary file
|
Binary file
|
data/lib/twitter4j4r.rb
CHANGED
data/lib/twitter4j4r/client.rb
CHANGED
@@ -1,63 +1,34 @@
|
|
1
|
-
require 'jar/twitter4j-core-
|
2
|
-
require 'jar/twitter4j-stream-
|
3
|
-
require 'jar/twitter4j-async-
|
4
|
-
|
5
|
-
require 'twitter4j4r/
|
6
|
-
require 'twitter4j4r/config'
|
7
|
-
|
8
|
-
module Twitter4j4r
|
9
|
-
class Client
|
10
|
-
def initialize(config)
|
11
|
-
unless config.is_a? Config
|
12
|
-
auth_map = config
|
13
|
-
config = Twitter4j4r::Config.new
|
14
|
-
config.consumer_key = auth_map[:consumer_key]
|
15
|
-
config.consumer_secret = auth_map[:consumer_secret]
|
16
|
-
config.access_token = auth_map[:access_token]
|
17
|
-
config.access_token_secret = auth_map[:access_secret]
|
18
|
-
end
|
19
|
-
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
self
|
36
|
-
end
|
37
|
-
|
38
|
-
def on_deletion(&block)
|
39
|
-
@deletion_block = block
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
def track(*terms, &block)
|
44
|
-
add_listener(&block)
|
45
|
-
@stream.filter(Java::Twitter4j::FilterQuery.new(0, nil, search_terms.to_java(:string)))
|
46
|
-
end
|
47
|
-
|
48
|
-
def sample(&block)
|
49
|
-
add_listener(&block)
|
50
|
-
@stream.sample
|
51
|
-
end
|
52
|
-
|
53
|
-
def add_listener(&block)
|
54
|
-
on_status(&block)
|
55
|
-
@stream.addListener(Listener.new(self, @status_block, @exception_block, @limitation_block, @deletion_block))
|
56
|
-
end
|
57
|
-
|
58
|
-
def stop
|
59
|
-
@stream.cleanUp
|
60
|
-
@stream.shutdown
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
1
|
+
require 'jar/twitter4j-core-3.0.3.jar'
|
2
|
+
require 'jar/twitter4j-stream-3.0.3.jar'
|
3
|
+
require 'jar/twitter4j-async-3.0.3.jar'
|
4
|
+
|
5
|
+
require 'twitter4j4r/stream'
|
6
|
+
require 'twitter4j4r/config'
|
7
|
+
|
8
|
+
module Twitter4j4r
|
9
|
+
class Client
|
10
|
+
def initialize(config)
|
11
|
+
unless config.is_a? Config
|
12
|
+
auth_map = config
|
13
|
+
config = Twitter4j4r::Config.new
|
14
|
+
config.consumer_key = auth_map[:consumer_key]
|
15
|
+
config.consumer_secret = auth_map[:consumer_secret]
|
16
|
+
config.access_token = auth_map[:access_token]
|
17
|
+
config.access_token_secret = auth_map[:access_secret]
|
18
|
+
end
|
19
|
+
|
20
|
+
@config = config.build
|
21
|
+
@streams = { }
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_stream name
|
25
|
+
stream = Twitter4j4r::Stream.new @config
|
26
|
+
@streams[name] = stream
|
27
|
+
stream
|
28
|
+
end
|
29
|
+
|
30
|
+
def stream name
|
31
|
+
@streams[name]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/twitter4j4r/config.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'jar/twitter4j-core-
|
1
|
+
require 'jar/twitter4j-core-3.0.3.jar'
|
2
2
|
|
3
3
|
module Twitter4j4r
|
4
4
|
class Config
|
@@ -25,11 +25,11 @@ module Twitter4j4r
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def username= username
|
28
|
-
|
28
|
+
raise "As of API v1.1, authorizing using username/password is not longer an option."
|
29
29
|
end
|
30
30
|
|
31
31
|
def password= password
|
32
|
-
|
32
|
+
raise "As of API v1.1, authorizing using username/password is not longer an option."
|
33
33
|
end
|
34
34
|
|
35
35
|
def build
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'jar/twitter4j-core-3.0.3.jar'
|
2
|
+
require 'jar/twitter4j-stream-3.0.3.jar'
|
3
|
+
require 'jar/twitter4j-async-3.0.3.jar'
|
4
|
+
|
5
|
+
require 'twitter4j4r/stream/public-listener'
|
6
|
+
require 'twitter4j4r/stream/user-listener'
|
7
|
+
|
8
|
+
module Twitter4j4r
|
9
|
+
class Stream
|
10
|
+
|
11
|
+
def initialize(config)
|
12
|
+
@stream = Java::Twitter4j::TwitterStreamFactory.new(config).instance
|
13
|
+
@blocks = { }
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_exception(&block)
|
17
|
+
on_notice(:exception, block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_favorite(&block)
|
21
|
+
on_notice(:favorite, block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_limitation(&block)
|
25
|
+
on_notice(:limitation, block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_status(&block)
|
29
|
+
on_notice(:status, block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_deletion(&block)
|
33
|
+
on_notice(:delete, block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_notice(block_name, block)
|
37
|
+
@blocks[block_name] = block
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def track(*terms, &block)
|
42
|
+
on_status(&block)
|
43
|
+
@stream.addListener(PublicListener.new(self, @blocks))
|
44
|
+
@stream.filter(Java::Twitter4j::FilterQuery.new(0, nil, search_terms.to_java(:string)))
|
45
|
+
end
|
46
|
+
|
47
|
+
def sample(&block)
|
48
|
+
on_status(&block)
|
49
|
+
@stream.addListener(PublicListener.new(self, @blocks))
|
50
|
+
@stream.sample
|
51
|
+
end
|
52
|
+
|
53
|
+
def stop
|
54
|
+
@stream.cleanUp
|
55
|
+
@stream.shutdown
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Twitter4j4r
|
2
|
+
class Listener
|
3
|
+
|
4
|
+
def initialize(client, blocks)
|
5
|
+
@client = client
|
6
|
+
@blocks = blocks
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
def call_block_with_client(block_key, *args)
|
11
|
+
@blocks[block_key].call(*((args + [@client])[0, @blocks[block_key].arity])) if @blocks[block_key]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'jar/twitter4j-stream-3.0.3.jar'
|
2
|
+
require 'jruby/core_ext'
|
3
|
+
|
4
|
+
|
5
|
+
require 'twitter4j4r/stream/listener'
|
6
|
+
|
7
|
+
module Twitter4j4r
|
8
|
+
class PublicListener < Listener
|
9
|
+
include Java::Twitter4j::StatusListener
|
10
|
+
|
11
|
+
[[ :onStatus, :status ],
|
12
|
+
[ :onException, :exception ],
|
13
|
+
[ :onTrackLimitationNotice, :limitation ],
|
14
|
+
[ :onDeletionNotice, :delete ]
|
15
|
+
].each do |method|
|
16
|
+
define_method(method[0]) do |*args|
|
17
|
+
call_block_with_client(method[1], *args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Twitter4j4r::PublicListener.become_java!
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'jar/twitter4j-stream-3.0.3.jar'
|
2
|
+
require 'jruby/core_ext'
|
3
|
+
|
4
|
+
require 'twitter4j4r/stream/listener'
|
5
|
+
|
6
|
+
module Twitter4j4r
|
7
|
+
class UserListener < Listener
|
8
|
+
include Java::Twitter4j::UserStreamListener
|
9
|
+
|
10
|
+
[[ :onException, :exception ],
|
11
|
+
[ :onDeletionNotice, :delete ],
|
12
|
+
[ :onBlock, :block ],
|
13
|
+
[ :onDirectMessage, :dm ],
|
14
|
+
[ :onFriendList, :friend_list ],
|
15
|
+
[ :onFavorite, :favorite ],
|
16
|
+
[ :onStatus, :status ],
|
17
|
+
[ :onFollow, :follow ],
|
18
|
+
[ :onUnblock, :unblock ],
|
19
|
+
[ :onUnfavorite, :unfavorite ],
|
20
|
+
[ :onUserListCreation, :user_list_creation ],
|
21
|
+
[ :onUserListDeletion, :user_list_deletion ],
|
22
|
+
[ :onUserListMemberAddition, :user_list_member_addition ],
|
23
|
+
[ :onUserListMemberDeletion, :user_list_member_deletion ],
|
24
|
+
[ :onUserListSubscription, :user_list_subscription ],
|
25
|
+
[ :onUserListUnsubscription, :user_list_unsubscription ],
|
26
|
+
[ :onUserListUpdate, :user_list_update ],
|
27
|
+
[ :onUserProfileUpdate, :user_profile_update ]
|
28
|
+
].each do |method|
|
29
|
+
define_method(method[0]) do |*args|
|
30
|
+
call_block_with_client(method[1], *args)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Twitter4j4r::UserListener.become_java!
|
data/lib/twitter4j4r/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Twitter4j4r
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
1
|
+
module Twitter4j4r
|
2
|
+
VERSION = "1.0.0"
|
3
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: incomplete-twitter4j4r
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 1.0.0
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Tobias Crawley
|
@@ -11,19 +11,19 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '1.8'
|
23
23
|
none: false
|
24
24
|
requirement: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.8'
|
29
29
|
none: false
|
@@ -38,18 +38,21 @@ executables: []
|
|
38
38
|
extensions: []
|
39
39
|
extra_rdoc_files: []
|
40
40
|
files:
|
41
|
-
-
|
41
|
+
- .gitignore
|
42
42
|
- Gemfile
|
43
43
|
- LICENSE
|
44
44
|
- README.md
|
45
45
|
- Rakefile
|
46
|
-
- lib/jar/twitter4j-async-
|
47
|
-
- lib/jar/twitter4j-core-
|
48
|
-
- lib/jar/twitter4j-stream-
|
46
|
+
- lib/jar/twitter4j-async-3.0.3.jar
|
47
|
+
- lib/jar/twitter4j-core-3.0.3.jar
|
48
|
+
- lib/jar/twitter4j-stream-3.0.3.jar
|
49
49
|
- lib/twitter4j4r.rb
|
50
50
|
- lib/twitter4j4r/client.rb
|
51
51
|
- lib/twitter4j4r/config.rb
|
52
|
-
- lib/twitter4j4r/
|
52
|
+
- lib/twitter4j4r/stream.rb
|
53
|
+
- lib/twitter4j4r/stream/listener.rb
|
54
|
+
- lib/twitter4j4r/stream/public-listener.rb
|
55
|
+
- lib/twitter4j4r/stream/user-listener.rb
|
53
56
|
- lib/twitter4j4r/version.rb
|
54
57
|
- twitter4j4r.gemspec
|
55
58
|
homepage: https://github.com/incompletepackets/twitter4j4r
|
@@ -61,17 +64,15 @@ require_paths:
|
|
61
64
|
- lib
|
62
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
66
|
requirements:
|
64
|
-
- -
|
67
|
+
- - '>='
|
65
68
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
-
MA==
|
69
|
+
version: '0'
|
68
70
|
none: false
|
69
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
72
|
requirements:
|
71
|
-
- -
|
73
|
+
- - '>='
|
72
74
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
74
|
-
MA==
|
75
|
+
version: '0'
|
75
76
|
none: false
|
76
77
|
requirements: []
|
77
78
|
rubyforge_project:
|
Binary file
|
Binary file
|
Binary file
|
data/lib/twitter4j4r/listener.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'jar/twitter4j-stream-2.2.6.jar'
|
2
|
-
require 'jruby/core_ext'
|
3
|
-
|
4
|
-
module Twitter4j4r
|
5
|
-
class Listener
|
6
|
-
include Java::Twitter4j::StatusListener
|
7
|
-
|
8
|
-
def initialize(client, status_block, exception_block, limitation_block, deletion_block)
|
9
|
-
@client = client
|
10
|
-
@status_block = status_block
|
11
|
-
@exception_block = exception_block
|
12
|
-
@limitation_block = limitation_block
|
13
|
-
@deletion_block = deletion_block
|
14
|
-
end
|
15
|
-
|
16
|
-
def onStatus(status)
|
17
|
-
call_block_with_client(@status_block, status)
|
18
|
-
end
|
19
|
-
|
20
|
-
def onException(exception)
|
21
|
-
call_block_with_client(@exception_block, exception)
|
22
|
-
end
|
23
|
-
|
24
|
-
def onTrackLimitationNotice(limited_count)
|
25
|
-
call_block_with_client(@limitation_block, limited_count)
|
26
|
-
end
|
27
|
-
|
28
|
-
def onDeletionNotice(notice)
|
29
|
-
call_block_with_client(@deletion_block, notice)
|
30
|
-
end
|
31
|
-
|
32
|
-
protected
|
33
|
-
def call_block_with_client(block, *args)
|
34
|
-
block.call(*((args + [@client])[0, block.arity])) if block
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Twitter4j4r::Listener.become_java!
|