value-domain-ddns 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: 4efeb73b63b1124f5425f79bde38f751d334aefe
4
+ data.tar.gz: 2f87111e32b4f5a9611d1dbd5af865dec9e80c7a
5
+ SHA512:
6
+ metadata.gz: 1886c08270895a5306d427ffdb5d2aad04b31ab659e82268fc87166daa6eb25309b6ef1b37c18bfc53844ee0b4dfcabe09fd5abd6af0c1903c19da2c3e511b80
7
+ data.tar.gz: 1b7ec8ab013a39bdd914523b4dee53da7446fc7fb979966d09f95e0789f2a1b0f418f39ceb8582fff5a28c081f05079dab9daeb874bf7b6f917338ba0b26194b
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in value-domain-ddns.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 daimatz
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,40 @@
1
+ # Value::Domain::Ddns
2
+
3
+ value-domain ddns script
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ gem install value-domain-ddns
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ write `config.json` to settings and put it into current directory.
14
+
15
+ ```json
16
+ {
17
+ "domain": "example.com",
18
+ "password": "example-password",
19
+ "hostname": "example"
20
+ }
21
+ ```
22
+
23
+ and then execute
24
+
25
+ ```sh
26
+ value-domain-ddns sync
27
+ ```
28
+
29
+ to execute syncing.
30
+
31
+ if `--config` option passed, read it.
32
+ `--domain`, `--password`, `--hostname`, `--ip` are also available.
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "value-domain-ddns"
6
+
7
+ require 'rubygems'
8
+ require 'thor'
9
+
10
+ class ValueDomainDdns::Cli < Thor
11
+ options :domain => :string, :password => :string,
12
+ :hostname => :string, :ip => :string
13
+ options :config => :string
14
+ desc "sync", "update and sync ddns record"
15
+ long_desc <<-EOD
16
+ Update and sync ddns record.
17
+ Default config file is `./config.json`.
18
+ If other fields are set, it overwrites config file's value.
19
+ EOD
20
+ def sync
21
+ config_file = options[:config] || "./config.json"
22
+ config = ValueDomainDdns::Config.load(config_file)
23
+ ddns = ValueDomainDdns::Core.new(config)
24
+ if !ddns.validate
25
+ STDERR.puts "domain, password, hostname are required."
26
+ exit
27
+ end
28
+ config[:ip] = ddns.get_ip if !config[:ip]
29
+ params = ddns.submit_params
30
+ params["p"] = '******'
31
+ puts "update to #{ValueDomainDdns::SUBMIT_BASE_URL} with params:"
32
+ p params
33
+ puts ddns.sync()
34
+ end
35
+ end
36
+
37
+ ValueDomainDdns::Cli.start(ARGV)
data/config.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "domain": "example.com",
3
+ "password": "example-password",
4
+ "hostname": "example"
5
+ }
@@ -0,0 +1,6 @@
1
+ module ValueDomainDdns
2
+ require "value-domain-ddns/version"
3
+ require "value-domain-ddns/constant"
4
+ require 'value-domain-ddns/core'
5
+ require 'value-domain-ddns/config'
6
+ end
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+
3
+ module ValueDomainDdns::Config
4
+ def self.keys
5
+ [:domain, :password, :hostname, :ip]
6
+ end
7
+ def self.load(filepath)
8
+ hash = {}
9
+ open(filepath) do |io|
10
+ JSON.load(io).each do |key, value|
11
+ hash[key.to_sym] = value
12
+ end
13
+ end
14
+ hash
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module ValueDomainDdns
2
+ GET_IP_URL = 'http://dyn.value-domain.com/cgi-bin/dyn.fcg?ip'
3
+ SUBMIT_BASE_URL = 'http://dyn.value-domain.com/cgi-bin/dyn.fcg'
4
+ end
@@ -0,0 +1,35 @@
1
+ require 'open-uri'
2
+ require 'uri'
3
+
4
+ require 'value-domain-ddns/constant'
5
+
6
+ class ValueDomainDdns::Core
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def validate
12
+ !!@config[:domain] && !!@config[:password] && !!@config[:hostname]
13
+ end
14
+
15
+ def get_ip()
16
+ open(ValueDomainDdns::GET_IP_URL).read
17
+ end
18
+
19
+ def submit_params
20
+ {
21
+ 'd' => @config[:domain],
22
+ 'p' => @config[:password],
23
+ 'h' => @config[:hostname],
24
+ 'i' => @config[:ip]
25
+ }
26
+ end
27
+
28
+ def sync()
29
+ query_string = submit_params.map { |k, v|
30
+ URI.encode(k.to_s) + '=' + URI.encode(v.to_s)
31
+ }.join('&')
32
+ submit_url = ValueDomainDdns::SUBMIT_BASE_URL + '?' + query_string
33
+ open(URI.parse(submit_url)).read
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module ValueDomainDdns
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+ require 'tempfile'
3
+
4
+ def make_json_file(hash)
5
+ file = Tempfile.new('json')
6
+ file.write(JSON.generate(hash))
7
+ file.close
8
+ file.path
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'value-domain-ddns/config'
2
+ require 'spec_helper'
3
+
4
+ describe ValueDomainDdns::Config do
5
+ describe '#load' do
6
+ it 'loads config file correctly' do
7
+ file = make_json_file(domain: 'example.com', password: 'hoge', dummy: 100)
8
+ config = ValueDomainDdns::Config.load(file)
9
+ expect(config[:domain]).to eq('example.com')
10
+ expect(config[:password]).to eq('hoge')
11
+ expect(config[:hostname]).to eq(nil)
12
+ expect(config[:ip]).to eq(nil)
13
+ expect(config[:dummy]).to eq(100)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'value-domain-ddns/core'
2
+
3
+ describe ValueDomainDdns::Core do
4
+ describe '#validate' do
5
+ it 'succeed when domain, password, hostname exist' do
6
+ config = {domain: 'example.com', password: 'pass', hostname: 'example'}
7
+ core = ValueDomainDdns::Core.new(config)
8
+ expect(core.validate).to eq(true)
9
+ end
10
+ context 'fails when required config lacks' do
11
+ it 'in domain' do
12
+ config = {password: 'pass', hostname: 'example'}
13
+ core = ValueDomainDdns::Core.new(config)
14
+ expect(core.validate).to eq(false)
15
+ end
16
+ it 'in password' do
17
+ config = {domain: 'example.com', hostname: 'example'}
18
+ core = ValueDomainDdns::Core.new(config)
19
+ expect(core.validate).to eq(false)
20
+ end
21
+ it 'in hostname' do
22
+ config = {domain: 'example.com', password: 'pass'}
23
+ core = ValueDomainDdns::Core.new(config)
24
+ expect(core.validate).to eq(false)
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '#get_ip' do
30
+ it 'succeed' do
31
+ regex = /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/
32
+ expect(ValueDomainDdns::Core.new({}).get_ip).to match(regex)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'value-domain-ddns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "value-domain-ddns"
8
+ spec.version = ValueDomainDdns::VERSION
9
+ spec.authors = ["daimatz"]
10
+ spec.email = ["dai@daimatz.net"]
11
+ spec.description = %q{value-domain ddns script}
12
+ spec.summary = %q{automatically updates value-domain ddns}
13
+ spec.homepage = "https://github.com/daimatz/value-domain-ddns"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "thor", ">= 0.17.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: value-domain-ddns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - daimatz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.17.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.17.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: value-domain ddns script
70
+ email:
71
+ - dai@daimatz.net
72
+ executables:
73
+ - value-domain-ddns
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/value-domain-ddns
84
+ - config.json
85
+ - lib/value-domain-ddns.rb
86
+ - lib/value-domain-ddns/config.rb
87
+ - lib/value-domain-ddns/constant.rb
88
+ - lib/value-domain-ddns/core.rb
89
+ - lib/value-domain-ddns/version.rb
90
+ - spec/spec_helper.rb
91
+ - spec/value-domain-ddns/config_spec.rb
92
+ - spec/value-domain-ddns/core_spec.rb
93
+ - value-domain-ddns.gemspec
94
+ homepage: https://github.com/daimatz/value-domain-ddns
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: automatically updates value-domain ddns
118
+ test_files:
119
+ - spec/spec_helper.rb
120
+ - spec/value-domain-ddns/config_spec.rb
121
+ - spec/value-domain-ddns/core_spec.rb