Class: Gimmie::Proxy
- Inherits:
-
Object
- Object
- Gimmie::Proxy
- Defined in:
- lib/gimmie/proxy.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #consumer ⇒ Object
-
#initialize(options = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #token(access_token) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Proxy
Returns a new instance of Proxy.
8 9 10 11 12 13 |
# File 'lib/gimmie/proxy.rb', line 8 def initialize( = {}) = [:cookie_key] || ENV['GIMMIE_COOKIE_KEY'] @oauth_key = [:oauth_key] || ENV['GIMMIE_OAUTH_KEY'] @oauth_secret = [:oauth_secret] || ENV['GIMMIE_OAUTH_SECRET'] @url_prefix = [:url_prefix] || ENV['GIMMIE_URL_PREFIX'] || 'https://api.gimmieworld.com' end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gimmie/proxy.rb', line 20 def call(env) player_uid, ignore = CGI::Cookie::parse(env['HTTP_COOKIE'])[] suffix = env['REQUEST_URI'].to_s.split('gimmieapi=').last destination_url = "#{@url_prefix}#{suffix}" response = token(player_uid || '').get(destination_url) response_headers = {} response.each_capitalized do |key,value| response_headers[key] = value unless key == 'Transfer-Encoding' && value == 'chunked' end [response.code.to_i, response_headers, [response.body]] end |
#consumer ⇒ Object
14 15 16 |
# File 'lib/gimmie/proxy.rb', line 14 def consumer @consumer ||= OAuth::Consumer.new(@oauth_key, @oauth_secret, :site => @url_prefix) end |
#token(access_token) ⇒ Object
17 18 19 |
# File 'lib/gimmie/proxy.rb', line 17 def token(access_token) OAuth::AccessToken.new(consumer, access_token, @oauth_secret) end |