Class: WebbyNode::APIObject
- Inherits:
-
Object
- Object
- WebbyNode::APIObject
- Includes:
- HTTParty
- Defined in:
- lib/webbynode-api.rb
Overview
Direct Known Subclasses
Client, DNS::Record, DNS::RecordList, DNS::Zone, DNS::ZoneList, Webby, WebbyList
Instance Attribute Summary collapse
-
#data ⇒ Object
Stores the results of the HTTParty API interactions.
-
#email ⇒ Object
E-mail address used to access the WebbyNode API.
-
#token ⇒ Object
API token used to access the WebbyNode API, visible at manager.webbynode.com/account.
Class Method Summary collapse
-
.auth_post(url, options = {}) ⇒ Hash
Uses HTTParty to submit a secure API POST request via email address and token.
Instance Method Summary collapse
-
#auth_get(url, options = {}) ⇒ Object
Uses HTTParty to submit a secure API request via email address and token.
- #auth_post(url, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ APIObject
constructor
Creates a new API object secured by e-mail address and API token.
-
#method_missing(method) ⇒ Object?
Catches simple requests for specific API data returned via a hash.
Constructor Details
#initialize(options = {}) ⇒ APIObject
Creates a new API object secured by e-mail address and API token
28 29 30 31 32 |
# File 'lib/webbynode-api.rb', line 28 def initialize( = {}) raise ArgumentError, ":email and :token are required arguments" unless [:email] && [:token] @email = [:email] @token = [:token] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object?
Catches simple requests for specific API data returned via a hash
78 79 80 81 |
# File 'lib/webbynode-api.rb', line 78 def method_missing(method) key = @data[method.to_s] if @data key end |
Instance Attribute Details
#data ⇒ Object
Stores the results of the HTTParty API interactions
20 21 22 |
# File 'lib/webbynode-api.rb', line 20 def data @data end |
#email ⇒ Object
E-mail address used to access the WebbyNode API
16 17 18 |
# File 'lib/webbynode-api.rb', line 16 def email @email end |
#token ⇒ Object
API token used to access the WebbyNode API, visible at manager.webbynode.com/account
18 19 20 |
# File 'lib/webbynode-api.rb', line 18 def token @token end |
Class Method Details
.auth_post(url, options = {}) ⇒ Hash
Uses HTTParty to submit a secure API POST request via email address and token. API access information should be included via the :email and :token hash keys, in a hash on the :query key of the options hash passed as the second argument in the method call.
64 65 66 67 68 69 70 |
# File 'lib/webbynode-api.rb', line 64 def self.auth_post(url, = {}) [:query] ||= {} raise ArgumentError, "API information is missing or incomplete" unless [:query][:email] && [:query][:token] results = self.post(url, ) raise ArgumentError, "Probable bad API information given" if results == {} return results end |
Instance Method Details
#auth_get(url, options = {}) ⇒ Object
Uses HTTParty to submit a secure API request via email address and token
38 39 40 41 42 43 44 45 |
# File 'lib/webbynode-api.rb', line 38 def auth_get(url, = {}) raise ArgumentError, "API information is missing or incomplete" unless @email && @token [:query] ||= {} [:query].merge!(:email => @email, :token => @token) results = self.class.get(url, ) raise ArgumentError, "Probable bad API information given" if results == {} return results end |
#auth_post(url, options = {}) ⇒ Object
47 48 49 |
# File 'lib/webbynode-api.rb', line 47 def auth_post(url, = {}) self.class.auth_post(url, ) end |