rubapi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubapi/controller.rb +28 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a6890dbc0ab667734bdfe53a3fe18191ab9feaa0
4
- data.tar.gz: 9ef2394c0cfd8ac737ffac797cb4ad2cce93d4d9
3
+ metadata.gz: f80b8e96bec40c2a7c6387864e9ec04a81d95bac
4
+ data.tar.gz: 86323cc0ce6788ac329f80430588c097c8100f6c
5
5
  SHA512:
6
- metadata.gz: 53bc2dc997a2110369af6bad7543dc11683a6976c9d50164e74d965c153c0faeba0088ecdf411c99df6b6f7175a6be493065a420e089fdd15f2cf01f7a3b2e40
7
- data.tar.gz: 46554545f3146bc95ecadb7585fc90b3dbb491b35086830fa41e18720b9fd5cbb610106791a3104ad183a90a9df1843263e2d5f2bdb580e346b730a975a4c3b3
6
+ metadata.gz: e29fa72ced6467304b78573ae5e866878b31ff5fa03dc5598e7f78fa529bd02e08e6b7b66fd972d71a3bcce4aaf50cfa0ffe19d941e06138c821a0d67941e98d
7
+ data.tar.gz: 721678a8a5c297226783aa4630b82c2c3b7cb39a774954f07f8a8a8fb81c21cd8adb41db19704cfe15fddfcdcd984fe3c5d68ed570a10eed3b84de3e3be380f3
@@ -7,37 +7,39 @@ module Rubapi
7
7
  end
8
8
 
9
9
  def index
10
+ not_defined
10
11
  end
11
12
 
12
13
  def show
14
+ not_defined
13
15
  end
14
16
 
15
17
  def create
18
+ not_defined
16
19
  end
17
20
 
18
21
  def update
22
+ not_defined
19
23
  end
20
24
 
21
25
  def delete
26
+ not_defined
22
27
  end
23
28
 
24
- def run(route)
25
- if route.nil?
26
- response.status = 404
27
- response.send_response
28
-
29
- return response
29
+ def not_defined
30
+ self.response.tap do |r|
31
+ r.status = 417
32
+ r.content = "{\"errors\":[\"not defined\"]}"
33
+ r.send_response
30
34
  end
35
+ end
31
36
 
32
- route[:controller] ||= self.class
33
- controller = route[:controller].new(self.response)
34
- controller.params = self.params
35
-
36
- response.tap do |r|
37
+ def send_response(content)
38
+ self.response.tap do |r|
37
39
  r.status = 200
38
40
 
39
41
  begin
40
- r.content = JSON.generate(controller.send(route[:method]))
42
+ r.content = JSON.generate(content)
41
43
  rescue
42
44
  r.content = "{\"errors\":[\"can't generate a json object\"]}"
43
45
  r.status = 417 #Execution failed
@@ -46,5 +48,19 @@ module Rubapi
46
48
  end
47
49
  end
48
50
  end
51
+
52
+ def run(route)
53
+ if route.nil?
54
+ response.status = 404
55
+ response.send_response
56
+
57
+ return response
58
+ end
59
+
60
+ route[:controller] ||= self.class
61
+ controller = route[:controller].new(self.response)
62
+ controller.params = self.params
63
+ controller.send(route[:method])
64
+ end
49
65
  end
50
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo K. Sasaki