tappy 1.0.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/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2010-03-22
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/tappy
7
+ lib/tappy.rb
8
+ lib/tappy/tappy_base.rb
9
+ lib/tappy/filter/filter.rb
10
+ lib/tappy/filter/agent_filter.rb
11
+ test/test_tappy.rb
data/README.txt ADDED
@@ -0,0 +1,46 @@
1
+ = Tappy
2
+
3
+ == DESCRIPTION:
4
+
5
+ Twitter API Proxy in ruby.
6
+
7
+ == REQUIREMENTS:
8
+
9
+ * sinatra
10
+ * typhoeus
11
+ * json
12
+
13
+ == INSTALL:
14
+
15
+ * sudo gem install tappy
16
+
17
+ == USAGE:
18
+
19
+ == DEVELOPERS:
20
+
21
+ * Francis Chong, francis at ignition dot hk
22
+
23
+ == LICENSE:
24
+
25
+ The MIT License
26
+
27
+ Copyright (c) 2010 Ignition Soft Limited
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining
30
+ a copy of this software and associated documentation files (the
31
+ 'Software'), to deal in the Software without restriction, including
32
+ without limitation the rights to use, copy, modify, merge, publish,
33
+ distribute, sublicense, and/or sell copies of the Software, and to
34
+ permit persons to whom the Software is furnished to do so, subject to
35
+ the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be
38
+ included in all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
41
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
44
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
45
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :gemcutter
7
+ Hoe.spec 'tappy' do
8
+ developer('Francis Chong', 'francis@ignition.hk')
9
+ end
10
+
11
+ # vim: syntax=ruby
data/bin/tappy ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tappy'
4
+
5
+ host = ARGV[1] resuce "localhost"
6
+ port = ARGV[2].to_i rescue 9090
7
+
8
+ Tappy::TappyBase.run! :host => host, :port => :port
@@ -0,0 +1,18 @@
1
+ module Tappy
2
+ class AgentFilter < Filter
3
+ def filter(response)
4
+ json = JSON.parse(response.body)
5
+ statues = json["statues"]
6
+ if statues
7
+ statues.each do |item|
8
+ if item["source"].match(options)
9
+ statues.delete(item)
10
+ end
11
+ end
12
+ statues.to_s
13
+ else
14
+ response.body
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Tappy
2
+ class Filter
3
+ attr_accessor :options
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def filter(response)
10
+ response
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ require 'sinatra/base'
2
+ require 'rubygems'
3
+ require 'typhoeus'
4
+ require 'json'
5
+
6
+ module Tappy
7
+ class TappyBase < Sinatra::Base
8
+ set :twitter_host, "http://api.twitter.com"
9
+ set :filter, "Tappy::AgentFilter"
10
+ set :filter_options, "foursquare"
11
+
12
+ helpers do
13
+ def handle_request(url, request_params={}, params={})
14
+ request_params[:timeout] = 15000
15
+ request_params[:headers] = {"Authorization" => request.env["HTTP_AUTHORIZATION"]}
16
+ request_params[:params] = params
17
+ Typhoeus::Request.run(url, request_params)
18
+ end
19
+ end
20
+
21
+ get "/" do
22
+ "Hello!"
23
+ end
24
+
25
+ get %r{^(.+)$} do |url|
26
+ url = options.twitter_host + url
27
+ req_params = {:method => :get}
28
+ response = handle_request(url, req_params)
29
+
30
+ filter = Object.class_eval(options.filter).new(options.filter_options)
31
+ filter.filter(response)
32
+ end
33
+
34
+ post %r{^(.+)$} do |url|
35
+ url = options.twitter_host + url
36
+ req_params = {:method => :post}
37
+ handle_request(url, req_params, params).body
38
+ end
39
+ end
40
+ end
data/lib/tappy.rb ADDED
@@ -0,0 +1,10 @@
1
+ path = File.expand_path(File.dirname(__FILE__))
2
+ $:.unshift(path) unless $:.include?(path)
3
+
4
+ require 'tappy/tappy_base'
5
+ require 'tappy/filter/filter'
6
+ require 'tappy/filter/agent_filter'
7
+
8
+ module Tappy
9
+ VERSION = '1.0.0'
10
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "tappy"
3
+
4
+ class TestTappy < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tappy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Francis Chong
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-22 00:00:00 +08:00
18
+ default_executable: tappy
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rubyforge
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 4
31
+ version: 2.0.4
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: gemcutter
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 5
44
+ - 0
45
+ version: 0.5.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: hoe
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 2
57
+ - 5
58
+ - 0
59
+ version: 2.5.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: Twitter API Proxy in ruby.
63
+ email:
64
+ - francis@ignition.hk
65
+ executables:
66
+ - tappy
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - History.txt
71
+ - Manifest.txt
72
+ - README.txt
73
+ files:
74
+ - .autotest
75
+ - History.txt
76
+ - Manifest.txt
77
+ - README.txt
78
+ - Rakefile
79
+ - bin/tappy
80
+ - lib/tappy.rb
81
+ - lib/tappy/tappy_base.rb
82
+ - lib/tappy/filter/filter.rb
83
+ - lib/tappy/filter/agent_filter.rb
84
+ - test/test_tappy.rb
85
+ has_rdoc: true
86
+ homepage:
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options:
91
+ - --main
92
+ - README.txt
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project: tappy
112
+ rubygems_version: 1.3.6
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Twitter API Proxy in ruby.
116
+ test_files:
117
+ - test/test_tappy.rb