dynect_rest 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.3
data/dynect_rest.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{dynect_rest}
8
- s.version = "0.4.0"
7
+ s.name = "dynect_rest"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Adam Jacob}]
12
- s.date = %q{2011-06-08}
13
- s.description = %q{Use the Dynect services REST API}
14
- s.email = %q{adam@opscode.com}
11
+ s.authors = ["Adam Jacob"]
12
+ s.date = "2012-04-11"
13
+ s.description = "Use the Dynect services REST API"
14
+ s.email = "adam@opscode.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -33,10 +33,10 @@ Gem::Specification.new do |s|
33
33
  "spec/dynect_rest_spec.rb",
34
34
  "spec/spec_helper.rb"
35
35
  ]
36
- s.homepage = %q{http://github.com/adamhjk/dynect-rest}
37
- s.require_paths = [%q{lib}]
38
- s.rubygems_version = %q{1.8.5}
39
- s.summary = %q{Dynect REST API library}
36
+ s.homepage = "http://github.com/adamhjk/dynect-rest"
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.10"
39
+ s.summary = "Dynect REST API library"
40
40
 
41
41
  if s.respond_to? :specification_version then
42
42
  s.specification_version = 3
data/lib/dynect_rest.rb CHANGED
@@ -32,12 +32,14 @@ class DynectRest
32
32
  # @param [String] Your dynect password
33
33
  # @param [String] The zone you are going to be editing
34
34
  # @param [Boolean] Whether to connect immediately or not - runs login for you
35
- def initialize(customer_name, user_name, password, zone=nil, connect=true)
35
+ # @param [Boolean] Verbosity
36
+ def initialize(customer_name, user_name, password, zone=nil, connect=true, verbose=false)
36
37
  @customer_name = customer_name
37
38
  @user_name = user_name
38
39
  @password = password
39
40
  @rest = RestClient::Resource.new('https://api2.dynect.net/REST/', :headers => { :content_type => 'application/json' })
40
41
  @zone = zone
42
+ @verbose = verbose
41
43
  login if connect
42
44
  end
43
45
 
@@ -128,13 +130,7 @@ class DynectRest
128
130
  ##
129
131
  %w{AAAA A CNAME DNSKEY DS KEY LOC MX NS PTR RP SOA SRV TXT}.each do |record_type|
130
132
  define_method underscore(record_type) do
131
- DynectRest::Resource.new(self,"#{record_type}Record" , @zone)
132
- end
133
- end
134
-
135
- %w{Node NodeList}.each do |type|
136
- define_method underscore(type) do
137
- DynectRest::Resource.new(self,"#{type}" , @zone)
133
+ DynectRest::Resource.new(self,"#{record_type}" , @zone)
138
134
  end
139
135
  end
140
136
 
@@ -190,7 +186,9 @@ class DynectRest
190
186
  response = block.call
191
187
  response.body
192
188
  rescue RestClient::Exception => e
193
- puts "I have #{e.inspect} with #{e.http_code}"
189
+ if @verbose
190
+ puts "I have #{e.inspect} with #{e.http_code}"
191
+ end
194
192
  if e.http_code == 307
195
193
  get(e.response)
196
194
  end
@@ -6,9 +6,9 @@
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
8
8
  # You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing, software
13
13
  # distributed under the License is distributed on an "AS IS" BASIS,
14
14
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,13 +25,13 @@ class DynectRest
25
25
  @dynect = dynect
26
26
  @record_type = record_type
27
27
  @fqdn = fqdn
28
- @record_id = record_id
29
- @ttl = ttl
28
+ @record_id = record_id
29
+ @ttl = ttl
30
30
  @zone = zone
31
- @rdata = rdata
31
+ @rdata = rdata
32
32
  end
33
33
 
34
- def [](rdata_key)
34
+ def [](rdata_key)
35
35
  @rdata[rdata_key]
36
36
  end
37
37
 
@@ -42,7 +42,7 @@ class DynectRest
42
42
  def fqdn(value=nil)
43
43
  value ? (@fqdn = value; self) : @fqdn
44
44
  end
45
-
45
+
46
46
  def record_id(value=nil)
47
47
  value ? (@record_id = value; self) : @record_id
48
48
  end
@@ -52,10 +52,11 @@ class DynectRest
52
52
  end
53
53
 
54
54
  def resource_path(full=false)
55
- if (full == true || full == :full)
56
- "/REST/#{@record_type}Record/#{@zone}"
55
+ @record_type << "Record" unless @record_type[-6,6] == "Record"
56
+ if (full == true || full == :full)
57
+ "/REST/#{@record_type}/#{@zone}"
57
58
  else
58
- "#{@record_type}Record/#{@zone}"
59
+ "#{@record_type}/#{@zone}"
59
60
  end
60
61
  end
61
62
 
@@ -63,7 +64,7 @@ class DynectRest
63
64
  if record_id && fqdn
64
65
  raw_rr = @dynect.get("#{resource_path}/#{fqdn}/#{record_id}")
65
66
  DynectRest::Resource.new(dynect,
66
- raw_rr["record_type"] + 'Record',
67
+ raw_rr["record_type"],
67
68
  raw_rr["zone"],
68
69
  raw_rr["fqdn"],
69
70
  raw_rr["record_id"],
@@ -79,10 +80,10 @@ class DynectRest
79
80
  end
80
81
  end
81
82
  case raw_rr_list.length
82
- when 0
83
- raise DynectRest::Exceptions::RequestFailed, "Cannot find #{record_type} record for #{fqdn}"
84
- when 1
85
- raw_rr_list[0]
83
+ when 0
84
+ raise DynectRest::Exceptions::RequestFailed, "Cannot find #{record_type} record for #{fqdn}"
85
+ when 1
86
+ raw_rr_list[0]
86
87
  else
87
88
  raw_rr_list
88
89
  end
@@ -107,7 +108,7 @@ class DynectRest
107
108
  else
108
109
  if replace == true || replace == :replace
109
110
  @dynect.put("#{resource_path}/#{@fqdn}", self)
110
- else
111
+ else
111
112
  @dynect.post("#{resource_path}/#{@fqdn}", self)
112
113
  end
113
114
  end
@@ -145,4 +146,3 @@ class DynectRest
145
146
  end
146
147
 
147
148
  end
148
-
@@ -74,14 +74,4 @@ describe DynectRest do
74
74
  subject { d.txt }
75
75
  its(:resource_path) { should == 'TXTRecord/zone' }
76
76
  end
77
-
78
- describe "node_list" do
79
- subject { d.node_list }
80
- its(:resource_path) { should == 'NodeList/zone' }
81
- end
82
-
83
- describe "node" do
84
- subject { d.node }
85
- its(:resource_path) { should == 'Node/zone' }
86
- end
87
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynect_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &21760740 !ruby/object:Gem::Requirement
16
+ requirement: &17352460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21760740
24
+ version_requirements: *17352460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &21759880 !ruby/object:Gem::Requirement
27
+ requirement: &17351940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *21759880
35
+ version_requirements: *17351940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &21758720 !ruby/object:Gem::Requirement
38
+ requirement: &17369800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *21758720
46
+ version_requirements: *17369800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &21799120 !ruby/object:Gem::Requirement
49
+ requirement: &17368800 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *21799120
57
+ version_requirements: *17368800
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &21798260 !ruby/object:Gem::Requirement
60
+ requirement: &17368240 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *21798260
68
+ version_requirements: *17368240
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &21797320 !ruby/object:Gem::Requirement
71
+ requirement: &17367600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *21797320
79
+ version_requirements: *17367600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &21796000 !ruby/object:Gem::Requirement
82
+ requirement: &17366920 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '2.0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *21796000
90
+ version_requirements: *17366920
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: yard
93
- requirement: &21795520 !ruby/object:Gem::Requirement
93
+ requirement: &17366360 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *21795520
101
+ version_requirements: *17366360
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: json
104
- requirement: &21794980 !ruby/object:Gem::Requirement
104
+ requirement: &17365740 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *21794980
112
+ version_requirements: *17365740
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rest-client
115
- requirement: &21794440 !ruby/object:Gem::Requirement
115
+ requirement: &17364880 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *21794440
123
+ version_requirements: *17364880
124
124
  description: Use the Dynect services REST API
125
125
  email: adam@opscode.com
126
126
  executables: []