dynectastic 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,24 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+
23
+ ## Bundler
24
+ .bundle
@@ -0,0 +1,9 @@
1
+ = Changelog
2
+
3
+ == 0.2.0
4
+
5
+ * Added support for Jobs.
6
+
7
+ == 0.1.2
8
+
9
+ * Initial public release.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ gem "httparty", "~>0.6.1"
5
+ gem "json", "~>1.4.6"
@@ -0,0 +1,14 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ crack (0.1.8)
5
+ httparty (0.6.1)
6
+ crack (= 0.1.8)
7
+ json (1.4.6)
8
+
9
+ PLATFORMS
10
+ ruby
11
+
12
+ DEPENDENCIES
13
+ httparty (~> 0.6.1)
14
+ json (~> 1.4.6)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ilya Sabanin
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.
@@ -0,0 +1,120 @@
1
+ = dynectastic
2
+
3
+ Dynectastic is a nice wrapper for Dynect's REST API. Use it to manage Zones, Records and Nodes on your Dynect account.
4
+
5
+ == Installation
6
+
7
+ gem install dynectastic
8
+
9
+ == Requirements
10
+
11
+ HTTParty 0.6.1
12
+
13
+ == Usage
14
+
15
+ First you need to create new Dynect session:
16
+
17
+ dynect = Dynectastic.session("dynect_customer_name", "dynect_login", "dynect_password")
18
+
19
+ Make sure to create a separate login/password pair for your API client or it will interfere with your web interface browsing.
20
+
21
+ Now you can use this "dynect" object to call various API methods.
22
+
23
+ == Requests
24
+
25
+ You can always access most recent request of a resource by calling last_request on it:
26
+
27
+ zone.freeze
28
+ zone.last_request # => #<Dynectastic::Request:...>
29
+
30
+ Every request store it's response:
31
+
32
+ zone.last_request.response # => #<HTTParty::Response:...>
33
+
34
+ == Jobs
35
+
36
+ Every request to Dynect has a special Job assigned to it. You can access it like this:
37
+
38
+ zone.publish # => true
39
+ zone.last_request.job.id # => 343245
40
+ zone.last_request.job.complete? # => true
41
+
42
+ Sometimes a long running job can not be completed in time, so Dynectastic returns false as a result of your request:
43
+
44
+ zone.publish # => false
45
+ zone.last_request.job.id # => 342626
46
+ zone.last_request.job.complete? # => false
47
+
48
+ Since Dynect does not allow you to run several jobs simultaneously, sometimes your requests will return Dynectastic::SessionBusy exception.
49
+ Luckily there is a built-in retry cycle for such exceptions: Dynectastic will sleep for a few seconds and retry your request 5 more times.
50
+
51
+ == Zone examples
52
+
53
+ With Dynectastic you can find, create, freeze, unfreeze, publish and destroy zones:
54
+
55
+ dynect.zones.build(
56
+ :name => "newfancyzone.com",
57
+ :contact => "stalin@communismwilleventuallywin.com",
58
+ :ttl => 1800
59
+ ).save
60
+
61
+ dynect.zones.find_all
62
+
63
+ zone = dynect.zones.find_by_name("newfancyzone.com")
64
+
65
+ zone.freeze
66
+ zone.frozen?
67
+ zone.unfreeze
68
+
69
+ zone.publish
70
+ zone.published?
71
+
72
+ zone.destroy
73
+
74
+ Don't forget that you have to publish a zone every time you make any changes to it (for example when you add new record).
75
+
76
+ == Record examples
77
+
78
+ For now it's possible to find, create, update and delete records:
79
+
80
+ dynect.records.cname.build(
81
+ :zone => "newfancyzone.com",
82
+ :node => "new_node.newfancyzone.com", # will be created automatically
83
+ :ttl => 1800,
84
+ :rdata => {
85
+ :cname => "something.somewhere.com"
86
+ }
87
+ ).save
88
+
89
+ dynect.records.cname.find_all(:zone => "newfancyzone.com", :node => "new_node.newfancyzone.com")
90
+
91
+ record = dynect.records.cname.find_by_id(0, :zone => "newfancyzone.com", :node => "new_node.newfancyzone.com")
92
+
93
+ record.rdata['cname'] = "some_other_thing.somewhere.com"
94
+ record.save
95
+
96
+ record.destroy
97
+
98
+ Dynect will automatically create Node for your record if it's missing.
99
+
100
+ You can use all other record types instead of "cname" such as "txt" or "a" or anything else.
101
+
102
+ == Node examples
103
+
104
+ The API only allow us to delete nodes, nothing else:
105
+
106
+ dynect.nodes.destroy("newfancyzone.com", "new_node.newfancyzone.com")
107
+
108
+ == Note on Patches/Pull Requests
109
+
110
+ * Fork the project.
111
+ * Make your feature addition or bug fix.
112
+ * Add tests for it. This is important so I don't break it in a
113
+ future version unintentionally.
114
+ * Commit, do not mess with rakefile, version, or history.
115
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
116
+ * Send me a pull request. Bonus points for topic branches.
117
+
118
+ == Copyright
119
+
120
+ Copyright (c) 2010 Ilya Sabanin. See LICENSE for details.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "dynectastic"
8
+ gem.summary = "Neat wrapper for Dynect REST API."
9
+ gem.description = "More or less complete set of tools for managing your Dynect zones, records and nodes via REST API."
10
+ gem.email = "ilya.sabanin@gmail.com"
11
+ gem.homepage = "http://github.com/iSabanin/dynectastic"
12
+ gem.authors = ["Ilya Sabanin"]
13
+ gem.add_dependency "httparty", ">= 0.6.1"
14
+ gem.add_development_dependency "shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "dynectastic #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,85 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{dynectastic}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ilya Sabanin"]
12
+ s.date = %q{2010-11-01}
13
+ s.description = %q{More or less complete set of tools for managing your Dynect zones, records and nodes via REST API.}
14
+ s.email = %q{ilya.sabanin@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "CHANGES.rdoc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "dynectastic.gemspec",
30
+ "lib/dynectastic.rb",
31
+ "lib/dynectastic/error_translator.rb",
32
+ "lib/dynectastic/errors.rb",
33
+ "lib/dynectastic/factories/node_factory.rb",
34
+ "lib/dynectastic/factories/record_factory.rb",
35
+ "lib/dynectastic/factories/zone_factory.rb",
36
+ "lib/dynectastic/job.rb",
37
+ "lib/dynectastic/record.rb",
38
+ "lib/dynectastic/request.rb",
39
+ "lib/dynectastic/resource.rb",
40
+ "lib/dynectastic/session.rb",
41
+ "lib/dynectastic/zone.rb",
42
+ "test/helper.rb",
43
+ "test/test_node_factory.rb",
44
+ "test/test_record.rb",
45
+ "test/test_record_factory.rb",
46
+ "test/test_request.rb",
47
+ "test/test_resource.rb",
48
+ "test/test_session.rb",
49
+ "test/test_zone.rb",
50
+ "test/test_zone_factory.rb"
51
+ ]
52
+ s.homepage = %q{http://github.com/iSabanin/dynectastic}
53
+ s.rdoc_options = ["--charset=UTF-8"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = %q{1.3.7}
56
+ s.summary = %q{Neat wrapper for Dynect REST API.}
57
+ s.test_files = [
58
+ "test/helper.rb",
59
+ "test/test_node_factory.rb",
60
+ "test/test_record.rb",
61
+ "test/test_record_factory.rb",
62
+ "test/test_request.rb",
63
+ "test/test_resource.rb",
64
+ "test/test_session.rb",
65
+ "test/test_zone.rb",
66
+ "test/test_zone_factory.rb"
67
+ ]
68
+
69
+ if s.respond_to? :specification_version then
70
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
+ s.specification_version = 3
72
+
73
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
75
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
76
+ else
77
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
78
+ s.add_dependency(%q<shoulda>, [">= 0"])
79
+ end
80
+ else
81
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
82
+ s.add_dependency(%q<shoulda>, [">= 0"])
83
+ end
84
+ end
85
+
@@ -0,0 +1,26 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Dynectastic
5
+
6
+ VERSION = '0.2.0'
7
+ API_URL = 'https://api2.dynect.net'
8
+ RETRIES = 5
9
+
10
+ def self.session(customer_name, user_name, password)
11
+ Session.new(customer_name, user_name, password)
12
+ end
13
+
14
+ end
15
+
16
+ require "dynectastic/errors"
17
+ require "dynectastic/error_translator"
18
+ require "dynectastic/request"
19
+ require "dynectastic/resource"
20
+ require "dynectastic/session"
21
+ require "dynectastic/zone"
22
+ require "dynectastic/record"
23
+ require "dynectastic/job"
24
+ require "dynectastic/factories/zone_factory"
25
+ require "dynectastic/factories/node_factory"
26
+ require "dynectastic/factories/record_factory"
@@ -0,0 +1,22 @@
1
+ module Dynectastic
2
+
3
+ module ErrorTranslator
4
+
5
+ extend self
6
+
7
+ def translate_to_exception(dynect_msg)
8
+ info, source, code = dynect_msg['INFO'], dynect_msg['SOURCE'], dynect_msg['ERR_CD']
9
+
10
+ case info
11
+ when /Credentials you entered did not match those in our database/i
12
+ return AuthenticationError.new(info, source, code)
13
+ when /This session already has a job running/i
14
+ return SessionBusy.new(info, source, code)
15
+ end
16
+
17
+ DynectError.new(info, source, code)
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,33 @@
1
+ module Dynectastic
2
+
3
+ class DynectError < Exception
4
+
5
+ attr_reader :text, :source, :code
6
+
7
+ def initialize(text, source, code)
8
+ @text, @source, @code = text, source, code
9
+ end
10
+
11
+ def message
12
+ %Q[#{ text }. (SOURCE: #{ source}; CODE: #{ code })]
13
+ end
14
+
15
+ end
16
+
17
+ class AuthenticationError < DynectError
18
+
19
+ def message
20
+ "Credentials you entered did not match those in Dynect's database."
21
+ end
22
+
23
+ end
24
+
25
+ class SessionBusy < DynectError
26
+
27
+ def message
28
+ "This session already has a job running. Try again later."
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ module Dynectastic
2
+
3
+ class NodeFactory < Resource
4
+
5
+ def destroy(zone, name)
6
+ delete("#{ entity_base }/#{ zone }/#{ name }")
7
+ end
8
+
9
+ def entity_base
10
+ "/REST/Node"
11
+ end
12
+
13
+ end
14
+
15
+ end