twiauth 0.1.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -5
- data/Gemfile +3 -0
- data/Rakefile +12 -39
- data/VERSION +1 -1
- data/lib/twiauth/client.rb +86 -0
- data/lib/twiauth.rb +2 -3
- data/spec/client_spec.rb +72 -0
- data/spec/config/config.yml.sample +4 -0
- data/spec/config/test.yml.sample +4 -0
- data/spec/spec_helper.rb +7 -9
- data/twiauth.gemspec +22 -57
- metadata +55 -41
- data/lib/twiauth/oauth.rb +0 -67
- data/lib/twiauth/store.rb +0 -35
- data/spec/config.yml.sample +0 -2
- data/spec/oauth_spec.rb +0 -24
- data/spec/store_spec.rb +0 -22
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,44 +1,17 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
gem.description = %Q{simple twitter authentication wrapper}
|
10
|
-
gem.email = "swessel@gr4yweb.de"
|
11
|
-
gem.homepage = "http://github.com/gr4y/twiauth"
|
12
|
-
gem.authors = ["Sascha Wessel"]
|
13
|
-
gem.add_dependency "oauth", ">= 0.4.0"
|
14
|
-
gem.add_dependency "rspec", "1.3.0"
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "generate rdoc"
|
23
|
-
require 'rake/rdoctask'
|
24
|
-
Rake::RDocTask.new do |rdoc|
|
25
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
26
|
-
rdoc.rdoc_dir = 'rdoc'
|
27
|
-
rdoc.title = "twiauth #{version}"
|
28
|
-
rdoc.rdoc_files.include('README*')
|
29
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
4
|
+
desc "generate documentation"
|
5
|
+
require 'yard'
|
6
|
+
YARD::Rake::YardocTask.new do |yard|
|
7
|
+
yard.files = ['lib/**/*.rb']
|
8
|
+
yard.options = ["--no-private"]
|
30
9
|
end
|
31
10
|
|
32
11
|
desc "run all specs"
|
33
|
-
|
34
|
-
|
35
|
-
require 'spec/rake/spectask'
|
36
|
-
Spec::Rake::SpecTask.new do |t|
|
37
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
38
|
-
end
|
39
|
-
rescue LoadError
|
40
|
-
warn "[twiauth] rspec is not installed. install it with: gem install rspec --version 1.3.0"
|
41
|
-
end
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
42
14
|
|
43
|
-
task :test => [:
|
44
|
-
task :
|
15
|
+
task :test => [:spec]
|
16
|
+
task :doc => [:yard]
|
17
|
+
task :default => [:test, :doc, :build]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0.rc1
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module TwiAuth
|
2
|
+
# oauth client
|
3
|
+
class Client
|
4
|
+
|
5
|
+
attr_accessor :consumer, :request_token, :access_token, :parser
|
6
|
+
|
7
|
+
# we only need to set the site
|
8
|
+
# all other configuration is default configuration
|
9
|
+
TWITTER_OAUTH_SPEC = { :site => 'https://api.twitter.com' }
|
10
|
+
|
11
|
+
#
|
12
|
+
# connect to the twitter api
|
13
|
+
#
|
14
|
+
# @client = TwiAuth::Client.new( {:key => @consumer_key, :secret => @consumer_secret})
|
15
|
+
#
|
16
|
+
def initialize(consumer, options = {})
|
17
|
+
# raise "options are nil" if options.nil?
|
18
|
+
self.access_token = nil # options[:access_token]
|
19
|
+
if self.access_token.nil?
|
20
|
+
raise "consumer could not be nil!" if consumer.nil?
|
21
|
+
self.consumer = connect(consumer['key'], consumer['secret'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_request_token
|
26
|
+
if self.request_token.nil?
|
27
|
+
self.request_token = self.consumer.get_request_token
|
28
|
+
end
|
29
|
+
self.request_token
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# get access token
|
34
|
+
#
|
35
|
+
def get_access_token(pin = nil)
|
36
|
+
if self.access_token.nil?
|
37
|
+
self.access_token = self.request_token.get_access_token(:oauth_verifier => pin)
|
38
|
+
end
|
39
|
+
self.access_token
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# get something from the api
|
44
|
+
#
|
45
|
+
def get(url, options = nil)
|
46
|
+
request(url, options, :get)
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# post something to the api
|
51
|
+
#
|
52
|
+
def post(url, options = nil)
|
53
|
+
request(url, options, :post)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
#
|
59
|
+
# create an oauth consumer
|
60
|
+
#
|
61
|
+
def connect(key, secret)
|
62
|
+
OAuth::Consumer.new(key, secret, TWITTER_OAUTH_SPEC)
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# send an post or get request with the specified options to the given url
|
67
|
+
#
|
68
|
+
def request(url, options = nil, http_method)
|
69
|
+
if http_method.eql?(:post)
|
70
|
+
response = get_access_token.post(url, options).body
|
71
|
+
elsif http_method.eql?(:get)
|
72
|
+
response = get_access_token.get(url).body
|
73
|
+
else
|
74
|
+
raise "invalid http_method"
|
75
|
+
end
|
76
|
+
parse_json(response)
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# parse the json string into an nice ruby hash
|
81
|
+
#
|
82
|
+
def parse_json(string)
|
83
|
+
Yajl::Parser.parse(string)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/twiauth.rb
CHANGED
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TwiAuth::Client do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@client = TwiAuth::Client.new(@consumer, @options)
|
7
|
+
@session = Capybara::Session.new(:akephalos)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should not be nil' do
|
11
|
+
@client.should_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have an method called get_request_token' do
|
15
|
+
(@client.public_methods.include?(:get_request_token)).should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should get an request_token' do
|
19
|
+
@client.get_request_token.should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'visits the authorize url' do
|
23
|
+
@session.visit(@client.get_request_token.authorize_url)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has an signin form' do
|
27
|
+
@session.has_selector?('div#signin_form').should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'fills out the form' do
|
31
|
+
@session.within('#signin_form') do
|
32
|
+
@session.fill_in 'username_or_email', :with => @test['user']
|
33
|
+
@session.fill_in 'password', :with => @test['password']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'has an allow button' do
|
38
|
+
@session.has_button?('allow').should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'clicks the allow botton' do
|
42
|
+
@session.click_button('allow')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should get an access_token' do
|
46
|
+
oauth_pin = @session.find_by_id('oauth_pin')
|
47
|
+
pin = oauth_pin.text.chomp!
|
48
|
+
@client.get_access_token(pin).should_not be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should have an public get method' do
|
52
|
+
(@client.public_methods.include? :get).should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should get an ok" do
|
56
|
+
response = @client.get('/1/help/test.json')
|
57
|
+
response.should_not be_nil
|
58
|
+
response.should == "ok"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should have an public post method' do
|
62
|
+
(@client.public_methods.include? :post).should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should post and delete a status" do
|
66
|
+
response = @client.post("/1/statuses/update.json", {:status => 'test status'})
|
67
|
+
response.should_not be_nil
|
68
|
+
destroy_response = @client.post("/1/statuses/destroy/#{response['id']}.json")
|
69
|
+
destroy_response.should_not be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
require 'akephalos'
|
1
3
|
require 'twiauth'
|
2
4
|
require 'yaml'
|
3
|
-
require 'json'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before(:all) do
|
8
|
+
path = File.dirname(__FILE__)
|
9
|
+
@consumer = YAML::load_file("#{path}/config/config.yml")
|
10
|
+
@test = YAML::load_file("#{path}/config/test.yml")
|
9
11
|
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def parse_json(object)
|
13
|
-
JSON.parser.new(object).parse
|
14
12
|
end
|
data/twiauth.gemspec
CHANGED
@@ -1,61 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'twiauth'
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "twiauth"
|
6
|
+
spec.version = TwiAuth::VERSION
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.authors = ["Sascha Wessel"]
|
9
|
+
spec.email = "swessel@gr4yweb.de"
|
10
|
+
spec.homepage = "http://github.com/gr4y/twiauth"
|
11
|
+
spec.summary = %Q{a very simple twitter authentication wrapper}
|
12
|
+
spec.description = %Q{simple twitter authentication wrapper}
|
9
13
|
|
10
|
-
|
11
|
-
s.authors = ["Sascha Wessel"]
|
12
|
-
s.date = %q{2010-09-12}
|
13
|
-
s.description = %q{simple twitter authentication wrapper}
|
14
|
-
s.email = %q{swessel@gr4yweb.de}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"lib/twiauth.rb",
|
26
|
-
"lib/twiauth/oauth.rb",
|
27
|
-
"lib/twiauth/store.rb",
|
28
|
-
"spec/config.yml.sample",
|
29
|
-
"spec/oauth_spec.rb",
|
30
|
-
"spec/spec_helper.rb",
|
31
|
-
"spec/store_spec.rb",
|
32
|
-
"twiauth.gemspec"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/gr4y/twiauth}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.7}
|
38
|
-
s.summary = %q{a very simple twitter authentication wrapper}
|
39
|
-
s.test_files = [
|
40
|
-
"spec/spec_helper.rb",
|
41
|
-
"spec/oauth_spec.rb",
|
42
|
-
"spec/store_spec.rb"
|
43
|
-
]
|
14
|
+
spec.rubyforge_project = "twiauth"
|
44
15
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_runtime_dependency(%q<oauth>, [">= 0.4.0"])
|
51
|
-
s.add_runtime_dependency(%q<rspec>, ["= 1.3.0"])
|
52
|
-
else
|
53
|
-
s.add_dependency(%q<oauth>, [">= 0.4.0"])
|
54
|
-
s.add_dependency(%q<rspec>, ["= 1.3.0"])
|
55
|
-
end
|
56
|
-
else
|
57
|
-
s.add_dependency(%q<oauth>, [">= 0.4.0"])
|
58
|
-
s.add_dependency(%q<rspec>, ["= 1.3.0"])
|
59
|
-
end
|
60
|
-
end
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.test_files = `git ls-files -- {test, spec, features}/*`.split("\n")
|
18
|
+
spec.require_paths = ["lib"]
|
61
19
|
|
20
|
+
spec.add_dependency "oauth", "~> 0.4.0"
|
21
|
+
spec.add_dependency "yajl-ruby", "~> 0.8.2"
|
22
|
+
spec.add_dependency "rspec", "~> 2.5.0"
|
23
|
+
spec.add_development_dependency "capybara", "~> 0.4.1"
|
24
|
+
spec.add_development_dependency "akephalos", "~> 0.2.5"
|
25
|
+
# see http://www.rubygems.org/read/chapter/20 for additional settings
|
26
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twiauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
version: 0.1.0
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.0.0.rc1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Sascha Wessel
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-04-02 00:00:00 +02:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -23,60 +19,84 @@ dependencies:
|
|
23
19
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
20
|
none: false
|
25
21
|
requirements:
|
26
|
-
- -
|
22
|
+
- - ~>
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 4
|
31
|
-
- 0
|
32
24
|
version: 0.4.0
|
33
25
|
type: :runtime
|
34
26
|
version_requirements: *id001
|
35
27
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
28
|
+
name: yajl-ruby
|
37
29
|
prerelease: false
|
38
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
31
|
none: false
|
40
32
|
requirements:
|
41
|
-
- -
|
33
|
+
- - ~>
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
- 1
|
45
|
-
- 3
|
46
|
-
- 0
|
47
|
-
version: 1.3.0
|
35
|
+
version: 0.8.2
|
48
36
|
type: :runtime
|
49
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.5.0
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: capybara
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.4.1
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: akephalos
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.5
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
50
71
|
description: simple twitter authentication wrapper
|
51
72
|
email: swessel@gr4yweb.de
|
52
73
|
executables: []
|
53
74
|
|
54
75
|
extensions: []
|
55
76
|
|
56
|
-
extra_rdoc_files:
|
57
|
-
|
58
|
-
- README.rdoc
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
59
79
|
files:
|
60
80
|
- .gitignore
|
81
|
+
- Gemfile
|
61
82
|
- LICENSE
|
62
83
|
- README.rdoc
|
63
84
|
- Rakefile
|
64
85
|
- VERSION
|
65
86
|
- lib/twiauth.rb
|
66
|
-
- lib/twiauth/
|
67
|
-
-
|
68
|
-
- spec/config.yml.sample
|
69
|
-
- spec/
|
87
|
+
- lib/twiauth/client.rb
|
88
|
+
- spec/client_spec.rb
|
89
|
+
- spec/config/config.yml.sample
|
90
|
+
- spec/config/test.yml.sample
|
70
91
|
- spec/spec_helper.rb
|
71
|
-
- spec/store_spec.rb
|
72
92
|
- twiauth.gemspec
|
73
93
|
has_rdoc: true
|
74
94
|
homepage: http://github.com/gr4y/twiauth
|
75
95
|
licenses: []
|
76
96
|
|
77
97
|
post_install_message:
|
78
|
-
rdoc_options:
|
79
|
-
|
98
|
+
rdoc_options: []
|
99
|
+
|
80
100
|
require_paths:
|
81
101
|
- lib
|
82
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -84,25 +104,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
104
|
requirements:
|
85
105
|
- - ">="
|
86
106
|
- !ruby/object:Gem::Version
|
87
|
-
segments:
|
88
|
-
- 0
|
89
107
|
version: "0"
|
90
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
109
|
none: false
|
92
110
|
requirements:
|
93
|
-
- - "
|
111
|
+
- - ">"
|
94
112
|
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
- 0
|
97
|
-
version: "0"
|
113
|
+
version: 1.3.1
|
98
114
|
requirements: []
|
99
115
|
|
100
|
-
rubyforge_project:
|
101
|
-
rubygems_version: 1.
|
116
|
+
rubyforge_project: twiauth
|
117
|
+
rubygems_version: 1.5.2
|
102
118
|
signing_key:
|
103
119
|
specification_version: 3
|
104
120
|
summary: a very simple twitter authentication wrapper
|
105
|
-
test_files:
|
106
|
-
|
107
|
-
- spec/oauth_spec.rb
|
108
|
-
- spec/store_spec.rb
|
121
|
+
test_files: []
|
122
|
+
|
data/lib/twiauth/oauth.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
module TwiAuth
|
2
|
-
# oauth communication wrapper
|
3
|
-
class OAuth
|
4
|
-
TWITTER_OAUTH_SPEC = {
|
5
|
-
:site => 'https://api.twitter.com',
|
6
|
-
:request_token_path => '/oauth/request_token',
|
7
|
-
:access_token_path => '/oauth/access_token',
|
8
|
-
:authorize_path => '/oauth/authorize'
|
9
|
-
}
|
10
|
-
|
11
|
-
# key for access token
|
12
|
-
ACCESS_TOKEN = 'ACCESS_TOKEN'
|
13
|
-
|
14
|
-
public
|
15
|
-
def initialize(key, secret)
|
16
|
-
@store = TwiAuth::Store.new
|
17
|
-
@oauth_consumer = ::OAuth::Consumer.new(key, secret, TWITTER_OAUTH_SPEC)
|
18
|
-
get_access_token
|
19
|
-
end
|
20
|
-
|
21
|
-
def get(path)
|
22
|
-
@access_token.get(path)
|
23
|
-
end
|
24
|
-
|
25
|
-
def post(path, body = nil)
|
26
|
-
@access_token.post(path, body)
|
27
|
-
end
|
28
|
-
|
29
|
-
def drop_access_token
|
30
|
-
@store.delete(ACCESS_TOKEN)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
def get_request_token
|
35
|
-
@oauth_consumer.get_request_token
|
36
|
-
end
|
37
|
-
|
38
|
-
def get_access_token
|
39
|
-
pull_access_token
|
40
|
-
if @access_token.nil?
|
41
|
-
get_initial_access_token
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def get_initial_access_token
|
46
|
-
request_token = get_request_token
|
47
|
-
puts "point your browser to \"#{request_token.authorize_url}\" and enter the pin: "
|
48
|
-
pin = STDIN.readline.chomp!
|
49
|
-
|
50
|
-
if pin.nil? || pin.empty?
|
51
|
-
raise Error
|
52
|
-
end
|
53
|
-
|
54
|
-
@access_token = request_token.get_access_token(:oauth_verifier => pin)
|
55
|
-
persist_access_token
|
56
|
-
end
|
57
|
-
|
58
|
-
def pull_access_token
|
59
|
-
@access_token = @store.get(ACCESS_TOKEN)
|
60
|
-
end
|
61
|
-
|
62
|
-
def persist_access_token
|
63
|
-
@store.put(ACCESS_TOKEN,@access_token)
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
data/lib/twiauth/store.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'pstore'
|
2
|
-
|
3
|
-
module TwiAuth
|
4
|
-
# A simple key value store using PStore, provided by ruby
|
5
|
-
class Store
|
6
|
-
# Filename for pstore data file
|
7
|
-
DATA_FILE = "data.pstore"
|
8
|
-
# :nodoc:
|
9
|
-
def initialize
|
10
|
-
@store = PStore.new("#{PATH}#{DATA_FILE}")
|
11
|
-
end
|
12
|
-
|
13
|
-
# put a key with value
|
14
|
-
def put(key, value)
|
15
|
-
@store.transaction do
|
16
|
-
@store[key] = value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# get the value of the key
|
21
|
-
def get(key)
|
22
|
-
@store.transaction do
|
23
|
-
@value = @store[key]
|
24
|
-
end
|
25
|
-
@value
|
26
|
-
end
|
27
|
-
|
28
|
-
# delete a key
|
29
|
-
def delete(key)
|
30
|
-
@store.transaction do
|
31
|
-
@store.delete(key)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/spec/config.yml.sample
DELETED
data/spec/oauth_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TwiAuth::OAuth do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
pull_config
|
7
|
-
@oauth = TwiAuth::OAuth.new(@oauth_key, @oauth_secret)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should be not nil" do
|
11
|
-
@oauth.should_not be_nil
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should get an ok" do
|
15
|
-
@oauth.get("/1/help/test.json").eql?("ok")
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should post and delete a status" do
|
19
|
-
response = @oauth.post("/1/statuses/update.json", {:status => 'test status'})
|
20
|
-
json = parse_json(response.body)
|
21
|
-
@oauth.get("/1/statuses/destroy/#{json['id']}.json")
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/spec/store_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TwiAuth::Store do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
@store = TwiAuth::Store.new
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should store some data" do
|
10
|
-
@store.put("test", "test-value")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should return some data" do
|
14
|
-
@store.get("test").should.eql?("test-value")
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should delete some data" do
|
18
|
-
@store.delete("test")
|
19
|
-
@store.get("test").should be_nil
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|