Sha256: 70f913c5586cb3ccc31e5c5f10c02783b1ada206ca13fc37990defcfc5a7e49a
Contents?: true
Size: 1.33 KB
Versions: 5
Compression:
Stored size: 1.33 KB
Contents
require "faraday" # @private module FaradayMiddleware # @private class InstagramOAuth2 < Faraday::Middleware def call(env) if (env[:method] == :get) || (env[:method] == :delete) query = if env[:url].query.nil? {} else Faraday::Utils.parse_query(env[:url].query) end if @access_token && !(query["client_secret"]) env[:url].query = Faraday::Utils.build_query(query.merge(access_token: @access_token)) env[:request_headers] = env[:request_headers].merge("Authorization" => "Token token=\"#{@access_token}\"") elsif @client_id env[:url].query = Faraday::Utils.build_query(query.merge(client_id: @client_id)) end else if @access_token && !(env[:body] && env[:body][:client_secret]) env[:body] = {} if env[:body].nil? env[:body] = env[:body].merge(access_token: @access_token) env[:request_headers] = env[:request_headers].merge("Authorization" => "Token token=\"#{@access_token}\"") elsif @client_id env[:body] = env[:body].merge(client_id: @client_id) end end @app.call env end def initialize(app, client_id, access_token = nil) @app = app @client_id = client_id @access_token = access_token end end end
Version data entries
5 entries across 5 versions & 2 rubygems