Created
May 24, 2012 18:53
-
-
Save sfaxon/2783496 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'debugger' | |
require 'bundler' | |
Bundler.setup | |
require 'typhoeus' | |
require 'faraday' | |
require File.join(File.dirname(__FILE__), 'lib/active_resource') | |
module ConnectDesk | |
module Request | |
class Auth < ::Faraday::Middleware | |
def initialize(app = nil, options = {}) | |
debugger | |
@per_options = options | |
super(app) | |
end | |
def call(env) | |
debugger | |
if @per_options[:request_auth_token] | |
env[:request_headers].merge!('X-AUTH-TOKEN' => @per_options[:request_auth_token]) | |
end | |
@app.call(env) | |
end | |
end | |
end | |
end | |
class User < ActiveResource::Base | |
# self.site = 'https://theconnectdesk.com' | |
self.site = 'http://localhost:3000' | |
# self.adapter = :typhoeus | |
# scope :auth, lambda { |token| insert 0, Test::Auth, token } | |
scope :as, lambda { |token| insert 0, ConnectDesk::Request::Auth, :request_auth_token => token} | |
end | |
debugger | |
User.find(1) | |
puts User.as('skret').find(1) | |
# curl -X GET -i --header "X-AUTH-TOKEN:47aca5a742647f0919fbaf268e2985b4" https://theconnectdesk.com/users/me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try: