pupil 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/pupil.rb +652 -0
- data/lib/pupil/keygen.rb +32 -0
- data/pupil.gemspec +67 -0
- data/spec/pupil_spec.rb +18 -0
- data/spec/spec_helper.rb +12 -0
- metadata +129 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
oauth (0.4.5)
|
11
|
+
rake (0.9.2)
|
12
|
+
rcov (0.9.10)
|
13
|
+
rspec (2.3.0)
|
14
|
+
rspec-core (~> 2.3.0)
|
15
|
+
rspec-expectations (~> 2.3.0)
|
16
|
+
rspec-mocks (~> 2.3.0)
|
17
|
+
rspec-core (2.3.1)
|
18
|
+
rspec-expectations (2.3.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.3.0)
|
21
|
+
yard (0.6.8)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler (~> 1.0.0)
|
28
|
+
jeweler (~> 1.6.4)
|
29
|
+
oauth
|
30
|
+
rcov
|
31
|
+
rspec (~> 2.3.0)
|
32
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Oame
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= pupil
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to pupil
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Oame. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "pupil"
|
18
|
+
gem.homepage = "http://github.com/oame/pupil"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{The Twitter API Wrapper for Ruby}
|
21
|
+
gem.description = %Q{The "Lazy" Twitter API wrapper for Ruby. It was made for Kbot library.}
|
22
|
+
gem.email = "oame@oameya.com"
|
23
|
+
gem.authors = ["Oame"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.3
|
data/lib/pupil.rb
ADDED
@@ -0,0 +1,652 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'rexml/document'
|
5
|
+
require 'uri'
|
6
|
+
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
7
|
+
require 'oauth'
|
8
|
+
#require 'pp'
|
9
|
+
|
10
|
+
class Pupil
|
11
|
+
attr_reader :screen_name
|
12
|
+
|
13
|
+
class UnsupportedParameter < StandardError; end
|
14
|
+
|
15
|
+
# @param [Hash] pupil_key
|
16
|
+
def initialize(pupil_key)
|
17
|
+
@screen_name = pupil_key[:screen_name]
|
18
|
+
@client = nil
|
19
|
+
@config = nil
|
20
|
+
consumer = OAuth::Consumer.new(
|
21
|
+
pupil_key[:consumer_key],
|
22
|
+
pupil_key[:consumer_secret],
|
23
|
+
:site => 'http://api.twitter.com'
|
24
|
+
)
|
25
|
+
@access_token = OAuth::AccessToken.new(
|
26
|
+
consumer,
|
27
|
+
pupil_key[:access_token],
|
28
|
+
pupil_key[:access_token_secret]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param [Hash] parameter
|
33
|
+
# @return [String] serialized parameters
|
34
|
+
def param_serializer parameter
|
35
|
+
ant = Hash.new
|
36
|
+
parameter.each do |key, value|
|
37
|
+
case key.to_sym
|
38
|
+
when :include
|
39
|
+
if value.class == String || Symbol
|
40
|
+
ant[:"include_#{value}"] = :true
|
41
|
+
break
|
42
|
+
end
|
43
|
+
|
44
|
+
value.each do |element|
|
45
|
+
raise UnsupportedParameter, 'include_entities is not supported.' if element.to_sym == :entities
|
46
|
+
ant[:"include_#{element}"] = :true
|
47
|
+
end
|
48
|
+
when :exclude
|
49
|
+
if value.class == String || Symbol
|
50
|
+
ant[:"exclude_#{value}"] = :true
|
51
|
+
break
|
52
|
+
end
|
53
|
+
|
54
|
+
value.each do |element|
|
55
|
+
ant[:"exclude_#{element}"] = :true
|
56
|
+
end
|
57
|
+
else
|
58
|
+
ant[key.to_sym] = value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
param = ant.inject(""){|k,v|k+"&#{v[0]}=#{v[1]}"}.sub!(/^&/,"?")
|
62
|
+
return param ? param : ""
|
63
|
+
end
|
64
|
+
|
65
|
+
class REXML::Document
|
66
|
+
def is_error?
|
67
|
+
if self.root.get_text("error") then
|
68
|
+
return true
|
69
|
+
else
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_error_message
|
75
|
+
return self.root.get_text("error")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
public
|
80
|
+
|
81
|
+
# @return [Hash] user profile
|
82
|
+
def verify_credentials
|
83
|
+
response = @access_token.get('/account/verify_credentials.xml')
|
84
|
+
doc = REXML::Document.new(response.body)
|
85
|
+
return false if doc.is_error?
|
86
|
+
user = User.new(doc.elements['/user'])
|
87
|
+
return user
|
88
|
+
end
|
89
|
+
|
90
|
+
# @param [Hash] param
|
91
|
+
# @return [Hash] alias to Pupil#home_timeline
|
92
|
+
# @deprecated Use {#home_timeline} instead of this method because
|
93
|
+
# is was obsoleted.
|
94
|
+
def friends_timeline(param = {})
|
95
|
+
param_s = param_serializer(param)
|
96
|
+
begin
|
97
|
+
response = @access_token.get("http://api.twitter.com/1/statuses/friends_timeline.xml"+param_s)
|
98
|
+
rescue
|
99
|
+
return false
|
100
|
+
end
|
101
|
+
doc = REXML::Document.new(response.body)
|
102
|
+
return false if doc.is_error?
|
103
|
+
statuses = Array.new
|
104
|
+
|
105
|
+
doc.get_elements('/statuses/status').each do |element|
|
106
|
+
status = Status.new(element)
|
107
|
+
statuses << status
|
108
|
+
end
|
109
|
+
|
110
|
+
return statuses
|
111
|
+
end
|
112
|
+
|
113
|
+
# @param [Hash] param
|
114
|
+
# @return [Array] timeline
|
115
|
+
def home_timeline(param = {})
|
116
|
+
param_s = param_serializer(param)
|
117
|
+
begin
|
118
|
+
response = @access_token.get("http://api.twitter.com/1/statuses/home_timeline.xml"+param_s)
|
119
|
+
rescue
|
120
|
+
return false
|
121
|
+
end
|
122
|
+
doc = REXML::Document.new(response.body)
|
123
|
+
return false if doc.is_error?
|
124
|
+
statuses = Array.new
|
125
|
+
doc.get_elements('/statuses/status').each{|element|
|
126
|
+
status = Status.new(element)
|
127
|
+
statuses << status
|
128
|
+
}
|
129
|
+
return statuses
|
130
|
+
end
|
131
|
+
|
132
|
+
# @param [Hash] param
|
133
|
+
# @return [Hash] timeline
|
134
|
+
# @option param [Fixnum] :user_id The ID of user
|
135
|
+
# @option param [String] :screen_name The Screen name of user
|
136
|
+
# @option param [Fixnum] :since_id
|
137
|
+
# @option param [Fixnum] :max_id
|
138
|
+
# @option param [Fixnum] :count
|
139
|
+
# @option param [Fixnum] :page Specifies
|
140
|
+
# @option param [Symbol] :trim_user
|
141
|
+
# @option param [Symbol] :include => :rts
|
142
|
+
# @option param [Symbol] :exclude => :replies
|
143
|
+
# @option param [Symbol] :contributor_details
|
144
|
+
# @example
|
145
|
+
# twitter = Pupil.new PUPIL_KEY
|
146
|
+
# twitter.user_timeline(:screen_name => 'o_ame', :exclude_replies => :true).each do |status|
|
147
|
+
# puts "#{status.user.screen_name}: #{status.text}"
|
148
|
+
# end
|
149
|
+
def user_timeline(param = {})
|
150
|
+
param_s = param_serializer(param)
|
151
|
+
begin
|
152
|
+
response = @access_token.get("http://api.twitter.com/1/statuses/user_timeline.xml"+param_s)
|
153
|
+
rescue
|
154
|
+
return false
|
155
|
+
end
|
156
|
+
doc = REXML::Document.new(response.body)
|
157
|
+
return false if doc.is_error?
|
158
|
+
statuses = Array.new
|
159
|
+
doc.get_elements('/statuses/status').each{|element|
|
160
|
+
status = Status.new(element)
|
161
|
+
statuses << status
|
162
|
+
}
|
163
|
+
return statuses
|
164
|
+
end
|
165
|
+
|
166
|
+
# @param [Hash] param
|
167
|
+
# @return [Hash] mention
|
168
|
+
def mentions(param = {})
|
169
|
+
param_s = param_serializer(param)
|
170
|
+
begin
|
171
|
+
response = @access_token.get("http://api.twitter.com/1/statuses/mentions.xml"+param_s)
|
172
|
+
rescue
|
173
|
+
return false
|
174
|
+
end
|
175
|
+
doc = REXML::Document.new(response.body)
|
176
|
+
return false if doc.is_error?
|
177
|
+
statuses = Array.new
|
178
|
+
|
179
|
+
doc.get_elements('/statuses/status').each{|element|
|
180
|
+
status = Status.new(element)
|
181
|
+
statuses << status
|
182
|
+
}
|
183
|
+
|
184
|
+
return statuses
|
185
|
+
end
|
186
|
+
|
187
|
+
# @param [Hash] param
|
188
|
+
# @return [Hash] directmessages
|
189
|
+
def dm(param = {})
|
190
|
+
param_s = param_serializer(param)
|
191
|
+
begin
|
192
|
+
response = @access_token.get("http://api.twitter.com/1/direct_messages.xml"+param_s)
|
193
|
+
rescue
|
194
|
+
return false
|
195
|
+
end
|
196
|
+
doc = REXML::Document.new(response.body)
|
197
|
+
return false if doc.is_error?
|
198
|
+
directmessages = Array.new
|
199
|
+
|
200
|
+
doc.get_elements('/direct-messages/direct_message').each{|element|
|
201
|
+
dm = DirectMessage.new(element)
|
202
|
+
directmessages << dm
|
203
|
+
}
|
204
|
+
|
205
|
+
return directmessages
|
206
|
+
end
|
207
|
+
|
208
|
+
# @param [Hash] param
|
209
|
+
# @return [Hash] directmessage you sent
|
210
|
+
def dm_sent(param = {})
|
211
|
+
param_s = param_serializer(param)
|
212
|
+
begin
|
213
|
+
response = @access_token.get("http://api.twitter.com/1/direct_messages/sent.xml"+param_s)
|
214
|
+
rescue
|
215
|
+
return false
|
216
|
+
end
|
217
|
+
doc = REXML::Document.new(response.body)
|
218
|
+
return false if doc.is_error?
|
219
|
+
directmessages = Array.new
|
220
|
+
|
221
|
+
doc.get_elements('/direct-messages/direct_message').each{|element|
|
222
|
+
dm = DirectMessage.new(element)
|
223
|
+
directmessages << dm
|
224
|
+
}
|
225
|
+
|
226
|
+
return directmessages
|
227
|
+
end
|
228
|
+
|
229
|
+
# @param [Fixnum] dm_id message id that you want to delete
|
230
|
+
# @return [Hash] response
|
231
|
+
def dm_destroy(dm_id)
|
232
|
+
begin
|
233
|
+
response = @access_token.post("http://api.twitter.com/1/direct_messages/destroy/#{dm_id}.xml")
|
234
|
+
rescue
|
235
|
+
return false
|
236
|
+
end
|
237
|
+
return response
|
238
|
+
end
|
239
|
+
|
240
|
+
# @param [String] src source user
|
241
|
+
# @param [String] dst destination user
|
242
|
+
# @return [Boolean] return true if paired users have friendship, or ruturn false
|
243
|
+
def friendship_exists?(src, dst)
|
244
|
+
begin
|
245
|
+
response = @access_token.get("http://api.twitter.com/1/friendships/exists.xml?user_a=#{src}&user_b=#{dst}")
|
246
|
+
rescue
|
247
|
+
return false
|
248
|
+
end
|
249
|
+
doc = REXML::Document.new(response.body)
|
250
|
+
return false if doc.is_error?
|
251
|
+
if doc.elements["friends"].text() == "true" then
|
252
|
+
return true
|
253
|
+
else
|
254
|
+
return false
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# @param [String] name screen_name
|
259
|
+
# @return [Hash] response
|
260
|
+
def follow name
|
261
|
+
begin
|
262
|
+
response = @access_token.post("http://api.twitter.com/1/friendships/create/#{name}.xml")
|
263
|
+
rescue
|
264
|
+
return false
|
265
|
+
end
|
266
|
+
return response
|
267
|
+
end
|
268
|
+
|
269
|
+
# @param [String] name screen_name
|
270
|
+
# @return [Hash] response
|
271
|
+
def unfollow name
|
272
|
+
begin
|
273
|
+
response = @access_token.post("http://api.twitter.com/1/friendships/destroy/#{name}.xml")
|
274
|
+
rescue
|
275
|
+
return false
|
276
|
+
end
|
277
|
+
return response
|
278
|
+
end
|
279
|
+
|
280
|
+
# @param [Fixnum] id id
|
281
|
+
# @return [Hash] response
|
282
|
+
def block(id)
|
283
|
+
begin
|
284
|
+
response = @access_token.post("http://api.twitter.com/1/blocks/create.xml?id=#{id}")
|
285
|
+
rescue
|
286
|
+
return false
|
287
|
+
end
|
288
|
+
return response
|
289
|
+
end
|
290
|
+
|
291
|
+
# @param [Fixnum] id id
|
292
|
+
# @return [Hash] response
|
293
|
+
def unblock(id)
|
294
|
+
begin
|
295
|
+
response = @access_token.post("http://api.twitter.com/1/blocks/destroy.xml?id=#{id}")
|
296
|
+
rescue
|
297
|
+
return false
|
298
|
+
end
|
299
|
+
return response
|
300
|
+
end
|
301
|
+
|
302
|
+
# @return [Hash] list of blocking users
|
303
|
+
def blocking
|
304
|
+
response = @access_token.get("http://api.twitter.com/1/blocks/blocking.xml")
|
305
|
+
doc = REXML::Document.new(response.body)
|
306
|
+
return false if doc.is_error?
|
307
|
+
users = Array.new
|
308
|
+
doc.get_elements('/users/user').each{|element|
|
309
|
+
user = User.new(element)
|
310
|
+
users << user
|
311
|
+
}
|
312
|
+
return users
|
313
|
+
end
|
314
|
+
|
315
|
+
# @param [Fixnum] id list id
|
316
|
+
# @param [String] ids id comma separated
|
317
|
+
# @return [Hash] response
|
318
|
+
def addlist(listid,ids)
|
319
|
+
response = @access_token.post("http://api.twitter.com/1/#{@username}/#{listid}/create_all.xml?user_id=#{ids}")
|
320
|
+
return response
|
321
|
+
end
|
322
|
+
|
323
|
+
# @return [Hash] lists
|
324
|
+
def lists
|
325
|
+
response = @access_token.get("http://api.twitter.com/1/#{@username}/lists.xml")
|
326
|
+
doc = REXML::Document.new(response.body)
|
327
|
+
return false if doc.is_error?
|
328
|
+
lists = Array.new
|
329
|
+
doc.get_elements('/lists_list/lists/list').each{|element|
|
330
|
+
list = List.new(element)
|
331
|
+
lists << list
|
332
|
+
}
|
333
|
+
return lists
|
334
|
+
end
|
335
|
+
|
336
|
+
|
337
|
+
def lists_member_create(listid,id)
|
338
|
+
begin
|
339
|
+
response = @access_token.post("http://api.twitter.com/1/#{@username}/#{listid}/members.xml?id=#{id}")
|
340
|
+
rescue
|
341
|
+
return false
|
342
|
+
else
|
343
|
+
return response
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
347
|
+
|
348
|
+
def lookup(param = [])
|
349
|
+
param_s = param.join(",")
|
350
|
+
begin
|
351
|
+
response = @access_token.get("http://api.twitter.com/1/users/lookup.xml?user_id="+param_s)
|
352
|
+
rescue
|
353
|
+
return false
|
354
|
+
end
|
355
|
+
doc = REXML::Document.new(response.body)
|
356
|
+
return false if doc.is_error?
|
357
|
+
users = Array.new
|
358
|
+
doc.get_elements('/users/user').each{|element|
|
359
|
+
user = User.new(element)
|
360
|
+
users << user
|
361
|
+
}
|
362
|
+
|
363
|
+
return users
|
364
|
+
end
|
365
|
+
|
366
|
+
def friends_ids(name)
|
367
|
+
begin
|
368
|
+
response = @access_token.get("http://api.twitter.com/1/friends/ids/#{name}.xml")
|
369
|
+
rescue
|
370
|
+
return false
|
371
|
+
end
|
372
|
+
doc = REXML::Document.new(response.body)
|
373
|
+
return false if doc.is_error?
|
374
|
+
ids = Array.new
|
375
|
+
|
376
|
+
doc.get_elements('/ids/id').each{|element|
|
377
|
+
ids << element.text()
|
378
|
+
}
|
379
|
+
|
380
|
+
return ids
|
381
|
+
end
|
382
|
+
|
383
|
+
def followers_ids(name)
|
384
|
+
begin
|
385
|
+
response = @access_token.get("http://api.twitter.com/1/followers/ids/#{name}.xml")
|
386
|
+
rescue
|
387
|
+
return false
|
388
|
+
end
|
389
|
+
doc = REXML::Document.new(response.body)
|
390
|
+
if doc.is_error? then
|
391
|
+
return doc.get_error_message
|
392
|
+
end
|
393
|
+
ids = Array.new
|
394
|
+
|
395
|
+
doc.get_elements('/ids/id').each{|element|
|
396
|
+
ids << element.text()
|
397
|
+
}
|
398
|
+
|
399
|
+
return ids
|
400
|
+
end
|
401
|
+
|
402
|
+
def rate_limit
|
403
|
+
begin
|
404
|
+
response = @access_token.get("http://api.twitter.com/1/account/rate_limit_status.xml")
|
405
|
+
rescue
|
406
|
+
return false
|
407
|
+
end
|
408
|
+
doc = REXML::Document.new(response.body)
|
409
|
+
return false if doc.is_error?
|
410
|
+
limit = doc.get_elements('/hash/hourly-limit').shift.text()
|
411
|
+
|
412
|
+
return limit
|
413
|
+
end
|
414
|
+
|
415
|
+
def update(status,irt='')
|
416
|
+
begin
|
417
|
+
response = @access_token.post(
|
418
|
+
'http://api.twitter.com/1/statuses/update.json',
|
419
|
+
'status'=> status,
|
420
|
+
'in_reply_to_status_id' => irt
|
421
|
+
)
|
422
|
+
rescue
|
423
|
+
return false
|
424
|
+
end
|
425
|
+
return response
|
426
|
+
end
|
427
|
+
|
428
|
+
def destroy(status_id)
|
429
|
+
begin
|
430
|
+
response = @access_token.post("http://api.twitter.com/1/statuses/destroy/#{status_id}.xml")
|
431
|
+
rescue
|
432
|
+
return false
|
433
|
+
end
|
434
|
+
return response
|
435
|
+
end
|
436
|
+
|
437
|
+
def update_location(location='')
|
438
|
+
location = URI.escape(location)
|
439
|
+
begin
|
440
|
+
response = @access_token.post("http://api.twitter.com/1/account/update_location.xml?location=#{location}")
|
441
|
+
rescue
|
442
|
+
return false
|
443
|
+
end
|
444
|
+
return response
|
445
|
+
end
|
446
|
+
|
447
|
+
class List
|
448
|
+
attr_reader :id
|
449
|
+
attr_reader :name
|
450
|
+
attr_reader :full_name
|
451
|
+
attr_reader :slug
|
452
|
+
attr_reader :description
|
453
|
+
attr_reader :subscriber_count
|
454
|
+
attr_reader :member_count
|
455
|
+
attr_reader :uri
|
456
|
+
attr_reader :following
|
457
|
+
attr_reader :mode
|
458
|
+
attr_reader :user
|
459
|
+
|
460
|
+
def initialize(element)
|
461
|
+
@id = element.elements['id'].text()
|
462
|
+
@name = element.elements['name'].text()
|
463
|
+
@full_name = element.elements['full_name'].text()
|
464
|
+
@slug = element.elements['slug'].text()
|
465
|
+
@description = element.elements['description'].text()
|
466
|
+
@subscriber_count = element.elements['subscriber_count'].text()
|
467
|
+
@member_count = element.elements['member_count'].text()
|
468
|
+
@uri = element.elements['uri'].text()
|
469
|
+
@following = element.elements['following'].text()
|
470
|
+
@mode = element.elements['mode'].text()
|
471
|
+
@user = User.new(element.elements['user'])
|
472
|
+
end
|
473
|
+
end
|
474
|
+
class DirectMessage
|
475
|
+
attr_reader :id
|
476
|
+
attr_reader :sender_id
|
477
|
+
attr_reader :text
|
478
|
+
attr_reader :recipient_id
|
479
|
+
attr_reader :created_at
|
480
|
+
attr_reader :sender_screen_name
|
481
|
+
attr_reader :recipient_screen_name
|
482
|
+
attr_reader :sender
|
483
|
+
attr_reader :recipient
|
484
|
+
|
485
|
+
def initialize(element)
|
486
|
+
@id = element.elements['id'].text()
|
487
|
+
@sender_id = element.elements['sender_id'].text()
|
488
|
+
@text = element.elements['text'].text()
|
489
|
+
@recipient_id = element.elements['recipient_id'].text()
|
490
|
+
@created_at = element.elements['created_at'].text()
|
491
|
+
@sender_screen_name = element.elements['sender_screen_name'].text()
|
492
|
+
@recipient_screen_name= element.elements['recipient_screen_name'].text()
|
493
|
+
@sender = User.new(element.elements['sender'])
|
494
|
+
@recipient = User.new(element.elements['recipient'])
|
495
|
+
end
|
496
|
+
end
|
497
|
+
class User
|
498
|
+
attr_reader :id
|
499
|
+
attr_reader :name
|
500
|
+
attr_reader :screen_name
|
501
|
+
attr_reader :description
|
502
|
+
attr_reader :url
|
503
|
+
attr_reader :followers_count
|
504
|
+
attr_reader :friends_count
|
505
|
+
attr_reader :statuses_count
|
506
|
+
attr_reader :location
|
507
|
+
attr_reader :profile_image_url
|
508
|
+
attr_reader :profile_background_color
|
509
|
+
attr_reader :profile_background_image_url
|
510
|
+
attr_reader :profile_background_tile
|
511
|
+
attr_reader :profile_text_color
|
512
|
+
attr_reader :profile_link_color
|
513
|
+
attr_reader :profile_sidebar_fill_color
|
514
|
+
attr_reader :profile_sidebar_border_color
|
515
|
+
attr_reader :protected
|
516
|
+
attr_reader :created_at
|
517
|
+
attr_reader :favourites_count
|
518
|
+
attr_reader :utc_offset
|
519
|
+
attr_reader :time_zone
|
520
|
+
attr_reader :notifications
|
521
|
+
attr_reader :geo_enabled
|
522
|
+
attr_reader :verified
|
523
|
+
attr_reader :lang
|
524
|
+
attr_reader :contributors_enabled
|
525
|
+
attr_reader :following
|
526
|
+
attr_reader :follow_request_sent
|
527
|
+
|
528
|
+
def initialize(element)
|
529
|
+
@id = element.elements['id'].text()
|
530
|
+
@name = element.elements['name'].text()
|
531
|
+
@screen_name = element.elements['screen_name'].text()
|
532
|
+
@location = element.elements['location'].text()
|
533
|
+
@description = element.elements['description'].text()
|
534
|
+
@profile_image_url = element.elements['profile_image_url'].text()
|
535
|
+
@url = element.elements['url'].text()
|
536
|
+
@protected = element.elements['protected'].text()
|
537
|
+
@followers_count = element.elements['followers_count'].text()
|
538
|
+
@friends_count = element.elements['friends_count'].text()
|
539
|
+
@profile_background_color = element.elements['profile_background_color'].text()
|
540
|
+
@profile_background_image_url = element.elements['profile_background_image_url'].text()
|
541
|
+
@profile_background_tile = element.elements['profile_background_tile'].text()
|
542
|
+
@profile_text_color = element.elements['profile_text_color'].text()
|
543
|
+
@profile_link_color = element.elements['profile_link_color'].text()
|
544
|
+
@profile_sidebar_fill_color = element.elements['profile_sidebar_fill_color'].text()
|
545
|
+
@profile_sidebar_border_color = element.elements['profile_sidebar_border_color'].text()
|
546
|
+
@statuses_count = element.elements['statuses_count'].text()
|
547
|
+
@created_at = element.elements['created_at'].text()
|
548
|
+
@favourites_count = element.elements['favourites_count'].text()
|
549
|
+
@utc_offset = element.elements['utc_offset'].text()
|
550
|
+
@time_zone = element.elements['time_zone'].text()
|
551
|
+
@notifications = element.elements['notifications'].text()
|
552
|
+
@geo_enabled = element.elements['geo_enabled'].text()
|
553
|
+
@verified = element.elements['verified'].text()
|
554
|
+
@lang = element.elements['lang'].text()
|
555
|
+
@contributors_enabled = element.elements['contributors_enabled'].text()
|
556
|
+
@following = element.elements['following'].text()
|
557
|
+
@follow_request_sent = element.elements['follow_request_sent'].text()
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
class Status
|
562
|
+
attr_reader :created_at
|
563
|
+
attr_reader :id
|
564
|
+
attr_reader :text
|
565
|
+
attr_reader :source
|
566
|
+
attr_reader :truncated
|
567
|
+
attr_reader :in_reply_to_status_id
|
568
|
+
attr_reader :in_reply_to_user_id
|
569
|
+
attr_reader :in_reply_to_screen_name
|
570
|
+
attr_reader :favorited
|
571
|
+
attr_reader :user
|
572
|
+
attr_reader :geo
|
573
|
+
attr_reader :place
|
574
|
+
attr_reader :coordinates
|
575
|
+
attr_reader :contributors
|
576
|
+
attr_reader :annotations
|
577
|
+
attr_reader :entities
|
578
|
+
|
579
|
+
def initialize(element)
|
580
|
+
@created_at = element.elements['created_at'].text()
|
581
|
+
@id = element.elements['id'].text()
|
582
|
+
@text = element.elements['text'].text()
|
583
|
+
@source = element.elements['source'].text()
|
584
|
+
@truncated = element.elements['truncated'].text()
|
585
|
+
@in_reply_to_status_id = element.elements['in_reply_to_status_id'].text()
|
586
|
+
@in_reply_to_user_id = element.elements['in_reply_to_user_id'].text()
|
587
|
+
@in_reply_to_screen_name = element.elements['in_reply_to_screen_name'].text()
|
588
|
+
@favorited = element.elements['favorited'].text()
|
589
|
+
@user = User.new(element.elements['user'])
|
590
|
+
@geo = element.elements['geo'].text()
|
591
|
+
@place = element.elements['place'].text()
|
592
|
+
@coordinates = (element.elements['coordinates'].nil?) ? nil : element.elements['coordinates'].text()
|
593
|
+
@contributors = (element.elements['contributors'].nil?) ? nil : element.elements['contributors'].text()
|
594
|
+
@annotations = (element.elements['annotations'].nil?) ? nil : element.elements['annotations'].text()
|
595
|
+
@entities = (element.elements['entities'].nil?) ? nil : Entities.new(element.elements['entities'])
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
class Entities
|
600
|
+
attr_reader :user_mentions
|
601
|
+
attr_reader :urls
|
602
|
+
attr_reader :hashtags
|
603
|
+
|
604
|
+
def initialize(element)
|
605
|
+
@user_mentions = UserMention.new(element.elements['user_mention'])
|
606
|
+
@urls = URL.new(element.elements['urls'])
|
607
|
+
@hashtags = Hashtag.new(element.elements['hashtags'])
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
class UserMention
|
612
|
+
attr_reader :id
|
613
|
+
attr_reader :screen_name
|
614
|
+
attr_reader :name
|
615
|
+
attr_reader :start
|
616
|
+
attr_reader :end
|
617
|
+
|
618
|
+
def initialize(element)
|
619
|
+
@id = element.elements['id'].text()
|
620
|
+
@screen_name = element.elements['screen_name'].text()
|
621
|
+
@name = element.elements['name'].text()
|
622
|
+
@start = element.attributes['start']
|
623
|
+
@end = element.attributes['end']
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
class URL
|
628
|
+
attr_reader :url
|
629
|
+
attr_reader :expanded_url
|
630
|
+
attr_reader :start
|
631
|
+
attr_reader :end
|
632
|
+
|
633
|
+
def initialize(element)
|
634
|
+
@url = element.elements['url'].text()
|
635
|
+
@expanded_url = element.elements['expanded_url'].text()
|
636
|
+
@start = element.attributes['start']
|
637
|
+
@end = element.attributes['end']
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
class Hashtag
|
642
|
+
attr_reader :text
|
643
|
+
attr_reader :start
|
644
|
+
attr_reader :end
|
645
|
+
|
646
|
+
def initialize(element)
|
647
|
+
@text = element.elements['text'].text()
|
648
|
+
@start = element.attributes['start']
|
649
|
+
@end = element.attributes['end']
|
650
|
+
end
|
651
|
+
end
|
652
|
+
end
|
data/lib/pupil/keygen.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'rubygems' if RUBY_VERSION < '1.9.0'
|
5
|
+
require 'oauth'
|
6
|
+
|
7
|
+
class Pupil
|
8
|
+
def self.keygen
|
9
|
+
print "Enter OAuth Consumer_Key: "
|
10
|
+
oauth_consumer_key = gets.chomp.strip
|
11
|
+
print "Enter OAuth Consumer_Secret: "
|
12
|
+
oauth_consumer_secret = gets.chomp.strip
|
13
|
+
|
14
|
+
CONSUMER_KEY = oauth_consumer_key
|
15
|
+
CONSUMER_SECRET = oauth_consumer_secret
|
16
|
+
|
17
|
+
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => 'http://twitter.com')
|
18
|
+
|
19
|
+
request_token = consumer.get_request_token
|
20
|
+
|
21
|
+
puts "Access to this URL and approve: #{request_token.authorize_url}"
|
22
|
+
|
23
|
+
print "Enter OAuth Verifier: "
|
24
|
+
oauth_verifier = gets.chomp.strip
|
25
|
+
|
26
|
+
access_token = request_token.get_access_token(:oauth_verifier => oauth_verifier)
|
27
|
+
|
28
|
+
puts "Process complete!"
|
29
|
+
puts "Access token: #{access_token.token}"
|
30
|
+
puts "Access token secret: #{access_token.secret}"
|
31
|
+
end
|
32
|
+
end
|
data/pupil.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pupil}
|
8
|
+
s.version = "0.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Oame}]
|
12
|
+
s.date = %q{2011-09-11}
|
13
|
+
s.description = %q{The "Lazy" Twitter API wrapper for Ruby. It was made for Kbot library.}
|
14
|
+
s.email = %q{oame@oameya.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/pupil.rb",
|
29
|
+
"lib/pupil/keygen.rb",
|
30
|
+
"pupil.gemspec",
|
31
|
+
"spec/pupil_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/oame/pupil}
|
35
|
+
s.licenses = [%q{MIT}]
|
36
|
+
s.require_paths = [%q{lib}]
|
37
|
+
s.rubygems_version = %q{1.8.5}
|
38
|
+
s.summary = %q{The Twitter API Wrapper for Ruby}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
46
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
49
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<oauth>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
56
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<oauth>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/spec/pupil_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
### WARNING ###
|
4
|
+
# pupil_spec require PUPIL_TESTKEY in spec_testkey.rb
|
5
|
+
# You should create file spec_testkey.rb into /spec to define PUPIL_TESTKEY with Pupil key.
|
6
|
+
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
8
|
+
|
9
|
+
describe Pupil, "が #home_timeline を呼ぶ時は" do
|
10
|
+
before do
|
11
|
+
pupil = Pupil.new PUPIL_TESTKEY
|
12
|
+
@home_timeline = pupil.home_timeline
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Array型を返すこと" do
|
16
|
+
@home_timeline.class.should == Array
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'pupil'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
require "#{File.dirname(__FILE__)}/pupil_testkey.rb"
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pupil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Oame
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: oauth
|
16
|
+
requirement: &2154807720 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154807720
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2154807120 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.3.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2154807120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
requirement: &2154806520 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.6.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2154806520
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &2154805920 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2154805920
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &2154805280 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.6.4
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2154805280
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rcov
|
71
|
+
requirement: &2154804680 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2154804680
|
80
|
+
description: The "Lazy" Twitter API wrapper for Ruby. It was made for Kbot library.
|
81
|
+
email: oame@oameya.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.rdoc
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .rspec
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- lib/pupil.rb
|
97
|
+
- lib/pupil/keygen.rb
|
98
|
+
- pupil.gemspec
|
99
|
+
- spec/pupil_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
homepage: http://github.com/oame/pupil
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -2172588966398234870
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.5
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: The Twitter API Wrapper for Ruby
|
129
|
+
test_files: []
|