streambot 0.5.1 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -8
- data/VERSION +1 -1
- data/lib/streambot.rb +0 -1
- data/lib/streambot/retweet.rb +1 -6
- metadata +3 -6
- data/lib/streambot/http.rb +0 -58
- data/test/streambot/test_http.rb +0 -28
data/README.rdoc
CHANGED
@@ -19,10 +19,8 @@ The full rdoc is available on rdoc.info[http://rdoc.info/projects/gr4y/streambot
|
|
19
19
|
|
20
20
|
require 'streambot'
|
21
21
|
|
22
|
-
@params = {"
|
23
|
-
|
24
|
-
"http" => {"username" => "username", "password" => "password"}
|
25
|
-
}
|
22
|
+
@params = { "oauth" => {"key" => "consumer key", "secret" => "consumer secret"},
|
23
|
+
"http" => {"username" => "username", "password" => "password"} }
|
26
24
|
@blacklist = ['mac_rt','apple_rt']
|
27
25
|
bot = StreamBot::Tracker.new(@params, @blacklist, 'apple','ipad','iphone os 4','steve jobs')
|
28
26
|
bot.start
|
@@ -33,12 +31,9 @@ Twitter has finally removed the http basic authentication for the REST API.
|
|
33
31
|
The Streaming API, which the tracker is using, still works with http basic authentication only.
|
34
32
|
So we still need both, the oauth credentials for retweeting and the http basic authentication credentials for tracking.
|
35
33
|
|
36
|
-
|
37
|
-
The auth type is the authentication mechanism you want to use for retweeting.
|
38
|
-
*oauth* or *http*
|
34
|
+
You need to register an application of the type desktop application on http://dev.twitter.com first!
|
39
35
|
|
40
36
|
=== oauth
|
41
|
-
*Warning!* You need to register an application of the type desktop application on http://dev.twitter.com first!
|
42
37
|
|
43
38
|
*key*:: The consumer key Twitter provides you
|
44
39
|
*secret*:: The consumer secret Twitter provides you
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.4
|
data/lib/streambot.rb
CHANGED
data/lib/streambot/retweet.rb
CHANGED
@@ -3,12 +3,7 @@ module StreamBot
|
|
3
3
|
class Retweet
|
4
4
|
# intitialize method aka constructor
|
5
5
|
def initialize(params)
|
6
|
-
|
7
|
-
auth_params = params[auth_type]
|
8
|
-
case auth_type
|
9
|
-
when "oauth" then @handler = StreamBot::OAuth.new(auth_params)
|
10
|
-
when "http" then @handler = StreamBot::HTTP.new(auth_params)
|
11
|
-
end
|
6
|
+
@handler = StreamBot::OAuth.new(params['oauth'])
|
12
7
|
end
|
13
8
|
|
14
9
|
# retweets the status with given id
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 4
|
9
|
+
version: 0.5.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sascha Wessel
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-09-09 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -107,7 +107,6 @@ files:
|
|
107
107
|
- lib/streambot.rb
|
108
108
|
- lib/streambot/callbacks.rb
|
109
109
|
- lib/streambot/handler.rb
|
110
|
-
- lib/streambot/http.rb
|
111
110
|
- lib/streambot/oauth.rb
|
112
111
|
- lib/streambot/retweet.rb
|
113
112
|
- lib/streambot/tracker.rb
|
@@ -116,7 +115,6 @@ files:
|
|
116
115
|
- test/streambot/base_test.rb
|
117
116
|
- test/streambot/test_oauth.rb
|
118
117
|
- test/streambot/test_retweet.rb
|
119
|
-
- test/streambot/test_http.rb
|
120
118
|
has_rdoc: true
|
121
119
|
homepage: http://github.com/gr4y/streambot
|
122
120
|
licenses: []
|
@@ -156,4 +154,3 @@ test_files:
|
|
156
154
|
- test/streambot/base_test.rb
|
157
155
|
- test/streambot/test_oauth.rb
|
158
156
|
- test/streambot/test_retweet.rb
|
159
|
-
- test/streambot/test_http.rb
|
data/lib/streambot/http.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module StreamBot
|
2
|
-
# http communication wrapper
|
3
|
-
class HTTP < StreamBot::Handler
|
4
|
-
BASE_URL = "http://api.twitter.com"
|
5
|
-
# intialize http communication wrapper
|
6
|
-
def initialize(auth)
|
7
|
-
@auth = auth
|
8
|
-
end
|
9
|
-
|
10
|
-
# post data to twitter api
|
11
|
-
#
|
12
|
-
# path takes the path like
|
13
|
-
# '/statuses/update.format'
|
14
|
-
#
|
15
|
-
# the body contains all data you send to twitter
|
16
|
-
# {:status => "a new status"}
|
17
|
-
#
|
18
|
-
def post(path, body)
|
19
|
-
LOG.debug("post #{body} to \"#{path}\"")
|
20
|
-
request = init_request(path, :post)
|
21
|
-
request.body = body if !body.nil?
|
22
|
-
do_request(request)
|
23
|
-
end
|
24
|
-
|
25
|
-
# get data from twitter api
|
26
|
-
#
|
27
|
-
# path takes the path like
|
28
|
-
# '/statuses/user_timeline.format'
|
29
|
-
#
|
30
|
-
def get(path)
|
31
|
-
LOG.debug("get data form \"#{path}\"")
|
32
|
-
request = init_request(path, :get)
|
33
|
-
do_request(request)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
def do_request(request)
|
38
|
-
request.basic_auth @auth['username'], @auth['password']
|
39
|
-
response = Net::HTTP.new(@uri.host, @uri.port).start do |http|
|
40
|
-
http.request(request)
|
41
|
-
end
|
42
|
-
parse_response(response)
|
43
|
-
end
|
44
|
-
|
45
|
-
# initialize an Net::HTTP::GET or Net::HTTP::POST request
|
46
|
-
# depends on type param
|
47
|
-
def init_request(path, type)
|
48
|
-
@url = "#{BASE_URL}#{path}"
|
49
|
-
@uri = URI.parse(@url)
|
50
|
-
case type
|
51
|
-
when :post then
|
52
|
-
Net::HTTP::Post.new(@uri.path)
|
53
|
-
when :get then
|
54
|
-
Net::HTTP::Get.new(@uri.path)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/test/streambot/test_http.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'streambot/base_test'
|
2
|
-
|
3
|
-
module StreamBot
|
4
|
-
# test for http wrapper class
|
5
|
-
class TestHttp < StreamBot::BaseTest
|
6
|
-
# setup
|
7
|
-
def setup
|
8
|
-
super
|
9
|
-
WebMock.disable_net_connect!
|
10
|
-
@http = StreamBot::HTTP.new(@params['http'])
|
11
|
-
stub_request(:post, "http://#{@params['http']['username']}:#{@params['http']['password']}@api.twitter.com/path/to/data").to_return(:body => "response")
|
12
|
-
end
|
13
|
-
|
14
|
-
# test a post with basic authentication
|
15
|
-
def test_post
|
16
|
-
res = @http.post('/path/to/data',nil)
|
17
|
-
assert_not_nil(res)
|
18
|
-
assert_equal("response", res)
|
19
|
-
end
|
20
|
-
|
21
|
-
# nil all variables
|
22
|
-
def teardown
|
23
|
-
@http = nil
|
24
|
-
WebMock.allow_net_connect!
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|