class Metadata::V2::Request

Attributes

args[R]
operation[R]

Public Class Methods

new(operation, *args) click to toggle source
# File lib/metadata/v2/request.rb, line 10
def initialize(operation, *args)
  @operation = operation
  @args      = args
  self
end

Public Instance Methods

body() click to toggle source
# File lib/metadata/v2/request.rb, line 31
def body
  @body ||= [id, operation, payload].compact.reject(&:empty?).join(' ')
end
checksum() click to toggle source
# File lib/metadata/v2/request.rb, line 35
def checksum
  @checksum ||= Zlib.crc32(body).to_s(16)
end
id() click to toggle source
# File lib/metadata/v2/request.rb, line 18
def id
  @id ||= 8.times.map { rand (0..15) }.map { |n| n.to_s(16) }.reduce(:+)
end
payload() click to toggle source
# File lib/metadata/v2/request.rb, line 22
def payload
  case args.size
  when 1
    Base64.encode64(*args).chomp
  when 2
    Base64.encode64(args.map { |arg| Base64.encode64(arg).chomp }.join(' ')).chomp
  end
end
to_s() click to toggle source
# File lib/metadata/v2/request.rb, line 39
def to_s
  ['V2', body.length, checksum, body].join(' ') + "\n"
end