Class: Transip
- Inherits:
-
Object
- Object
- Transip
- Defined in:
- lib/transip.rb
Overview
Savon Gem - See: savonrb.com/. Wouldn’t be so simple without it!
Constant Summary collapse
- WSDL =
'https://api.transip.nl/wsdl/?service=DomainService'
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#login ⇒ Object
Returns the value of attribute login.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#actions ⇒ Object
Returns Array with all possible SOAP WSDL actions.
-
#client ⇒ Object
Returns a Savon::Client object to be used in the connection.
-
#client! ⇒ Object
Same as client method but initializes a brand new fresh client.
-
#cookie ⇒ Object
Used as authentication.
-
#generate_hash(password) ⇒ Object
Generates the needed authentication hash.
-
#initialize(login, ip, mode = :readonly) ⇒ Transip
constructor
Example: transip = Transip.new(‘username’, ‘12.34.12.3’) # will use readonly mode transip = Transip.new(‘username’, ‘12.34.12.3’, ‘readwrite’) # use this in production.
-
#request(action, options = nil) ⇒ Object
Returns the response.to_hash (raw Savon::SOAP::Response is also stored in @response).
Constructor Details
#initialize(login, ip, mode = :readonly) ⇒ Transip
31 32 33 34 35 |
# File 'lib/transip.rb', line 31 def initialize(login, ip, mode = :readonly) @login = login @ip = ip @mode = mode end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
25 26 27 |
# File 'lib/transip.rb', line 25 def hash @hash end |
#ip ⇒ Object
Returns the value of attribute ip.
25 26 27 |
# File 'lib/transip.rb', line 25 def ip @ip end |
#login ⇒ Object
Returns the value of attribute login.
25 26 27 |
# File 'lib/transip.rb', line 25 def login @login end |
#mode ⇒ Object
Returns the value of attribute mode.
25 26 27 |
# File 'lib/transip.rb', line 25 def mode @mode end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
26 27 28 |
# File 'lib/transip.rb', line 26 def response @response end |
Instance Method Details
#actions ⇒ Object
Returns Array with all possible SOAP WSDL actions.
72 73 74 |
# File 'lib/transip.rb', line 72 def actions client.wsdl.soap_actions end |
#client ⇒ Object
Returns a Savon::Client object to be used in the connection. This object is re-used and cached as @client.
67 68 69 |
# File 'lib/transip.rb', line 67 def client @client ||= client! end |
#client! ⇒ Object
Same as client method but initializes a brand new fresh client. You have to use this one when you want to re-set the mode (readwrite, readonly), or authentication details of your client.
57 58 59 60 61 62 63 |
# File 'lib/transip.rb', line 57 def client! @client = Savon::Client.new do wsdl.document = WSDL end @client.http.headers["Cookie"] = return @client end |
#cookie ⇒ Object
Used as authentication
49 50 51 52 |
# File 'lib/transip.rb', line 49 def raise StandardError, "Don't have an authentication hash yet. Please set a hash using generate_hash('your_api_password') or hash= method." if hash.blank? "login=#{login}; hash=#{hash}; mode=#{mode}; " end |
#generate_hash(password) ⇒ Object
Generates the needed authentication hash.
NOTE: The password is NOT your general TransIP password but one specially for the API. Configure it in the Control Panel.
42 43 44 45 46 |
# File 'lib/transip.rb', line 42 def generate_hash(password) digest_string = "#{login}:#{password}@#{ip}" digest = Digest::MD5.hexdigest(digest_string) @hash = digest end |
#request(action, options = nil) ⇒ Object
Returns the response.to_hash (raw Savon::SOAP::Response is also stored in @response). Examples:
hash_response = transip.request(:get_domain_names)
hash_response[:get_domain_names_response][:return][:item] # => ["your.domain", "names.list"]
For more info see the Transip API docs. Be sure to rescue all the errors.. since it is hardcore error throwing.
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/transip.rb', line 82 def request(action, = nil) if .nil? @response = client.request(action) elsif .is_a?(Hash) @response = client.request(action) do soap.body = end else raise ArgumentError, "Expected options to be nil or a Hash!" end @response.to_hash end |