Sha256: 9a89afa8ec825d00a461e2d926cb608190d490343137db312fa64f68f8c2df18

Contents?: true

Size: 967 Bytes

Versions: 5

Compression:

Stored size: 967 Bytes

Contents

# encoding: UTF-8

# To be removed when Crack is updated, see below.
require 'multi_json'

module Contactology
  class Parser < HTTParty::Parser
    SupportedFormats.merge!({'text/plain' => :json})


    protected


    ##
    # Private: This was put in place entirely to appease Ruby 1.9.2-p290's more
    # strict YAML parsing, which breaks Crack 0.1.8's JSON decoding.
    #
    # This will be removed when Crack supports decoding the API's returned
    # values.
    #
    def json
      decode_json(body)
    end

    ##
    # Private: This was put in place entirely to appease Ruby 1.9.2-p290's more
    # strict YAML parsing, which breaks Crack 0.1.8's JSON decoding.
    #
    # This will be removed when Crack supports decoding the API's returned
    # values.
    #
    def decode_json(body)
      if body.to_s =~ /^(?:[\d]+|null|true|false)$/
        MultiJson.decode("[#{body}]").first
      else
        MultiJson.decode body
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contactology-1.0.0 lib/contactology/parser.rb
contactology-0.1.2 lib/contactology/parser.rb
contactology-0.1.1 lib/contactology/parser.rb
contactology-0.1.0 lib/contactology/parser.rb
contactology-0.0.2 lib/contactology/parser.rb