File: oauth2.rb

package info (click to toggle)
ruby-em-http-request 1.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 628 kB
  • ctags: 243
  • sloc: ruby: 3,478; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 649 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module EventMachine
  module Middleware
    class OAuth2
      include EM::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