Permalink
Browse files

OmniAuth-Weibo2 first commit

  • Loading branch information...
0 parents commit 8413911703f131a3e76a22eb38294c21f4d39fca @xixilive xixilive committed Dec 14, 2011
Showing with 167 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +1 −0 .rspec
  3. +12 −0 Gemfile
  4. +10 −0 Guardfile
  5. +16 −0 README.md
  6. +12 −0 Rakefile
  7. +2 −0 lib/omniauth-weibo2.rb
  8. +5 −0 lib/omniauth-weibo2/version.rb
  9. +45 −0 lib/omniauth/strategies/weibo2.rb
  10. +22 −0 omniauth-weibo2.gemspec
  11. +7 −0 spec/omniauth/strategies/weibo2_spec.rb
  12. +18 −0 spec/spec_helper.rb
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+/pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1 @@
+--colour
@@ -0,0 +1,12 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in omniauth-weibo2.gemspec
+gemspec
+
+group :development, :test do
+ gem 'guard'
+ gem 'guard-rspec'
+ gem 'guard-bundler'
+ gem 'rb-fsevent'
+ gem 'growl'
+end
@@ -0,0 +1,10 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
+
+guard 'bundler' do
+ watch('Gemfile')
+ watch('omniauth-github.gemspec')
+end
@@ -0,0 +1,16 @@
+# OmniAuth Weibo2
+
+**Note:** This gem is designed to work with weibo.com v2 which authorize via OAuth2
+
+## Getting Started
+This is an example that you might put into a Rails initializer at
+`config/initializers/omniauth.rb`:
+
+```ruby
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :weibo2, "APP_KEY", "APP_SECRET"
+end
+```
+## <a name="resources"></a>Resources
+The [Weibo Wiki](http://open.weibo.com/wiki/Oauth2)
+
@@ -0,0 +1,12 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new
+
+desc 'Run specs'
+task :default => :spec
@@ -0,0 +1,2 @@
+require 'omniauth-weibo2/version'
+require 'omniauth/strategies/weibo2'
@@ -0,0 +1,5 @@
+module OmniAuth
+ module Weibo2
+ VERSION = "1.0.0"
+ end
+end
@@ -0,0 +1,45 @@
+require 'omniauth-oauth2'
+module OmniAuth
+ module Strategies
+ class Weibo2 < OmniAuth::Strategies::OAuth2
+ option :client_options, {
+ :site => 'https://api.weibo.com',
+ :authorize_url => 'https://api.weibo.com/oauth2/authorize',
+ :token_url => 'https://api.weibo.com/oauth2/access_token',
+ :raw_info_url => 'https://api.weibo.com/2/users/show.json'
+ }
+
+ def request_phase
+ super
+ end
+
+ uid { raw_info['id'] }
+
+ info do
+ {
+ 'nickname' => raw_info['screen_name'],
+ 'email' => "#{raw_info['id']}@weibo.com",
+ 'name' => raw_info['name'],
+ 'location' => raw_info['location'],
+ 'description' => raw_info['description'],
+ 'image' => raw_info['profile_image_url'],
+ 'urls' => {
+ 'weibo' => raw_info['domain'].present?? "http://weibo.com/#{raw_info['domain']}" : "http://weibo.com/u/#{raw_info['id']}",
+ 'blog' => raw_info['url']
+ }
+ }
+ end
+
+ extra do
+ {:raw_info => raw_info}
+ end
+
+ def raw_info
+ access_token.options[:mode] = :query
+ @raw_info ||= access_token.get(default_options[:client_options][:raw_info_url]).parsed
+ end
+ end
+ end
+end
+
+OmniAuth.config.add_camelization 'weibo2', 'Weibo2'
@@ -0,0 +1,22 @@
+require File.expand_path('../lib/omniauth-weibo2/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.add_dependency 'omniauth', '~> 1.0'
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
+ gem.add_development_dependency 'rspec', '~> 2.7'
+ gem.add_development_dependency 'rack-test'
+ gem.add_development_dependency 'webmock'
+ gem.add_development_dependency 'simplecov'
+
+ gem.authors = ["Mickey"]
+ gem.email = ["xixilive@gmail.com"]
+ gem.description = %q{This gem is designed to work with weibo.com version 2}
+ gem.summary = %q{OmniAuth strategy for weibo.com v2}
+ gem.homepage = 'http://github.com/xixilive/omniauth-weibo2'
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ #gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "omniauth-weibo2"
+ gem.require_paths = ["lib"]
+ gem.version = OmniAuth::Weibo2::VERSION
+end
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe OmniAuth::Strategies::Weibo2 do
+ it 'should do some testing' do
+ pending
+ end
+end
@@ -0,0 +1,18 @@
+$:.unshift File.expand_path('..', __FILE__)
+$:.unshift File.expand_path('../../lib', __FILE__)
+
+require 'simplecov'
+SimpleCov.start
+
+require 'rspec'
+require 'rack/test'
+require 'webmock/rspec'
+require 'omniauth'
+require 'omniauth-oauth2'
+
+RSpec.configure do |config|
+ config.include WebMock::API
+ config.include Rack::Test::Methods
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
+end
+

0 comments on commit 8413911

Please sign in to comment.