Class: Vkponchik::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/vkponchik/response.rb

Overview

API response

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Response

Returns a new instance of Response.

Parameters:

  • hash (Hash)


7
8
9
# File 'lib/vkponchik/response.rb', line 7

def initialize(hash)
  @hash = hash
end

Instance Method Details

#[](arg) ⇒ Object?

Returns:

  • (Object?)


29
30
31
# File 'lib/vkponchik/response.rb', line 29

def [](arg)
  @hash[arg.to_s]
end

#error?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/vkponchik/response.rb', line 12

def error?
  !@hash['success']
end

#error_full_messageString?

Returns:

  • (String?)


22
23
24
25
26
# File 'lib/vkponchik/response.rb', line 22

def error_full_message
  return unless error?

  "#{@hash['error']}: #{@hash['msg']}"
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vkponchik/response.rb', line 17

def success?
  !error?
end