Class: Alidns::Service
- Inherits:
-
Object
- Object
- Alidns::Service
- Defined in:
- lib/alidns/service.rb
Instance Method Summary collapse
- #describe_domains ⇒ Object
- #describe_doname_record(domainname) ⇒ Object
-
#initialize ⇒ Service
constructor
A new instance of Service.
- #params_to_str(params) ⇒ Object
- #public_params ⇒ Object
- #update_domain_record(record_id, rr, type, value, ttl = 600, priority = 1, line = "default") ⇒ Object
Constructor Details
#initialize ⇒ Service
Returns a new instance of Service.
10 11 12 13 14 15 16 17 |
# File 'lib/alidns/service.rb', line 10 def initialize $logger = Logging.logger['alidns'] $logger.level = Alidns.config.log_level $logger.add_appenders Logging.appenders.stdout, Logging.appenders.file(Alidns.config.log_file) @app_key = Alidns.config.app_key @app_secret = Alidns.config.app_secret @host = Alidns.config.host end |
Instance Method Details
#describe_domains ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/alidns/service.rb', line 19 def describe_domains begin retries ||= 0 params = public_params params["Action"] = "DescribeDomains" params = params_to_str(params) params = params + "&" + Alidns::Sign.sign("GET", @app_key, @app_secret, params) url = "#{Alidns.config.host}/?#{params}" response = RestClient.get(url) response.body rescue retry if (retries += 1) < 3 end end |
#describe_doname_record(domainname) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/alidns/service.rb', line 34 def describe_doname_record(domainname) begin retries ||= 0 params = public_params params["Action"] = "DescribeDomainRecords" params["DomainName"] = "#{domainname}" params = params_to_str(params) params = params + "&" + Alidns::Sign.sign("GET", @app_key, @app_secret, params) url = "#{Alidns.config.host}/?#{params}" response = RestClient.get(url) response.body rescue retry if (retries += 1) < 3 end end |
#params_to_str(params) ⇒ Object
85 86 87 |
# File 'lib/alidns/service.rb', line 85 def params_to_str(params) params = params.to_a.map{|k| "#{k.first}=#{k.last}"}.join('&') end |
#public_params ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/alidns/service.rb', line 72 def public_params params = {} params["Format"] = Alidns.config.response_format params["Version"] = "2015-01-09" params["SignatureMethod"] = "HMAC-SHA1" params["Timestamp"] = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ") params["SignatureVersion"] = "1.0" params["SignatureNonce"]= rand(10 ** 30).to_s.rjust(30,'0') params["AccessKeyId"] = Alidns.config.app_key params end |
#update_domain_record(record_id, rr, type, value, ttl = 600, priority = 1, line = "default") ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/alidns/service.rb', line 50 def update_domain_record(record_id, rr , type, value, ttl=600 , priority = 1, line="default") begin retries ||= 0 params = public_params params["Action"] = "UpdateDomainRecord" params["RecordId"] = record_id params["RR"] = rr params["Type"] = type params["Value"] = value params["TTL"] = ttl params["Priority"] = priority params["Line"] = line params = params_to_str(params) params = params + "&" + Alidns::Sign.sign("GET", @app_key, @app_secret, params) url = "#{Alidns.config.host}/?#{params}" response = RestClient.get(url) response.body rescue retry if (retries += 1) < 3 end end |