actionframework-baseapi 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/actionframework/baseapi.rb +43 -48
  3. metadata +31 -3
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmYwOWNhMTE1YjE4YzRkNTk5ZDM5NWZlMjc4Y2U0ODRkZjRmOWZhYQ==
4
+ NzVjZDkyNzE3ZWIwYTEzODczMDY4MmVhOWU1NGJhNjczOGM2YjQwZQ==
5
5
  data.tar.gz: !binary |-
6
- N2RjMmE1MzlmMzAzMjRhZGEzMTc0YzJkODI1YzdiNDJjMTllZWUxZQ==
6
+ ZDI4OWQxYzQ0NWNiZWM5MDJkMDAxMzYzNTk1M2RjMWE3MjYyY2E2NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjUxMzY3ZWY2MTFmNmNhZDRlYmYyNTcyNWU3ZmY5OTVkNjMwNzYxOTU1NjA1
10
- NGE5MjNiM2JmOThjYjczMDExZWFjMDgwYWJiN2QyMzk3NmI0ZTRjYzgyMDQ5
11
- M2ZkOWM5M2VhOTViNDRkZTQ4YTI1N2QxNzk4YmQ0NGFhZjFjNmQ=
9
+ MmQ1NTZiOWQzNDhkYTRiZGZhYzljYjVlYjI2MzljNjM2MzIyNzYwNTZiZWFm
10
+ NDg3ZTQ0Y2UxNzgyZWQyZWVmNTkyMTkyYTAwYjIyZDVkOTgwY2IwOTBkMGRh
11
+ OWVhN2MzZDlkMTIyYTRjYjBlYjJkN2ViYzViOGQ2MjdkMTJkMmM=
12
12
  data.tar.gz: !binary |-
13
- ZmIzNjQ3ZGUwMWY2MTAwYzY5ZmUzYTU3OWFjNWJkMDZmMTFkNGZhZDE1ZjQ5
14
- M2RhZjk1YjYxMTlmNmU5NWFjMWVhNWEzMGQ1YmExNzFkZWY1Zjk3NmEyNWM3
15
- ZDkwYmQ1ZTJlNWZmYjMzOGQwYzQ1OGRlN2NjOTJmYjkxZjk1ZTQ=
13
+ ZGI1ZmI2OWI0NjVjZjllNGNjMDVhYzUyYjMzYmZkYTJmN2Q2OGJiNjhmNGEy
14
+ NTcyMWM3NTE3ZDUyZTIzOGI4MTVhNDNmN2EyYTE3NDI0YmMyZGEyODE3MDFk
15
+ N2I5MDQ1MGM0OWQ1MWFmZDIxYjYwNDg3MTM1OTUwYmE0MmQ1YTM=
@@ -1,49 +1,44 @@
1
- require 'rack'
1
+ ########################
2
+ ## Licensed under MIT ##
3
+ #### © BramVDB.com #####
4
+ ########################
5
+
6
+ require 'json'
7
+
2
8
  module ActionFramework
3
- class BaseAPI
4
- def initialize
5
- api_init
6
- end
7
-
8
- class << self
9
- attr_accessor :config,:routes
10
-
11
- def config key,value
12
- @config[key] = value
13
- end
14
-
15
- def api_init
16
- @routes = {}
17
- @config = {}
18
- end
19
-
20
- def api suffix,method
21
- if(@config[:json] == true)
22
- prefix = "/json/"
23
- end
24
- @routes[method] = prefix+(suffix.to_s.gsub("_","/"))
25
- end
26
-
27
- def call env
28
- @request = Rack::Request.new env
29
- @response = Rack::Response.new
30
-
31
- if(@routes[@request.method].nil?)
32
- @response.write "404 Not Found"
33
- return @response.finish
34
- end
35
- methodname = @routes[method].split("/")
36
- response = self.send(methodname[methodname.length-1])
37
- if(@config[:json] == true)
38
- response = response.to_json
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.1.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-03-17 00:00:00.000000000 Z
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: []