incomplete-twitter4j4r 0.3.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 ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in twitter4j4r.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thomas Claridge
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,66 @@
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
+ @config = Twitter4j4r::Config.new
28
+ @config.username = 'username'
29
+ @config.password = 'password'
30
+
31
+ @client = Twitter4j4r::Client.new @config
32
+
33
+ Or with OAuth:
34
+
35
+ @config = Twitter4j4r::Config.new
36
+ @config.consumer_key = 'ABC456'
37
+ @config.consumer_secret = 'ABC456'
38
+ @config.access_token = 'ABC456'
39
+ @config.access_token_secret = 'ABC456'
40
+
41
+ @client = Twitter4j4r::Client.new @config
42
+
43
+ To access the sample stream:
44
+
45
+ @client.sample do |tweet|
46
+ puts "#{tweet.user.screen_name} says \"#{tweet.text}\""
47
+ end
48
+
49
+ Tracking a keyword:
50
+
51
+ @client.track('bieber') do |tweet|
52
+ puts "#{tweet.user.screen_name} says #{tweet.text}"
53
+ end
54
+
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
63
+
64
+
65
+
66
+ Thanks to [Tobias Crawley](https://github.com/tobias) for the original codebase.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
Binary file
Binary file
Binary file
@@ -0,0 +1,58 @@
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
+ 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
+ @stream = Java::Twitter4j::TwitterStreamFactory.new(config.build).instanceend
21
+ end
22
+
23
+ def on_exception(&block)
24
+ @exception_block = block
25
+ self
26
+ end
27
+
28
+ def on_limitation(&block)
29
+ @limitation_block = block
30
+ self
31
+ end
32
+
33
+ def on_status(&block)
34
+ @status_block = block
35
+ self
36
+ end
37
+
38
+ def track(*terms, &block)
39
+ add_listener(&block)
40
+ @stream.filter(Java::Twitter4j::FilterQuery.new(0, nil, search_terms.to_java(:string)))
41
+ end
42
+
43
+ def sample(&block)
44
+ add_listener(&block)
45
+ @stream.sample
46
+ end
47
+
48
+ def add_listener(&block)
49
+ on_status(&block)
50
+ @stream.addListener(Listener.new(self, @status_block, @exception_block, @limitation_block, @deletion_block))
51
+ end
52
+
53
+ def stop
54
+ @stream.cleanUp
55
+ @stream.shutdown
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,38 @@
1
+ require 'jar/twitter4j-core-2.2.6.jar'
2
+
3
+ module Twitter4j4r
4
+ class Config
5
+ def initialize
6
+ @config = Java::Twitter4jConf::ConfigurationBuilder.new
7
+ @config.setDebugEnabled true
8
+ end
9
+
10
+ def consumer_key= consumer_key
11
+ @config.setOAuthConsumerKey consumer_key
12
+ end
13
+
14
+ def consumer_secret= consumer_secret
15
+ @config.setOAuthConsumerSecret consumer_secret
16
+ end
17
+
18
+ def access_token= access_token
19
+ @config.setOAuthAccessToken access_token
20
+ end
21
+
22
+ def access_token_secret= access_token_secret
23
+ @config.setOAuthAccessTokenSecret access_token_secret
24
+ end
25
+
26
+ def username= username
27
+ @config.setUser username
28
+ end
29
+
30
+ def password= password
31
+ @config.setPassword password
32
+ end
33
+
34
+ def build
35
+ @config.build
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
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)
9
+ @client = client
10
+ @status_block = status_block
11
+ @exception_block = exception_block
12
+ @limitation_block = limitation_block
13
+ end
14
+
15
+ def onStatus(status)
16
+ call_block_with_client(@status_block, status)
17
+ end
18
+
19
+ def onException(exception)
20
+ call_block_with_client(@exception_block, exception)
21
+ end
22
+
23
+ def onTrackLimitationNotice(limited_count)
24
+ call_block_with_client(@limitation_block, limited_count)
25
+ end
26
+
27
+ protected
28
+ def call_block_with_client(block, *args)
29
+ block.call(*((args + [@client])[0, block.arity])) if block
30
+ end
31
+ end
32
+ end
33
+
34
+ Twitter4j4r::Listener.become_java!
@@ -0,0 +1,3 @@
1
+ module Twitter4j4r
2
+ VERSION = "0.3.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "twitter4j4r/client"
2
+ require "twitter4j4r/config"
3
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/twitter4j4r/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "incomplete-twitter4j4r"
6
+ gem.version = Twitter4j4r::VERSION
7
+ gem.authors = ["Tobias Crawley", "Marek Jelen", "Thomas Claridge"]
8
+ gem.email = ["toby@tcrawley.org", "", "thomas.claridge@incompletepackets.co.nz"]
9
+ gem.homepage = "https://github.com/incompletepackets/twitter4j4r"
10
+ gem.description = %q{A thin, woefully inadequate wrapper around http://twitter4j.org/}
11
+ gem.summary = %q{A thin, woefully inadequate wrapper around http://twitter4j.org/ that only supports the stream api with keywords.}
12
+ gem.license = "MIT"
13
+
14
+ gem.platform = "java"
15
+ gem.files = `git ls-files`.split($\)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+
19
+ gem.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: incomplete-twitter4j4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: java
7
+ authors:
8
+ - Tobias Crawley
9
+ - Marek Jelen
10
+ - Thomas Claridge
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-05-07 00:00:00.000000000 Z
15
+ dependencies: []
16
+ description: A thin, woefully inadequate wrapper around http://twitter4j.org/
17
+ email:
18
+ - toby@tcrawley.org
19
+ - ''
20
+ - thomas.claridge@incompletepackets.co.nz
21
+ executables: []
22
+ extensions: []
23
+ extra_rdoc_files: []
24
+ files:
25
+ - .gitignore
26
+ - Gemfile
27
+ - LICENSE
28
+ - README.md
29
+ - Rakefile
30
+ - lib/jar/twitter4j-async-2.2.6.jar
31
+ - lib/jar/twitter4j-core-2.2.6.jar
32
+ - lib/jar/twitter4j-stream-2.2.6.jar
33
+ - lib/twitter4j4r.rb
34
+ - lib/twitter4j4r/client.rb
35
+ - lib/twitter4j4r/config.rb
36
+ - lib/twitter4j4r/listener.rb
37
+ - lib/twitter4j4r/version.rb
38
+ - twitter4j4r.gemspec
39
+ homepage: https://github.com/incompletepackets/twitter4j4r
40
+ licenses:
41
+ - MIT
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: A thin, woefully inadequate wrapper around http://twitter4j.org/ that only
64
+ supports the stream api with keywords.
65
+ test_files: []