Sha256: 5cfb22a5911a3f200cd0d98377ebbbfef2b410bc417597b3620fb3d120bc1264

Contents?: true

Size: 1.69 KB

Versions: 17

Compression:

Stored size: 1.69 KB

Contents

require 'multi_json'
require 'base64'

module Aws
  module Json
    class Builder

      # @param [Seahorse::Model::Shapes::Shape] shape
      # @param [Hash] params
      # @return [String<JSON>]
      def to_json(shape, params)
        MultiJson.dump(format(shape, params))
      end

      private

      # @param [Seahorse::Model::Shapes::Structure] structure
      # @param [Hash] values
      # @return [Hash]
      def structure(structure, values)
        values.each.with_object({}) do |(key, value), data|
          if structure.member?(key) && !value.nil?
            member_shape = structure.member(key)
            name = member_shape.location_name || key
            data[name] = format(member_shape, value)
          end
        end
      end

      # @param [Seahorse::Model::Shapes::List] list
      # @param [Array] values
      # @return [Array]
      def list(list, values)
        values.collect { |value| format(list.member, value) }
      end

      # @param [Seahorse::Model::Shapes::Map] map
      # @param [Hash] values
      # @return [Hash]
      def map(map, values)
        values.each.with_object({}) do |(key, value), data|
          data[key] = format(map.value, value)
        end
      end

      # @param [Seahorse::Model::Shapes::Shape] shape
      # @param [Object] value
      # @return [Object]
      def format(shape, value)
        case shape.type
        when 'structure' then structure(shape, value)
        when 'list'      then list(shape, value)
        when 'map'       then map(shape, value)
        when 'timestamp' then shape.format_time(value, 'unixTimestamp')
        when 'blob'      then Base64.strict_encode64(value)
        else value
        end
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.10 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.9 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.8 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.7 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.6 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.5 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.4 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.3 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.2 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.1 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.0 lib/aws-sdk-core/json/builder.rb
aws-sdk-core-2.0.0.rc16 lib/aws/json/builder.rb
aws-sdk-core-2.0.0.rc15 lib/aws/json/builder.rb
aws-sdk-core-2.0.0.rc14 lib/aws/json/builder.rb
aws-sdk-core-2.0.0.rc13 lib/aws/json/builder.rb
aws-sdk-core-2.0.0.rc12 lib/aws/json/builder.rb
aws-sdk-core-2.0.0.rc11 lib/aws/json/builder.rb