useless 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/lib/useless.rb +11 -1
  2. data/lib/useless/rack.rb +18 -26
  3. data/lib/useless/rack/authentication/access_token.rb +39 -0
  4. data/lib/useless/rack/authentication/query_string.rb +19 -0
  5. data/lib/useless/rack/authentication/request_header.rb +19 -0
  6. data/lib/useless/rack/exceptions.rb +28 -0
  7. data/lib/useless/rack/files.rb +37 -0
  8. data/lib/useless/rack/fs.rb +17 -0
  9. data/lib/useless/rack/mongo.rb +16 -0
  10. data/lib/useless/version.rb +1 -1
  11. data/spec/spec_helper.rb +4 -3
  12. data/spec/useless/fs_spec.rb +1 -0
  13. data/spec/useless/mongo_spec.rb +1 -0
  14. data/spec/useless/rack/{middleware/authentication → authentication}/query_string_spec.rb +8 -7
  15. data/spec/useless/rack/{middleware/authentication → authentication}/request_header_spec.rb +8 -7
  16. data/spec/useless/rack/exceptions_spec.rb +31 -0
  17. data/spec/useless/rack/files_spec.rb +49 -0
  18. data/spec/useless/rack/fs_spec.rb +18 -0
  19. data/spec/useless/rack/mongo_spec.rb +18 -0
  20. data/spec/useless/rack_spec.rb +77 -0
  21. data/useless.gemspec +7 -7
  22. metadata +49 -50
  23. data/assets/DOC.html +0 -39
  24. data/assets/application.css +0 -134
  25. data/lib/useless/logger.rb +0 -48
  26. data/lib/useless/rack/base.rb +0 -26
  27. data/lib/useless/rack/base/files.rb +0 -33
  28. data/lib/useless/rack/middleware/assets.rb +0 -38
  29. data/lib/useless/rack/middleware/authentication/access_token.rb +0 -41
  30. data/lib/useless/rack/middleware/authentication/query_string.rb +0 -21
  31. data/lib/useless/rack/middleware/authentication/request_header.rb +0 -21
  32. data/lib/useless/rack/middleware/exceptions.rb +0 -41
  33. data/lib/useless/rack/middleware/fs.rb +0 -17
  34. data/lib/useless/rack/middleware/mongo.rb +0 -18
  35. data/spec/useless/logger_spec.rb +0 -87
  36. data/spec/useless/rack/base/files_spec.rb +0 -42
  37. data/spec/useless/rack/middleware/exceptions_spec.rb +0 -47
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'useless'
4
+ require 'useless/rack/fs'
5
+
6
+ describe Useless::Rack::FS do
7
+
8
+ it 'should set useless.fs to Useless.fs' do
9
+ base = -> env do
10
+ [200, { 'Content-Type' => 'text/plain' }, [env['useless.fs'].object_id]]
11
+ end
12
+
13
+ app = Useless::Rack::FS.new(base)
14
+ response = app.call({})
15
+ response[2].first.should == Useless.fs.object_id
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'useless'
4
+ require 'useless/rack/fs'
5
+
6
+ describe Useless::Rack::Mongo do
7
+
8
+ it 'should set useless.mongo to Useless.mongo' do
9
+ base = -> env do
10
+ [200, { 'Content-Type' => 'text/plain' }, [env['useless.mongo'].object_id]]
11
+ end
12
+
13
+ app = Useless::Rack::Mongo.new(base)
14
+ response = app.call({})
15
+ response[2].first.should == Useless.mongo.object_id
16
+ end
17
+
18
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ require 'useless/rack'
4
+
5
+ describe Useless::Rack do
6
+
7
+ def simple_app(&block)
8
+ base = -> env { [200, {'Content-Type' => 'text/plain'}, ['base']] }
9
+ Useless::Rack.new base do
10
+ map 'subdomain' => block
11
+ end
12
+ end
13
+
14
+ it 'should appropriately route requests to subdomains' do
15
+ app = simple_app do |env|
16
+ [200, {'Content-Type' => 'text/plain'}, ['in subdomain']]
17
+ end
18
+
19
+ response = Rack::MockRequest.new(app).get('http://subdomain.useless.info')
20
+ response.should be_ok
21
+ response.body.should == 'in subdomain'
22
+ end
23
+
24
+ it 'should route the request to the base if no subdomain is specified' do
25
+ app = simple_app do |env|
26
+ [200, {'Content-Type' => 'text/plain'}, ['in subdomain']]
27
+ end
28
+
29
+ response = Rack::MockRequest.new(app).get('http://useless.info')
30
+ response.should be_ok
31
+ response.body.should == 'base'
32
+ end
33
+
34
+ it 'should provide Mongo access via useless.mongo' do
35
+ app = simple_app do |env|
36
+ doc = env['useless.mongo']['streets'].find_one
37
+ [200, {'Content-Type' => 'text/plain'}, [doc['name']]]
38
+ end
39
+
40
+ Useless.mongo['streets'] << { 'name' => 'Havemeyer' }
41
+
42
+ response = Rack::MockRequest.new(app).get('http://subdomain.useless.info')
43
+ response.should be_ok
44
+ response.body.should == 'Havemeyer'
45
+ end
46
+
47
+ it 'should provide FS access via useless.fs' do
48
+ file = File.open(asset_path('muffin-milk.jpg'))
49
+ file_id = Useless::FS.for_env.put(file)
50
+
51
+ app = simple_app do |env|
52
+ file = env['useless.fs'].get(file_id)
53
+ [200, {'Content-Type' => 'image/jpeg'}, file]
54
+ end
55
+
56
+ response = Rack::MockRequest.new(app).get('http://subdomain.useless.info')
57
+ response.should be_ok
58
+ file.rewind
59
+ response.body.should == file.read.force_encoding('BINARY')
60
+ end
61
+
62
+ it 'should provide logger access via useless.logger' do
63
+ app = simple_app do |env|
64
+ env['useless.logger'].info 'Blurgh'
65
+ [200, {'Content-Type' => 'text/plain'}, ['whatever']]
66
+ end
67
+
68
+ io = StringIO.new
69
+ response = Rack::MockRequest.new(app).get('http://subdomain.useless.info',
70
+ 'rack.errors' => io)
71
+ io.rewind
72
+ log = io.read
73
+ log.should =~ /INFO/
74
+ log.should =~ /Blurgh$/
75
+ end
76
+
77
+ end
@@ -16,12 +16,12 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^spec/})
17
17
  gem.require_paths = ['lib']
18
18
 
19
- gem.add_runtime_dependency 'rack'
20
- gem.add_runtime_dependency 'low', '0.0.15'
21
- gem.add_runtime_dependency 'mongo'
22
- gem.add_runtime_dependency 'bson'
23
- gem.add_runtime_dependency 'bson_ext'
19
+ gem.add_runtime_dependency 'rack', '~> 1.5.2'
20
+ gem.add_runtime_dependency 'low', '0.0.18'
21
+ gem.add_runtime_dependency 'mongo', '~> 1.8.2'
22
+ gem.add_runtime_dependency 'bson', '~> 1.8.2'
23
+ gem.add_runtime_dependency 'bson_ext', '~> 1.8.2'
24
24
 
25
- gem.add_development_dependency 'rspec'
26
- gem.add_development_dependency 'rack-test'
25
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
26
+ gem.add_development_dependency 'rack-test', '~> 0.6.2'
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.5.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 1.5.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: low
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.0.15
37
+ version: 0.0.18
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,87 +42,87 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.0.15
45
+ version: 0.0.18
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: mongo
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 1.8.2
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.8.2
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: bson
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 1.8.2
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 1.8.2
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: bson_ext
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 1.8.2
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
93
+ version: 1.8.2
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: rspec
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: '0'
101
+ version: 2.12.0
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: 2.12.0
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: rack-test
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.6.2
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 0.6.2
126
126
  description: Library for building a useless.io-compliant APIs in Ruby.
127
127
  email:
128
128
  - khy@me.com
@@ -134,32 +134,29 @@ files:
134
134
  - Gemfile
135
135
  - README.md
136
136
  - Rakefile
137
- - assets/DOC.html
138
- - assets/application.css
139
137
  - lib/useless.rb
140
138
  - lib/useless/fs.rb
141
- - lib/useless/logger.rb
142
139
  - lib/useless/mongo.rb
143
140
  - lib/useless/rack.rb
144
- - lib/useless/rack/base.rb
145
- - lib/useless/rack/base/files.rb
146
- - lib/useless/rack/middleware/assets.rb
147
- - lib/useless/rack/middleware/authentication/access_token.rb
148
- - lib/useless/rack/middleware/authentication/query_string.rb
149
- - lib/useless/rack/middleware/authentication/request_header.rb
150
- - lib/useless/rack/middleware/exceptions.rb
151
- - lib/useless/rack/middleware/fs.rb
152
- - lib/useless/rack/middleware/mongo.rb
141
+ - lib/useless/rack/authentication/access_token.rb
142
+ - lib/useless/rack/authentication/query_string.rb
143
+ - lib/useless/rack/authentication/request_header.rb
144
+ - lib/useless/rack/exceptions.rb
145
+ - lib/useless/rack/files.rb
146
+ - lib/useless/rack/fs.rb
147
+ - lib/useless/rack/mongo.rb
153
148
  - lib/useless/version.rb
154
149
  - spec/spec_helper.rb
155
150
  - spec/support/assets/muffin-milk.jpg
156
151
  - spec/useless/fs_spec.rb
157
- - spec/useless/logger_spec.rb
158
152
  - spec/useless/mongo_spec.rb
159
- - spec/useless/rack/base/files_spec.rb
160
- - spec/useless/rack/middleware/authentication/query_string_spec.rb
161
- - spec/useless/rack/middleware/authentication/request_header_spec.rb
162
- - spec/useless/rack/middleware/exceptions_spec.rb
153
+ - spec/useless/rack/authentication/query_string_spec.rb
154
+ - spec/useless/rack/authentication/request_header_spec.rb
155
+ - spec/useless/rack/exceptions_spec.rb
156
+ - spec/useless/rack/files_spec.rb
157
+ - spec/useless/rack/fs_spec.rb
158
+ - spec/useless/rack/mongo_spec.rb
159
+ - spec/useless/rack_spec.rb
163
160
  - useless.gemspec
164
161
  homepage: https://github.com/khy/useless.rb
165
162
  licenses: []
@@ -189,9 +186,11 @@ test_files:
189
186
  - spec/spec_helper.rb
190
187
  - spec/support/assets/muffin-milk.jpg
191
188
  - spec/useless/fs_spec.rb
192
- - spec/useless/logger_spec.rb
193
189
  - spec/useless/mongo_spec.rb
194
- - spec/useless/rack/base/files_spec.rb
195
- - spec/useless/rack/middleware/authentication/query_string_spec.rb
196
- - spec/useless/rack/middleware/authentication/request_header_spec.rb
197
- - spec/useless/rack/middleware/exceptions_spec.rb
190
+ - spec/useless/rack/authentication/query_string_spec.rb
191
+ - spec/useless/rack/authentication/request_header_spec.rb
192
+ - spec/useless/rack/exceptions_spec.rb
193
+ - spec/useless/rack/files_spec.rb
194
+ - spec/useless/rack/fs_spec.rb
195
+ - spec/useless/rack/mongo_spec.rb
196
+ - spec/useless/rack_spec.rb
@@ -1,39 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>useless.io</title>
5
- <link href="/application.css" media="screen" rel="stylesheet" type="text/css" />
6
- </head>
7
- <body>
8
- <div id="container">
9
- <h1 class="platform-title"><span class="the-name-of-the-website">useless.io</span> the useless platform</h1>
10
-
11
- <p class="platform-description">a collection of APIs that are more or less useless.</p>
12
-
13
- <h2>Platform Guidelines</h2>
14
-
15
- <h3>Authentication</h3>
16
-
17
- <p>Some endpoints require authentication. In order to do so, the client must
18
- specify an <em>access token</em>. This can be done by using either the
19
- <code>Authorization</code> request header field or the
20
- <code>access_token</code> query string parameter. For example:</p>
21
-
22
- <pre>
23
- GET /photos/1 HTTP/1.1
24
- Host: street-art.useless.io
25
- Authorization: 7Fjfp0ZBr1KtDRbnfVdmIw
26
- </pre>
27
-
28
- <p>If an endpoint requires authentication and an access token is not specified
29
- using one of these methods, a <code>401 Unauthorized</code> response will be returned. If
30
- an invalid access token is ever specified, regardless of whether the endpoint
31
- requires authentication, a <code>401 Unauthorized</code> response will also be returned.</p>
32
-
33
- <h3>Dates</h3>
34
-
35
- <p>All dates are UTC and will conform to the ISO 8601 format. If a request expects
36
- date or time data, it should formatted in the same way. For example: <code>2011-11-13T21:23:47+00:00</code></p>
37
- </div>
38
- </body>
39
- </html>
@@ -1,134 +0,0 @@
1
- body {
2
- margin: 0;
3
- font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
4
- font-size: 16px;
5
- color: #333;
6
- line-height: 21px;
7
- font-weight: 200;
8
- background-color: #EEE;
9
- }
10
-
11
- #container {
12
- margin: 0 auto;
13
- width: 760px;
14
- padding: 3em 2em;
15
- border-left: 1px solid #DDD;
16
- border-right: 1px solid #DDD;
17
- background-color: #FFF;
18
- }
19
-
20
- h1, h2, h3, h4, h5, h6 {
21
- font-weight: normal;
22
- }
23
-
24
- h1 {
25
- margin: 0 0 .25em;
26
- }
27
-
28
- h1.platform-title {
29
- color: #999;
30
- }
31
-
32
- h1.platform-title span.the-name-of-the-website {
33
- color: #333;
34
- }
35
-
36
- h2 {
37
- border-bottom: 1px solid #DDD;
38
- padding-bottom: 0.25em;
39
- }
40
-
41
- h3.endpoint, h3.endpoint pre {
42
- margin-bottom: 0.25em;
43
- }
44
-
45
- h3 {
46
- font-size: 1.25em;
47
- margin-top: 4em;
48
- }
49
-
50
- h3:first-of-type {
51
- margin-top: inherit;
52
- }
53
-
54
- h4 {
55
- font-weight: bold;
56
- margin-bottom: 0.25em;
57
- }
58
-
59
- p.api-description, p.platform-description {
60
- margin-bottom: 3em;
61
- }
62
-
63
- p.platform-description {
64
- margin-top: 0;
65
- color: #AAA;
66
- }
67
-
68
- p.endpoint-description {
69
- margin-top: 0;
70
- }
71
-
72
- code.base-api-url {
73
- color: #777777;
74
- display: block;
75
- }
76
-
77
- ul.attributes {
78
- overflow: hidden;
79
- *zoom: 1;
80
- padding: 0;
81
- margin: 0;
82
- list-style: none;
83
- margin-bottom: 2em;
84
- }
85
-
86
- ul.attributes li {
87
- float: left;
88
- padding: 3px 10px;
89
- border: 1px solid #DDD;
90
- background-color: #EEE;
91
- font-size: 0.8em;
92
- }
93
-
94
- ul.attributes li.called-out {
95
- border-color: #AAA;
96
- background-color: lightYellow;
97
- }
98
-
99
- table {
100
- width: 100%;
101
- border: 1px solid #DDD;
102
- border-spacing: 0;
103
- }
104
-
105
- table th {
106
- font-weight: inherit;
107
- }
108
-
109
- table td, th {
110
- border-right: 1px solid #DDD;
111
- border-bottom: 1px solid #DDD;
112
- padding: 5px;
113
- }
114
-
115
- table th {
116
- text-align: left;
117
- color: #999;
118
- }
119
-
120
- table td:last-child, table th:last-child {
121
- border-right-width: 0;
122
- }
123
-
124
- table tbody tr:last-child td, table tbody tr:last-child th {
125
- border-bottom-width: 0;
126
- }
127
-
128
- pre.example {
129
- margin-top: 0;
130
- padding: 1em;
131
- border: 1px solid #DDD;
132
- background-color: #EEE;
133
- overflow: auto;
134
- }