Class: Hover::Api
- Inherits:
-
Object
- Object
- Hover::Api
- Defined in:
- lib/hover/api.rb
Constant Summary collapse
- URL =
'https://www.hover.com/api/'
- AUTH_URL =
'https://www.hover.com/api/login'
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #authenticate(username, password) ⇒ Object
- #create_record(id, name, type, content) ⇒ Object
- #dns(params = {}) ⇒ Object
- #domain(id, params = {}) ⇒ Object
- #domain_dns(id, params = {}) ⇒ Object
- #domains(params = {}) ⇒ Object
-
#initialize(username, password) ⇒ Api
constructor
A new instance of Api.
- #update_record(id, params = {}) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Api
Returns a new instance of Api.
11 12 13 14 15 16 17 |
# File 'lib/hover/api.rb', line 11 def initialize(username, password) self.username = username self.password = password session = authenticate(username, password) self.client = RestClient::Resource.new(URL, :cookies => {:hoverauth => session}) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/hover/api.rb', line 9 def client @client end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/hover/api.rb', line 9 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/hover/api.rb', line 9 def username @username end |
Instance Method Details
#authenticate(username, password) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hover/api.rb', line 19 def authenticate(username, password) auth = {username: username, password: password} RestClient.post(AUTH_URL, auth) do |response, request, result| if [302,200].include?(response.code) return response.["hoverauth"] else raise "Failed to authenticate" end end end |
#create_record(id, name, type, content) ⇒ Object
50 51 52 53 54 |
# File 'lib/hover/api.rb', line 50 def create_record(id, name, type, content) params = {:name => name, :type => type, :content => content} response = post("domains/#{id}/dns", params) JSON.parse(response) end |
#dns(params = {}) ⇒ Object
35 36 37 38 |
# File 'lib/hover/api.rb', line 35 def dns(params = {}) response = get("dns", params) JSON.parse(response)["domains"] end |
#domain(id, params = {}) ⇒ Object
40 41 42 43 |
# File 'lib/hover/api.rb', line 40 def domain(id, params={}) response = get("domains/#{id}", params) JSON.parse(response)["domain"] end |
#domain_dns(id, params = {}) ⇒ Object
45 46 47 48 |
# File 'lib/hover/api.rb', line 45 def domain_dns(id, params={}) response = get("domains/#{id}/dns", params) JSON.parse(response)["domains"].first["entries"] end |
#domains(params = {}) ⇒ Object
30 31 32 33 |
# File 'lib/hover/api.rb', line 30 def domains(params = {}) response = get("domains", params) JSON.parse(response)["domains"] end |
#update_record(id, params = {}) ⇒ Object
56 57 58 59 |
# File 'lib/hover/api.rb', line 56 def update_record(id, params={}) response = put("dns/#{id}", params) JSON.parse(response) end |