rubytter 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,9 +6,11 @@ http://wiki.github.com/jugyo/rubytter
6
6
 
7
7
  Rubytter is simple twitter library.
8
8
 
9
- == FEATURES/PROBLEMS:
9
+ == FEATURES:
10
10
 
11
- implemented API methods:
11
+ * Supports OAuth
12
+
13
+ === implemented API methods:
12
14
 
13
15
  - /statuses/update
14
16
  - /statuses/destroy/id
@@ -46,15 +48,21 @@ implemented API methods:
46
48
 
47
49
  == SYNOPSIS:
48
50
 
49
- initialize:
51
+ === initialize:
50
52
 
51
53
  client = Rubytter.new(user_id, password)
52
54
 
53
- update status:
55
+ or
56
+
57
+ client = OAuthRubytter.new(access_token)
58
+
59
+ You must specify valid instance of OAuth::AccessToken as acces_token.
60
+
61
+ === update status:
54
62
 
55
63
  client.update('hello twitter!!')
56
64
 
57
- get friends timeline:
65
+ === get friends timeline:
58
66
 
59
67
  client.friends_timeline.each do |status|
60
68
  puts "#{status.user.screen_name}: #{status.text}"
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ # must use oauth library.
3
+ class OAuthRubytter < Rubytter
4
+ # access_token: must be instance of OAuth::AccessToken
5
+ def initialize(access_token, options = {})
6
+ super(options)
7
+ @access_token = access_token
8
+ end
9
+
10
+ def get(path, params = {})
11
+ path += '.json'
12
+ @access_token.get(path, params, @header)
13
+ end
14
+
15
+ def post(path, params = {})
16
+ path += '.json'
17
+ @access_token.post(path, params, @header)
18
+ end
19
+ end
data/lib/rubytter.rb CHANGED
@@ -5,9 +5,12 @@ require 'net/https'
5
5
  require 'cgi'
6
6
 
7
7
  require 'rubytter/connection'
8
+ require 'rubytter/oauth_rubytter'
8
9
 
9
10
  class Rubytter
10
11
 
12
+ VERSION = '0.7.0'
13
+
11
14
  class APIError < StandardError
12
15
  attr_reader :response
13
16
  def initialize(msg, response = nil)
@@ -16,8 +19,6 @@ class Rubytter
16
19
  end
17
20
  end
18
21
 
19
- VERSION = '0.6.5'
20
-
21
22
  attr_reader :login
22
23
  attr_accessor :host, :header
23
24
 
@@ -206,7 +207,13 @@ class Rubytter
206
207
  def self.get_struct(keys)
207
208
  @@structs ||= {}
208
209
  unless @@structs.has_key?(keys)
209
- @@structs[keys] = Struct.new(*keys)
210
+ struct = Struct.new(*keys)
211
+ struct.class_eval do
212
+ def method_missing(*args, &block)
213
+ nil
214
+ end
215
+ end
216
+ @@structs[keys] = struct
210
217
  end
211
218
  @@structs[keys]
212
219
  end
@@ -189,8 +189,8 @@ class Rubytter
189
189
  struct.e[0].a.should == 1
190
190
  struct.e[0].b.should == 2
191
191
  struct.e[1].c.should == '"<>&'
192
- lambda {struct.x}.should raise_error(NoMethodError)
193
- lambda {struct.regex}.should raise_error(NoMethodError)
192
+ struct.x.should == nil
193
+ struct.regex.should == nil
194
194
  end
195
195
 
196
196
  it 'should create same structs from same datas' do
@@ -248,5 +248,26 @@ class Rubytter
248
248
  status.user.screen_name.should == "jugyo"
249
249
  status.user.profile_image_url.should == "http://s3.amazonaws.com/twitter_production/profile_images/63467667/megane2_normal.png"
250
250
  end
251
+
252
+ it 'should post using access_token' do
253
+ access_token = Object.new
254
+ rubytter = OAuthRubytter.new(access_token)
255
+ access_token.should_receive(:post).with('/statuses/update.json', {:status => 'test'}, {"User-Agent"=>"Rubytter/0.6.6 (http://github.com/jugyo/rubytter)"})
256
+ rubytter.update('test')
257
+ end
258
+
259
+ it 'should get using access_token' do
260
+ access_token = Object.new
261
+ rubytter = OAuthRubytter.new(access_token)
262
+ access_token.should_receive(:get).with('/statuses/friends_timeline.json', {}, {"User-Agent"=>"Rubytter/0.6.6 (http://github.com/jugyo/rubytter)"})
263
+ rubytter.friends_timeline
264
+ end
265
+
266
+ it 'should get with params using access_token' do
267
+ access_token = Object.new
268
+ rubytter = OAuthRubytter.new(access_token)
269
+ access_token.should_receive(:get).with('/statuses/friends_timeline.json', {:page => 2}, {"User-Agent"=>"Rubytter/0.6.6 (http://github.com/jugyo/rubytter)"})
270
+ rubytter.friends_timeline(:page => 2)
271
+ end
251
272
  end
252
273
  end
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.6.5
4
+ version: 0.7.0
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-03-25 00:00:00 +09:00
12
+ date: 2009-04-06 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,7 @@ extra_rdoc_files:
33
33
  - History.txt
34
34
  files:
35
35
  - lib/rubytter/connection.rb
36
+ - lib/rubytter/oauth_rubytter.rb
36
37
  - lib/rubytter.rb
37
38
  - spec/rubytter_spec.rb
38
39
  - spec/spec_helper.rb