Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

init commit

  • Loading branch information...
commit d961de12a30a12f05a221e8944ae28d3154398ec 0 parents
@siuying authored
23 .autotest
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
1  .gitignore
@@ -0,0 +1 @@
+*.gem
6 History.txt
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2010-03-22
+
+* 1 major enhancement
+
+ * Birthday!
+
11 Manifest.txt
@@ -0,0 +1,11 @@
+.autotest
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/tappy
+lib/tappy.rb
+lib/tappy/tappy_base.rb
+lib/tappy/filter/filter.rb
+lib/tappy/filter/agent_filter.rb
+test/test_tappy.rb
49 README.txt
@@ -0,0 +1,49 @@
+= Tappy
+
+== DESCRIPTION:
+
+Twitter API Proxy in ruby.
+
+== REQUIREMENTS:
+
+* sinatra
+* typhoeus
+* json
+
+== INSTALL:
+
+* sudo gem install tappy
+
+== USAGE:
+
+* To filter twitter client "foursuqare"
+** tappy 0.0.0.0 3000 "foursuqare"
+
+== DEVELOPERS:
+
+* Francis Chong, francis at ignition dot hk
+
+== LICENSE:
+
+The MIT License
+
+Copyright (c) 2010 Ignition Soft Limited
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 Rakefile
@@ -0,0 +1,11 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.plugin :gemcutter
+Hoe.spec 'tappy' do
+ developer('Francis Chong', 'francis@ignition.hk')
+end
+
+# vim: syntax=ruby
19 bin/tappy
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'tappy'
+
+host = ARGV[0] || "localhost"
+port = ARGV[1].to_i
+port = 9090 if port == 0
+@@filter_option = ARGV[2] || "foursquare"
+
+module Tappy
+ class MyTappy < TappyBase
+ set :filter_options, @@filter_option
+ end
+end
+
+puts "Start Tappy server on #{host}:#{port}, options: #{@@filter_option}"
+
+Tappy::MyTappy.run! :host => host, :port => port
3  config.ru
@@ -0,0 +1,3 @@
+require 'lib/tappy'
+
+run Tappy::TappyBase
10 lib/tappy.rb
@@ -0,0 +1,10 @@
+path = File.expand_path(File.dirname(__FILE__))
+$:.unshift(path) unless $:.include?(path)
+
+require 'tappy/tappy_base'
+require 'tappy/filter/filter'
+require 'tappy/filter/agent_filter'
+
+module Tappy
+ VERSION = '1.0.4'
+end
34 lib/tappy/filter/agent_filter.rb
@@ -0,0 +1,34 @@
+require 'json'
+
+module Tappy
+ class AgentFilter < Filter
+ def filter(response)
+ json = JSON.parse(response.body)
+ begin
+ if json.class == Array
+ filtered = []
+
+ json.each do |item|
+ source = item["source"]
+ if !source.nil?
+ if source.match(options)
+ puts "filterer: #{item["source"]}"
+ else
+ filtered << json
+ end
+ else
+ puts "not filtered: #{source}"
+ return response.body
+ end
+ end
+ result = filtered.to_json
+ result
+ else
+ response.body
+ end
+ rescue
+ response.body
+ end
+ end
+ end
+end
14 lib/tappy/filter/filter.rb
@@ -0,0 +1,14 @@
+module Tappy
+ class Filter
+ attr_accessor :options
+
+ def initialize(options)
+ @options = options
+ puts "filter options: #{options}"
+ end
+
+ def filter(response)
+ response
+ end
+ end
+end
40 lib/tappy/tappy_base.rb
@@ -0,0 +1,40 @@
+require 'sinatra/base'
+require 'rubygems'
+require 'typhoeus'
+require 'json'
+
+module Tappy
+ class TappyBase < Sinatra::Base
+ set :twitter_host, "http://api.twitter.com"
+ set :filter, "Tappy::AgentFilter"
+ set :filter_options, ENV["TAPPY_OPTIONS"] || "foursquare"
+
+ helpers do
+ def handle_request(url, request_params={}, params={})
+ request_params[:timeout] = 15000
+ request_params[:headers] = {"Authorization" => request.env["HTTP_AUTHORIZATION"]}
+ request_params[:params] = params
+ Typhoeus::Request.run(url, request_params)
+ end
+ end
+
+ get "/" do
+ "Hello!"
+ end
+
+ get %r{^(.+)$} do |url|
+ url = options.twitter_host + url
+ req_params = {:method => :get}
+ response = handle_request(url, req_params)
+
+ filter = Object.class_eval(options.filter).new(options.filter_options)
+ filter.filter(response)
+ end
+
+ post %r{^(.+)$} do |url|
+ url = options.twitter_host + url
+ req_params = {:method => :post}
+ handle_request(url, req_params, params).body
+ end
+ end
+end
41 tappy.gemspec
@@ -0,0 +1,41 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{tappy}
+ s.version = "1.0.4"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Francis Chong"]
+ s.date = %q{2010-03-22}
+ s.default_executable = %q{tappy}
+ s.description = %q{Twitter API Proxy in ruby.}
+ s.email = ["francis@ignition.hk"]
+ s.executables = ["tappy"]
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
+ s.files = [".autotest", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/tappy", "lib/tappy.rb", "lib/tappy/tappy_base.rb", "lib/tappy/filter/filter.rb", "lib/tappy/filter/agent_filter.rb", "test/test_tappy.rb"]
+ s.rdoc_options = ["--main", "README.txt"]
+ s.require_paths = ["lib"]
+ s.rubyforge_project = %q{tappy}
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{Twitter API Proxy in ruby.}
+ s.test_files = ["test/test_tappy.rb"]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
+ s.add_development_dependency(%q<gemcutter>, [">= 0.5.0"])
+ s.add_development_dependency(%q<hoe>, [">= 2.5.0"])
+ else
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
+ s.add_dependency(%q<gemcutter>, [">= 0.5.0"])
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
+ end
+ else
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
+ s.add_dependency(%q<gemcutter>, [">= 0.5.0"])
+ s.add_dependency(%q<hoe>, [">= 2.5.0"])
+ end
+end
8 test/test_tappy.rb
@@ -0,0 +1,8 @@
+require "test/unit"
+require "tappy"
+
+class TestTappy < Test::Unit::TestCase
+ def test_sanity
+ flunk "write tests or I will kneecap you"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.