rubytter 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -0,0 +1,26 @@
1
+ class Rubytter
2
+ class OAuth
3
+ def initialize(key, secret, ca_file = nil)
4
+ @key = key
5
+ @secret = secret
6
+ @ca_file = ca_file
7
+ end
8
+
9
+ def get_access_token_with_xauth(login, password)
10
+ if @ca_file
11
+ consumer = ::OAuth::Consumer.new(@key, @secret,
12
+ :site => 'https://api.twitter.com', :ca_file => @ca_file)
13
+ else
14
+ consumer = ::OAuth::Consumer.new(@key, @secret,
15
+ :site => 'https://api.twitter.com')
16
+ consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
17
+ end
18
+
19
+ consumer.get_access_token(nil, {}, {
20
+ :x_auth_mode => "client_auth",
21
+ :x_auth_username => login,
22
+ :x_auth_password => password
23
+ })
24
+ end
25
+ end
26
+ end
data/lib/rubytter.rb CHANGED
@@ -7,8 +7,8 @@ require 'cgi'
7
7
  require 'oauth'
8
8
  require 'rubytter/core_ext'
9
9
  require 'rubytter/connection'
10
+ require 'rubytter/oauth'
10
11
  require 'rubytter/oauth_rubytter'
11
- require 'rubytter/xauth_rubytter'
12
12
 
13
13
  class Rubytter
14
14
  VERSION = File.read(File.join(File.dirname(__FILE__), '../VERSION')).strip
@@ -0,0 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ class Rubytter::OAuth
6
+ describe Rubytter::OAuth do
7
+ context 'ca_file is specified' do
8
+ before do
9
+ @oauth = Rubytter::OAuth.new('key', 'secret', 'ca_file')
10
+ end
11
+
12
+ it 'should get_access_token_with_xauth' do
13
+ consumer = Object.new
14
+ ::OAuth::Consumer.should_receive(:new).
15
+ with(
16
+ 'key',
17
+ 'secret',
18
+ :site => 'https://api.twitter.com',
19
+ :ca_file => 'ca_file'
20
+ ).
21
+ and_return(consumer)
22
+ consumer.should_receive(:get_access_token).
23
+ with(
24
+ nil,
25
+ {},
26
+ :x_auth_mode => "client_auth",
27
+ :x_auth_username => 'login',
28
+ :x_auth_password => 'password'
29
+ ).
30
+ and_return('token')
31
+ token = @oauth.get_access_token_with_xauth('login', 'password')
32
+ token.should == 'token'
33
+ end
34
+ end
35
+
36
+ context 'ca_file is not specified' do
37
+ before do
38
+ @oauth = Rubytter::OAuth.new('key', 'secret')
39
+ end
40
+
41
+ it 'should get_access_token_with_xauth' do
42
+ consumer = Object.new
43
+ http = Object.new
44
+ consumer.should_receive(:http).and_return(http)
45
+ http.should_receive(:"verify_mode=").with(OpenSSL::SSL::VERIFY_NONE)
46
+ ::OAuth::Consumer.should_receive(:new).
47
+ with(
48
+ 'key',
49
+ 'secret',
50
+ :site => 'https://api.twitter.com'
51
+ ).
52
+ and_return(consumer)
53
+ consumer.should_receive(:get_access_token).
54
+ with(
55
+ nil,
56
+ {},
57
+ :x_auth_mode => "client_auth",
58
+ :x_auth_username => 'login',
59
+ :x_auth_password => 'password'
60
+ ).
61
+ and_return('token')
62
+ token = @oauth.get_access_token_with_xauth('login', 'password')
63
+ token.should == 'token'
64
+ end
65
+ end
66
+ end
67
+ 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: 1.1.0
4
+ version: 1.2.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: 2010-03-12 00:00:00 +09:00
12
+ date: 2010-03-13 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -61,9 +61,9 @@ files:
61
61
  - lib/rubytter.rb
62
62
  - lib/rubytter/connection.rb
63
63
  - lib/rubytter/core_ext.rb
64
+ - lib/rubytter/oauth.rb
64
65
  - lib/rubytter/oauth_rubytter.rb
65
- - lib/rubytter/xauth_rubytter.rb
66
- - spec/rubytter/xauth_rubytter_spec.rb
66
+ - spec/rubytter/oauth_spec.rb
67
67
  - spec/rubytter_spec.rb
68
68
  - spec/search.json
69
69
  - spec/spec_helper.rb
@@ -96,7 +96,7 @@ signing_key:
96
96
  specification_version: 3
97
97
  summary: Simple twitter client.
98
98
  test_files:
99
- - spec/rubytter/xauth_rubytter_spec.rb
99
+ - spec/rubytter/oauth_spec.rb
100
100
  - spec/rubytter_spec.rb
101
101
  - spec/spec_helper.rb
102
102
  - examples/direct_message.rb
@@ -1,32 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- class XAuthRubytter < OAuthRubytter
3
- def self.init(config)
4
- @@key = config[:key]
5
- @@secret = config[:secret]
6
- @@ca_file = config[:ca_file]
7
- end
8
-
9
- attr_reader :access_token
10
-
11
- def initialize(login, password, options = {})
12
- setup(options)
13
- @access_token = get_access_token(login, password)
14
- end
15
-
16
- def get_access_token(login, password)
17
- if @@ca_file
18
- consumer = OAuth::Consumer.new(@@key, @@secret,
19
- :site => 'https://api.twitter.com', :ca_file => @@ca_file)
20
- else
21
- consumer = OAuth::Consumer.new(@@key, @@secret,
22
- :site => 'https://api.twitter.com')
23
- consumer.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
24
- end
25
-
26
- consumer.get_access_token(nil, {}, {
27
- :x_auth_mode => "client_auth",
28
- :x_auth_username => login,
29
- :x_auth_password => password,
30
- })
31
- end
32
- end
@@ -1,13 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- class XAuthRubytter
6
- describe XAuthRubytter do
7
- it 'should set key and secret' do
8
- XAuthRubytter.init(:key => 'foo', :secret => 'bar')
9
- XAuthRubytter.class_eval{ @@key }.should == 'foo'
10
- XAuthRubytter.class_eval{ @@secret }.should == 'bar'
11
- end
12
- end
13
- end