twiauth 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .idea
23
+ **/config.yml
24
+ access_token.yml
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Sascha Wessel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,35 @@
1
+ = twiauth
2
+
3
+ == Description
4
+
5
+ tiwauth is an short and simple oauth wrapper for twitter.
6
+ You need to register an application of the type desktop application on dev.twitter.com first!
7
+
8
+ == Example
9
+
10
+ @oauth = TwiAuth::OAuth.new(@oauth_key, @oauth_secret)
11
+ @oauth.get('/1/statuses/home_timeline.json')
12
+
13
+ This returns your timeline in the json format. You still need to parse it with the json library of your choise.
14
+
15
+ == Testing
16
+
17
+ the tests are very poor, but it's hard to test
18
+
19
+ == Documentation
20
+
21
+ the full documentatin is available on RubyDoc.info
22
+
23
+ == Note on Patches/Pull Requests
24
+
25
+ * Fork the project.
26
+ * Make your feature addition or bug fix.
27
+ * Add tests for it. This is important so I don't break it in a
28
+ future version unintentionally.
29
+ * Commit, do not mess with rakefile, version, or history.
30
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
31
+ * Send me a pull request. Bonus points for topic branches.
32
+
33
+ == Copyright
34
+
35
+ Copyright (c) 2010 Sascha Wessel. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake'
2
+ require 'rubygems'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "twiauth"
8
+ gem.summary = %Q{a very simple twitter authentication wrapper}
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')
30
+ end
31
+
32
+ desc "run all specs"
33
+ begin
34
+ gem 'rspec','1.3.0'
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
42
+
43
+ task :test => [:check_dependencies, :spec]
44
+ task :default => [:test, :build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,6 @@
1
+ module TwiAuth
2
+ module Handler
3
+ def get(path) end
4
+ def post(path, body = nil) end
5
+ end
6
+ end
@@ -0,0 +1,71 @@
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
+ ACCESS_TOKEN = 'access_token.yml'
12
+
13
+ public
14
+ def initialize(key, secret)
15
+ @oauth_consumer = ::OAuth::Consumer.new(key, secret, TWITTER_OAUTH_SPEC)
16
+ get_access_token
17
+ end
18
+
19
+ def get(path)
20
+ @access_token.get(path)
21
+ end
22
+
23
+ def post(path, body = nil)
24
+ @access_token.post(path, body)
25
+ end
26
+
27
+ def drop_access_token
28
+ if ::File.exists?(ACCESS_TOKEN)
29
+ ::File.delete(ACCESS_TOKEN)
30
+ end
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
+ if ::File.exists?(ACCESS_TOKEN)
60
+ @access_token = ::YAML.load_file(ACCESS_TOKEN)
61
+ end
62
+ end
63
+
64
+ def persist_access_token
65
+ ::File.open(ACCESS_TOKEN, 'w') do |out|
66
+ YAML.dump(@access_token, out)
67
+ end
68
+ end
69
+
70
+ end
71
+ end
data/lib/twiauth.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'oauth'
2
+ require 'twiauth/oauth'
3
+
4
+ module TwiAuth
5
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
+ VERSION = ::File.exist?(PATH + 'VERSION') ? ::File.read(PATH+'VERSION') : ""
8
+ end
@@ -0,0 +1,2 @@
1
+ oauth_key: {your oauth key}
2
+ oauth_secret: {your oauth secret}
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,22 @@
1
+ require 'twiauth'
2
+ require 'yaml'
3
+ require 'json'
4
+
5
+ def pull_config
6
+ yml_config = YAML.load_file(File.dirname(__FILE__) + "/config.yml")
7
+ yml_config.each do |key, value|
8
+ instance_variable_set("@#{key}", value)
9
+ end
10
+ end
11
+
12
+ def parse_json(object)
13
+ JSON.parser.new(object).parse
14
+ end
15
+
16
+ def assign(key, value, object)
17
+ object.instance_variable_set("@#{key}", value)
18
+ end
19
+
20
+ def pull(key, object)
21
+ object.instance_variable_get("@#{key}")
22
+ end
data/twiauth.gemspec ADDED
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{twiauth}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sascha Wessel"]
12
+ s.date = %q{2010-09-10}
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/handler.rb",
27
+ "lib/twiauth/oauth.rb",
28
+ "spec/config.yml.sample",
29
+ "spec/oauth_spec.rb",
30
+ "spec/spec_helper.rb",
31
+ "twiauth.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/gr4y/twiauth}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{a very simple twitter authentication wrapper}
38
+ s.test_files = [
39
+ "spec/spec_helper.rb",
40
+ "spec/oauth_spec.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<oauth>, [">= 0.4.0"])
49
+ s.add_runtime_dependency(%q<rspec>, ["= 1.3.0"])
50
+ else
51
+ s.add_dependency(%q<oauth>, [">= 0.4.0"])
52
+ s.add_dependency(%q<rspec>, ["= 1.3.0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<oauth>, [">= 0.4.0"])
56
+ s.add_dependency(%q<rspec>, ["= 1.3.0"])
57
+ end
58
+ end
59
+
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twiauth
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Sascha Wessel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-10 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 4
31
+ - 0
32
+ version: 0.4.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 3
46
+ - 0
47
+ version: 1.3.0
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ description: simple twitter authentication wrapper
51
+ email: swessel@gr4yweb.de
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files:
57
+ - LICENSE
58
+ - README.rdoc
59
+ files:
60
+ - .gitignore
61
+ - LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/twiauth.rb
66
+ - lib/twiauth/handler.rb
67
+ - lib/twiauth/oauth.rb
68
+ - spec/config.yml.sample
69
+ - spec/oauth_spec.rb
70
+ - spec/spec_helper.rb
71
+ - twiauth.gemspec
72
+ has_rdoc: true
73
+ homepage: http://github.com/gr4y/twiauth
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.7
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: a very simple twitter authentication wrapper
104
+ test_files:
105
+ - spec/spec_helper.rb
106
+ - spec/oauth_spec.rb