This repository was archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathxml2json.rb
More file actions
54 lines (47 loc) · 1.28 KB
/
xml2json.rb
File metadata and controls
54 lines (47 loc) · 1.28 KB
1
2
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Xml2Json < Sinatra::Base
before do
content_type :json
end
get '/' do
if params['url']
response = HTTParty.get(params['url'])
r = response.dup.to_json
"#{params['callback']}(#{r})"
else
content_type :html
%Q(
<!DOCTYPE html>
<html lang="en">
<head><title>XML2JSONP API Proxy</title></head>
<body>
<h1>XML2JSONP API Proxy</h1>
<code>required params['url'] and params['callback']</code><p>
<a href='http://github.com/bitzesty/xml2jsonp'>http://github.com/bitzesty/xml2jsonp</a>
by <a href='http://bitzesty.com'>Bit Zesty - Ruby on Rails, London UK</a></p>
</body>
</html>
)
end
end
post '/' do
url = params.delete('url')
callback = params.delete('callback')
response = HTTParty.post(url, params)
r = response.dup.to_json
"#{params['callback']}(#{r})"
end
put '/' do
url = params.delete('url')
callback = params.delete('callback')
response = HTTParty.put(url, params)
r = response.dup.to_json
"#{params['callback']}(#{r})"
end
delete '/' do
url = params.delete('url')
callback = params.delete('callback')
response = HTTParty.delete(url, params)
r = response.dup.to_json
"#{params['callback']}(#{r})"
end
end