dme-api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "rest-client", ">= 1.6"
5
+ gem "json", ">= 1.4"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.1"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ json (1.4.6)
10
+ mime-types (1.16)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rest-client (1.6.1)
14
+ mime-types (>= 1.16)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.0.0)
21
+ jeweler (~> 1.5.1)
22
+ json (>= 1.4)
23
+ rcov
24
+ rest-client (>= 1.6)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Evidon, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = dme-api
2
+
3
+ A simple wrapper around the DNS Made Easy REST API
4
+
5
+ == Contributing to dme-api
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Evidon, Inc. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "dme-api"
16
+ gem.homepage = "http://github.com/chetan/dme-api"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Simple wrapper around the DNS Made Easy REST API}
19
+ gem.description = %Q{Simple wrapper around the DNS Made Easy REST API}
20
+ gem.email = "chetan@"
21
+ gem.authors = ["Chetan Sarva"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "dme-api #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/dme-api.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dme-api}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Chetan Sarva}]
12
+ s.date = %q{2011-06-17}
13
+ s.description = %q{Simple wrapper around the DNS Made Easy REST API}
14
+ s.email = %q{chetan@}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "dme-api.gemspec",
27
+ "lib/dme-api.rb",
28
+ "test/helper.rb",
29
+ "test/test_dme-api.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/chetan/dme-api}
32
+ s.licenses = [%q{MIT}]
33
+ s.require_paths = [%q{lib}]
34
+ s.rubygems_version = %q{1.8.5}
35
+ s.summary = %q{Simple wrapper around the DNS Made Easy REST API}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_dme-api.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<rest-client>, [">= 1.6"])
46
+ s.add_runtime_dependency(%q<json>, [">= 1.4"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<rest-client>, [">= 1.6"])
52
+ s.add_dependency(%q<json>, [">= 1.4"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rest-client>, [">= 1.6"])
59
+ s.add_dependency(%q<json>, [">= 1.4"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
data/lib/dme-api.rb ADDED
@@ -0,0 +1,61 @@
1
+
2
+ require 'json'
3
+ require 'open-uri'
4
+ require 'openssl'
5
+ require 'optparse'
6
+ require 'rest_client'
7
+ require 'socket'
8
+ require 'time'
9
+
10
+ class DME
11
+
12
+ def initialize(api_key, secret_key, domain)
13
+
14
+ @@dme_rest_url = "http://api.dnsmadeeasy.com/V1.2/domains/"
15
+
16
+ @api_key = api_key
17
+ @secret_key = secret_key
18
+ @domain = domain
19
+ end
20
+
21
+ def get(name)
22
+ response = RestClient.get(get_url(), get_headers())
23
+
24
+ # find the record we want
25
+ JSON.parse(response.to_str).select { |x| x["name"] == name }.first
26
+ end
27
+
28
+ def create(record)
29
+ response = RestClient.post get_url(),
30
+ record.to_json,
31
+ get_headers(:"content-type" => :json)
32
+ JSON.parse(response)
33
+ end
34
+
35
+ def delete(id)
36
+ response = RestClient.delete get_url(id), get_headers()
37
+ end
38
+
39
+
40
+ private
41
+
42
+ def get_url(id = nil)
43
+ u = @@dme_rest_url + @domain + "/records"
44
+ if not id.nil? then
45
+ u += "/#{id}"
46
+ end
47
+ return u
48
+ end
49
+
50
+ def get_headers(additional_headers = {})
51
+ t = Time.now.httpdate
52
+ hmac = OpenSSL::HMAC.hexdigest('sha1', @secret_key, t)
53
+ {
54
+ :"x-dnsme-apiKey" => @api_key,
55
+ :"x-dnsme-hmac" => hmac,
56
+ :"x-dnsme-requestDate" => t,
57
+ :accept =>:json
58
+ }.merge(additional_headers)
59
+ end
60
+
61
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'dme-api'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ class TestDmeApi < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @api = ""
7
+ @secret = ""
8
+ @domain = ""
9
+ end
10
+
11
+ def test_requires
12
+ require 'dme-api'
13
+ end
14
+
15
+ def test_new
16
+ DME.new(@api, @secret, @domain)
17
+ end
18
+
19
+ def test_get
20
+ dme = DME.new(@api, @secret, @domain)
21
+ r = dme.get("www")
22
+ assert r
23
+ assert r.kind_of? Hash
24
+ assert r["name"] == "www"
25
+ assert r["type"] == "CNAME"
26
+ assert r.keys.include? "ttl"
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dme-api
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Chetan Sarva
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-17 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :runtime
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 1
30
+ - 6
31
+ version: "1.6"
32
+ prerelease: false
33
+ name: rest-client
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 7
43
+ segments:
44
+ - 1
45
+ - 4
46
+ version: "1.4"
47
+ prerelease: false
48
+ name: json
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 23
58
+ segments:
59
+ - 1
60
+ - 0
61
+ - 0
62
+ version: 1.0.0
63
+ prerelease: false
64
+ name: bundler
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ type: :development
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 1
74
+ segments:
75
+ - 1
76
+ - 5
77
+ - 1
78
+ version: 1.5.1
79
+ prerelease: false
80
+ name: jeweler
81
+ version_requirements: *id004
82
+ - !ruby/object:Gem::Dependency
83
+ type: :development
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ prerelease: false
94
+ name: rcov
95
+ version_requirements: *id005
96
+ description: Simple wrapper around the DNS Made Easy REST API
97
+ email: chetan@
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ files:
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - dme-api.gemspec
113
+ - lib/dme-api.rb
114
+ - test/helper.rb
115
+ - test/test_dme-api.rb
116
+ homepage: http://github.com/chetan/dme-api
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 3
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ requirements: []
143
+
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.5
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Simple wrapper around the DNS Made Easy REST API
149
+ test_files:
150
+ - test/helper.rb
151
+ - test/test_dme-api.rb