Class: URLVoid::Client
- Inherits:
-
Object
- Object
- URLVoid::Client
- Defined in:
- lib/rb-urlvoid/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Class Method Summary collapse
-
.query_api(path) ⇒ Hash
Send a query to URLVoid API.
Instance Method Summary collapse
-
#endpoint ⇒ String
URLVoid API endpoint URL.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#query_api(path) ⇒ Hash
Send a query to URLVoid API.
-
#with_http_error_handling { ... } ⇒ Object
Handling HTTP request that raise an exception.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 |
# 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 |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/rb-urlvoid/client.rb', line 4 def api_key @api_key end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
4 5 6 |
# File 'lib/rb-urlvoid/client.rb', line 4 def identifier @identifier end |
Class Method Details
.query_api(path) ⇒ Hash
Send a query to URLVoid API
45 46 47 |
# File 'lib/rb-urlvoid/client.rb', line 45 def self.query_api(path) new.query_api path end |
Instance Method Details
#endpoint ⇒ String
URLVoid API endpoint URL
15 16 17 |
# File 'lib/rb-urlvoid/client.rb', line 15 def endpoint "http://api.urlvoid.com/#{identifier}/#{api_key}" end |
#query_api(path) ⇒ Hash
Send a query to URLVoid API
33 34 35 36 37 38 39 |
# 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 { ... } ⇒ Object
Handling HTTP request that raise an exception
23 24 25 26 27 |
# File 'lib/rb-urlvoid/client.rb', line 23 def with_http_error_handling yield rescue RestClient::ExceptionWithResponse => e raise URLVoidError, e. end |