summaryrefslogtreecommitdiff
path: root/lib/oxidized/api/rest.rb
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2013-10-26 02:32:51 -0700
committerytti <saku@ytti.fi>2013-10-26 02:32:51 -0700
commitf2acb9455edae1bc1c80de28af2362da9da206bf (patch)
tree3c92898daade43cdbbec317c07c2073b2a40e730 /lib/oxidized/api/rest.rb
parent4455a5b91accda5da7c1b8128cb045c7eb7bb5da (diff)
parent7982a7d3956910406e59952e1b215d5b4dd1d8e5 (diff)
Merge pull request #8 from nopedial/master
ascii/json output initial differentiation
Diffstat (limited to 'lib/oxidized/api/rest.rb')
-rw-r--r--lib/oxidized/api/rest.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb
index d1bd7dc..cdf5c80 100644
--- a/lib/oxidized/api/rest.rb
+++ b/lib/oxidized/api/rest.rb
@@ -4,11 +4,14 @@ module Oxidized
module API
class Rest
module Helpers
- def send res, msg='OK', status=200
- msg = {:result => msg}
- res['Content-Type'] = 'application/json'
- res.status = status
- res.body = JSON.dump msg
+ def send res, msg='OK', ascii=false, status=200
+ res.body = msg
+ if not ascii
+ msg = {:result => msg}
+ res['Content-Type'] = 'application/json'
+ res.status = status
+ res.body = JSON.dump msg
+ end
end
end
include Oxidized::API::Rest::Helpers
@@ -47,9 +50,12 @@ module Oxidized
if $1.include? '/'
group, node = $1.split("/")[1..2]
else
- group, node = 0, $1
+ group, node = nil, $1
+ end
+ ascii = if node[-4..-1] == '.txt'
+ node = node[0..-5]
end
- send res, @nodes.fetch(node, group)
+ send res, @nodes.fetch(node, group), ascii
rescue Oxidized::NotSupported => e
send res, e
end