Sha256: d4808613613621af57fa01dbb78ba6768b453cc4915f7f239a0aaa1a8c6bb3fd

Contents?: true

Size: 873 Bytes

Versions: 1

Compression:

Stored size: 873 Bytes

Contents

require 'sinatra'
require 'wordpress-com'

set :views, File.dirname(__FILE__)
enable :sessions

get '/' do
  if params[:code]
    wpc = WordpressCom.new(session[:client_id], session[:client_secret])
    wpc.get_token(params[:code], session[:redirect_uri])
    session[:wpc] = wpc.serialize
    redirect to('/')
  elsif session[:wpc]
    haml :authorizer_result
  else
    haml :authorizer_form
  end
end

post '/' do
  session[:client_id] = params[:client_id]
  session[:client_secret] = params[:client_secret]
  session[:blog] = params[:blog]
  session[:redirect_uri] = request.url

  wpc = WordpressCom.new(session[:client_id], session[:client_secret])
  redirect to(
    if session[:blog]
      wpc.authorize_url(request.url, :blog => session[:blog])
    else 
      wpc.authorize_url(request.url)
    end )
end

post '/forget' do
  session.clear
  redirect to('/')
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wordpress-com-0.0.1 examples/authorizer.rb