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 ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test/proxy.yaml
19
+ test/public
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in joopo.gemspec
4
+ gemspec
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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/joopo ADDED
@@ -0,0 +1,5 @@
1
+ puts "## JOOPO - a simple development proxy\n\n"
2
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
3
+
4
+ require 'joopo'
5
+ Joopo::Proxy.run!
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
@@ -0,0 +1,3 @@
1
+ module Joopo
2
+ VERSION = "0.0.1"
3
+ 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: