Sha256: f16b10ee305c630195ec04e9016652d6ab178f19d29bce2149620b1bd3b44a39

Contents?: true

Size: 572 Bytes

Versions: 1

Compression:

Stored size: 572 Bytes

Contents

module FubClient
  module Middleware
    class Parser < Faraday::Response::Middleware
      
      def on_complete(env)
        original_json = MultiJson.load(env[:body])
        json = original_json.deep_transform_keys{ |k| k.to_s.snakecase.to_sym }
        metadata = json[:_metadata]
        if metadata.nil?
          result = json
        else
          result = json[metadata[:collection].snakecase.to_sym]
        end
        env[:body] = {
          data: result,
          errors: json[:errors],
          metadata: metadata
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fub_client-0.1.1 lib/fub_client/middleware/parser.rb