staccato-proxy 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c92d157ddd27707f56e4dfc270ba34f2cabc0d8
4
+ data.tar.gz: 45c90eb181612e6400dafd24e4b763ab05e4fba0
5
+ SHA512:
6
+ metadata.gz: b28e7f555723271b3c1874a3f7c2b9e35ee4a9cccb608f1850145821c9e0dfafd0d427532934b956c30d6aacf54ff05d685191490c3261fc0cd398dbbebc9a21
7
+ data.tar.gz: 3aa6bff217f845cfc29d492a33ff78979aa0b8c0e055ac08963fccea77839aeef65f17088bdd19f23e6f7305bcfd8ace0bce0030c858d9b7d7663fd8d683f356
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## Staccato::Proxy 0.0.2 ##
2
+
3
+ * Fix minor bug in Listener
4
+ * Debug flag to support logging of receives/sends
5
+
6
+ *Tony Pitale*
7
+
8
+ ## Staccato::Proxy 0.0.1 ##
9
+
10
+ * Initial implementation
11
+
12
+ *Tony Pitale*
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in staccato-proxy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tony Pitale
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,29 @@
1
+ # Staccato::Proxy
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'staccato-proxy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install staccato-proxy
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/staccato-proxy/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'staccato-proxy'
4
+ require 'staccato/proxy/cli'
5
+
6
+ supervisor = Staccato::Proxy::CLI.new(ARGV).run
7
+
8
+ trap("INT") {supervisor.terminate; exit 0}
9
+ trap("TERM") {supervisor.terminate; exit 0}
10
+ sleep
@@ -0,0 +1,39 @@
1
+ module Staccato::Proxy
2
+ class CLI
3
+ def initialize(args)
4
+ @options = parse_options(args)
5
+ end
6
+
7
+ def run
8
+ Staccato::Proxy::Supervisor.new(@options).run
9
+ end
10
+
11
+ private
12
+ def parse_options(args)
13
+ {}.tap do |options|
14
+ OptionParser.new do |parser|
15
+ parser.banner = [
16
+ "Usage: #{@name} --help\n"
17
+ ].compact.join
18
+
19
+ parser.on('--debug') do
20
+ options[:debug] = true
21
+ end
22
+
23
+ # parser.on('-c', '--config FILE') do |path|
24
+ # options[:config_path] = path
25
+ # end
26
+
27
+ # parser.on("-l", "--log FILE") do |path|
28
+ # options[:log_path] = path
29
+ # end
30
+
31
+ parser.on_tail("-?", "--help", "Display this usage information.") do
32
+ puts "#{parser}\n"
33
+ exit
34
+ end
35
+ end.parse!(args)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module Staccato::Proxy
2
+ class Listener
3
+ include Celluloid::IO
4
+
5
+ FRAME_SIZE = 4096
6
+
7
+ def initialize(host, port, debug = false)
8
+ @socket = UDPSocket.new.tap {|s| s.bind(host, port)}
9
+ @debug = debug
10
+
11
+ async.run
12
+ end
13
+
14
+ def finalize
15
+ @socket.close if @socket
16
+ end
17
+
18
+ def run
19
+ loop {async.receive(@socket.recvfrom(FRAME_SIZE))}
20
+ end
21
+
22
+ def receive(data)
23
+ debug data
24
+ sender.async.submit(data[0])
25
+ end
26
+
27
+ def sender
28
+ Celluloid::Actor[:staccato_proxy_sender]
29
+ end
30
+
31
+ def log(msg)
32
+ Celluloid.logger.info(msg)
33
+ end
34
+
35
+ def debug(msg)
36
+ log(msg) if @debug
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ module Staccato::Proxy
2
+ class Sender
3
+ include Celluloid
4
+
5
+ def initialize(url, debug = false)
6
+ @url = url
7
+ @debug = debug
8
+ end
9
+
10
+ def submit(data)
11
+ debug data
12
+ # data should already be form encoded with `URI.encode_www_form`
13
+ ::HTTP.post(@url, :body => data, socket_class: Celluloid::IO::TCPSocket)
14
+ end
15
+
16
+ def log(msg)
17
+ Celluloid.logger.info(msg)
18
+ end
19
+
20
+ def debug(msg)
21
+ log(msg) if @debug
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ module Staccato::Proxy
2
+ class Supervisor
3
+ attr_reader :options
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ @group = Celluloid::SupervisionGroup.run!
8
+ end
9
+
10
+ def host
11
+ options.fetch(:host, '0.0.0.0')
12
+ end
13
+
14
+ def port
15
+ options.fetch(:port, 9090)
16
+ end
17
+
18
+ def url
19
+ options.fetch(:url, GA_COLLECTION_URL)
20
+ end
21
+
22
+ def debug?
23
+ options.fetch(:debug, false)
24
+ end
25
+
26
+ def run
27
+ @group.supervise_as(:staccato_proxy_listener, Staccato::Proxy::Listener, host, port, debug?)
28
+ @group.supervise_as(:staccato_proxy_sender, Staccato::Proxy::Sender, url, debug?)
29
+ self
30
+ end
31
+
32
+ def terminate
33
+ @group.terminate
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Staccato
2
+ module Proxy
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'optparse'
2
+ require 'http'
3
+ require 'celluloid/io'
4
+
5
+ require "staccato/proxy/version"
6
+
7
+ module Staccato
8
+ module Proxy
9
+ GA_COLLECTION_URL = 'http://www.google-analytics.com/collect'
10
+ end
11
+ end
12
+
13
+ require 'staccato/proxy/listener'
14
+ require 'staccato/proxy/sender'
15
+ require 'staccato/proxy/supervisor'
@@ -0,0 +1 @@
1
+ require 'staccato/proxy'
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'bundler/setup'
5
+
6
+ require 'rspec'
7
+ require 'mocha/api'
8
+ require 'bourne'
9
+
10
+ require File.expand_path('../../lib/staccato-proxy', __FILE__)
11
+
12
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
13
+ RSpec.configure do |config|
14
+ config.mock_with :mocha
15
+
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ # Run specs in random order to surface order dependencies. If you find an
21
+ # order dependency and want to debug it, you can fix the order by providing
22
+ # the seed, which is printed after each run.
23
+ # --seed 1234
24
+ config.order = 'random'
25
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'staccato/proxy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "staccato-proxy"
8
+ spec.version = Staccato::Proxy::VERSION
9
+ spec.authors = ["Tony Pitale"]
10
+ spec.email = ["tpitale@gmail.com"]
11
+ spec.description = "Ruby Google Analytics Measurement UDP Proxy"
12
+ spec.summary = "Ruby Google Analytics Measurement UDP Proxy"
13
+ spec.homepage = "https://github.com/tpitale/staccato-proxy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "http"
22
+ spec.add_dependency "celluloid-io"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "mocha"
28
+ spec.add_development_dependency "bourne"
29
+ spec.add_development_dependency "simplecov"
30
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: staccato-proxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Tony Pitale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: celluloid-io
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bourne
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Ruby Google Analytics Measurement UDP Proxy
126
+ email:
127
+ - tpitale@gmail.com
128
+ executables:
129
+ - staccato-proxy
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".ruby-version"
136
+ - CHANGELOG.md
137
+ - CODE_OF_CONDUCT.md
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/staccato-proxy
143
+ - lib/staccato-proxy.rb
144
+ - lib/staccato/proxy.rb
145
+ - lib/staccato/proxy/cli.rb
146
+ - lib/staccato/proxy/listener.rb
147
+ - lib/staccato/proxy/sender.rb
148
+ - lib/staccato/proxy/supervisor.rb
149
+ - lib/staccato/proxy/version.rb
150
+ - spec/spec_helper.rb
151
+ - staccato-proxy.gemspec
152
+ homepage: https://github.com/tpitale/staccato-proxy
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.4.5
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Ruby Google Analytics Measurement UDP Proxy
176
+ test_files:
177
+ - spec/spec_helper.rb