tuiter 0.0.3 → 0.0.4
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/CHANGELOG +45 -32
- data/lib/tuiter.log +45 -0
- data/lib/tuiter/client.rb +35 -0
- data/lib/tuiter/version.rb +1 -1
- metadata +2 -5
- data/lib/tuiter/client.rb~ +0 -244
- data/lib/tuiter/data/direct_message.rb~ +0 -44
- data/lib/tuiter/version.rb~ +0 -16
data/CHANGELOG
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
|
+
== v0.0.4
|
|
2
|
+
* Adding remove friendship method
|
|
3
|
+
|
|
4
|
+
== v0.0.3
|
|
5
|
+
* Resolving a simple conflict and adding get_followers_ids method
|
|
6
|
+
* alterando gemspec
|
|
7
|
+
* adding get_friends call to api
|
|
8
|
+
* Autotest configuration file
|
|
9
|
+
* Adding followers ids retrieval method
|
|
10
|
+
* Testing client on try update message and result http response status error
|
|
11
|
+
* Added RCOV rake task
|
|
12
|
+
* Tests for rate_limit and shoulda macro should_load_attribute_on_initialize
|
|
13
|
+
|
|
1
14
|
== v0.0.2
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
15
|
+
* Added github profile path on AUTHORS
|
|
16
|
+
* Bumping version, including direct message files
|
|
17
|
+
* Updating AUTHORS. Giving credit where is due
|
|
18
|
+
* Adding DirectMessage data structure and listing method. Bumping tiny version one up
|
|
19
|
+
* Fixing the installation instructions on the README file
|
|
20
|
+
* Refactoring client tests to use fakeweb and less expectations
|
|
21
|
+
* Tests for StatusBasic and Status
|
|
22
|
+
* Tests for User, UserBasic and UserExtended - 100% tests coverage
|
|
23
|
+
* Added rake tasks to execute rcov
|
|
24
|
+
* Adding some json fixtures for testing
|
|
25
|
+
* Fixing a false cognate on README
|
|
26
|
+
* Added initial tests
|
|
27
|
+
* Namespace done right
|
|
28
|
+
* Fixed requires definitely
|
|
29
|
+
* Fixed requires again
|
|
30
|
+
* Fixed requires
|
|
31
|
+
* Updating README
|
|
32
|
+
* Updating tuiter.gemspec
|
|
33
|
+
* Adding a rake task to publish tuiter on Rubyforge
|
|
34
|
+
* Added http proxy support to all operations
|
|
35
|
+
* Added check RUBY_PLATFORM because JRuby does not support native extensions
|
|
36
|
+
* Rakefile and gemspec updated, it should work fine now
|
|
37
|
+
* Trying to fix the gemspec
|
|
38
|
+
* Small fix on tuiter gemspec
|
|
39
|
+
* Adding the gemspec to allow Github to generate and publish a tuiter gem
|
|
40
|
+
* Adding the most simple and obvious example ever
|
|
41
|
+
* The most simple and basic example that could ever be
|
|
42
|
+
* Updating .gitignore
|
|
43
|
+
* Adding a README, just for kicks
|
|
44
|
+
* Moving the requires out of the client
|
|
45
|
+
* Cleaning up some stuff, organizing things, the plumbing
|
|
46
|
+
* Adding authors, license and changelog files
|
|
34
47
|
|
|
35
48
|
== v0.0.1
|
|
36
49
|
* Extracting tuiter from tuitersfera
|
data/lib/tuiter.log
CHANGED
|
@@ -69,3 +69,48 @@ I, [2009-04-04T11:27:33.356890 #877] INFO -- : [Tuiter:877] Sat Apr 04 11:27:33
|
|
|
69
69
|
I, [2009-04-05T20:41:37.553400 #2715] INFO -- : [Tuiter:2715] Sun Apr 05 20:41:37 -0300 2009 : initialize()
|
|
70
70
|
I, [2009-04-05T20:41:44.512426 #2715] INFO -- : [Tuiter:2715] Sun Apr 05 20:41:44 -0300 2009 : request() query: http://twitter.com/followers/ids/el_cocho.json
|
|
71
71
|
I, [2009-04-05T20:41:44.995093 #2715] INFO -- : [Tuiter:2715] Sun Apr 05 20:41:44 -0300 2009 : request() debug: http status is 200 OK
|
|
72
|
+
I, [2009-04-14T17:29:43.673209 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:29:43 -0300 2009 : initialize()
|
|
73
|
+
I, [2009-04-14T17:30:14.177041 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:14 -0300 2009 : initialize()
|
|
74
|
+
I, [2009-04-14T17:30:49.449220 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:49 -0300 2009 : request() query: http://twitter.com/friendships/exists.json?user_a=jacktorrance&user_b=el_cocho
|
|
75
|
+
I, [2009-04-14T17:30:50.093362 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:50 -0300 2009 : request() debug: http status is 200 OK
|
|
76
|
+
I, [2009-04-14T17:30:55.416097 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:55 -0300 2009 : request() query: http://twitter.com/friendships/exists.json?user_a=jacktorran&user_b=el_cocho
|
|
77
|
+
I, [2009-04-14T17:30:57.054399 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:57 -0300 2009 : request() http error: 403 Forbidden in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:278:in `open_http'
|
|
78
|
+
I, [2009-04-14T17:30:58.953377 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:58 -0300 2009 : request() query: http://twitter.com/friendships/exists.json?user_a=jacktorrance&user_b=el_cocho
|
|
79
|
+
I, [2009-04-14T17:30:59.436056 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:30:59 -0300 2009 : request() debug: http status is 200 OK
|
|
80
|
+
I, [2009-04-14T17:31:11.345039 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:31:11 -0300 2009 : request() query: http://twitter.com/friendships/exists.json?user_a=jacktorrance&user_b=el_cocho
|
|
81
|
+
I, [2009-04-14T17:31:13.529470 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:31:13 -0300 2009 : request() debug: http status is 200 OK
|
|
82
|
+
I, [2009-04-14T17:31:22.881538 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:31:22 -0300 2009 : request() query: http://twitter.com/friendships/exists.json?user_a=el_cocho&user_b=jacktorrance
|
|
83
|
+
I, [2009-04-14T17:31:23.414882 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:31:23 -0300 2009 : request() debug: http status is 200 OK
|
|
84
|
+
I, [2009-04-14T17:33:57.281787 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:33:57 -0300 2009 : friendship_new() following: 8405350
|
|
85
|
+
I, [2009-04-14T17:35:44.743006 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:35:44 -0300 2009 : friendship_new() following: el_cocho
|
|
86
|
+
I, [2009-04-14T17:35:45.739301 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:35:45 -0300 2009 : friendship_new() success: OK
|
|
87
|
+
I, [2009-04-14T17:37:58.969786 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:37:58 -0300 2009 : update() sending: una loucuja es una loucuja
|
|
88
|
+
I, [2009-04-14T17:38:00.575303 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:38:00 -0300 2009 : update() success: OK
|
|
89
|
+
I, [2009-04-14T17:38:25.434711 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:38:25 -0300 2009 : update() sending: txelci 4 x liverpoul 4
|
|
90
|
+
I, [2009-04-14T17:38:26.858112 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:38:26 -0300 2009 : update() success: OK
|
|
91
|
+
I, [2009-04-14T17:40:24.503832 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:40:24 -0300 2009 : friendship_new() following: jacktorrance
|
|
92
|
+
I, [2009-04-14T17:40:25.489296 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:40:25 -0300 2009 : friendship_new() success: OK
|
|
93
|
+
I, [2009-04-14T17:41:05.943669 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:05 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
94
|
+
I, [2009-04-14T17:41:07.368539 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:07 -0300 2009 : update() success: OK
|
|
95
|
+
I, [2009-04-14T17:41:07.368652 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:07 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
96
|
+
I, [2009-04-14T17:41:08.125190 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:08 -0300 2009 : update() success: OK
|
|
97
|
+
I, [2009-04-14T17:41:08.125270 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:08 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
98
|
+
I, [2009-04-14T17:41:08.842099 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:08 -0300 2009 : update() success: OK
|
|
99
|
+
I, [2009-04-14T17:41:08.842202 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:08 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
100
|
+
I, [2009-04-14T17:41:09.840732 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:09 -0300 2009 : update() success: OK
|
|
101
|
+
I, [2009-04-14T17:41:09.840915 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:09 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
102
|
+
I, [2009-04-14T17:41:10.827714 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:10 -0300 2009 : update() success: OK
|
|
103
|
+
I, [2009-04-14T17:41:10.827843 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:10 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
104
|
+
I, [2009-04-14T17:41:11.520762 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:11 -0300 2009 : update() success: OK
|
|
105
|
+
I, [2009-04-14T17:41:11.520945 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:11 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
106
|
+
I, [2009-04-14T17:41:12.803576 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:12 -0300 2009 : update() success: OK
|
|
107
|
+
I, [2009-04-14T17:41:12.803678 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:12 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
108
|
+
I, [2009-04-14T17:41:13.521870 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:13 -0300 2009 : update() success: OK
|
|
109
|
+
I, [2009-04-14T17:41:13.521949 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:13 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
110
|
+
I, [2009-04-14T17:41:15.314131 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:15 -0300 2009 : update() success: OK
|
|
111
|
+
I, [2009-04-14T17:41:15.314258 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:15 -0300 2009 : update() sending: all work and no play makes jack a dull bot
|
|
112
|
+
I, [2009-04-14T17:41:16.017922 #42602] INFO -- : [Tuiter:42602] Tue Apr 14 17:41:16 -0300 2009 : update() success: OK
|
|
113
|
+
I, [2009-04-14T17:43:06.041230 #43489] INFO -- : [Tuiter:43489] Tue Apr 14 17:43:06 -0300 2009 : initialize()
|
|
114
|
+
I, [2009-04-14T20:56:00.218333 #56199] INFO -- : [Tuiter:56199] Tue Apr 14 20:56:00 -0300 2009 : initialize()
|
|
115
|
+
I, [2009-04-14T20:57:05.965585 #56199] INFO -- : [Tuiter:56199] Tue Apr 14 20:57:05 -0300 2009 : friendship_new() following: el_cocho
|
|
116
|
+
I, [2009-04-14T20:57:06.640700 #56199] INFO -- : [Tuiter:56199] Tue Apr 14 20:57:06 -0300 2009 : remove_friendship() success: OK
|
data/lib/tuiter/client.rb
CHANGED
|
@@ -74,6 +74,22 @@ module Tuiter
|
|
|
74
74
|
res.error!
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
|
+
|
|
78
|
+
def remove_friendship(user, follow = nil)
|
|
79
|
+
log("friendship_new() following: #{user}")
|
|
80
|
+
url = URI.parse("http://twitter.com/friendships/destroy/#{user}.json")
|
|
81
|
+
req = Net::HTTP::Post.new(url.path)
|
|
82
|
+
req.basic_auth @username, @password
|
|
83
|
+
res = new_http_for(url).start {|http| http.request(req) }
|
|
84
|
+
case res
|
|
85
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
86
|
+
log("remove_friendship() success: OK")
|
|
87
|
+
return res # OK
|
|
88
|
+
else
|
|
89
|
+
log("remove_friendship() error: #{res.error!}")
|
|
90
|
+
res.error!
|
|
91
|
+
end
|
|
92
|
+
end
|
|
77
93
|
|
|
78
94
|
def verify_credentials?
|
|
79
95
|
if res = request("http://twitter.com/account/verify_credentials.json")
|
|
@@ -109,6 +125,25 @@ module Tuiter
|
|
|
109
125
|
return nil
|
|
110
126
|
end
|
|
111
127
|
end
|
|
128
|
+
|
|
129
|
+
def get_friends(options = {})
|
|
130
|
+
if options[:id]
|
|
131
|
+
query = "http://twitter.com/statuses/friends/#{options[:id]}.json"
|
|
132
|
+
else
|
|
133
|
+
query = "http://twitter.com/statuses/friends.json"
|
|
134
|
+
end
|
|
135
|
+
if options[:page]
|
|
136
|
+
params = "?page=#{options[:page]}"
|
|
137
|
+
else
|
|
138
|
+
params = ""
|
|
139
|
+
end
|
|
140
|
+
if res = request(query+params)
|
|
141
|
+
data = JSON.parse(res)
|
|
142
|
+
return data.map { |d| User.new(d) }
|
|
143
|
+
else
|
|
144
|
+
return nil
|
|
145
|
+
end
|
|
146
|
+
end
|
|
112
147
|
|
|
113
148
|
def get_replies(options = {})
|
|
114
149
|
query = "http://twitter.com/statuses/replies.json"
|
data/lib/tuiter/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tuiter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Manoel Lemos
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2009-04-
|
|
13
|
+
date: 2009-04-14 00:00:00 -03:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -39,16 +39,13 @@ files:
|
|
|
39
39
|
- README.rdoc
|
|
40
40
|
- lib/tuiter
|
|
41
41
|
- lib/tuiter/client.rb
|
|
42
|
-
- lib/tuiter/client.rb~
|
|
43
42
|
- lib/tuiter/data
|
|
44
43
|
- lib/tuiter/data/direct_message.rb
|
|
45
|
-
- lib/tuiter/data/direct_message.rb~
|
|
46
44
|
- lib/tuiter/data/rate_limit.rb
|
|
47
45
|
- lib/tuiter/data/status.rb
|
|
48
46
|
- lib/tuiter/data/user.rb
|
|
49
47
|
- lib/tuiter/end_points.rb
|
|
50
48
|
- lib/tuiter/version.rb
|
|
51
|
-
- lib/tuiter/version.rb~
|
|
52
49
|
- lib/tuiter.log
|
|
53
50
|
- lib/tuiter.rb
|
|
54
51
|
- examples/basic_example.rb
|
data/lib/tuiter/client.rb~
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
module Tuiter
|
|
2
|
-
|
|
3
|
-
class Client
|
|
4
|
-
attr_accessor :username, :password
|
|
5
|
-
|
|
6
|
-
def initialize(options = {})
|
|
7
|
-
@pid = Process.pid
|
|
8
|
-
@logger = options[:logger] || Logger.new('tuiter.log')
|
|
9
|
-
@username = options[:username]
|
|
10
|
-
@password = options[:password]
|
|
11
|
-
@use_proxy = setup_a_proxy?
|
|
12
|
-
log("initialize()")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def update(status, in_reply_to_status_id = nil)
|
|
16
|
-
log("update() sending: #{status}")
|
|
17
|
-
url = URI.parse('http://twitter.com/statuses/update.json')
|
|
18
|
-
req = Net::HTTP::Post.new(url.path)
|
|
19
|
-
req.basic_auth @username, @password
|
|
20
|
-
req.set_form_data({'status'=>status, 'in_reply_to_status_id'=>in_reply_to_status_id })
|
|
21
|
-
res = new_http_for(url).start {|http| http.request(req) }
|
|
22
|
-
case res
|
|
23
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
24
|
-
log("update() success: OK")
|
|
25
|
-
return res # OK
|
|
26
|
-
else
|
|
27
|
-
log("update() error: #{res.to_s}")
|
|
28
|
-
res.error!
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def direct_new(user, text)
|
|
33
|
-
log("direct_new() sending: #{text} to #{user}")
|
|
34
|
-
url = URI.parse('http://twitter.com/direct_messages/new.json')
|
|
35
|
-
req = Net::HTTP::Post.new(url.path)
|
|
36
|
-
req.basic_auth @username, @password
|
|
37
|
-
req.set_form_data({'user'=>user, 'text'=>text })
|
|
38
|
-
res = new_http_for(url).start {|http| http.request(req) }
|
|
39
|
-
case res
|
|
40
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
41
|
-
log("direct_new() success: OK")
|
|
42
|
-
return res # OK
|
|
43
|
-
else
|
|
44
|
-
log("direct_new() error: #{res.error!}")
|
|
45
|
-
res.error!
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def direct_list(options = {})
|
|
50
|
-
url = 'http://twitter.com/direct_messages.json'
|
|
51
|
-
params = parse_options(options) || ""
|
|
52
|
-
|
|
53
|
-
if res = request(url+params)
|
|
54
|
-
data = JSON.parse(res)
|
|
55
|
-
return data.map { |d| DirectMessage.new(d) }
|
|
56
|
-
else
|
|
57
|
-
return nil
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def friendship_new(user, follow = nil)
|
|
62
|
-
log("friendship_new() following: #{user}")
|
|
63
|
-
url = URI.parse("http://twitter.com/friendships/create/#{user}.json")
|
|
64
|
-
req = Net::HTTP::Post.new(url.path)
|
|
65
|
-
req.basic_auth @username, @password
|
|
66
|
-
req.set_form_data({'follow'=>"true"}) if follow
|
|
67
|
-
res = new_http_for(url).start {|http| http.request(req) }
|
|
68
|
-
case res
|
|
69
|
-
when Net::HTTPSuccess, Net::HTTPRedirection
|
|
70
|
-
log("friendship_new() success: OK")
|
|
71
|
-
return res # OK
|
|
72
|
-
else
|
|
73
|
-
log("friendship_new() error: #{res.error!}")
|
|
74
|
-
res.error!
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def verify_credentials?
|
|
79
|
-
if res = request("http://twitter.com/account/verify_credentials.json")
|
|
80
|
-
return UserExtended.new(JSON.parse(res))
|
|
81
|
-
else
|
|
82
|
-
return nil
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def get_followers(options = {})
|
|
87
|
-
if options[:id]
|
|
88
|
-
query = "http://twitter.com/statuses/followers/#{options[:id]}.json"
|
|
89
|
-
else
|
|
90
|
-
query = "http://twitter.com/statuses/followers.json"
|
|
91
|
-
end
|
|
92
|
-
if options[:page]
|
|
93
|
-
params = "?page=#{options[:page]}"
|
|
94
|
-
else
|
|
95
|
-
params = ""
|
|
96
|
-
end
|
|
97
|
-
if res = request(query+params)
|
|
98
|
-
data = JSON.parse(res)
|
|
99
|
-
return data.map { |d| User.new(d) }
|
|
100
|
-
else
|
|
101
|
-
return nil
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def get_replies(options = {})
|
|
106
|
-
query = "http://twitter.com/statuses/replies.json"
|
|
107
|
-
if options[:since]
|
|
108
|
-
params = "?since=#{options[:since]}"
|
|
109
|
-
elsif options[:since_id]
|
|
110
|
-
params = "?since_id=#{options[:since_id]}"
|
|
111
|
-
else
|
|
112
|
-
params = ""
|
|
113
|
-
end
|
|
114
|
-
if options[:page]
|
|
115
|
-
if params == ""
|
|
116
|
-
params = "?page=#{options[:page]}"
|
|
117
|
-
else
|
|
118
|
-
params = params + "&" + "page=#{options[:page]}"
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
if res = request(query+params)
|
|
122
|
-
data = JSON.parse(res)
|
|
123
|
-
return data.map { |d| Status.new(d) }
|
|
124
|
-
else
|
|
125
|
-
return nil
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def get_client
|
|
130
|
-
if res = request("http://twitter.com/users/show/#{@username}.json")
|
|
131
|
-
return UserExtended.new(JSON.parse(res))
|
|
132
|
-
else
|
|
133
|
-
return nil
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def get_user(id)
|
|
138
|
-
if res = request("http://twitter.com/users/show/#{id}.json")
|
|
139
|
-
return UserExtended.new(JSON.parse(res))
|
|
140
|
-
else
|
|
141
|
-
return nil
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def get_status(id)
|
|
146
|
-
if res = request("http://twitter.com/statuses/show/#{id}.json")
|
|
147
|
-
return Status.new(JSON.parse(res))
|
|
148
|
-
else
|
|
149
|
-
return nil
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def rate_limit
|
|
154
|
-
if res = request("http://twitter.com/account/rate_limit_status.json")
|
|
155
|
-
return RateLimit.new(JSON.parse(res))
|
|
156
|
-
else
|
|
157
|
-
return nil
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def follows_me?(id)
|
|
162
|
-
if res = request("http://twitter.com/friendships/exists.json?user_a=#{id}&user_b=#{@username}")
|
|
163
|
-
return true if res == "true"
|
|
164
|
-
return false
|
|
165
|
-
else
|
|
166
|
-
return nil
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
private
|
|
171
|
-
|
|
172
|
-
def request(url)
|
|
173
|
-
http = nil
|
|
174
|
-
status = Timeout::timeout(10) do
|
|
175
|
-
log("request() query: #{url}")
|
|
176
|
-
http = open(url, :http_basic_authentication=>[@username, @password])
|
|
177
|
-
log("request() debug: http status is #{http.status.join(' ')}")
|
|
178
|
-
if http.status == ["200", "OK"]
|
|
179
|
-
res = http.read
|
|
180
|
-
return res
|
|
181
|
-
end
|
|
182
|
-
return nil
|
|
183
|
-
end
|
|
184
|
-
rescue Timeout::Error
|
|
185
|
-
log("request() error: timeout error")
|
|
186
|
-
return nil
|
|
187
|
-
rescue OpenURI::HTTPError => e
|
|
188
|
-
log("request() http error: #{e.message} in #{e.backtrace.first.to_s}")
|
|
189
|
-
return nil
|
|
190
|
-
rescue Exception => e
|
|
191
|
-
log("request() error: #{e.message} in #{e.backtrace.first.to_s}")
|
|
192
|
-
return nil
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def parse_options(options)
|
|
196
|
-
if options[:since]
|
|
197
|
-
params = "?since=#{options[:since]}"
|
|
198
|
-
elsif options[:since_id]
|
|
199
|
-
params = "?since_id=#{options[:since_id]}"
|
|
200
|
-
else
|
|
201
|
-
params = ""
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
if options[:page]
|
|
205
|
-
if params == ""
|
|
206
|
-
params = "?page=#{options[:page]}"
|
|
207
|
-
else
|
|
208
|
-
params = params + "&" + "page=#{options[:page]}"
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
return params
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
def setup_a_proxy?
|
|
216
|
-
http_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY'] || nil
|
|
217
|
-
|
|
218
|
-
if http_proxy
|
|
219
|
-
proxy = URI.parse(http_proxy)
|
|
220
|
-
|
|
221
|
-
@proxy_host = proxy.host
|
|
222
|
-
@proxy_port = proxy.port
|
|
223
|
-
@proxy_user, @proxy_pass = proxy.userinfo.split(/:/) if proxy.userinfo
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
http_proxy != nil
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def new_http_for(url)
|
|
230
|
-
if @use_proxy
|
|
231
|
-
http = Net::HTTP.new(url.host, url.port, @proxy_host, @proxy_port, @proxy_user, @proxy_pass)
|
|
232
|
-
else
|
|
233
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def log(message)
|
|
238
|
-
@logger.info "[Tuiter:#{@pid}] #{Time.now.to_s} : #{message}"
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
end
|
|
244
|
-
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module Tuiter
|
|
2
|
-
|
|
3
|
-
class DirectMessageBasic
|
|
4
|
-
attr_accessor :id
|
|
5
|
-
attr_accessor :text
|
|
6
|
-
attr_accessor :created_at
|
|
7
|
-
attr_accessor :sender_id
|
|
8
|
-
attr_accessor :sender_screen_name
|
|
9
|
-
attr_accessor :recipient_id
|
|
10
|
-
attr_accessor :recipient_screen_name
|
|
11
|
-
|
|
12
|
-
def initialize(data = nil)
|
|
13
|
-
unless data.nil?
|
|
14
|
-
@id = data['id']
|
|
15
|
-
@text = data['text']
|
|
16
|
-
@created_at = (data['created_at'] ? DateTime.parse(data['created_at']) : DateTime.now)
|
|
17
|
-
@sender_id = data['sender_id']
|
|
18
|
-
@sender_screen_name = data['sender_screen_name']
|
|
19
|
-
@recipient_id = data['recipient_id']
|
|
20
|
-
@recipient_screen_name = data['recipient_screen_name']
|
|
21
|
-
else
|
|
22
|
-
@created_at = DateTime.now
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class DirectMessage < DirectMessageBasic
|
|
30
|
-
attr_accessor :sender
|
|
31
|
-
attr_accessor :recipient
|
|
32
|
-
|
|
33
|
-
def initialize(data = nil)
|
|
34
|
-
unless data.nil?
|
|
35
|
-
super(data)
|
|
36
|
-
@sender = UserBasic.new(data['sender'])
|
|
37
|
-
@recipient = UserBasic.new(data['recipient'])
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
data/lib/tuiter/version.rb~
DELETED