flexible_api_server 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flexible_api_server/version.rb +1 -1
- data/lib/flexible_api_server.rb +9 -6
- metadata +7 -7
data/lib/flexible_api_server.rb
CHANGED
@@ -18,6 +18,10 @@ module FlexibleApiServer
|
|
18
18
|
class App < Sinatra::Base
|
19
19
|
|
20
20
|
register Sinatra::RespondTo
|
21
|
+
mime_type :jsonp, 'application/javascript'
|
22
|
+
mime_type :js, 'application/json'
|
23
|
+
mime_type :xml, 'application/xml'
|
24
|
+
|
21
25
|
set :assume_xhr_is_js, true
|
22
26
|
set :default_content, :js
|
23
27
|
set :raise_errors, false
|
@@ -25,7 +29,7 @@ module FlexibleApiServer
|
|
25
29
|
set :views, File.dirname(__FILE__) + '/../views'
|
26
30
|
|
27
31
|
FILTERED_COLUMNS = [:password, :password_confirmation]
|
28
|
-
ALLOWED_FORMATS = [:js, :xml]
|
32
|
+
ALLOWED_FORMATS = [:js, :xml, :jsonp]
|
29
33
|
|
30
34
|
def assign(k, v)
|
31
35
|
@assign ||= {}
|
@@ -33,9 +37,6 @@ module FlexibleApiServer
|
|
33
37
|
nil
|
34
38
|
end
|
35
39
|
|
36
|
-
JSON_CONTENT_TYPE = 'application/json;charset=utf-8'
|
37
|
-
XML_CONTENT_TYPE = 'application/xml;charset=utf-8'
|
38
|
-
|
39
40
|
def free_render(code, hash = '') # blank by default, not nil
|
40
41
|
status code
|
41
42
|
# Filter some things out
|
@@ -43,14 +44,16 @@ module FlexibleApiServer
|
|
43
44
|
hash[column] = '[filtered]' if hash.has_key?(column)
|
44
45
|
end if hash.is_a?(Hash)
|
45
46
|
# and respond
|
47
|
+
charset 'utf-8'
|
46
48
|
format :js unless ALLOWED_FORMATS.include? format
|
47
49
|
respond_to do |wants|
|
50
|
+
wants.jsonp do
|
51
|
+
(params[:callback] || 'callback') + "(#{hash.to_json});"
|
52
|
+
end
|
48
53
|
wants.js do
|
49
|
-
headers['Content-type'] = JSON_CONTENT_TYPE
|
50
54
|
hash.to_json
|
51
55
|
end
|
52
56
|
wants.xml do
|
53
|
-
headers['Content-type'] = XML_CONTENT_TYPE
|
54
57
|
hash.to_xml
|
55
58
|
end
|
56
59
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexible_api_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 12
|
10
|
+
version: 0.0.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Crepezzi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-04 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -68,12 +68,12 @@ dependencies:
|
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
hash:
|
71
|
+
hash: 17
|
72
72
|
segments:
|
73
73
|
- 0
|
74
74
|
- 0
|
75
|
-
-
|
76
|
-
version: 0.0.
|
75
|
+
- 7
|
76
|
+
version: 0.0.7
|
77
77
|
type: :runtime
|
78
78
|
version_requirements: *id004
|
79
79
|
- !ruby/object:Gem::Dependency
|