dozens_jp_cli 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -2
- data/lib/dozens_jp_cli.rb +26 -3
- data/lib/dozens_jp_cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99f0c0c5aad12ccd35fdff8e9bfecea720b5b594
|
4
|
+
data.tar.gz: 145014e8730f80fb9842eda68de513b155942848
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e4910bd1604daa766f1c32ba74e95e26a36ee723c0df8f15737ba1940d107ba30533646ef4ef36bcbd1bae37112d92ccc540ee309940ebaebb268bdf2ffa4e
|
7
|
+
data.tar.gz: c870ed56cd71122836143f36e5b3cc2596ef11891ea2da350a40186e9fb217fd5ac531d3931751d724e68b6e39891c6a1cb8d5d80557bf8185fad02f87a0fd28
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ gem 'dozens_jp_cli'
|
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
15
|
-
$ bundle
|
15
|
+
$ bundle install
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
@@ -20,7 +20,30 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'dozens_jp_cli'
|
26
|
+
|
27
|
+
|
28
|
+
dozens_user_id = "youname"
|
29
|
+
dozens_user_token = "xxxxxxxxxxxxxxxxxx"
|
30
|
+
|
31
|
+
d = Dozens.new(dozens_user_id,dozens_user_token)
|
32
|
+
|
33
|
+
## create new zone
|
34
|
+
ret = d.zone_create_new("dns.example.com", "webmaster@dns.example.com")
|
35
|
+
## delete a zone
|
36
|
+
ret = d.zone_delete("dns.example.com")
|
37
|
+
## add a record into zone
|
38
|
+
ret = d.record_create("www.dns.example.com","dns.example.com")
|
39
|
+
## or
|
40
|
+
ret = d.record_create("www","dns.example.com")
|
41
|
+
## delete a record
|
42
|
+
ret = d.record_delete("www.dns.example.com")
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
|
24
47
|
|
25
48
|
## Contributing
|
26
49
|
|
data/lib/dozens_jp_cli.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'mechanize'
|
2
|
+
require 'resolv'
|
2
3
|
|
3
4
|
require "dozens_jp_cli/version"
|
4
5
|
|
5
|
-
|
6
|
+
## TODO: DozensJP DNS round robin is supported, but this script dose not support dns round robin
|
6
7
|
class Dozens
|
7
8
|
attr_accessor :ua
|
8
9
|
API_BASE_URI = "http://dozens.jp/api"
|
@@ -85,8 +86,18 @@ class Dozens
|
|
85
86
|
def zone_exists?(name)
|
86
87
|
self.find_zone_id(name)!=nil
|
87
88
|
end
|
89
|
+
def record_name(id)
|
90
|
+
## TODO dns round robin
|
91
|
+
zone = self.zone_list.each{|zone|
|
92
|
+
record = self.record_list(zone["name"]).each{|record|
|
93
|
+
return record["name"] if record['id'] == id
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return nil
|
97
|
+
end
|
88
98
|
|
89
99
|
def find_record_id(name)
|
100
|
+
## TODO dns round robin
|
90
101
|
zone = self.zone_list.find{|e|
|
91
102
|
name =~/#{e["name"]}/
|
92
103
|
}
|
@@ -127,14 +138,26 @@ class Dozens
|
|
127
138
|
|
128
139
|
|
129
140
|
end
|
130
|
-
def record_update(
|
141
|
+
def record_update(record_id_or_name,prio=10,content=nil,ttl=7200,force=false)
|
142
|
+
## TODO dns round robin
|
143
|
+
record_id = ( record_id_or_name =~ /\d+/ ) ? record_id_or_name : self.find_record_id(record_id_or_name)
|
131
144
|
content = self.current_global_ip unless content
|
132
145
|
params = {"prio"=>prio,"content"=>content,"ttl"=>ttl}.to_json
|
133
146
|
url = API_BASE_URI+"/record/update/#{record_id}.json"
|
134
147
|
ret = self.post(url,nil,params)
|
135
148
|
JSON.parse(ret)["record"]
|
136
149
|
end
|
137
|
-
|
150
|
+
def address_is_changed?(record_id_or_name,content=nil)
|
151
|
+
## TODO dns round robin
|
152
|
+
record_name = ( record_id_or_name =~ /\d+/ ) ? self.record_name(record_id_or_name): record_id_or_name
|
153
|
+
current_dns_result = Resolv.getaddresses(record_name)
|
154
|
+
if current_dns_result
|
155
|
+
current_dns_result = current_dns_result.first
|
156
|
+
end
|
157
|
+
replace_content = (content) ? content : self.current_global_ip
|
158
|
+
return current_dns_result != replace_content
|
159
|
+
end
|
160
|
+
alias :address_is_changed :address_is_changed?
|
138
161
|
def current_global_ip
|
139
162
|
url = "http://myexternalip.com/json"
|
140
163
|
ret = self.get(url,{},[])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dozens_jp_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takuya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|