kmts 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/CHANGELOG +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +202 -0
- data/README.md +64 -0
- data/README.rdoc +14 -0
- data/Rakefile +5 -0
- data/bin/km_send +35 -0
- data/doc/Accept.html +546 -0
- data/doc/Gemfile.html +110 -0
- data/doc/Hash.html +283 -0
- data/doc/Helper.html +318 -0
- data/doc/KMError.html +159 -0
- data/doc/KMTS.html +493 -0
- data/doc/KMTS/IdentError.html +159 -0
- data/doc/KMTS/InitError.html +159 -0
- data/doc/KMTS/SaaS.html +451 -0
- data/doc/Object.html +211 -0
- data/doc/README_rdoc.html +122 -0
- data/doc/Rakefile.html +111 -0
- data/doc/String.html +244 -0
- data/doc/bin/km_send.html +54 -0
- data/doc/created.rid +15 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +142 -0
- data/doc/js/darkfish.js +116 -0
- data/doc/js/jquery.js +32 -0
- data/doc/js/quicksearch.js +114 -0
- data/doc/js/thickbox-compressed.js +10 -0
- data/doc/lib/km/saas_rb.html +54 -0
- data/doc/lib/km/version_rb.html +52 -0
- data/doc/lib/km_rb.html +60 -0
- data/doc/rdoc.css +730 -0
- data/doc/spec/accept_rb.html +62 -0
- data/doc/spec/km_old_rb.html +54 -0
- data/doc/spec/km_saas_spec_rb.html +56 -0
- data/doc/spec/km_send_spec_rb.html +54 -0
- data/doc/spec/km_spec_rb.html +54 -0
- data/doc/spec/setup_rb.html +60 -0
- data/doc/spec/watchr_rb.html +52 -0
- data/kmts.gemspec +26 -0
- data/lib/kmts.rb +245 -0
- data/lib/kmts/saas.rb +39 -0
- data/lib/kmts/version.rb +3 -0
- data/spec/accept.rb +91 -0
- data/spec/km_old.rb +105 -0
- data/spec/km_saas_spec.rb +107 -0
- data/spec/km_send_spec.rb +98 -0
- data/spec/km_spec.rb +175 -0
- data/spec/setup.rb +77 -0
- data/spec/watchr.rb +3 -0
- metadata +190 -0
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kmts (2.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
json (1.5.1)
|
11
|
+
rake (0.8.7)
|
12
|
+
rspec (2.4.0)
|
13
|
+
rspec-core (~> 2.4.0)
|
14
|
+
rspec-expectations (~> 2.4.0)
|
15
|
+
rspec-mocks (~> 2.4.0)
|
16
|
+
rspec-core (2.4.0)
|
17
|
+
rspec-expectations (2.4.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.4.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (>= 1.0.0)
|
26
|
+
json
|
27
|
+
kmts!
|
28
|
+
rake
|
29
|
+
rspec (~> 2.4.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
## KISSmetrics Threadsafe Ruby library
|
2
|
+
|
3
|
+
This gem is a threadsafe fork of the original `km` gem.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
The best way to install the gem is using `gem install kmts` or by adding it to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'kmts', '~> 1.0.0', require: "km"
|
11
|
+
```
|
12
|
+
|
13
|
+
Otherwise, the gem is available on GitHub:
|
14
|
+
|
15
|
+
https://github.com/kissmetrics/kmts
|
16
|
+
|
17
|
+
You will need your API key which you can find in your [site settings](http://support.kissmetrics.com/misc/site-settings).
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Before calling any of the common methods you **must** call `KMTS.init` with a valid API key:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
KMTS.init('KM_KEY' [, options])
|
25
|
+
```
|
26
|
+
|
27
|
+
The available options are:
|
28
|
+
|
29
|
+
* `log_dir`: sets the logging directory. Default is `'/tmp'`. Please make sure that the directory exists, and that whatever web process is writing to the log has permission to write to that directory. The log file will contain a list of the URLs that would be requested (`trk.kissmetrics.com` URLs - please refer to [API Specifications](http://support.kissmetrics.com/apis/specifications.html).
|
30
|
+
* `use_cron`: toggles whether to send data directly to KISSmetrics, or log to a file and send in the background via cron (see [Sending Data with Cron](http://support.kissmetrics.com/apis/cron) for more information). Default is `false`, which means data is sent directly to KISSmetrics. Using cron is optional, but **recommended**.
|
31
|
+
* `to_stderr`: allows toggling of printing output to `stderr`. Default is `true`.
|
32
|
+
* `dryrun`: New option as of November 25, 2012. Toggles whether to send data to KISSmetrics, or just log it to a file to review for debugging. Default is `false`, which means data is sent to KISSmetrics, regardless of whether you're working in a production or development environment.
|
33
|
+
* `env`: Updated option as of November 25, 2012. The environment variable now just helps us name the log files that store the history of event requests. This uses the Rails and Rack variables to determine if your Ruby environment is in `development`. If the Rails and Rack variables are not available, we default to `production`.
|
34
|
+
|
35
|
+
### Sample:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
KMTS.init("this is your key", :log_dir => '/var/logs/kissmetrics/')
|
39
|
+
```
|
40
|
+
|
41
|
+
## Example Calls
|
42
|
+
|
43
|
+
**Note**: these calls use the newer syntax of the threadsafe gem. They are not compatible with the previous gem.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
KMTS.record('bob@bob.com', 'Viewed Homepage')
|
47
|
+
KMTS.record('bob@bob.com', 'Signed Up', {'Plan' => 'Pro', 'Amount' => 99.95})
|
48
|
+
KMTS.record('bob@bob.com', 'Signed Up', {'_d' => 1, '_t' => 1234567890})
|
49
|
+
KMTS.set('bob@bob.com', {:gender=>'male', 'Plan Name' => 'Pro'})
|
50
|
+
KMTS.alias('bob', 'bob@bob.com')
|
51
|
+
```
|
52
|
+
|
53
|
+
## Troubleshooting
|
54
|
+
|
55
|
+
If you were watching for the events in [KISSmetrics Live](http://support.kissmetrics.com/tools/live) and did not see them, it helps to review what our library logged. In the log directory, you may see these files:
|
56
|
+
|
57
|
+
* `kissmetrics_production_sent.log`
|
58
|
+
* `kissmetrics_production_query.log`
|
59
|
+
* `kissmetrics_production_error.log`
|
60
|
+
* `kissmetrics_development_sent.log`
|
61
|
+
* `kissmetrics_development_query.log`
|
62
|
+
* `kissmetrics_development_error.log`
|
63
|
+
|
64
|
+
If you contact support to troubleshoot, please refer to the contents of these files, if possible.
|
data/README.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
= Documentation
|
2
|
+
|
3
|
+
We are hosting our documentation for our Ruby API here: http://support.kissmetrics.com/apis/ruby
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
|
7
|
+
gem install kmts
|
8
|
+
|
9
|
+
= SaaS
|
10
|
+
|
11
|
+
This gem includes SaaS calls. For more information please refer to:
|
12
|
+
http://support.kissmetrics.com/getting-started/saas_basics
|
13
|
+
|
14
|
+
For the methods used, see the {rdoc for SaaS}[link:KMTS/SaaS.html]
|
data/Rakefile
ADDED
data/bin/km_send
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'optparse'
|
4
|
+
require 'kmts'
|
5
|
+
|
6
|
+
env = 'production'
|
7
|
+
force = false
|
8
|
+
begin
|
9
|
+
parser = OptionParser.new()
|
10
|
+
parser.banner = "#{File.basename($0)} [<log_dir>]\n\n"
|
11
|
+
|
12
|
+
parser.on("-f", "--force", "Force sending the data to KMTS, ignoring the environment.") do |e|
|
13
|
+
force = true
|
14
|
+
end
|
15
|
+
|
16
|
+
parser.on("-e", "--env ENVIRONMENT", "The environment to run in. Default: production") do |e|
|
17
|
+
puts "Note, only production will actually send queries to the kissmetrics servers unless the --force flag is used." unless force
|
18
|
+
env = e
|
19
|
+
end
|
20
|
+
|
21
|
+
parser.on_tail("-h", "--help", "This help.") do
|
22
|
+
puts parser
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
opts = parser.parse(ARGV)
|
27
|
+
rescue => e
|
28
|
+
$stderr.puts "\nERROR: #{e.message}\n\n"
|
29
|
+
$stderr.puts parser.help
|
30
|
+
exit(-1)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
KMTS.init('', :log_dir => opts[0] || KMTS.log_dir, :host => opts[1] || KMTS.host, :force => force, :env => env)
|
35
|
+
KMTS.send_logged_queries
|
data/doc/Accept.html
ADDED
@@ -0,0 +1,546 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: Accept</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="./js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="./js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="./js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="class">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="./index.html">Home</a>
|
29
|
+
<a href="./index.html#classes">Classes</a>
|
30
|
+
<a href="./index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="./spec/accept_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="spec/accept.rb">spec/accept.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="class-metadata">
|
52
|
+
|
53
|
+
<!-- Parent Class -->
|
54
|
+
|
55
|
+
<div id="parent-class-section" class="section">
|
56
|
+
<h3 class="section-header">Parent</h3>
|
57
|
+
|
58
|
+
<p class="link"><a href="Object.html">Object</a></p>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
|
62
|
+
|
63
|
+
<!-- Namespace Contents -->
|
64
|
+
|
65
|
+
|
66
|
+
<!-- Method Quickref -->
|
67
|
+
|
68
|
+
<div id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
<li><a href="#method-c-new">::new</a></li>
|
73
|
+
|
74
|
+
<li><a href="#method-i-clear">#clear</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-close">#close</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-handle_input">#handle_input</a></li>
|
79
|
+
|
80
|
+
<li><a href="#method-i-input_history">#input_history</a></li>
|
81
|
+
|
82
|
+
<li><a href="#method-i-parse_input">#parse_input</a></li>
|
83
|
+
|
84
|
+
<li><a href="#method-i-wait">#wait</a></li>
|
85
|
+
|
86
|
+
</ul>
|
87
|
+
</div>
|
88
|
+
|
89
|
+
|
90
|
+
<!-- Included Modules -->
|
91
|
+
|
92
|
+
</div>
|
93
|
+
|
94
|
+
<div id="project-metadata">
|
95
|
+
|
96
|
+
|
97
|
+
<div id="fileindex-section" class="section project-section">
|
98
|
+
<h3 class="section-header">Files</h3>
|
99
|
+
<ul>
|
100
|
+
|
101
|
+
<li class="file"><a href="./Gemfile.html">Gemfile</a></li>
|
102
|
+
|
103
|
+
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
104
|
+
|
105
|
+
<li class="file"><a href="./Rakefile.html">Rakefile</a></li>
|
106
|
+
|
107
|
+
</ul>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
|
111
|
+
<div id="classindex-section" class="section project-section">
|
112
|
+
<h3 class="section-header">Class/Module Index
|
113
|
+
<span class="search-toggle"><img src="./images/find.png"
|
114
|
+
height="16" width="16" alt="[+]"
|
115
|
+
title="show/hide quicksearch" /></span></h3>
|
116
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
117
|
+
<fieldset>
|
118
|
+
<legend>Quicksearch</legend>
|
119
|
+
<input type="text" name="quicksearch" value=""
|
120
|
+
class="quicksearch-field" />
|
121
|
+
</fieldset>
|
122
|
+
</form>
|
123
|
+
|
124
|
+
<ul class="link-list">
|
125
|
+
|
126
|
+
<li><a href="./KMTS.html">KMTS</a></li>
|
127
|
+
|
128
|
+
<li><a href="./KMTS/IdentError.html">KMTS::IdentError</a></li>
|
129
|
+
|
130
|
+
<li><a href="./KMTS/InitError.html">KMTS::InitError</a></li>
|
131
|
+
|
132
|
+
<li><a href="./KMTS/SaaS.html">KMTS::SaaS</a></li>
|
133
|
+
|
134
|
+
<li><a href="./Accept.html">Accept</a></li>
|
135
|
+
|
136
|
+
<li><a href="./Hash.html">Hash</a></li>
|
137
|
+
|
138
|
+
<li><a href="./Helper.html">Helper</a></li>
|
139
|
+
|
140
|
+
<li><a href="./KMError.html">KMError</a></li>
|
141
|
+
|
142
|
+
<li><a href="./Object.html">Object</a></li>
|
143
|
+
|
144
|
+
<li><a href="./String.html">String</a></li>
|
145
|
+
|
146
|
+
</ul>
|
147
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
148
|
+
</div>
|
149
|
+
|
150
|
+
|
151
|
+
</div>
|
152
|
+
</div>
|
153
|
+
|
154
|
+
<div id="documentation">
|
155
|
+
<h1 class="class">Accept</h1>
|
156
|
+
|
157
|
+
<div id="description">
|
158
|
+
|
159
|
+
<p>a library to accept connections as a server, and send back what it received
|
160
|
+
on request.</p>
|
161
|
+
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<!-- Constants -->
|
165
|
+
|
166
|
+
<div id="constants-list" class="section">
|
167
|
+
<h3 class="section-header">Constants</h3>
|
168
|
+
<dl>
|
169
|
+
|
170
|
+
<dt><a name="URI_REXEGP">URI_REXEGP</a></dt>
|
171
|
+
|
172
|
+
<dd class="description"></dd>
|
173
|
+
|
174
|
+
|
175
|
+
</dl>
|
176
|
+
</div>
|
177
|
+
|
178
|
+
|
179
|
+
<!-- Attributes -->
|
180
|
+
|
181
|
+
<div id="attribute-method-details" class="method-section section">
|
182
|
+
<h3 class="section-header">Attributes</h3>
|
183
|
+
|
184
|
+
|
185
|
+
<div id="server-attribute-method" class="method-detail">
|
186
|
+
<a name="server"></a>
|
187
|
+
|
188
|
+
<a name="server="></a>
|
189
|
+
|
190
|
+
<div class="method-heading attribute-method-heading">
|
191
|
+
<span class="method-name">server</span><span
|
192
|
+
class="attribute-access-type">[RW]</span>
|
193
|
+
</div>
|
194
|
+
|
195
|
+
<div class="method-description">
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
</div>
|
200
|
+
</div>
|
201
|
+
|
202
|
+
<div id="session-attribute-method" class="method-detail">
|
203
|
+
<a name="session"></a>
|
204
|
+
|
205
|
+
<a name="session="></a>
|
206
|
+
|
207
|
+
<div class="method-heading attribute-method-heading">
|
208
|
+
<span class="method-name">session</span><span
|
209
|
+
class="attribute-access-type">[RW]</span>
|
210
|
+
</div>
|
211
|
+
|
212
|
+
<div class="method-description">
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
</div>
|
217
|
+
</div>
|
218
|
+
|
219
|
+
<div id="opts-attribute-method" class="method-detail">
|
220
|
+
<a name="opts"></a>
|
221
|
+
|
222
|
+
<div class="method-heading attribute-method-heading">
|
223
|
+
<span class="method-name">opts</span><span
|
224
|
+
class="attribute-access-type">[R]</span>
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<div class="method-description">
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
</div>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</div>
|
235
|
+
|
236
|
+
|
237
|
+
<!-- Methods -->
|
238
|
+
|
239
|
+
<div id="public-class-method-details" class="method-section section">
|
240
|
+
<h3 class="section-header">Public Class Methods</h3>
|
241
|
+
|
242
|
+
|
243
|
+
<div id="new-method" class="method-detail ">
|
244
|
+
<a name="method-c-new"></a>
|
245
|
+
|
246
|
+
|
247
|
+
<div class="method-heading">
|
248
|
+
<span class="method-name">new</span><span
|
249
|
+
class="method-args">(args = {})</span>
|
250
|
+
<span class="method-click-advice">click to toggle source</span>
|
251
|
+
</div>
|
252
|
+
|
253
|
+
|
254
|
+
<div class="method-description">
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
<div class="method-source-code"
|
261
|
+
id="new-source">
|
262
|
+
<pre>
|
263
|
+
<span class="ruby-comment"># File spec/accept.rb, line 14</span>
|
264
|
+
def initialize(args = {})
|
265
|
+
opts = { :port => 9292, :debug => false }
|
266
|
+
opts.update(args)
|
267
|
+
|
268
|
+
puts "Starting up server on port #{opts[:port]} ..."
|
269
|
+
<span class="ruby-ivar">@opts</span> = opts
|
270
|
+
<span class="ruby-ivar">@server</span> = <span class="ruby-constant">TCPServer</span>.new(opts[:port])
|
271
|
+
@@input_history = []
|
272
|
+
<span class="ruby-ivar">@handle</span> = <span class="ruby-constant">Thread</span>.start do
|
273
|
+
while (<span class="ruby-ivar">@session</span> = server.accept)
|
274
|
+
<span class="ruby-constant">Thread</span>.start do
|
275
|
+
<span class="ruby-comment"># puts "log: Connection from #{session.peeraddr[2]} at #{session.peeraddr[3]}"</span>
|
276
|
+
<span class="ruby-comment"># session.puts "Server: Connection from #{session.peeraddr[2]}\n"</span>
|
277
|
+
handle_input
|
278
|
+
session.close
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end</pre>
|
283
|
+
</div>
|
284
|
+
|
285
|
+
</div>
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
</div>
|
291
|
+
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
<div id="public-instance-method-details" class="method-section section">
|
296
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
297
|
+
|
298
|
+
|
299
|
+
<div id="clear-method" class="method-detail ">
|
300
|
+
<a name="method-i-clear"></a>
|
301
|
+
|
302
|
+
|
303
|
+
<div class="method-heading">
|
304
|
+
<span class="method-name">clear</span><span
|
305
|
+
class="method-args">()</span>
|
306
|
+
<span class="method-click-advice">click to toggle source</span>
|
307
|
+
</div>
|
308
|
+
|
309
|
+
|
310
|
+
<div class="method-description">
|
311
|
+
|
312
|
+
<p>clear history</p>
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
<div class="method-source-code"
|
317
|
+
id="clear-source">
|
318
|
+
<pre>
|
319
|
+
<span class="ruby-comment"># File spec/accept.rb, line 80</span>
|
320
|
+
def clear
|
321
|
+
@@input_history.clear
|
322
|
+
end</pre>
|
323
|
+
</div>
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
</div>
|
331
|
+
|
332
|
+
|
333
|
+
<div id="close-method" class="method-detail ">
|
334
|
+
<a name="method-i-close"></a>
|
335
|
+
|
336
|
+
|
337
|
+
<div class="method-heading">
|
338
|
+
<span class="method-name">close</span><span
|
339
|
+
class="method-args">()</span>
|
340
|
+
<span class="method-click-advice">click to toggle source</span>
|
341
|
+
</div>
|
342
|
+
|
343
|
+
|
344
|
+
<div class="method-description">
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
<div class="method-source-code"
|
351
|
+
id="close-source">
|
352
|
+
<pre>
|
353
|
+
<span class="ruby-comment"># File spec/accept.rb, line 75</span>
|
354
|
+
def close
|
355
|
+
session = nil
|
356
|
+
server.close
|
357
|
+
end</pre>
|
358
|
+
</div>
|
359
|
+
|
360
|
+
</div>
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
</div>
|
366
|
+
|
367
|
+
|
368
|
+
<div id="handle_input-method" class="method-detail ">
|
369
|
+
<a name="method-i-handle_input"></a>
|
370
|
+
|
371
|
+
|
372
|
+
<div class="method-heading">
|
373
|
+
<span class="method-name">handle_input</span><span
|
374
|
+
class="method-args">()</span>
|
375
|
+
<span class="method-click-advice">click to toggle source</span>
|
376
|
+
</div>
|
377
|
+
|
378
|
+
|
379
|
+
<div class="method-description">
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
<div class="method-source-code"
|
386
|
+
id="handle_input-source">
|
387
|
+
<pre>
|
388
|
+
<span class="ruby-comment"># File spec/accept.rb, line 40</span>
|
389
|
+
def handle_input
|
390
|
+
input = session.gets
|
391
|
+
if input
|
392
|
+
puts "received: #{input.inspect}" if opts[:debug]
|
393
|
+
case input
|
394
|
+
when <span class="ruby-regexp">/clear/</span>
|
395
|
+
clear
|
396
|
+
when <span class="ruby-regexp">/history/</span>
|
397
|
+
session.puts input_history.to_json
|
398
|
+
when <span class="ruby-regexp">/exit/</span>
|
399
|
+
begin
|
400
|
+
close
|
401
|
+
rescue <span class="ruby-constant">Exception</span>
|
402
|
+
end
|
403
|
+
return
|
404
|
+
when <span class="ruby-regexp">/^\s*(GET|POST|PUT|DELETE)\s+([^ ]*)\s+(.*)$/</span>
|
405
|
+
@@input_history << parse_input(input)
|
406
|
+
else
|
407
|
+
@@input_history << input.chomp
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end</pre>
|
411
|
+
</div>
|
412
|
+
|
413
|
+
</div>
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
</div>
|
419
|
+
|
420
|
+
|
421
|
+
<div id="input_history-method" class="method-detail ">
|
422
|
+
<a name="method-i-input_history"></a>
|
423
|
+
|
424
|
+
|
425
|
+
<div class="method-heading">
|
426
|
+
<span class="method-name">input_history</span><span
|
427
|
+
class="method-args">()</span>
|
428
|
+
<span class="method-click-advice">click to toggle source</span>
|
429
|
+
</div>
|
430
|
+
|
431
|
+
|
432
|
+
<div class="method-description">
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
<div class="method-source-code"
|
439
|
+
id="input_history-source">
|
440
|
+
<pre>
|
441
|
+
<span class="ruby-comment"># File spec/accept.rb, line 33</span>
|
442
|
+
def input_history
|
443
|
+
@@input_history
|
444
|
+
end</pre>
|
445
|
+
</div>
|
446
|
+
|
447
|
+
</div>
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
</div>
|
453
|
+
|
454
|
+
|
455
|
+
<div id="parse_input-method" class="method-detail ">
|
456
|
+
<a name="method-i-parse_input"></a>
|
457
|
+
|
458
|
+
|
459
|
+
<div class="method-heading">
|
460
|
+
<span class="method-name">parse_input</span><span
|
461
|
+
class="method-args">(input)</span>
|
462
|
+
<span class="method-click-advice">click to toggle source</span>
|
463
|
+
</div>
|
464
|
+
|
465
|
+
|
466
|
+
<div class="method-description">
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
<div class="method-source-code"
|
473
|
+
id="parse_input-source">
|
474
|
+
<pre>
|
475
|
+
<span class="ruby-comment"># File spec/accept.rb, line 62</span>
|
476
|
+
def parse_input(input)
|
477
|
+
data = {}
|
478
|
+
data[:raw] = input.chomp
|
479
|
+
(method,uri,http) = input.scan(<span class="ruby-regexp">/^\s*(\w+)\s+([^ ]*)\s+(.*)$/</span>).flatten
|
480
|
+
|
481
|
+
data[:method] = method
|
482
|
+
data[:http] = http.chomp
|
483
|
+
data[:uri] = uri
|
484
|
+
u = <span class="ruby-constant">URI</span>(uri)
|
485
|
+
data[:path] = u.path
|
486
|
+
data[:query] = <span class="ruby-constant">CGI</span>.parse(u.query)
|
487
|
+
return data
|
488
|
+
end</pre>
|
489
|
+
</div>
|
490
|
+
|
491
|
+
</div>
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
</div>
|
497
|
+
|
498
|
+
|
499
|
+
<div id="wait-method" class="method-detail ">
|
500
|
+
<a name="method-i-wait"></a>
|
501
|
+
|
502
|
+
|
503
|
+
<div class="method-heading">
|
504
|
+
<span class="method-name">wait</span><span
|
505
|
+
class="method-args">()</span>
|
506
|
+
<span class="method-click-advice">click to toggle source</span>
|
507
|
+
</div>
|
508
|
+
|
509
|
+
|
510
|
+
<div class="method-description">
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
<div class="method-source-code"
|
517
|
+
id="wait-source">
|
518
|
+
<pre>
|
519
|
+
<span class="ruby-comment"># File spec/accept.rb, line 36</span>
|
520
|
+
def wait
|
521
|
+
<span class="ruby-ivar">@handle</span>.join
|
522
|
+
end</pre>
|
523
|
+
</div>
|
524
|
+
|
525
|
+
</div>
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
|
530
|
+
</div>
|
531
|
+
|
532
|
+
|
533
|
+
</div>
|
534
|
+
|
535
|
+
|
536
|
+
</div>
|
537
|
+
|
538
|
+
<div id="validator-badges">
|
539
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
540
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
541
|
+
Rdoc Generator</a> 2</small>.</p>
|
542
|
+
</div>
|
543
|
+
|
544
|
+
</body>
|
545
|
+
</html>
|
546
|
+
|