rubytter 0.9.3 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ begin
9
9
  gem.description = %Q{Rubytter is a simple twitter client.}
10
10
  gem.email = "jugyo.org@gmail.com"
11
11
  gem.homepage = "http://github.com/jugyo/rubytter"
12
+ gem.rubyforge_project = "rubytter"
12
13
  gem.authors = ["jugyo"]
13
14
  gem.files = FileList['lib/**/*.rb', 'README.rdoc', 'History.txt', 'Rakefile', 'spec/**/*.rb', 'spec/**/*.json', 'examples/**/*.rb']
14
15
  gem.add_dependency("json_pure", ">= 1.1.3")
data/examples/lists.rb ADDED
@@ -0,0 +1,37 @@
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
+
13
+ puts 'create list...'
14
+ list = client.create_list('test')
15
+ puts " => : #{list.full_name}"
16
+
17
+ puts 'get lists..'
18
+ puts ' =>' + client.lists(ARGV[0]).lists.map{|i| i.slug}.inspect
19
+
20
+ puts 'add member to list...'
21
+ add_user = client.user('termtter')
22
+ client.add_member_to_list(list.slug, add_user.id)
23
+ members = client.list_members(ARGV[0], list.slug)
24
+ puts ' =>' + members.users.map{|i| i.screen_name}.inspect
25
+
26
+ puts 'remove member from list...'
27
+ client.remove_member_from_list(list.slug, add_user.id)
28
+ members = client.list_members(ARGV[0], list.slug)
29
+ puts ' =>' + members.users.map{|i| i.screen_name}.inspect
30
+
31
+ puts 'delete list...'
32
+ client.delete_list(list.slug)
33
+
34
+ puts 'get lists..'
35
+ puts ' =>' + client.lists(ARGV[0]).lists.map{|i| i.slug}.inspect
36
+
37
+ puts 'done'
@@ -19,6 +19,18 @@ class OAuthRubytter < Rubytter
19
19
  structize(@access_token.post(path, params, @header))
20
20
  end
21
21
 
22
+ def put(path, params = {})
23
+ path += '.json'
24
+ structize(@access_token.put(path, params, @header))
25
+ end
26
+
27
+ def delete(path, params = {})
28
+ path += '.json'
29
+ param_str = self.class.to_param_str(params)
30
+ path = path + '?' + param_str unless param_str.empty?
31
+ structize(@access_token.delete(path, @header))
32
+ end
33
+
22
34
  def structize(res)
23
35
  json_data = JSON.parse(res.body)
24
36
  case res.code
data/lib/rubytter.rb CHANGED
@@ -8,6 +8,8 @@ require 'rubytter/connection'
8
8
  require 'rubytter/oauth_rubytter'
9
9
 
10
10
  class Rubytter
11
+ VERSION = File.read(File.join(File.dirname(__FILE__), '../VERSION')).strip
12
+
11
13
  class APIError < StandardError
12
14
  attr_reader :response
13
15
  def initialize(msg, response = nil)
@@ -73,27 +75,58 @@ class Rubytter
73
75
  saved_search /saved_searches/show/%s get
74
76
  create_saved_search /saved_searches/create post
75
77
  remove_saved_search /saved_searches/destroy/%s delete
78
+ create_list /:user/lists post
79
+ update_list /:user/lists/%s put
80
+ delete_list /:user/lists/%s delete
81
+ lists /%s/lists
82
+ lists_followers /%s/lists/memberships
83
+ list_statuses /%s/lists/%s/statuses
84
+ list /%s/lists/%s
85
+ list_members /%s/%s/members
86
+ add_member_to_list /:user/%s/members post
87
+ remove_member_from_list /:user/%s/members delete
88
+ list_following /%s/%s/subscribers
89
+ follow_list /%s/%s/subscribers post
90
+ remove_list /%s/%s/subscribers delete
76
91
  ".strip.split("\n").map{|line| line.strip.split(/\s+/)}
77
92
  end
78
93
 
79
94
  api_settings.each do |array|
80
95
  method, path, http_method = *array
81
96
  http_method ||= 'get'
82
- if /%s$/ =~ path
97
+ if /%s/ =~ path
83
98
  eval <<-EOS
84
- def #{method}(id, params = {})
85
- #{http_method}('#{path}' % id, params)
99
+ def #{method}(*args)
100
+ path = login ? '#{path}'.gsub(':user', login) :'#{path}'
101
+ params = args.last.kind_of?(Hash) ? args.pop : {}
102
+ #{http_method}(path % args, params)
86
103
  end
87
104
  EOS
88
105
  else
89
106
  eval <<-EOS
90
107
  def #{method}(params = {})
91
- #{http_method}('#{path}', params)
108
+ path = login ? '#{path}'.gsub(':user', login) :'#{path}'
109
+ #{http_method}(path, params)
92
110
  end
93
111
  EOS
94
112
  end
95
113
  end
96
114
 
115
+ alias_method :__create_list, :create_list
116
+ def create_list(name, params = {})
117
+ __create_list(params.merge({:name => name}))
118
+ end
119
+
120
+ alias_method :__add_member_to_list, :add_member_to_list
121
+ def add_member_to_list(list_slug, user_id, params = {})
122
+ __add_member_to_list(list_slug, params.merge({:id => user_id}))
123
+ end
124
+
125
+ alias_method :__remove_member_from_list, :remove_member_from_list
126
+ def remove_member_from_list(list_slug, user_id, params = {})
127
+ __remove_member_from_list(list_slug, params.merge({:id => user_id}))
128
+ end
129
+
97
130
  alias_method :__update_status, :update_status
98
131
  def update_status(params = {})
99
132
  params[:source] = @app_name if @app_name
@@ -128,7 +161,13 @@ class Rubytter
128
161
  req = create_request(Net::HTTP::Post.new(path))
129
162
  self.class.structize(http_request(@host, req, param_str))
130
163
  end
131
- alias delete post
164
+
165
+ def delete(path, params = {})
166
+ path += '.json'
167
+ param_str = self.class.to_param_str(params)
168
+ req = create_request(Net::HTTP::Delete.new(path))
169
+ self.class.structize(http_request(@host, req, param_str))
170
+ end
132
171
 
133
172
  def search(query, params = {})
134
173
  path = '/search.json'
@@ -317,6 +317,38 @@ class Rubytter
317
317
  status.user.profile_image_url.should == "http://s3.amazonaws.com/twitter_production/profile_images/63467667/megane2_normal.png"
318
318
  end
319
319
 
320
+ it 'should POST /:user/list to create list' do
321
+ @rubytter.should_receive(:post).with("/test/lists", {:name=>"foo"})
322
+ @rubytter.create_list('foo')
323
+ end
324
+
325
+ it 'should PUT /:user/list to update list' do
326
+ @rubytter.should_receive(:put).with("/test/lists/foo", {})
327
+ @rubytter.update_list('foo')
328
+ end
329
+
330
+ it 'should DELETE /:user/list to delete list' do
331
+ @rubytter.should_receive(:delete).with("/test/lists/foo", {})
332
+ @rubytter.delete_list('foo')
333
+ end
334
+
335
+ it 'should GET lists for specified user' do
336
+ @rubytter.should_receive(:get).with("/jugyo/lists", {})
337
+ @rubytter.lists('jugyo')
338
+ end
339
+
340
+ it 'should add member to list' do
341
+ @rubytter.should_receive(:post).with("/test/foo/members", {:id=>"jugyo"})
342
+ @rubytter.add_member_to_list('foo', 'jugyo')
343
+ end
344
+
345
+ it 'should remove member to list' do
346
+ @rubytter.should_receive(:delete).with("/test/foo/members", {:id=>"jugyo"})
347
+ @rubytter.remove_member_from_list('foo', 'jugyo')
348
+ end
349
+
350
+ # TODO: You should write more specs for Lists API...
351
+
320
352
  it 'should post using access_token' do
321
353
  access_token = Object.new
322
354
  rubytter = OAuthRubytter.new(access_token)
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: 0.9.3
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-30 00:00:00 +09:00
12
+ date: 2009-11-11 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - examples/follow.rb
50
50
  - examples/friends_timeline.rb
51
51
  - examples/limit.rb
52
+ - examples/lists.rb
52
53
  - examples/replies.rb
53
54
  - examples/search.rb
54
55
  - examples/update_status.rb
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  version:
83
84
  requirements: []
84
85
 
85
- rubyforge_project:
86
+ rubyforge_project: rubytter
86
87
  rubygems_version: 1.3.5
87
88
  signing_key:
88
89
  specification_version: 3
@@ -95,6 +96,7 @@ test_files:
95
96
  - examples/follow.rb
96
97
  - examples/friends_timeline.rb
97
98
  - examples/limit.rb
99
+ - examples/lists.rb
98
100
  - examples/replies.rb
99
101
  - examples/search.rb
100
102
  - examples/update_status.rb