joopo 0.0.1
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/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/bin/joopo +5 -0
- data/joopo.gemspec +23 -0
- data/lib/joopo/version.rb +3 -0
- data/lib/joopo.rb +56 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Thomas Peklak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Joopo
|
2
|
+
|
3
|
+
A universal proxy for external apis.
|
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.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install joopo
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ joopo config.yaml
|
14
|
+
|
15
|
+
## Proxy configuration
|
16
|
+
|
17
|
+
The configuration YAML can have the following entries:
|
18
|
+
|
19
|
+
- port: the port for Sinatra, defaults to `4567`
|
20
|
+
- public_folder: the public folder that servers your files, defaults to `public`
|
21
|
+
- apis: a list of key values of external apis that should be proxied
|
22
|
+
|
23
|
+
###Sample
|
24
|
+
|
25
|
+
port: 4567
|
26
|
+
public: test/public
|
27
|
+
apis:
|
28
|
+
testapi: http://localhost:9000/test/
|
29
|
+
|
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`.
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Run the proxy with `joopo config.yaml`. Now you are able to make request.
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/joopo
ADDED
data/joopo.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/joopo/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Thomas Peklak"]
|
6
|
+
gem.email = ["thomas.peklak@gmail.com"]
|
7
|
+
gem.description = %q{A universal proxy for external apis.}
|
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 = ""
|
10
|
+
|
11
|
+
gem.required_ruby_version = ">= 1.8.7"
|
12
|
+
gem.required_rubygems_version = ">= 1.3.6"
|
13
|
+
gem.rubyforge_project = "joopo"
|
14
|
+
|
15
|
+
gem.add_dependency(%q<sinatra>, ["~> 1.2"])
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($\)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.name = "joopo"
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
gem.version = Joopo::VERSION
|
23
|
+
end
|
data/lib/joopo.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "joopo/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'net/http'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module Joopo
|
9
|
+
class Proxy < Sinatra::Base
|
10
|
+
|
11
|
+
config = (ARGV.size == 0) ? 'proxy.yaml' : ARGV[0]
|
12
|
+
raise ArgumentError, "'#{config}' file does not exist" if(!File.exists?(config))
|
13
|
+
|
14
|
+
settings = YAML.load(File.open(config))
|
15
|
+
settings['public_folder'] ||= 'public'
|
16
|
+
settings['port'] ||= 4567
|
17
|
+
settings['apis'] ||= {}
|
18
|
+
|
19
|
+
|
20
|
+
set :public_folder, Dir.pwd + '/' + settings['public_folder']
|
21
|
+
set :port, settings['port']
|
22
|
+
|
23
|
+
get '/:api/*' do
|
24
|
+
api = params[:api]
|
25
|
+
pass unless settings['apis'].has_key?(params[:api])
|
26
|
+
response = open(settings['apis'][api] + params['splat'].first + '?' + hash_to_querystring(params.clone))
|
27
|
+
content_type response.content_type
|
28
|
+
response.read
|
29
|
+
end
|
30
|
+
|
31
|
+
post '/:api/*' do
|
32
|
+
api = params[:api]
|
33
|
+
pass unless settings['apis'].has_key?(params[:api])
|
34
|
+
|
35
|
+
query_params = request.env['QUERY_STRING']
|
36
|
+
post_vars = request.env["rack.request.form_hash"]
|
37
|
+
|
38
|
+
uri = URI.parse(settings['apis'][api] + params['splat'].first + '?' + query_params)
|
39
|
+
|
40
|
+
response = Net::HTTP.post_form(uri, post_vars)
|
41
|
+
content_type response.content_type
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
|
45
|
+
def hash_to_querystring(hash)
|
46
|
+
hash.delete('splat')
|
47
|
+
hash.delete('captures')
|
48
|
+
hash.keys.inject('') do |query_string, key|
|
49
|
+
query_string << '&' << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
run! if app_file == $0
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: joopo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Peklak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.2'
|
30
|
+
description: A universal proxy for external apis.
|
31
|
+
email:
|
32
|
+
- thomas.peklak@gmail.com
|
33
|
+
executables:
|
34
|
+
- joopo
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/joopo
|
44
|
+
- joopo.gemspec
|
45
|
+
- lib/joopo.rb
|
46
|
+
- lib/joopo/version.rb
|
47
|
+
homepage: ''
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.8.7
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.3.6
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project: joopo
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: This gem opens a server via Sinatra that can be used to proxy external apis.
|
71
|
+
This is usefull for JavaScript development when you need to connect to a server
|
72
|
+
that is not on your development domain.
|
73
|
+
test_files: []
|
74
|
+
has_rdoc:
|