class URLVoid::Client
Attributes
api_key[R]
identifier[R]
Public Class Methods
new()
click to toggle source
# File lib/rb-urlvoid/client.rb, line 6 def initialize raise URLVoidError, "API key not found" unless configatron.key?("api_key") @api_key = configatron.api_key @identifier = configatron.identifier end
query_api(path)
click to toggle source
Send a query to URLVoid
API
@param [String] path URL path @return [Hash] Parsed response
# File lib/rb-urlvoid/client.rb, line 45 def self.query_api(path) new.query_api path end
Public Instance Methods
endpoint()
click to toggle source
URLVoid
API endpoint URL
@return [String] Endpoint URL
# File lib/rb-urlvoid/client.rb, line 15 def endpoint "http://api.urlvoid.com/#{identifier}/#{api_key}" end
query_api(path)
click to toggle source
Send a query to URLVoid
API
@param [String] path URL path @return [Hash] Parsed response
# File lib/rb-urlvoid/client.rb, line 33 def query_api(path) with_http_error_handling do res = RestClient.get(endpoint + path) h = Hash.from_xml(res.body) h["response"] end end
with_http_error_handling() { || ... }
click to toggle source
Handling HTTP request that raise an exception
@raise URLVoidError
@yield Give a block that handling HTTP request error
# File lib/rb-urlvoid/client.rb, line 23 def with_http_error_handling yield rescue RestClient::ExceptionWithResponse => e raise URLVoidError, e.message end