Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit c21b4d5fabb5b79ca26be1551d9720c20472be57 0 parents
@ballantyne authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in omniauth-plurk.gemspec
+gemspec
0  README
No changes.
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
2  lib/omniauth-plurk.rb
@@ -0,0 +1,2 @@
+require "omniauth-plurk/version"
+require 'omniauth/strategies/plurk'
5 lib/omniauth-plurk/version.rb
@@ -0,0 +1,5 @@
+module Omniauth
+ module Plurk
+ VERSION = "1.0.0.rc2"
+ end
+end
66 lib/omniauth/strategies/plurk.rb
@@ -0,0 +1,66 @@
+require 'omniauth-oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ class Weibo < OmniAuth::Strategies::OAuth
+ option :name, 'weibo'
+ option :sign_in, true
+ def initialize(*args)
+ super
+ # taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tsina.rb#L15-21
+ options.client_options = {
+ :access_token_path => '/OAuth/access_token',
+ :authorize_path => '/OAuth/authorize',
+ :request_token_path => '/OAuth/request_token',
+ :site => 'http://www.plurk.com',
+ }
+ end
+
+ def consumer
+ consumer = ::OAuth::Consumer.new(options.consumer_key, options.consumer_secret, options.client_options)
+ consumer
+ end
+
+ uid { access_token.params[:id] }
+
+ info do
+ {
+ 'name' => raw_info['full_name'],
+ 'nickname' => raw_info['display_name'] || raw_info['nick_name'],
+ 'location' => raw_info['location'],
+ 'image' => raw_info['has_profile_image'] == 1 ? "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif" : 'http://www.plurk.com/static/default_medium.gif',
+ 'urls' => {'Plurk' => 'http://plurk.com/' + raw_info['nick_name']},
+ }
+ end
+
+ extra do
+ { :raw_info => raw_info }
+ end
+
+ #taken from https://github.com/intridea/omniauth/blob/0-3-stable/oa-oauth/lib/omniauth/strategies/oauth/tsina.rb#L52-67
+ def request_phase
+ request_token = consumer.get_request_token(:oauth_callback => callback_url)
+ session['oauth'] ||= {}
+ session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
+
+ if request_token.callback_confirmed?
+ redirect request_token.authorize_url(options[:authorize_params])
+ else
+ redirect request_token.authorize_url(options[:authorize_params].merge(:oauth_callback => callback_url))
+ end
+
+ rescue ::Timeout::Error => e
+ fail!(:timeout, e)
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
+ fail!(:service_unavailable, e)
+ end
+
+ def raw_info
+ @raw_info ||= MultiJson.decode(access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
+ rescue ::Errno::ETIMEDOUT
+ raise ::Timeout::Error
+ end
+ end
+ end
+end
24 omniauth-plurk.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "omniauth-plurk/version"
+
+Gem::Specification.new do |s|
+ s.name = "omniauth-plurk"
+ s.version = Omniauth::Plurk::VERSION
+ s.authors = ["Scott Ballantyne"]
+ s.email = ["ussballantyne@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "omniauth-plurk"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.