infoblox 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,13 @@
1
1
  module Infoblox
2
2
  class Connection
3
- attr_accessor :username, :password, :host, :connection, :logger, :ssl_opts
3
+ attr_accessor :adapter,
4
+ :adapter_block,
5
+ :connection,
6
+ :host,
7
+ :logger,
8
+ :password,
9
+ :ssl_opts,
10
+ :username
4
11
 
5
12
  def get(href, params={})
6
13
  wrap do
@@ -43,11 +50,25 @@ module Infoblox
43
50
  def connection
44
51
  @connection ||= Faraday.new(:url => self.host, :ssl => {:verify => false}) do |faraday|
45
52
  faraday.use Faraday::Response::Logger, logger if logger
46
-
47
53
  faraday.request :json
48
54
  faraday.basic_auth(self.username, self.password)
49
- faraday.adapter :net_http
55
+ faraday.adapter(self.adapter, &self.adapter_block)
56
+ end
57
+ end
58
+
59
+ ##
60
+ # The host variable is expected to be a protocol with a host name.
61
+ # If the host has no protocol, https:// is added before it.
62
+ #
63
+ def host=(new_host)
64
+ unless new_host =~ /^http(s)?:\/\//
65
+ new_host = "https://#{new_host}"
50
66
  end
67
+ @host = new_host
68
+ end
69
+
70
+ def adapter
71
+ @adapter ||= :net_http
51
72
  end
52
73
 
53
74
  private
@@ -1,3 +1,3 @@
1
1
  module Infoblox
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ describe Infoblox::Connection do
3
+
4
+ ["localhost", "127.0.0.1", "http://localhost:3000", "https://localhost", "http://localhost:3000/"].each do |host|
5
+ it "should build URL without failure" do
6
+ conn_params = {
7
+ username: "billy",
8
+ password: "boi",
9
+ host: host
10
+ }
11
+ uri = "/wapi/v1.0/record:host"
12
+
13
+ ic = Infoblox::Connection.new(conn_params)
14
+ ic.adapter = :test
15
+ ic.adapter_block = stub_get(uri)
16
+
17
+ # execute the request. There should be no "URI::BadURIError: both URI are relative" error
18
+ ic.get(uri)
19
+ end
20
+ end
21
+
22
+ def stub_get(uri)
23
+ Proc.new do |stub|
24
+ stub.get(uri) { [ 200, {}, 'Yay!'] }
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infoblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-10 00:00:00.000000000 Z
12
+ date: 2014-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -132,6 +132,7 @@ files:
132
132
  - lib/infoblox/resource/network_container.rb
133
133
  - lib/infoblox/resource/ptr.rb
134
134
  - lib/infoblox/version.rb
135
+ - spec/connection_spec.rb
135
136
  - spec/host_spec.rb
136
137
  - spec/resource_spec.rb
137
138
  - spec/spec_helper.rb
@@ -148,12 +149,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
149
  - - ! '>='
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 4416688330478250235
151
155
  required_rubygems_version: !ruby/object:Gem::Requirement
152
156
  none: false
153
157
  requirements:
154
158
  - - ! '>='
155
159
  - !ruby/object:Gem::Version
156
160
  version: '0'
161
+ segments:
162
+ - 0
163
+ hash: 4416688330478250235
157
164
  requirements: []
158
165
  rubyforge_project:
159
166
  rubygems_version: 1.8.25
@@ -162,7 +169,7 @@ specification_version: 3
162
169
  summary: This gem is a Ruby interface to the Infoblox WAPI. Resources supported for
163
170
  REST operations include CNAME, Host, HostIpv4addr, Ipv4addr, Network, and NewtorkContainer.
164
171
  test_files:
172
+ - spec/connection_spec.rb
165
173
  - spec/host_spec.rb
166
174
  - spec/resource_spec.rb
167
175
  - spec/spec_helper.rb
168
- has_rdoc: