Created
February 3, 2016 17:54
-
-
Save dpsk/d426fbbadefbc74959c4 to your computer and use it in GitHub Desktop.
Revisions
-
dpsk created this gist
Feb 3, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ module API class Base < Grape::API mount API::V1::ApplicationV1 => "/api" end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ module API module V1 class ApplicationV1 < Grape::API require 'builder' format :xml default_format :xml unless Rails.env.development? rescue_from :all do |message, backtrace, options, env| Rails.logger.info message.inspect Rails.logger.info backtrace.inspect Rails.logger.info options.inspect Rails.logger.info env.inspect Rack::Response.new([{message: "Invalid Request"}.to_xml(root: :error)], 400, { "Content-type" => "application/xml" }).finish end end get "/action" do @data = Data.get(params) XMLResponses::Data::generate(@data) end end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ module API module V1 module XMLResponses::Data def self.generate(data) xml = Builder::XmlMarkup.new(:indent => 2) xml.Response do |resp| resp.APIVersion "1.0" resp.DataField data.field end end end end end