rubytter 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,10 +1,10 @@
1
1
  = rubytter
2
2
 
3
- http://wiki.github.com/jugyo/rubytter
3
+ http://github.com/jugyo/rubytter
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Rubytter is simple twitter library.
7
+ Rubytter is a simple twitter library.
8
8
 
9
9
  == FEATURES:
10
10
 
@@ -13,38 +13,66 @@ Rubytter is simple twitter library.
13
13
  === implemented API methods:
14
14
 
15
15
  - /statuses/update
16
- - /statuses/destroy/id
16
+ - /statuses/destroy/%s
17
17
  - /statuses/public_timeline
18
+ - /statuses/home_timeline
18
19
  - /statuses/friends_timeline
19
20
  - /statuses/replies
20
- - /statuses/user_timeline/id
21
- - /statuses/show/id
22
- - /statuses/friends/id
23
- - /statuses/followers/id
24
- - /users/show/id
21
+ - /statuses/mentions
22
+ - /statuses/user_timeline/%s
23
+ - /statuses/show/%s
24
+ - /statuses/friends/%s
25
+ - /statuses/followers/%s
26
+ - /statuses/retweet/%s
27
+ - /statuses/retweets/%s
28
+ - /statuses/retweeted_by_me
29
+ - /statuses/retweeted_to_me
30
+ - /statuses/retweets_of_me
31
+ - /users/show/%s
25
32
  - /direct_messages
26
33
  - /direct_messages/sent
27
34
  - /direct_messages/new
28
- - /direct_messages/destroy/id
29
- - /friendships/create/id
30
- - /friendships/destroy/id
35
+ - /direct_messages/destroy/%s
36
+ - /friendships/create/%s
37
+ - /friendships/destroy/%s
31
38
  - /friendships/exists
32
- - /followers/ids/id
33
- - /friends/ids/id
34
- - /favorites
35
- - /favorites/create/id
36
- - /favorites/destroy/id
39
+ - /followers/ids/%s
40
+ - /friends/ids/%s
41
+ - /favorites/%s
42
+ - /favorites/create/%s
43
+ - /favorites/destroy/%s
37
44
  - /account/verify_credentials
38
45
  - /account/end_session
39
46
  - /account/update_delivery_device
40
47
  - /account/update_profile_colors
41
48
  - /account/rate_limit_status
42
49
  - /account/update_profile
43
- - /notifications/follow/id
44
- - /notifications/leave/id
45
- - /blocks/create/id
46
- - /blocks/destroy/id
50
+ - /notifications/follow/%s
51
+ - /notifications/leave/%s
52
+ - /blocks/create/%s
53
+ - /blocks/destroy/%s
54
+ - /blocks/exists/%s
55
+ - /blocks/blocking
56
+ - /blocks/blocking/ids
57
+ - /saved_searches
58
+ - /saved_searches/show/%s
59
+ - /saved_searches/create
60
+ - /saved_searches/destroy/%s
61
+ - /:user/lists (create)
62
+ - /:user/lists/%s (update)
63
+ - /:user/lists/%s (delete)
64
+ - /:user/lists
65
+ - /:user/lists/memberships
66
+ - /:user/lists/%s/statuses
67
+ - /:user/lists/%s
68
+ - /%s/%s/members
69
+ - /:user/%s/members
70
+ - /:user/%s/members
71
+ - /%s/%s/subscribers
72
+ - /%s/%s/subscribers
73
+ - /%s/%s/subscribers
47
74
  - (search.twitter.com)/search
75
+ - (api.twitter.com)/1/users/search
48
76
 
49
77
  == SYNOPSIS:
50
78
 
@@ -79,18 +107,13 @@ or
79
107
 
80
108
  == INSTALL:
81
109
 
82
- sudo gem install rubytter
83
-
84
- or
85
-
86
- gem source -a http://gems.github.com
87
- sudo gem install jugyo-rubytter
110
+ gem install rubytter
88
111
 
89
112
  == LICENSE:
90
113
 
91
114
  (The MIT License)
92
115
 
93
- Copyright (c) 2008-2009 jugyo
116
+ Copyright (c) 2008-2010 jugyo
94
117
 
95
118
  Permission is hereby granted, free of charge, to any person obtaining
96
119
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.rubyforge_project = "rubytter"
13
13
  gem.authors = ["jugyo"]
14
14
  gem.files = FileList['lib/**/*.rb', 'VERSION', 'README.rdoc', 'History.txt', 'Rakefile', 'spec/**/*.rb', 'spec/**/*.json', 'examples/**/*.rb']
15
- gem.add_dependency("json_pure", ">= 1.1.3")
15
+ gem.add_dependency("json", ">= 1.1.3")
16
16
  gem.add_development_dependency "rspec"
17
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
18
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'rubygems'
4
+ require 'rubytter'
5
+
6
+ if ARGV.size < 2
7
+ puts "Usage: ruby #{File.basename(__FILE__)} user_id password"
8
+ exit
9
+ end
10
+
11
+ client = Rubytter.new(ARGV[0], ARGV[1])
12
+ client.home_timeline.each do |status|
13
+ puts "#{status.user.screen_name}: #{status.text}"
14
+ end
@@ -19,7 +19,17 @@ class OAuthRubytter < Rubytter
19
19
  parse_response(@access_token.post(path, params.stringify_keys, @header))
20
20
  end
21
21
 
22
- private
22
+ def put(path, params = {})
23
+ path += '.json'
24
+ parse_response(@access_token.put(path, params.stringify_keys, @header))
25
+ end
26
+
27
+ def delete(path, params = {})
28
+ path += '.json'
29
+ param_str = to_param_str(params)
30
+ path = path + '?' + param_str unless param_str.empty?
31
+ parse_response(@access_token.delete(path, @header))
32
+ end
23
33
 
24
34
  def parse_response(res)
25
35
  json_data = JSON.parse(res.body)
data/lib/rubytter.rb CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  # -*- coding: utf-8 -*-
2
3
  require 'rubygems'
3
4
  require 'json'
@@ -39,6 +40,7 @@ class Rubytter
39
40
  update_status /statuses/update post
40
41
  remove_status /statuses/destroy/%s delete
41
42
  public_timeline /statuses/public_timeline
43
+ home_timeline /statuses/home_timeline
42
44
  friends_timeline /statuses/friends_timeline
43
45
  replies /statuses/replies
44
46
  mentions /statuses/mentions
@@ -46,6 +48,11 @@ class Rubytter
46
48
  show /statuses/show/%s
47
49
  friends /statuses/friends/%s
48
50
  followers /statuses/followers/%s
51
+ retweet /statuses/retweet/%s post
52
+ retweets /statuses/retweets/%s
53
+ retweeted_by_me /statuses/retweeted_by_me
54
+ retweeted_to_me /statuses/retweeted_to_me
55
+ retweets_of_me /statuses/retweets_of_me
49
56
  user /users/show/%s
50
57
  direct_messages /direct_messages
51
58
  sent_direct_messages /direct_messages/sent
@@ -56,7 +63,7 @@ class Rubytter
56
63
  friendship_exists /friendships/exists
57
64
  followers_ids /followers/ids/%s
58
65
  friends_ids /friends/ids/%s
59
- favorites /favorites
66
+ favorites /favorites/%s
60
67
  favorite /favorites/create/%s post
61
68
  remove_favorite /favorites/destroy/%s delete
62
69
  verify_credentials /account/verify_credentials get
@@ -100,7 +107,9 @@ class Rubytter
100
107
  def #{method}(*args)
101
108
  path = login ? '#{path}'.gsub(':user', login) :'#{path}'
102
109
  params = args.last.kind_of?(Hash) ? args.pop : {}
103
- #{http_method}(path % args, params)
110
+ path = path % args
111
+ path.sub!(/\\/\\z/, '')
112
+ #{http_method}(path, params)
104
113
  end
105
114
  EOS
106
115
  else
@@ -184,6 +193,14 @@ class Rubytter
184
193
  )
185
194
  end
186
195
 
196
+ def search_user(query, params = {})
197
+ path = '/1/users/search.json'
198
+ param_str = '?' + to_param_str(params.merge({:q => query}))
199
+ path = path + param_str unless param_str.empty?
200
+ req = create_request(Net::HTTP::Get.new(path))
201
+ structize(http_request("api.#{@host}", req))
202
+ end
203
+
187
204
  def search_result_to_hash(json)
188
205
  {
189
206
  'id' => json['id'],
@@ -239,6 +256,12 @@ class Rubytter
239
256
  def method_missing(name, *args)
240
257
  self[name]
241
258
  end
259
+
260
+ def symbolize_keys!
261
+ each do |key, value|
262
+ self[(key.to_sym rescue key) || key] = value
263
+ end
264
+ end
242
265
  end
243
266
 
244
267
  data.keys.each do |k|
@@ -219,6 +219,7 @@ class Rubytter
219
219
  struct = @rubytter.structize(hash)
220
220
  struct.to_hash.should == {
221
221
  :a => "a",
222
+ "b" => 1,
222
223
  :b => 1,
223
224
  :c => {:b => 2, :a => 1},
224
225
  :e => [{:b => 2, :a => 1}, {:c => "\"<>&"}],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -13,7 +13,7 @@ date: 2010-01-31 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: json_pure
16
+ name: json
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,12 +49,12 @@ files:
49
49
  - examples/favorite.rb
50
50
  - examples/follow.rb
51
51
  - examples/friends_timeline.rb
52
+ - examples/home_timeline.rb
52
53
  - examples/limit.rb
53
54
  - examples/lists.rb
54
55
  - examples/replies.rb
55
56
  - examples/search.rb
56
57
  - examples/update_status.rb
57
- - examples/use_oauth.rb
58
58
  - examples/user.rb
59
59
  - lib/rubytter.rb
60
60
  - lib/rubytter/connection.rb
@@ -98,10 +98,10 @@ test_files:
98
98
  - examples/favorite.rb
99
99
  - examples/follow.rb
100
100
  - examples/friends_timeline.rb
101
+ - examples/home_timeline.rb
101
102
  - examples/limit.rb
102
103
  - examples/lists.rb
103
104
  - examples/replies.rb
104
105
  - examples/search.rb
105
106
  - examples/update_status.rb
106
- - examples/use_oauth.rb
107
107
  - examples/user.rb
@@ -1,28 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
- require 'rubygems'
3
- require 'rubytter'
4
- require 'oauth'
5
-
6
- key = "httN2PgAfeEuOywgw4m2g"
7
- secret = "qunvnx27QC98380PUHQ0YUhSoMFMA2HJQZisWKDOgI"
8
-
9
- consumer = OAuth::Consumer.new(key, secret, :site => "http://twitter.com")
10
-
11
- request_token = consumer.get_request_token
12
- system('open', request_token.authorize_url) || puts("Access here: #{request_token.authorize_url}\nand...")
13
-
14
- print "Enter PIN: "
15
- pin = gets.strip
16
-
17
- access_token = request_token.get_access_token(
18
- :oauth_token => request_token.token,
19
- :oauth_verifier => pin
20
- )
21
-
22
- client = OAuthRubytter.new(access_token)
23
- client.friends_timeline.each do |status|
24
- puts "#{status.user.screen_name}: #{status.text}"
25
- end
26
-
27
- require 'irby'
28
- client.irb