Sha256: a259459c59a4a2d8178a07a22c0e81ec814e3a946b6efabee1ebd66b0f0b6045

Contents?: true

Size: 651 Bytes

Versions: 2

Compression:

Stored size: 651 Bytes

Contents

module ZMachine
  module Middleware
    class OAuth2
      include ZMachine::HttpEncoding
      attr_accessor :access_token

      def initialize(opts={})
        self.access_token = opts[:access_token] or raise "No :access_token provided"
      end

      def request(client, head, body)
        uri = client.req.uri.dup
        update_uri! uri
        client.req.set_uri uri

        [head, body]
      end

      def update_uri!(uri)
        if uri.query.nil?
          uri.query = encode_param(:access_token, access_token)
        else
          uri.query += "&#{encode_param(:access_token, access_token)}"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
z-http-request-0.2.0 lib/z-http/middleware/oauth2.rb
z-http-request-0.1.0 lib/z-http/middleware/oauth2.rb