rubytter 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.1.0
@@ -1,7 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
2
  require 'rubygems'
3
3
  require 'rubytter'
4
- require 'oauth'
5
4
 
6
5
  key = ""
7
6
  secret = ""
@@ -0,0 +1,23 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
2
+ require 'rubygems'
3
+ require 'rubytter'
4
+
5
+ XAuthRubytter.init(
6
+ :key => 'CONSUMER-KEY',
7
+ :secret => 'CONSUMER-SECRET'
8
+ )
9
+
10
+ # # OR
11
+ # XAuthRubytter.init(
12
+ # :key => 'CONSUMER-KEY',
13
+ # :secret => 'CONSUMER-SECRET',
14
+ # :ca_file => 'PATH-TO-CA_FILE'
15
+ # )
16
+
17
+ client = XAuthRubytter.new('LOGIN', 'PASSWORD')
18
+ p client.access_token.token
19
+ p client.access_token.secret
20
+
21
+ client.friends_timeline.each do |status|
22
+ puts "#{status.user.screen_name}: #{status.text}"
23
+ end
@@ -0,0 +1,32 @@
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
data/lib/rubytter.rb CHANGED
@@ -1,13 +1,14 @@
1
-
2
1
  # -*- coding: utf-8 -*-
3
2
  require 'rubygems'
4
3
  require 'json'
5
4
  require 'net/https'
6
5
  require 'cgi'
7
6
 
7
+ require 'oauth'
8
+ require 'rubytter/core_ext'
8
9
  require 'rubytter/connection'
9
10
  require 'rubytter/oauth_rubytter'
10
- require 'rubytter/core_ext'
11
+ require 'rubytter/xauth_rubytter'
11
12
 
12
13
  class Rubytter
13
14
  VERSION = File.read(File.join(File.dirname(__FILE__), '../VERSION')).strip
@@ -26,6 +27,10 @@ class Rubytter
26
27
  def initialize(login = nil, password = nil, options = {})
27
28
  @login = login
28
29
  @password = password
30
+ setup(options)
31
+ end
32
+
33
+ def setup(options)
29
34
  @host = options[:host] || 'twitter.com'
30
35
  @header = {'User-Agent' => "Rubytter/#{VERSION} (http://github.com/jugyo/rubytter)"}
31
36
  @header.merge!(options[:header]) if options[:header]
@@ -0,0 +1,13 @@
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
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.3
4
+ version: 1.1.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-01-31 00:00:00 +09:00
12
+ date: 2010-03-12 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -56,11 +56,14 @@ files:
56
56
  - examples/search.rb
57
57
  - examples/update_status.rb
58
58
  - examples/use_oauth.rb
59
+ - examples/use_xauth.rb
59
60
  - examples/user.rb
60
61
  - lib/rubytter.rb
61
62
  - lib/rubytter/connection.rb
62
63
  - lib/rubytter/core_ext.rb
63
64
  - lib/rubytter/oauth_rubytter.rb
65
+ - lib/rubytter/xauth_rubytter.rb
66
+ - spec/rubytter/xauth_rubytter_spec.rb
64
67
  - spec/rubytter_spec.rb
65
68
  - spec/search.json
66
69
  - spec/spec_helper.rb
@@ -93,6 +96,7 @@ signing_key:
93
96
  specification_version: 3
94
97
  summary: Simple twitter client.
95
98
  test_files:
99
+ - spec/rubytter/xauth_rubytter_spec.rb
96
100
  - spec/rubytter_spec.rb
97
101
  - spec/spec_helper.rb
98
102
  - examples/direct_message.rb
@@ -106,4 +110,5 @@ test_files:
106
110
  - examples/search.rb
107
111
  - examples/update_status.rb
108
112
  - examples/use_oauth.rb
113
+ - examples/use_xauth.rb
109
114
  - examples/user.rb