Sha256: 13e5d4d971f1d8803696365fb1e649a1d67d0f329b3e2b0a8be483c9baacc34f

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

module Admin
  class VimeoAccountController < Admin::BaseController

    include ::RefinerycmsVimeoVideos::Account
    
    def authorization
      debugger
      if not authorized? and ready_to_authorize?
        
        # begin authorization process
        base = Vimeo::Advanced::Base.new(
          account[:consumer_key],
          account[:consumer_secret])
        request_token = base.get_request_token
        session[:oauth_secret] = request_token.secret
        
        debugger
        redirect_to base.authorize_url
        
      elsif ready_to_authorize?
        
        # already authorized
        flash.notice = "You have already authorized your account."
        redirect_to "/admin"
        
      else
        
        # not ready to authorize
        raise ArgumentError, 'Not ready to authorize. Type in consumer_key and consumer_secret.'
      
      end
    end
  
    def callback
      debugger
      # vimeo will redirect us here upon successful authorization
      base = Vimeo::Advanced::Base.new(
        account[:consumer_key],
        account[:consumer_secret])
      access_token = base.get_access_token(params[:oauth_token], session[:oauth_secret], params[:oauth_verifier])
      RefinerySetting.find_by_name('vimeo_token').update_attribute(:value, access_token.token)
      RefinerySetting.find_by_name('vimeo_secret').update_attribute(:value, access_token.secret)
      flash.notice = "You successfully authorized your vimeo account for integration in your backend. You can now start using it."
      redirect_to '/admin'
    
    end
    
    protected
    
      def restrict_controller
      end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
refinerycms-vimeo-videos-0.1.5 app/controllers/admin/vimeo_account_controller.rb