joopo 0.0.1 → 0.0.2
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/README.md +13 -6
- data/joopo.gemspec +1 -1
- data/lib/joopo/version.rb +1 -1
- data/lib/joopo.rb +19 -9
- metadata +3 -3
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A universal proxy for external apis.
|
4
4
|
|
5
|
-
This gem opens a server via Sinatra that can be used to proxy external apis. This is usefull for JavaScript development when you need to connect to a server that is not on your development domain.
|
5
|
+
This gem opens a server via Sinatra that can be used to proxy external apis. This is usefull for JavaScript development when you need to connect to a server that is not on your development domain. Additionally you can serve your static files and stub apis with fake responses. See example below.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,12 +22,19 @@ The configuration YAML can have the following entries:
|
|
22
22
|
|
23
23
|
###Sample
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
public: test/public
|
26
|
+
apis:
|
27
|
+
testapi: http://localhost:9000/test/
|
28
|
+
fakeapi:
|
29
|
+
content_type: json
|
30
|
+
content: |
|
31
|
+
{
|
32
|
+
"test": "Hello World"
|
33
|
+
}
|
29
34
|
|
30
|
-
With this configuration you can make request to `http://localhost:4567/testapi/whatever/you?like` that are proxied to `http://localhost:9000/test/whatever/you?like`.
|
35
|
+
With this configuration you can make request to `http://localhost:4567/testapi/whatever/you?like` that are proxied to `http://localhost:9000/test/whatever/you?like`. Your static files in `test/public` are served from this proxy, too. E.g. if you have a file `styles.css` in the directory `test/public/styles`, you can access it via `http://localhost:4567/styles/styles.css`.
|
36
|
+
|
37
|
+
Because of the _fakeapi_ entry all requests to `http://localhost:4567/fakeapi/` and its subdirectoies will return a json with content `{"test": "Hello World"}`.
|
31
38
|
|
32
39
|
## Usage
|
33
40
|
|
data/joopo.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["thomas.peklak@gmail.com"]
|
7
7
|
gem.description = %q{A universal proxy for external apis.}
|
8
8
|
gem.summary = %q{This gem opens a server via Sinatra that can be used to proxy external apis. This is usefull for JavaScript development when you need to connect to a server that is not on your development domain.}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/thomaspeklak/joopo"
|
10
10
|
|
11
11
|
gem.required_ruby_version = ">= 1.8.7"
|
12
12
|
gem.required_rubygems_version = ">= 1.3.6"
|
data/lib/joopo/version.rb
CHANGED
data/lib/joopo.rb
CHANGED
@@ -23,23 +23,33 @@ module Joopo
|
|
23
23
|
get '/:api/*' do
|
24
24
|
api = params[:api]
|
25
25
|
pass unless settings['apis'].has_key?(params[:api])
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
if settings['apis'][api].class == Hash
|
27
|
+
content_type settings['apis'][api]['content_type']
|
28
|
+
settings['apis'][api]['content']
|
29
|
+
else
|
30
|
+
response = open(settings['apis'][api] + params['splat'].first + '?' + hash_to_querystring(params.clone))
|
31
|
+
content_type response.content_type
|
32
|
+
response.read
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
post '/:api/*' do
|
32
37
|
api = params[:api]
|
33
38
|
pass unless settings['apis'].has_key?(params[:api])
|
34
39
|
|
35
|
-
|
36
|
-
|
40
|
+
if settings['apis'][api].class == Hash
|
41
|
+
content_type settings['apis'][api]['content_type']
|
42
|
+
settings['apis'][api]['content']
|
43
|
+
else
|
44
|
+
query_params = request.env['QUERY_STRING']
|
45
|
+
post_vars = request.env["rack.request.form_hash"]
|
37
46
|
|
38
|
-
|
47
|
+
uri = URI.parse(settings['apis'][api] + params['splat'].first + '?' + query_params)
|
39
48
|
|
40
|
-
|
41
|
-
|
42
|
-
|
49
|
+
response = Net::HTTP.post_form(uri, post_vars)
|
50
|
+
content_type response.content_type
|
51
|
+
response.body
|
52
|
+
end
|
43
53
|
end
|
44
54
|
|
45
55
|
def hash_to_querystring(hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joopo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -44,7 +44,7 @@ files:
|
|
44
44
|
- joopo.gemspec
|
45
45
|
- lib/joopo.rb
|
46
46
|
- lib/joopo/version.rb
|
47
|
-
homepage:
|
47
|
+
homepage: https://github.com/thomaspeklak/joopo
|
48
48
|
licenses: []
|
49
49
|
post_install_message:
|
50
50
|
rdoc_options: []
|