rubytter 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rubytter.rb CHANGED
@@ -9,7 +9,7 @@ require 'rubytter/oauth_rubytter'
9
9
 
10
10
  class Rubytter
11
11
 
12
- VERSION = '0.9.1'
12
+ VERSION = '0.9.2'
13
13
 
14
14
  class APIError < StandardError
15
15
  attr_reader :response
@@ -9,16 +9,14 @@ class OAuthRubytter < Rubytter
9
9
 
10
10
  def get(path, params = {})
11
11
  path += '.json'
12
- param_str = '?' + self.class.to_param_str(params)
13
- path = path + param_str unless param_str.empty?
12
+ param_str = self.class.to_param_str(params)
13
+ path = path + '?' + param_str unless param_str.empty?
14
14
  structize(@access_token.get(path, @header))
15
15
  end
16
16
 
17
17
  def post(path, params = {})
18
18
  path += '.json'
19
- param_str = '?' + self.class.to_param_str(params)
20
- path = path + param_str unless param_str.empty?
21
- structize(@access_token.post(path, @header))
19
+ structize(@access_token.post(path, params, @header))
22
20
  end
23
21
 
24
22
  def structize(res)
@@ -206,7 +206,6 @@ class Rubytter
206
206
  end
207
207
 
208
208
  it 'should convert struct to hash' do
209
- pending
210
209
  hash = {
211
210
  :a => 'a',
212
211
  'b' => 1,
@@ -218,7 +217,14 @@ class Rubytter
218
217
  :e => [{:a => 1, :b => 2}, {:c => '&quot;&lt;&gt;&amp;'}]
219
218
  }
220
219
  struct = Rubytter.structize(hash)
221
- struct.to_hash.should == {"a"=>"a", "b"=>1, "c"=>{"a"=>1, "b"=>2}, "d"=>{"a"=>{"a"=>1, "b"=>2}, "b"=>1}, "e"=>[{"a"=>1, "b"=>2}, {"c"=>"\"<>&"}]}
220
+ struct.to_hash.should == {
221
+ :a => "a",
222
+ "b" => 1,
223
+ :b => 1,
224
+ :c => {:b => 2, :a => 1},
225
+ :e => [{:b => 2, :a => 1}, {:c => "\"<>&"}],
226
+ :d => {:b => 1, :a => {:b => 2, :a => 1}}
227
+ }
222
228
  end
223
229
 
224
230
  it 'should convert struct to hash with escape as HTML' do
@@ -312,27 +318,45 @@ class Rubytter
312
318
  end
313
319
 
314
320
  it 'should post using access_token' do
315
- pending('use mock')
316
321
  access_token = Object.new
317
322
  rubytter = OAuthRubytter.new(access_token)
318
- access_token.should_receive(:post).with('/statuses/update.json?status=tset', {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"})
323
+ response = simple_mock(:body => '{}', :code => '200')
324
+ access_token.should_receive(:post).with(
325
+ "/statuses/update.json",
326
+ {:status => 'test'},
327
+ {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
328
+ ).and_return(response)
319
329
  rubytter.update('test')
320
330
  end
321
331
 
322
332
  it 'should get using access_token' do
323
- pending('use mock')
324
333
  access_token = Object.new
325
334
  rubytter = OAuthRubytter.new(access_token)
326
- access_token.should_receive(:get).with('/statuses/friends_timeline.json', {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"})
335
+ response = simple_mock(:body => '{}', :code => '200')
336
+ access_token.should_receive(:get).with(
337
+ '/statuses/friends_timeline.json',
338
+ {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
339
+ ).and_return(response)
327
340
  rubytter.friends_timeline
328
341
  end
329
342
 
330
343
  it 'should get with params using access_token' do
331
- pending('use mock')
332
344
  access_token = Object.new
333
345
  rubytter = OAuthRubytter.new(access_token)
334
- access_token.should_receive(:get).with('/statuses/friends_timeline.json?page=2', {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"})
346
+ response = simple_mock(:body => '{}', :code => '200')
347
+ access_token.should_receive(:get).with(
348
+ '/statuses/friends_timeline.json?page=2',
349
+ {"User-Agent"=>"Rubytter/#{Rubytter::VERSION} (http://github.com/jugyo/rubytter)"}
350
+ ).and_return(response)
335
351
  rubytter.friends_timeline(:page => 2)
336
352
  end
353
+
354
+ def simple_mock(options)
355
+ o = Object.new
356
+ options.each do |k, v|
357
+ o.should_receive(k).and_return(v)
358
+ end
359
+ o
360
+ end
337
361
  end
338
362
  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.9.1
4
+ version: 0.9.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-17 00:00:00 +09:00
12
+ date: 2009-10-18 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,7 +43,6 @@ files:
43
43
  - examples/follow.rb
44
44
  - examples/friends_timeline.rb
45
45
  - examples/limit.rb
46
- - examples/oauth.rb
47
46
  - examples/replies.rb
48
47
  - examples/search.rb
49
48
  - examples/update_status.rb
data/examples/oauth.rb DELETED
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
- require 'rubygems'
4
- require 'rubytter'
5
- require 'oauth'
6
-
7
- consumer = OAuth::Consumer.new(
8
- 'O80mRgLxHgpzB5yVOnxmiA', 'jylXMjnIbfaNKpEQjgcVeZWJFTaKXFnj1RA4qTeEM', :site => 'http://twitter.com')
9
- access_token = OAuth::AccessToken.new(
10
- consumer, '3748631-AD24zbOF7TifLl3aeetzrwguivUnhJOizw0BBOOTU', 'lRNx3DtHhJ8UTu3tneoDzPMUk99iZKBY8vz4Sj9VQ6A')
11
- client = OAuthRubytter.new(access_token)
12
-
13
- client.friends_timeline.each do |status|
14
- puts "#{status.user.screen_name}: #{status.text}"
15
- end