class Dnsblim::APIResponse
A class representing a reply from the API
Attributes
reply[RW]
success[RW]
Public Class Methods
new(api_reply, api_status, **args)
click to toggle source
@param [HTTParty::Response] api_reply Response received by the API @param [Integer] api_status HTTP Status Code for response @param [Hash] args A hash of options to parse with
# File lib/dnsblim/api_response.rb, line 23 def initialize(api_reply, api_status, **args) if args.fetch(:ip_addr, nil) @ip_addr = args.fetch(:ip_addr) end if args.fetch(:quiet, nil) @quiet = args.fetch(:quiet) end @reply = JSON.parse(api_reply) if @reply.fetch('reply', nil) if @reply['reply'].fetch('mysql', nil) @mysql = @reply['reply'].fetch('mysql', nil) end if @reply['reply'].fetch('bl', nil) @bl = @reply['reply'].fetch('bl', nil) end end if @reply.fetch('list', nil) and @reply.fetch('prune', nil) @record_type = args[:record_type] end if @reply.fetch('dupes', nil) and @reply.fetch('message', nil) @ips = args.fetch(:ip_addrs, nil) @duplicates = @reply['dupes'] @message = @reply['message'] end @status_code = api_status @success = @reply['success'] end
parse(api_reply, api_status, **args)
click to toggle source
@param [HTTParty::Response] api_reply Response received by the API @param [Integer] api_status HTTP Status Code for response @param [Hash] args A hash of options to parse with @return [APIResponse.new()]
# File lib/dnsblim/api_response.rb, line 55 def self.parse(api_reply, api_status, **args) new(api_reply, api_status, args) end
Public Instance Methods
inspect()
click to toggle source
# File lib/dnsblim/api_response.rb, line 11 def inspect string = "#<#{self.class.name}:#{object_id} " string << @reply.inspect << '>' end
print_table(type)
click to toggle source
@param [String] type Type of response from API
# File lib/dnsblim/api_response.rb, line 65 def print_table(type) case type when 'stats' Dnsblim::CLI::Tables::StatsTable.new.run(@reply, {quiet: @quiet, record_type: @record_type}) when 'check' Dnsblim::CLI::Tables::CheckTable.new.run(@reply, {quiet: @quiet, ip_addr: @ip_addr}) when 'mcheck' Dnsblim::CLI::Tables::MCheckTable.new.run(@reply, {quiet: @quiet}) when 'madd' Dnsblim::CLI::Tables::AdditionTable.new.run(@reply, {quiet: @quiet, additions: 'multiple', message: @message, success: @success, duplicates: @duplicates, ip_addrs: @ips}) when 'add' Dnsblim::CLI::Tables::AdditionTable.new.run(@reply, {quiet: @quiet, additions: 'single', message: @message, success: @success, duplicates: @duplicates, ip_addrs: @ips}) else raise ArgumentError('Invalid Type given to Dnsblim::APIResponse.print_table') end end
success?()
click to toggle source
# File lib/dnsblim/api_response.rb, line 60 def success? @success end
to_s()
click to toggle source
# File lib/dnsblim/api_response.rb, line 16 def to_s @reply end