class TunnelBroker::APIResponse

class to give some helpful handling of the TunnelBroker API response

Constants

BADAUTH
CHANGE
NO_CHANGE

Attributes

response[R]

Public Class Methods

new(response) click to toggle source
# File lib/tunnelbroker/api_response.rb, line 13
def initialize(response)
  parse_response(response.lines.first)
end

Public Instance Methods

changed?() click to toggle source
# File lib/tunnelbroker/api_response.rb, line 25
def changed?
  if @changed.nil?
    false
  else
    @changed
  end
end
success?() click to toggle source
# File lib/tunnelbroker/api_response.rb, line 17
def success?
  if @success.nil?
    false
  else
    @success
  end
end

Private Instance Methods

bad_auth(match) click to toggle source
# File lib/tunnelbroker/api_response.rb, line 45
def bad_auth(match)
  @success = false
  @changed = false
  @response = { msg: match[1], data: {} }
end
change(match) click to toggle source
# File lib/tunnelbroker/api_response.rb, line 51
def change(match)
  @success = true
  @changed = true
  matched_response(match)
end
matched_response(match) click to toggle source
# File lib/tunnelbroker/api_response.rb, line 63
def matched_response(match)
  @response = { msg: match[1], data: { ip: match[2] } }
end
no_change(match) click to toggle source
# File lib/tunnelbroker/api_response.rb, line 57
def no_change(match)
  @success = true
  @changed = false
  matched_response(match)
end
parse_response(firstline) click to toggle source
# File lib/tunnelbroker/api_response.rb, line 35
def parse_response(firstline)
  if BADAUTH.match(firstline)
    bad_auth($LAST_MATCH_INFO)
  elsif CHANGE.match(firstline)
    change($LAST_MATCH_INFO)
  elsif NO_CHANGE.match(firstline)
    no_change($LAST_MATCH_INFO)
  end
end