Exception: ToNetMeApi::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/to_net_me_api/error.rb

Overview

An exception raised by ‘ToNetMeApi::Result` when given a response with an error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Error

An exception is initialized by the data from response mash.

Parameters:

  • data (Hash)

    Error data.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/to_net_me_api/error.rb', line 16

def initialize(data)
  @error_code = data["error_code"]
  @error_msg  = data["error_msg"]
  
  request_params = parse_params(data["request_params"])
  
  # @method_name  = request_params.delete('method')
  # @access_token = request_params.delete('access_token')
  # @oauth        = request_params.delete('oauth')
  # @params       = request_params
  
  @captcha_sid  = data["captcha_sid"]
  @captcha_img  = data["captcha_img"]
end

Instance Attribute Details

#captcha_imgString (readonly)

Captcha image URL (only for “Captcha needed” errors).

Returns:

  • (String)


12
13
14
# File 'lib/to_net_me_api/error.rb', line 12

def captcha_img
  @captcha_img
end

#captcha_sidString (readonly)

Captcha identifier (only for “Captcha needed” errors).

Returns:

  • (String)


9
10
11
# File 'lib/to_net_me_api/error.rb', line 9

def captcha_sid
  @captcha_sid
end

#error_codeFixnum (readonly)

An error code.

Returns:

  • (Fixnum)


6
7
8
# File 'lib/to_net_me_api/error.rb', line 6

def error_code
  @error_code
end

Instance Method Details

#messageString

A full description of the error.

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/to_net_me_api/error.rb', line 33

def message
  message = "VKontakte returned an error #{@error_code}: '#{@error_msg}'"
  # message << " after calling method '#{@method_name}'"
  
  # if @params.empty?
  #   message << " without parameters."
  # else
  #   message << " with parameters #{@params.inspect}."
  # end
  
  message
end