apiary 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,9 @@ Apiary let's you use any existing class and turn it into an API. For instance, s
12
12
  end
13
13
  end
14
14
 
15
- You can convert this to an API by annotating this class with three lines.
15
+ You can convert this to an API by annotating this class with four lines.
16
+
17
+ require 'apiary'
16
18
 
17
19
  class Temperature
18
20
  include Apiary # Include Apiary as a module in your class
@@ -31,4 +33,6 @@ Now, your API is complete! You can run this with `Temperature.run`. This will cr
31
33
 
32
34
  And you'll get back
33
35
 
34
- 74.21
36
+ 74.21
37
+
38
+ Currently, `get`, `post`, `put` and `delete` are supported. You can also supply a path after any verb to have a custom path. Also, the current Rack env hash is available under `rack_env` if you need to take a look at the current request.
@@ -7,7 +7,9 @@ require 'apiary/version'
7
7
 
8
8
  module Apiary
9
9
  ApiMethod = Struct.new(:method, :http_method, :path)
10
-
10
+
11
+ attr_accessor :rack_env
12
+
11
13
  module ClassMethods
12
14
 
13
15
  def get(path = nil)
@@ -18,6 +20,14 @@ module Apiary
18
20
  __set_routing(:get, path)
19
21
  end
20
22
 
23
+ def put(path = nil)
24
+ __set_routing(:put, path)
25
+ end
26
+
27
+ def delete(path = nil)
28
+ __set_routing(:put, path)
29
+ end
30
+
21
31
  def version(number)
22
32
  @version = number
23
33
  end
@@ -52,8 +62,10 @@ module Apiary
52
62
  path = "#{@version}/#{cmd.path || default_path(cmd.method)}".squeeze('/')
53
63
  route = router.add(path)
54
64
  route.send(cmd.http_method) if cmd.http_method
55
- route.to { |env|
56
- Rack::Response.new((blk ? blk.call : new).send(cmd.method, *env['router.response'].param_values).to_s).finish
65
+ route.to { |env|
66
+ instance = (blk ? blk.call : new)
67
+ instance.rack_env = env
68
+ Rack::Response.new(instance.send(cmd.method, *env['router.response'].param_values).to_s).finish
57
69
  }
58
70
  end
59
71
  router
@@ -1,3 +1,3 @@
1
1
  module Apiary
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiary
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-16 00:00:00 -08:00
18
+ date: 2011-01-17 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21