Class: MTProto::Type::RPC::Auth::SentCode

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/type/rpc/auth/sent_code.rb

Class Method Summary collapse

Class Method Details

.parse(response) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mtproto/type/rpc/auth/sent_code.rb', line 12

def self.parse(response)
  constructor = response[0, 4].unpack1('L<')

  if constructor == Type::GzipPacked::CONSTRUCTOR
    response = Type::GzipPacked.unpack(response)
    constructor = response[0, 4].unpack1('L<')
  end

  if constructor == Type::RpcError::CONSTRUCTOR
    error = Type::RpcError.deserialize(response)
    raise MTProto::RpcError.new(error.error_code, error.error_message)
  end

  if constructor == Type::SentCode::CONSTRUCTOR
    sent_code = Type::SentCode.deserialize(response)
    sent_code.to_h
  else
    raise UnexpectedConstructorError.new(constructor)
  end
end