Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added XML Parsing and Loosened MultiJson dependency #20

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/weary/response.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'rack/response'

autoload :MultiJson, 'multi_json'
autoload :MultiXml, 'multi_xml'

module Weary
class Response
Expand Down Expand Up @@ -52,8 +53,13 @@ def call(env)

def parse
raise "The response does not contain a body" if body.nil? || body.empty?
raise "Unable to parse Content-Type: #{content_type}" unless content_type =~ /json($|;.*)/
MultiJson.decode body
raise "Unable to parse Content-Type: #{content_type}" unless content_type =~ /(json|xml)($|;.*)/
case content_type.match(/(json|xml)($|;.*)/)[1]
when 'json'
MultiJson.decode body
when 'xml'
MultiXml.parse body
end
end
end
end
11 changes: 6 additions & 5 deletions weary.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ Gem::Specification.new do |s|

s.require_paths = ['lib']

s.add_runtime_dependency "rack", "~> 1.4.0"
s.add_runtime_dependency "addressable", "~> 2.2.7"
s.add_runtime_dependency "promise", "~> 0.3.0"
s.add_runtime_dependency "simple_oauth", "~> 0.1.5"
s.add_runtime_dependency "multi_json", "~> 1.2.0"
s.add_runtime_dependency "rack"
s.add_runtime_dependency "addressable"
s.add_runtime_dependency "promise"
s.add_runtime_dependency "simple_oauth"
s.add_runtime_dependency "multi_json"
s.add_runtime_dependency "multi_xml"
end