domainshare 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1e0b76f27282acdaf9af3b0af603cd48fac9e23
4
+ data.tar.gz: 5dffdedc88f2f0a7a7b62c72380803ff90db4e85
5
+ SHA512:
6
+ metadata.gz: 854cc9f0156d792c615279abf24431b905fae2e123590320d8accf7764b9398b2f0289c6d531265bd68006b037d17d6f26da6ab18b79abbf16c15e3a2294a47c
7
+ data.tar.gz: b45a7831d038bb2589d6194b925ae3c87e77b21280c00dc4f1922613d1fa9e8530029fff9a65d9606618b29ae0944be2b9d65ee4ba2ad1dcaf4d068f32ccc769
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in domainshare.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Domainshare
2
+
3
+ Gem for .tk DomainShare API. Basically the (pretty messy) domainshare lib code.
4
+ Help me refactoring if you like ;-)
5
+
6
+ You can find the original code at http://www.nic.tk/en/domainsharelibs.html
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'domainshare'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install domainshare
21
+
22
+ ## Usage
23
+
24
+ Test connection
25
+
26
+ ```
27
+ conn = DSCLIENT::API.new(username, password)
28
+ puts conn.ping()
29
+ ```
30
+
31
+ Register a domain:
32
+
33
+ ```
34
+ puts conn.register({"domainname" => "sld",
35
+ "enduseremail" => "user-email@example.com",
36
+ "nameserver" => ["ns1.example.com", "ns2.example.com"] })
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/disclaimer.txt ADDED
@@ -0,0 +1,26 @@
1
+ ******************************************
2
+
3
+ DISCLAIMER
4
+
5
+ ******************************************
6
+
7
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
8
+ HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
9
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
10
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
11
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
13
+ THE COPYRIGHT OWNER OR CONTRIBUTORS BE
14
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
17
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR
21
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24
+ OF SUCH DAMAGE.
25
+
26
+ (C) 2010 Dot TK Limited
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'domainshare/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "domainshare"
8
+ spec.version = Domainshare::VERSION
9
+ spec.authors = ["Phillipp Röll"]
10
+ spec.email = ["phillipp.roell@trafficplex.de"]
11
+ spec.description = %q{.tk Domainshare API as rubygem}
12
+ spec.summary = %q{.tk Domainshare API as rubygem}
13
+ spec.homepage = "https://github.com/phillipp/domainshare"
14
+ spec.license = ""
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'rexml/document'
4
+ require "domainshare/version"
5
+ require "domainshare/apifunc"
6
+ require "domainshare/client"
7
+
8
+ module Domainshare
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,41 @@
1
+ module Domainshare
2
+ class APIFUNC
3
+ def initialize( name , args = [], opt_args = [])
4
+ @name = name
5
+ @args = args
6
+ @opt_args = opt_args
7
+ end
8
+
9
+ def args
10
+ @args
11
+ end
12
+
13
+ def opt_args
14
+ @opt_args
15
+ end
16
+
17
+ def has_arg(value)
18
+ @args.include(value)
19
+ end
20
+
21
+ def encode_kvpair(req, k, vs)
22
+ Array(vs).map {|v| "#{URI::encode(k.to_s)}=#{URI::encode(v.to_s)}" }
23
+ end
24
+
25
+ def set_form_data(req, params, sep = '&')
26
+ req.body = params.map {|k, v| encode_kvpair(req, k, v) }.flatten.join(sep)
27
+ req.content_type = 'application/x-www-form-urlencoded'
28
+ end
29
+
30
+ def call( params = {}, type = "xml" )
31
+ http = Net::HTTP.new("api.domainshare.tk", 443)
32
+ http.use_ssl = true
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
34
+
35
+ req = Net::HTTP::Post.new("/" + @name + "." + type)
36
+ set_form_data( req, params, ';')
37
+ resp = http.start {|http| http.request(req) }
38
+ resp.body
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,106 @@
1
+ module Domainshare
2
+ class Client
3
+ @@WARN = false
4
+ def initialize(email, password)
5
+ if (email.empty? or password.empty?) and @@WARN
6
+ puts "Either email or password is empty. Most of the functions will not work, unless those are added to each funtion calls"
7
+ end
8
+ @email = email
9
+ @password = password
10
+ @function_list = { "ping" => {},
11
+ "availability_check" => {:args => ["email", "password", "domainname"] },
12
+ "register" => {:args => ["email", "password", "domainname", "enduseremail"], :opt_args => [ "monthsofregistration", "nameserver", "forwardurl" ] },
13
+ "renew" => { :args => ["email", "password", "domainname"], :opt_args => ["monthsofregistration"] },
14
+ "host_registration" => { :args => ["email", "password", "hostname", "ipaddress"] },
15
+ "host_removal" => { :args => ["email", "password", "hostname"] },
16
+ "host_list" => { :args => ["email", "password", "domainname"] },
17
+ "modify" => { :args => ["email", "password", "domainname"], :opt_args => ["nameserver", "forwardurl"] },
18
+ "resend_email" => { :args => ["email", "password", "domainname"], :opt_args => ["enduseremail"] },
19
+ "domain_deactivate" => { :args => ["email", "password", "domainname", "reason"] },
20
+ "domain_reactivate" => { :args => ["email", "password", "domainname"] },
21
+ "update_parking" => { :args => ["email", "password", "domainname"], :opt_args => ["category", "keyword"]} }
22
+ # Extend function_list to add new API functions.
23
+ # :args -> Mandatory arguments,
24
+ # :opt_args -> Optional arguments.
25
+
26
+ init_functions()
27
+ end
28
+
29
+ def init_functions
30
+ @functions = {}
31
+ @function_list.each do |name, value|
32
+ @functions[name] = APIFUNC.new( name, args = value[:args] ? value[:args] : {}, opt_args = value[:opt_args] ? value[:opt_args] : {} )
33
+ end
34
+ end
35
+
36
+ def list_functions(detail = true)
37
+ # Lists all the supported functions along with mandatory and optional
38
+ # arguments, where relevant.
39
+ i=0
40
+ puts "Available API functions are"
41
+ @functions.each do |key, value|
42
+ i += 1
43
+ print i, ". ",key, "\n"
44
+ print "\tArguments:- ", value.args, "\n" if not value.args.empty?
45
+ print "\tOptional Arguments:- ", value.opt_args, "\n" if not value.opt_args.empty? and detail
46
+ puts
47
+ end
48
+ end
49
+
50
+ def call_function(name, type, params = {})
51
+ # Searches in function lists for function 'name' and calls the
52
+ # API function with params.
53
+
54
+ params = {} if not params.is_a? Hash
55
+ params["email"] = @email if not params.has_key?("email")
56
+ params["password"] = @password if not params.has_key?("password")
57
+
58
+ return error_msg(type, ["Function not defined ", name] ) if not @functions.has_key?(name)
59
+
60
+ function = @functions[name]
61
+
62
+ function.args.each do |value|
63
+ if not params.has_key?(value)
64
+ return error_msg(type, [value, " not defined in input; Mandatory parameters are ", function.args.join(",")] )
65
+ end
66
+ end
67
+ function.call(params, type=type)
68
+ end
69
+
70
+ def error_msg(type, str)
71
+ # Generates and returns the client side error messages in
72
+ # user-specified format
73
+ if type == 'json'
74
+ return '{"status":"NOT OK","reason":"'.concat(str.join()).concat('"}')
75
+ else
76
+ xml = <<EOS
77
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
78
+ <dottk>
79
+ <status>NOT OK</status>
80
+ <reason></reason>
81
+ </dottk>
82
+ EOS
83
+ doc = REXML::Document.new xml
84
+ doc.elements["dottk"].elements["reason"].text = str.join()
85
+ return doc.to_s
86
+ end
87
+ end
88
+
89
+ def method_missing(*arg)
90
+ # Parses the API function calls (ping, ping_xml, ping_json etc.)
91
+ # into name and type (ping, xml), and calls call_function.
92
+
93
+ name = arg[0].id2name
94
+ type = "xml"
95
+
96
+ if name =~ /_xml$/
97
+ name.slice!(/\_xml$/)
98
+ elsif name =~ /_json$/
99
+ name.slice!(/_json$/)
100
+ type = "json"
101
+ end
102
+ call_function(name, type, *arg[1,arg.size])
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ module Domainshare
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domainshare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Phillipp Röll
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-10 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: .tk Domainshare API as rubygem
42
+ email:
43
+ - phillipp.roell@trafficplex.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - README.md
51
+ - Rakefile
52
+ - disclaimer.txt
53
+ - domainshare.gemspec
54
+ - lib/domainshare.rb
55
+ - lib/domainshare/apifunc.rb
56
+ - lib/domainshare/client.rb
57
+ - lib/domainshare/version.rb
58
+ homepage: https://github.com/phillipp/domainshare
59
+ licenses:
60
+ - ''
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.1.10
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: .tk Domainshare API as rubygem
82
+ test_files: []