From 58aeb2c6ec778740f5cbf3ab24183c20e0936a34 Mon Sep 17 00:00:00 2001 From: Josephine Sayco Date: Thu, 7 Sep 2017 13:49:22 +0800 Subject: [PATCH] add ability to parse response from JSONAPI --- lib/httparty/parser.rb | 21 +++++++++++---------- spec/httparty/request_spec.rb | 6 ++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/httparty/parser.rb b/lib/httparty/parser.rb index 64e12df1..3c78358b 100644 --- a/lib/httparty/parser.rb +++ b/lib/httparty/parser.rb @@ -38,16 +38,17 @@ module HTTParty # @abstract Read the Custom Parsers section for more information. class Parser SupportedFormats = { - 'text/xml' => :xml, - 'application/xml' => :xml, - 'application/json' => :json, - 'text/json' => :json, - 'application/javascript' => :plain, - 'text/javascript' => :plain, - 'text/html' => :html, - 'text/plain' => :plain, - 'text/csv' => :csv, - 'application/csv' => :csv, + 'text/xml' => :xml, + 'application/xml' => :xml, + 'application/json' => :json, + 'application/vnd.api+json' => :json, + 'text/json' => :json, + 'application/javascript' => :plain, + 'text/javascript' => :plain, + 'text/html' => :html, + 'text/plain' => :plain, + 'text/csv' => :csv, + 'application/csv' => :csv, 'text/comma-separated-values' => :csv } diff --git a/spec/httparty/request_spec.rb b/spec/httparty/request_spec.rb index eae82fbe..32a372d4 100644 --- a/spec/httparty/request_spec.rb +++ b/spec/httparty/request_spec.rb @@ -373,6 +373,12 @@ end end + it 'should handle application/vnd.api+json' do + ["application/vnd.api+json", "application/vnd.api+json; charset=iso8859-1"].each do |ct| + expect(@request.send(:format_from_mimetype, ct)).to eq(:json) + end + end + it 'should handle application/json' do ["application/json", "application/json; charset=iso8859-1"].each do |ct| expect(@request.send(:format_from_mimetype, ct)).to eq(:json)