lib/botscout.rb in botscout-0.0.1 vs lib/botscout.rb in botscout-0.0.2
- old
+ new
@@ -1,6 +1,7 @@
require "botscout/version"
+require 'httparty'
module Botscout
class Client
include HTTParty
format :xml
@@ -10,24 +11,42 @@
def initialize(key = "")
@key = key
end
def test(options ={})
- _options = (@key.present? ? { :key => @key } : {}).merge(options)
- @response = self.class.get('/test', :query => _options)
+ _options = ((@key.nil? || @key.empty?) ? {} : { :key => @key } ).merge(options)
+ @response = self.class.get('/test/', :query => _options)
Result.new(@response.body)
end
class Result
- attr_accessor :response, :result, :matched
+ attr_reader :response, :result, :matched
- def initialize(xml_response = "")
- @response = xml_response
+ def initialize(response = "")
+ @response = response.to_s
parse!
end
+ def bot?
+ @result.to_s == "Y"
+ end
+
+ def success?
+ !has_error?
+ end
+
+ def error
+ @response.match(/\A!(.*)/) && $1
+ end
+
+ def has_error?
+ !!@response.match(/\A!/)
+ end
+
+ private
+
def parse!
if has_error?
@result = nil
else
results = @response.split "|"
@@ -43,26 +62,10 @@
end
self
end
- def bot?
- @result.to_s == "Y"
- end
- def success?
- !has_error?
- end
-
- def error
- @response.match(/\A!(.*)/) && $1
- end
-
- def has_error?
- !!@response.match(/\A!/)
- end
-
- private
def parse_standart(response_array)
{
:count => response_array[2].to_i,
:field => response_array[1],
:matched => response_array[0]