useless 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
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>
@@ -5,13 +5,10 @@ require 'low/rack/request_logger'
5
5
  require 'low/rack/subdomain_map'
6
6
  require 'low/scoped_logger'
7
7
 
8
- require 'useless/mongo'
9
- require 'useless/fs'
10
8
  require 'useless/rack/middleware/exceptions'
11
9
  require 'useless/rack/middleware/assets'
12
10
  require 'useless/rack/middleware/mongo'
13
11
  require 'useless/rack/middleware/fs'
14
- require 'useless/rack/middleware/doc'
15
12
  require 'useless/rack/middleware/authentication/query_string'
16
13
  require 'useless/rack/middleware/authentication/request_header'
17
14
  require 'useless/rack/base'
@@ -20,11 +17,11 @@ module Useless
20
17
  class Rack
21
18
 
22
19
  def self.mongo
23
- @mongo ||= Useless::Mongo.for_env
20
+ @mongo ||= Mongo.for_env
24
21
  end
25
22
 
26
23
  def self.fs
27
- @fs ||= Useless::FS.new(mongo)
24
+ @fs ||= FS.new(mongo)
28
25
  end
29
26
 
30
27
  def initialize(map = nil, &block)
@@ -38,8 +35,6 @@ module Useless
38
35
  end
39
36
 
40
37
  def call(env)
41
- map = @map
42
-
43
38
  ::Rack::Builder.app do
44
39
  use Middleware::Exceptions
45
40
  use Low::Rack::RequestId
@@ -50,11 +45,10 @@ module Useless
50
45
  use Middleware::Assets
51
46
  use Middleware::Mongo
52
47
  use Middleware::FS
53
- use Middleware::Doc
54
48
  use Middleware::Authentication::QueryString
55
49
  use Middleware::Authentication::RequestHeader
56
50
 
57
- run Low::Rack::SubdomainMap.new(Base.new, map)
51
+ run Low::Rack::SubdomainMap.new(Base.new, @map)
58
52
  end.call(env)
59
53
  end
60
54
 
@@ -1,20 +1,26 @@
1
+ require 'useless/rack/base/files'
2
+
1
3
  module Useless
2
4
  class Rack
3
5
  # Useless::Base is the Rack endpoint for useless.io proper. It has two
4
6
  # responsibilties: show documentation, and serve file from 'useless.fs'.
5
7
  class Base
6
- autoload :Doc, 'useless/rack/base/doc'
7
- autoload :Files, 'useless/rack/base/files'
8
-
9
8
  def call(env)
10
9
  # Show platform documentation at root
11
- app = ::Rack::URLMap.new '/' => Doc,
10
+ app = ::Rack::URLMap.new '/' => platform_documentation,
12
11
 
13
12
  # serve files out of /files/* via the Files Rack endpoint.
14
13
  '/files/' => Files.new
15
14
 
16
15
  app.call(env)
17
16
  end
17
+
18
+ def platform_documentation
19
+ @root_app ||= begin
20
+ file = File.expand_path('../../../../assets/DOC.html', __FILE__)
21
+ [200, {'Content-Type' => 'text/html'}, file]
22
+ end
23
+ end
18
24
  end
19
25
  end
20
26
  end
@@ -14,7 +14,7 @@ module Useless
14
14
  end
15
15
 
16
16
  # The path is relative to the assets directory in the gem root
17
- path = File.expand_path("../../../../../assets#{env['PATH_INFO']}", __FILE__)
17
+ path = File.expand_path("../../../../assets#{env['PATH_INFO']}", __FILE__)
18
18
 
19
19
  # If there's a corresponding file:
20
20
  if File.exists?(path) and !File.directory?(path)
@@ -1,3 +1,3 @@
1
1
  module Useless
2
- VERSION = '0.0.10'
2
+ VERSION = '0.1.0'
3
3
  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.0.10
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -131,10 +131,10 @@ extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
133
  - .gitignore
134
- - DOC.html
135
134
  - Gemfile
136
135
  - README.md
137
136
  - Rakefile
137
+ - assets/DOC.html
138
138
  - assets/application.css
139
139
  - lib/useless.rb
140
140
  - lib/useless/fs.rb
@@ -142,14 +142,11 @@ files:
142
142
  - lib/useless/mongo.rb
143
143
  - lib/useless/rack.rb
144
144
  - lib/useless/rack/base.rb
145
- - lib/useless/rack/base/doc.rb
146
145
  - lib/useless/rack/base/files.rb
147
- - lib/useless/rack/doc.rb
148
146
  - lib/useless/rack/middleware/assets.rb
149
147
  - lib/useless/rack/middleware/authentication/access_token.rb
150
148
  - lib/useless/rack/middleware/authentication/query_string.rb
151
149
  - lib/useless/rack/middleware/authentication/request_header.rb
152
- - lib/useless/rack/middleware/doc.rb
153
150
  - lib/useless/rack/middleware/exceptions.rb
154
151
  - lib/useless/rack/middleware/fs.rb
155
152
  - lib/useless/rack/middleware/mongo.rb
data/DOC.html DELETED
@@ -1,28 +0,0 @@
1
- <h1 class="platform-title"><span class="the-name-of-the-website">useless.io</span> the useless platform</h1>
2
-
3
- <p class="platform-description">a collection of APIs that are more or less useless.</p>
4
-
5
- <h2>Platform Guidelines</h2>
6
-
7
- <h3>Authentication</h3>
8
-
9
- <p>Some endpoints require authentication. In order to do so, the client must
10
- specify an <em>access token</em>. This can be done by using either the
11
- <code>Authorization</code> request header field or the
12
- <code>access_token</code> query string parameter. For example:</p>
13
-
14
- <pre>
15
- GET /photos/1 HTTP/1.1
16
- Host: street-art.useless.io
17
- Authorization: 7Fjfp0ZBr1KtDRbnfVdmIw
18
- </pre>
19
-
20
- <p>If an endpoint requires authentication and an access token is not specified
21
- using one of these methods, a <code>401 Unauthorized</code> response will be returned. If
22
- an invalid access token is ever specified, regardless of whether the endpoint
23
- requires authentication, a <code>401 Unauthorized</code> response will also be returned.</p>
24
-
25
- <h3>Dates</h3>
26
-
27
- <p>All dates are UTC and will conform to the ISO 8601 format. If a request expects
28
- date or time data, it should formatted in the same way. For example: <code>2011-11-13T21:23:47+00:00</code></p>
@@ -1,12 +0,0 @@
1
- module Useless
2
- class Rack
3
- class Base
4
- # Useless::Base::Doc just calls .serve on `useless.doc`
5
- module Doc
6
- def self.call(env)
7
- env['useless.doc'].serve File.expand_path('../../../../../DOC.html', __FILE__)
8
- end
9
- end
10
- end
11
- end
12
- end
@@ -1,35 +0,0 @@
1
- require 'erb'
2
-
3
- module Useless
4
- class Rack
5
- # `Useless::Doc` is a module that handles serving documentation
6
- module Doc
7
- TEMPLATE = <<-BLOCK
8
- <!DOCTYPE html>
9
- <html>
10
- <head>
11
- <title>useless.io</title>
12
- <link href="/application.css" media="screen" rel="stylesheet" type="text/css" />
13
- </head>
14
- <body>
15
- <div id="container">
16
- <%= body %>
17
- </div>
18
- </body>
19
- </html>
20
- BLOCK
21
-
22
- def self.serve(file_or_path)
23
- # Read the contents of the file or the file at the specified path.
24
- body = file_or_path.is_a?(File) ?
25
- file_or_path.read : File.read(file_or_path)
26
-
27
- # Render the template,
28
- response = ERB.new(TEMPLATE).result(binding)
29
-
30
- # and return it as a Rack response.
31
- [200, {'Content-Type' => 'text/html'}, [response]]
32
- end
33
- end
34
- end
35
- end
@@ -1,19 +0,0 @@
1
- require 'useless/rack/doc'
2
-
3
- module Useless
4
- class Rack
5
- module Middleware
6
- # `Doc` simply adds Useless::Doc instance to env as useless.doc'.
7
- class Doc
8
- def initialize(app)
9
- @app = app
10
- end
11
-
12
- def call(env)
13
- env['useless.doc'] = Useless::Rack::Doc
14
- @app.call(env)
15
- end
16
- end
17
- end
18
- end
19
- end