Permalink
Browse files

gslb feature, rebased with evans code

  • Loading branch information...
2 parents 8c5ef1f + 2f2e8e3 commit dffc0dfa7af9433cedf374de0f3cb37bfc6f6658 @ranjib ranjib committed Oct 21, 2013
Showing with 124 additions and 175 deletions.
  1. +4 −0 .travis.yml
  2. +1 −12 Gemfile
  3. +23 −25 Gemfile.lock
  4. +2 −21 Rakefile
  5. +13 −65 dynect_rest.gemspec
  6. +15 −6 lib/dynect_rest.rb
  7. +11 −0 lib/dynect_rest/exceptions.rb
  8. +21 −0 lib/dynect_rest/version.rb
  9. +34 −42 spec/dynect_rest_spec.rb
  10. +0 −4 spec/spec_helper.rb
View
4 .travis.yml
@@ -0,0 +1,4 @@
+rvm:
+ - 1.8.7
+ - 1.9.3
+ - 2.0.0
View
13 Gemfile
@@ -1,15 +1,4 @@
source 'http://rubygems.org'
-gem 'rest-client', :require=>"rest_client"
-gem 'json'
-
-
-group :development do
- gem 'rake'
- gem "rspec", "~> 2.0.0"
- gem "yard"
- gem 'jeweler'
-end
-
-
+gemspec
View
48 Gemfile.lock
@@ -1,36 +1,34 @@
+PATH
+ remote: .
+ specs:
+ dynect_rest (0.4.3)
+ json
+ rest-client
+
GEM
remote: http://rubygems.org/
specs:
- diff-lcs (1.1.2)
- git (1.2.5)
- jeweler (1.6.2)
- bundler (~> 1.0)
- git (>= 1.2.5)
- rake
- json (1.5.1)
- mime-types (1.16)
- rake (0.9.1)
- rest-client (1.6.3)
+ diff-lcs (1.2.4)
+ json (1.8.0)
+ mime-types (1.24)
+ rake (10.1.0)
+ rest-client (1.6.7)
mime-types (>= 1.16)
- rspec (2.0.1)
- rspec-core (~> 2.0.1)
- rspec-expectations (~> 2.0.1)
- rspec-mocks (~> 2.0.1)
- rspec-core (2.0.1)
- rspec-expectations (2.0.1)
- diff-lcs (>= 1.1.2)
- rspec-mocks (2.0.1)
- rspec-core (~> 2.0.1)
- rspec-expectations (~> 2.0.1)
- yard (0.7.1)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.2)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.3)
+ yard (0.8.7)
PLATFORMS
ruby
DEPENDENCIES
- jeweler
- json
+ dynect_rest!
rake
- rest-client
- rspec (~> 2.0.0)
+ rspec (>= 2.10.0)
yard
View
23 Rakefile
@@ -1,27 +1,8 @@
require 'rubygems'
require 'rake'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "dynect_rest"
- gem.summary = %Q{Dynect REST API library}
- gem.description = %Q{Use the Dynect services REST API}
- gem.email = "adam@opscode.com"
- gem.homepage = "http://github.com/adamhjk/dynect-rest"
- gem.authors = ["Adam Jacob"]
- gem.add_development_dependency "rspec", ">= 2.0"
- gem.add_development_dependency "yard", ">= 0"
- gem.add_dependency('json')
- gem.add_dependency('rest-client')
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
-
+require "bundler/gem_tasks"
require 'rspec/core/rake_task'
+
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
View
78 dynect_rest.gemspec
@@ -1,81 +1,29 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
-# -*- encoding: utf-8 -*-
+$:.unshift(File.dirname(__FILE__) + '/lib')
+require 'dynect_rest/version'
Gem::Specification.new do |s|
s.name = "dynect_rest"
- s.version = "0.4.3"
+ s.version = DynectRest::VERSION
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Adam Jacob"]
- s.date = "2012-04-11"
+ s.authors = ["Adam Jacob", "Ranjib Dey"]
+ s.date = "2013-08-23"
s.description = "Use the Dynect services REST API"
s.email = "adam@opscode.com"
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
- s.files = [
- ".document",
- ".rspec",
- "Gemfile",
- "Gemfile.lock",
- "LICENSE",
- "README.rdoc",
- "Rakefile",
- "VERSION",
- "dynect_rest.gemspec",
- "example.rb",
- "lib/dynect_rest.rb",
- "lib/dynect_rest/exceptions.rb",
- "lib/dynect_rest/gslb.rb",
- "lib/dynect_rest/resource.rb",
- "spec/dynect_rest_spec.rb",
- "spec/spec_helper.rb"
- ]
s.homepage = "http://github.com/adamhjk/dynect-rest"
+ s.files = %w(Rakefile LICENSE ) + Dir.glob("{lib,spec}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
+ s.homepage = "http://github.com/adamhjk/dynect_rest"
s.require_paths = ["lib"]
- s.rubygems_version = "1.8.10"
+ s.rubygems_version = "2.0.3"
s.summary = "Dynect REST API library"
-
- if s.respond_to? :specification_version then
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
- s.add_runtime_dependency(%q<json>, [">= 0"])
- s.add_development_dependency(%q<rake>, [">= 0"])
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
- s.add_development_dependency(%q<yard>, [">= 0"])
- s.add_development_dependency(%q<jeweler>, [">= 0"])
- s.add_development_dependency(%q<rspec>, [">= 2.0"])
- s.add_development_dependency(%q<yard>, [">= 0"])
- s.add_runtime_dependency(%q<json>, [">= 0"])
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
- else
- s.add_dependency(%q<rest-client>, [">= 0"])
- s.add_dependency(%q<json>, [">= 0"])
- s.add_dependency(%q<rake>, [">= 0"])
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
- s.add_dependency(%q<yard>, [">= 0"])
- s.add_dependency(%q<jeweler>, [">= 0"])
- s.add_dependency(%q<rspec>, [">= 2.0"])
- s.add_dependency(%q<yard>, [">= 0"])
- s.add_dependency(%q<json>, [">= 0"])
- s.add_dependency(%q<rest-client>, [">= 0"])
- end
- else
- s.add_dependency(%q<rest-client>, [">= 0"])
- s.add_dependency(%q<json>, [">= 0"])
- s.add_dependency(%q<rake>, [">= 0"])
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
- s.add_dependency(%q<yard>, [">= 0"])
- s.add_dependency(%q<jeweler>, [">= 0"])
- s.add_dependency(%q<rspec>, [">= 2.0"])
- s.add_dependency(%q<yard>, [">= 0"])
- s.add_dependency(%q<json>, [">= 0"])
- s.add_dependency(%q<rest-client>, [">= 0"])
- end
+ s.add_dependency "rest-client"
+ s.add_dependency "json"
+ s.add_development_dependency "rake"
+ s.add_development_dependency "rspec", ">= 2.10.0"
+ s.add_development_dependency "yard"
end
View
21 lib/dynect_rest.rb
@@ -34,11 +34,11 @@ class DynectRest
# @param [String] The zone you are going to be editing
# @param [Boolean] Whether to connect immediately or not - runs login for you
# @param [Boolean] Verbosity
- def initialize(customer_name, user_name, password, zone=nil, connect=true, verbose=false)
+ def initialize(customer_name, user_name, password, zone=nil, connect=true, verbose=false, max_redirects=10)
@customer_name = customer_name
@user_name = user_name
@password = password
- @rest = RestClient::Resource.new('https://api2.dynect.net/REST/', :headers => { :content_type => 'application/json' })
+ @rest = RestClient::Resource.new('https://api2.dynect.net/REST/', :headers => { :content_type => 'application/json' }, :max_redirects=>max_redirects)
@zone = zone
@verbose = verbose
login if connect
@@ -198,25 +198,34 @@ def api_request(&block)
puts "I have #{e.inspect} with #{e.http_code}"
end
if e.http_code == 307
+ e.response.sub!('/REST/','') if e.response =~ /^\/REST\//
get(e.response)
end
e.response
end
- parse_response(JSON.parse(response_body))
+
+ parse_response(JSON.parse(response_body || '{}'))
end
def parse_response(response)
case response["status"]
when "success"
response["data"]
- when "failure", "incomplete"
+ when "incomplete"
+ # we get 'incomplete' when the API is running slow and claims the session has a previous job running
+ # raise an error and return the job ID in case we want to ask the API what the job's status is
+ error_messages = []
+ error_messages.push( "This session may have a job _still_ running (slowly). Call /REST/Job/#{response["job_id"]} to get its status." )
+ response["msgs"].each do |error_message|
+ error_messages << "#{error_message["LVL"]} #{error_message["ERR_CD"]} #{error_message["SOURCE"]} - #{error_message["INFO"]}"
+ end
+ raise DynectRest::Exceptions::IncompleteRequest.new( "#{error_messages.join("\n")}", response["job_id"] )
+ when "failure"
error_messages = []
response["msgs"].each do |error_message|
error_messages << "#{error_message["LVL"]} #{error_message["ERR_CD"]} #{error_message["SOURCE"]} - #{error_message["INFO"]}"
end
raise DynectRest::Exceptions::RequestFailed, "Request failed: #{error_messages.join("\n")}"
end
end
-
-
end
View
11 lib/dynect_rest/exceptions.rb
@@ -19,5 +19,16 @@
class DynectRest
class Exceptions
class RequestFailed < RuntimeError; end
+ # we need to handle API calls that return a status of 'incomplete' and return the job_id
+ class IncompleteRequest < RuntimeError
+
+ attr_reader :job_id, :message
+
+ def initialize( message, job_id )
+ @message = message
+ @job_id = job_id
+ end
+
+ end
end
end
View
21 lib/dynect_rest/version.rb
@@ -0,0 +1,21 @@
+#
+# Author:: Ranjib Dey (dey.ranjib@gmail.com)
+# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class DynectRest
+ VERSION='0.4.3'
+end
View
76 spec/dynect_rest_spec.rb
@@ -1,82 +1,74 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe DynectRest do
- let(:d) do
+
+ let(:dynect) do
DynectRest.new("customer", "username", "password", "zone", false)
end
- describe "a" do
- subject { d.a }
- its(:resource_path) { should == 'ARecord/zone' }
+ it "A Record" do
+ expect(dynect.a.resource_path).to eq('ARecord/zone')
end
- describe "aaaa" do
- subject { d.aaaa }
- its(:resource_path) { should == 'AAAARecord/zone' }
+ it "AAAA Record" do
+ expect(dynect.aaaa.resource_path).to eq('AAAARecord/zone')
end
- describe "cname" do
- subject { d.cname }
- its(:resource_path) { should == 'CNAMERecord/zone' }
+ it "CNAME Record" do
+ expect(dynect.cname.resource_path).to eq('CNAMERecord/zone')
end
- describe "dnskey" do
- subject { d.dnskey }
- its(:resource_path) { should == 'DNSKEYRecord/zone' }
+ it "DNSKEY Record" do
+ expect(dynect.dnskey.resource_path).to eq('DNSKEYRecord/zone')
end
- describe "ds" do
- subject { d.ds }
- its(:resource_path) { should == 'DSRecord/zone' }
+ it "DS Record" do
+ expect(dynect.ds.resource_path).to eq('DSRecord/zone')
end
describe "gslb" do
- subject { d.gslb }
+ subject { dynect.gslb }
its(:resource_path) { should == 'GSLB/zone' }
end
describe "key" do
- subject { d.key }
+ subject { dynect.key }
its(:resource_path) { should == 'KEYRecord/zone' }
end
- describe "loc" do
- subject { d.loc }
- its(:resource_path) { should == 'LOCRecord/zone' }
+ it "KEY Record" do
+ expect(dynect.key.resource_path).to eq('KEYRecord/zone')
+ end
+
+ it "LOC Record" do
+ expect(dynect.loc.resource_path).to eq('LOCRecord/zone')
end
- describe "mx" do
- subject { d.mx }
- its(:resource_path) { should == 'MXRecord/zone' }
+ it "MX Record" do
+ expect(dynect.mx.resource_path).to eq('MXRecord/zone')
end
- describe "ns" do
- subject { d.ns }
- its(:resource_path) { should == 'NSRecord/zone' }
+ it "NS Record" do
+ expect(dynect.ns.resource_path).to eq('NSRecord/zone')
end
- describe "ptr" do
- subject { d.ptr }
- its(:resource_path) { should == 'PTRRecord/zone' }
+ it "PTR Record" do
+ expect(dynect.ptr.resource_path).to eq('PTRRecord/zone')
end
- describe "rp" do
- subject { d.rp }
- its(:resource_path) { should == 'RPRecord/zone' }
+ it "RPR Record" do
+ expect(dynect.rp.resource_path).to eq('RPRecord/zone')
end
- describe "soa" do
- subject { d.soa }
- its(:resource_path) { should == 'SOARecord/zone' }
+ it "SOA Record" do
+ expect(dynect.soa.resource_path).to eq('SOARecord/zone')
end
- describe "srv" do
- subject { d.srv }
- its(:resource_path) { should == 'SRVRecord/zone' }
+ it "SRV Record" do
+ expect(dynect.srv.resource_path).to eq('SRVRecord/zone')
end
- describe "txt" do
- subject { d.txt }
- its(:resource_path) { should == 'TXTRecord/zone' }
+ it "TXT Record" do
+ expect(dynect.txt.resource_path).to eq('TXTRecord/zone')
end
end
View
4 spec/spec_helper.rb
@@ -3,7 +3,3 @@
require 'dynect_rest'
require 'rspec'
require 'rspec/autorun'
-
-RSpec.configure do |config|
-
-end

0 comments on commit dffc0df

Please sign in to comment.