class Aws::Api::OperationExample

Public Class Methods

new(options) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 7
def initialize(options)
  @obj_name = options[:svc_var_name]
  @method_name = options[:method_name]
  @operation = options[:operation]
  @streaming_output = !!(
    @operation.output &&
    @operation.output.payload_member &&
    @operation.output.payload_member.definition['streaming']
  )
end

Public Instance Methods

inspect()
Alias for: to_str
to_s()
Alias for: to_str
to_str() click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 18
def to_str
  "resp = #{@obj_name}.#{@method_name}(#{params[1...-1]})"
end
Also aliased as: to_s, inspect

Private Instance Methods

key_name(shape, inspect = true) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 127
def key_name(shape, inspect = true)
  shape_name(shape.key)
end
list(shape, i, visited) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 61
def list(shape, i, visited)
  if multiline?(shape.member)
    multiline_list(shape, i, visited)
  else
    "[#{value(shape.member)}, '...']"
  end
end
map(shape, i, visited) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 46
def map(shape, i, visited)
  if multiline?(shape.value)
    multiline_map(shape, i, visited)
  else
    "{ #{key_name(shape)} => #{value(shape.value)} }"
  end
end
member(shape, i, visited) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 76
def member(shape, i, visited)
  if visited.include?(shape.name)
    recursive = ['{']
    recursive << "#{i}  # recursive #{shape.name} ..."
    recursive << "#{i}}"
    return recursive.join("\n")
  elsif shape.name == 'AttributeValue'
    msg='"value", #<Hash,Array,String,Numeric,Boolean,nil,IO,Set>'
    return msg
  else
    visited = visited + [shape.name]
  end
  case shape
  when Seahorse::Model::Shapes::Structure then structure(shape, i, visited)
  when Seahorse::Model::Shapes::Map then map(shape, i, visited)
  when Seahorse::Model::Shapes::List then list(shape, i, visited)
  else value(shape)
  end
end
multiline?(shape) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 116
def multiline?(shape)
  Seahorse::Model::Shapes::Structure === shape ||
  Seahorse::Model::Shapes::List === shape ||
  Seahorse::Model::Shapes::Map === shape
end
multiline_list(shape, i, visited) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 69
def multiline_list(shape, i, visited)
  lines = ["["]
  lines << "#{i}  #{member(shape.member, i + '  ', visited)},"
  lines << "#{i}]"
  lines.join("\n")
end
multiline_map(shape, i, visited) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 54
def multiline_map(shape, i, visited)
  lines = ["{"]
  lines << "#{i}  #{key_name(shape)} => #{member(shape.value, i + '  ', visited)},"
  lines << "#{i}}"
  lines.join("\n")
end
params() click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 26
def params
  return '' if @operation.input.nil?
  structure(@operation.input, '', [])
end
shape_name(shape, inspect = true) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 122
def shape_name(shape, inspect = true)
  value = shape.name
  inspect ? value.inspect : value
end
string_value(shape) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 108
def string_value(shape)
  if shape.enum
    shape.enum.to_a.join('|').inspect
  else
    shape_name(shape)
  end
end
structure(shape, i, visited) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 31
def structure(shape, i, visited)
  lines = ['{']
  if @streaming_output
    lines << "#{i}  response_target: '/path/to/file', # optional target file path"
  end
  shape.members.each do |member_name, member_shape|
    if shape.required.include?(member_name)
      lines << "#{i}  # required"
    end
    lines << "#{i}  #{member_name}: #{member(member_shape, i + '  ', visited)},"
  end
  lines << "#{i}}"
  lines.join("\n")
end
value(shape) click to toggle source
# File lib/aws-sdk-core/api/operation_example.rb, line 96
def value(shape)
  case shape
  when Seahorse::Model::Shapes::String then string_value(shape)
  when Seahorse::Model::Shapes::Integer then 1
  when Seahorse::Model::Shapes::Float then 1.1
  when Seahorse::Model::Shapes::Boolean then true
  when Seahorse::Model::Shapes::Timestamp then 'Time.now'
  when Seahorse::Model::Shapes::Blob then "#{shape_name(shape, false)}<String,IO>".inspect
  else raise "unhandled shape type `#{shape.type}'"
  end
end