actionframework-baseapi 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/actionframework/baseapi.rb +43 -48
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzVjZDkyNzE3ZWIwYTEzODczMDY4MmVhOWU1NGJhNjczOGM2YjQwZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDI4OWQxYzQ0NWNiZWM5MDJkMDAxMzYzNTk1M2RjMWE3MjYyY2E2NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmQ1NTZiOWQzNDhkYTRiZGZhYzljYjVlYjI2MzljNjM2MzIyNzYwNTZiZWFm
|
10
|
+
NDg3ZTQ0Y2UxNzgyZWQyZWVmNTkyMTkyYTAwYjIyZDVkOTgwY2IwOTBkMGRh
|
11
|
+
OWVhN2MzZDlkMTIyYTRjYjBlYjJkN2ViYzViOGQ2MjdkMTJkMmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZGI1ZmI2OWI0NjVjZjllNGNjMDVhYzUyYjMzYmZkYTJmN2Q2OGJiNjhmNGEy
|
14
|
+
NTcyMWM3NTE3ZDUyZTIzOGI4MTVhNDNmN2EyYTE3NDI0YmMyZGEyODE3MDFk
|
15
|
+
N2I5MDQ1MGM0OWQ1MWFmZDIxYjYwNDg3MTM1OTUwYmE0MmQ1YTM=
|
@@ -1,49 +1,44 @@
|
|
1
|
-
|
1
|
+
########################
|
2
|
+
## Licensed under MIT ##
|
3
|
+
#### © BramVDB.com #####
|
4
|
+
########################
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
|
2
8
|
module ActionFramework
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
@response.write response
|
41
|
-
@response.finish
|
42
|
-
end
|
43
|
-
|
44
|
-
def params
|
45
|
-
@request.params
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
9
|
+
class BaseAPI
|
10
|
+
@@config = {}
|
11
|
+
@@routes = {}
|
12
|
+
|
13
|
+
def self.config(key,value)
|
14
|
+
@@config[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.api(suffix,method)
|
18
|
+
array = @@routes[method] || @@routes[method.to_s.upcase] = []
|
19
|
+
array << suffix.to_s.gsub("_","/")
|
20
|
+
end
|
21
|
+
|
22
|
+
def call env
|
23
|
+
@request = Rack::Request.new(env)
|
24
|
+
@response = Rack::Response.new
|
25
|
+
|
26
|
+
path = @request.path
|
27
|
+
path.slice!(0)
|
28
|
+
|
29
|
+
if(@@routes[@request.request_method].nil? || !@@routes[@request.request_method].include?(path))
|
30
|
+
@response.write "404 Not Found"
|
31
|
+
@response.status = 404
|
32
|
+
return @response.finish
|
33
|
+
end
|
34
|
+
|
35
|
+
res = self.send(path.gsub("/","_"))
|
36
|
+
if(@@config[:json])
|
37
|
+
@response.header["Content-type"] = "application/json"
|
38
|
+
res = res.to_json
|
39
|
+
end
|
40
|
+
@response.write res
|
41
|
+
return @response.finish
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionframework-baseapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bram Vandenbogaerde
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
-
dependencies:
|
11
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: ActionFramework class to create simple API's (kind of like Grape)
|
14
42
|
email: ''
|
15
43
|
executables: []
|