gimmie 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gimmie/proxy.rb +32 -0
- data/lib/gimmie.rb +4 -0
- metadata +68 -0
data/lib/gimmie/proxy.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
require 'cgi/cookie'
|
3
|
+
|
4
|
+
# routes.rb
|
5
|
+
# match "/gimmie" => Gimmie::Proxy.new
|
6
|
+
module Gimmie
|
7
|
+
class Proxy
|
8
|
+
def initialize(options = {})
|
9
|
+
@cookie_key = options[:cookie_key] || ENV['GIMMIE_COOKIE_KEY']
|
10
|
+
@oauth_key = options[:oauth_key] || ENV['GIMMIE_OAUTH_KEY']
|
11
|
+
@oauth_secret = options[:oauth_secret] || ENV['GIMMIE_OAUTH_SECRET']
|
12
|
+
@url_prefix = options[:url_prefix] || ENV['GIMMIE_URL_PREFIX'] || 'https://api.gimmieworld.com'
|
13
|
+
end
|
14
|
+
def consumer
|
15
|
+
@consumer ||= OAuth::Consumer.new(@oauth_key, @oauth_secret, :site => @url_prefix)
|
16
|
+
end
|
17
|
+
def token(access_token)
|
18
|
+
OAuth::AccessToken.new(consumer, access_token, @oauth_secret)
|
19
|
+
end
|
20
|
+
def call(env)
|
21
|
+
player_uid, ignore = CGI::Cookie::parse(env['HTTP_COOKIE'])[@cookie_key]
|
22
|
+
suffix = env['REQUEST_URI'].to_s.split('gimmieapi=').last
|
23
|
+
destination_url = "#{@url_prefix}#{suffix}"
|
24
|
+
response = token(player_uid || '').get(destination_url)
|
25
|
+
response_headers = {}
|
26
|
+
response.each_capitalized do |key,value|
|
27
|
+
response_headers[key] = value unless key == 'Transfer-Encoding' && value == 'chunked'
|
28
|
+
end
|
29
|
+
[response.code.to_i, response_headers, [response.body]]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/gimmie.rb
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gimmie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chew Choon Keat
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70195699918580 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70195699918580
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: oauth
|
27
|
+
requirement: &70195699918000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.6
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70195699918000
|
36
|
+
description: OAuth Proxy for Gimmie API
|
37
|
+
email: choonkeat@gmail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/gimmie.rb
|
43
|
+
- lib/gimmie/proxy.rb
|
44
|
+
homepage: http://gimmieworld.com
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.10
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: OAuth Proxy for Gimmie API
|
68
|
+
test_files: []
|