dozens_jp_cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1706ff1a218d2ef56b41174d5899823376b04ea4
4
+ data.tar.gz: 0458587b0c3ebd027ba54cae004474d8bdb7b4e8
5
+ SHA512:
6
+ metadata.gz: 6d1c4cee3e11362c7e083ce49f941ac531881ef2463590732bf99ca84f3de2a8fe3cf679fc1a466e0b7daf69ec9bb0bb91c9b5d2b2c2b7d75fcb5f3a5db11d99
7
+ data.tar.gz: ab2c68e244d6984f0fdf2e93016508ce66e38ea9dd503e508fdff8791675e5e8574e854581fb2ea86325d7fd583470447cba1a6765b047a63f9be8dbda7a5cbb
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dozens_jp_cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 takuya
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # dozens_jp_cli
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dozens_jp_cli'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dozens_jp_cli
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/dozens_jp_cli/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
32
+
33
+
34
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dozens_jp_cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dozens_jp_cli"
8
+ spec.version = DozensJpCli::VERSION
9
+ spec.authors = ["takuya"]
10
+ spec.email = ["takuya.1st+nospam@gmail.com"]
11
+ spec.summary = %q{dozens.jp client. }
12
+ spec.description = %q{dozens.jp client. for update A recored }
13
+ spec.homepage = ""
14
+ spec.license = "GNUv3"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "mechanize"
24
+ end
@@ -0,0 +1,3 @@
1
+ module DozensJpCli
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,80 @@
1
+ require "dozens_jp_cli/version"
2
+
3
+
4
+ class Dozens
5
+ attr_accessor :ua
6
+
7
+ def initialize(user,auth_key)
8
+ @user = user
9
+ @auth_key = auth_key
10
+ @ua = Mechanize.new
11
+ end
12
+ def get(uri,header=nil,params=[])
13
+ self.request(:get,uri,header,params)
14
+ end
15
+ def post(uri,header=nil,params=[])
16
+ self.request(:post,uri,header,params)
17
+ end
18
+ def request(method,uri,header=nil,params=[])
19
+ header = {"X-Auth-Token"=> @auth_token } unless header
20
+ begin
21
+ ua.get(uri, params,nil,header) if method == :get
22
+ ua.post(uri,params,header) if method == :post
23
+ rescue =>e
24
+ raise e
25
+ end
26
+ ua.page.body
27
+ end
28
+ def auth_token
29
+ if @auth_token && @expires && @expires > Time.now then
30
+ return @auth_token
31
+ end
32
+ begin
33
+ self.get("http://dozens.jp/api/authorize.json",{"X-Auth-User"=>@user,"X-Auth-Key"=>@auth_key})
34
+ rescue =>e
35
+ raise e
36
+ end
37
+ @auth_token = JSON.parse(ua.page.body)["auth_token"]
38
+ @expires = Time.now+60*60*24
39
+ @auth_token
40
+ end
41
+
42
+ def zone_list
43
+ uri = "http://dozens.jp/api/zone.json"
44
+ ret = self.get(uri)
45
+ @domains = JSON.parse(ret)["domain"]
46
+ end
47
+ def record_list(zone_name)
48
+ uri = "http://dozens.jp/api/record/#{zone_name}.json"
49
+ ret = self.get(uri)
50
+ @records = JSON.parse(ret)["record"]
51
+ end
52
+ def find_record_id(name)
53
+ zone = self.zone_list.find{|e|
54
+ name =~/#{e["name"]}/
55
+ }
56
+ return nil unless zone
57
+ record = self.record_list(zone["name"]).find{|e|
58
+ name =~/#{e["name"]}/
59
+ }
60
+ return nil unless record
61
+ record["id"]
62
+ end
63
+ def record_update(record_id,prio=10,content=nil,ttl=7200)
64
+ content = self.current_global_ip unless content
65
+ params = {"prio"=>prio,"content"=>content,"ttl"=>ttl}.to_json
66
+ url = "http://dozens.jp/api/record/update/#{record_id}.json"
67
+ ret = self.post(url,nil,params)
68
+ @records = JSON.parse(ret)["record"]
69
+ end
70
+
71
+ def current_global_ip
72
+ url = "http://myexternalip.com/json"
73
+ ret = self.get(url)
74
+ ret = JSON.parse(ret)["ip"]
75
+ end
76
+
77
+
78
+
79
+
80
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dozens_jp_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - takuya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mechanize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'dozens.jp client. for update A recored '
56
+ email:
57
+ - takuya.1st+nospam@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - dozens_jp_cli.gemspec
68
+ - lib/dozens_jp_cli.rb
69
+ - lib/dozens_jp_cli/version.rb
70
+ homepage: ''
71
+ licenses:
72
+ - GNUv3
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.14
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: dozens.jp client.
94
+ test_files: []