netvisor 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/lib/netvisor.rb +20 -3
- data/lib/netvisor/configuration.rb +3 -2
- data/lib/netvisor/element_base.rb +1 -1
- data/lib/netvisor/request.rb +3 -2
- data/lib/netvisor/version.rb +1 -1
- data/netvisor.gemspec +1 -0
- data/spec/netvisor/element_base_spec.rb +28 -0
- metadata +19 -3
data/CHANGELOG.md
CHANGED
data/lib/netvisor.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
require 'logging'
|
1
2
|
require "netvisor/version"
|
2
3
|
require "netvisor/base"
|
3
4
|
require "netvisor/configuration"
|
4
5
|
|
5
6
|
module Netvisor
|
6
7
|
class << self
|
7
|
-
attr_accessor :configuration
|
8
|
+
attr_accessor :configuration, :logger
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.new
|
@@ -16,10 +17,26 @@ module Netvisor
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.configuration
|
19
|
-
@configuration
|
20
|
+
init_config if (@configuration.nil? || @configuration == 1)
|
21
|
+
@configuration
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.reset
|
23
|
-
|
25
|
+
init_config
|
26
|
+
init_logger
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.init_logger
|
30
|
+
@logger = Logging.logger(STDOUT)
|
31
|
+
@logger.level = configuration.log_level
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.init_config
|
35
|
+
@configuration = Configuration.new(:sender => 'Netvisor gem', :log_level => :debug)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.logger
|
39
|
+
init_logger if (@logger.nil? || @logger == 1)
|
40
|
+
@logger
|
24
41
|
end
|
25
42
|
end
|
@@ -7,9 +7,10 @@ module Netvisor
|
|
7
7
|
:language,
|
8
8
|
:organisation_id,
|
9
9
|
:customer_key,
|
10
|
-
:partner_key
|
10
|
+
:partner_key,
|
11
|
+
:log_level) do
|
11
12
|
|
12
|
-
# Initialize override to accept named parameters (
|
13
|
+
# Initialize override to accept named parameters (Configuration(:host => 'foo'...))
|
13
14
|
# http://stackoverflow.com/questions/5407940/named-parameters-in-ruby-structs
|
14
15
|
def initialize *args
|
15
16
|
return super unless (args.length == 1 and args.first.instance_of? Hash)
|
data/lib/netvisor/request.rb
CHANGED
@@ -7,13 +7,14 @@ module Netvisor
|
|
7
7
|
def dispatch(xml, service, method = nil, id = nil)
|
8
8
|
url = self.class.build_url(service, method, id)
|
9
9
|
headers = self.class.build_headers(url)
|
10
|
+
Netvisor.logger.debug "dispatch: URL #{url}"
|
11
|
+
Netvisor.logger.debug "dispatch: Headers #{headers}"
|
10
12
|
xml.gsub!("<?xml version=\"1.0\"?>", '')
|
11
13
|
|
12
14
|
res = Faraday.post(url) do |req|
|
13
15
|
req.headers.merge!(headers)
|
14
16
|
req.body = xml
|
15
17
|
end
|
16
|
-
p res
|
17
18
|
Netvisor::Response.parse(res.body)
|
18
19
|
end
|
19
20
|
|
@@ -49,7 +50,7 @@ module Netvisor
|
|
49
50
|
Netvisor.configuration.customer_key,
|
50
51
|
Netvisor.configuration.partner_key
|
51
52
|
]
|
52
|
-
|
53
|
+
Netvisor.logger.debug "build_mac: #{arr.join('&')}"
|
53
54
|
Digest::SHA2.hexdigest(arr.join('&'))
|
54
55
|
end
|
55
56
|
end
|
data/lib/netvisor/version.rb
CHANGED
data/netvisor.gemspec
CHANGED
@@ -33,4 +33,5 @@ EOF
|
|
33
33
|
spec.add_runtime_dependency 'system_timer', '~> 1.2.4' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9')
|
34
34
|
spec.add_runtime_dependency 'nokogiri-happymapper-deiga', '~> 0.5.10'
|
35
35
|
spec.add_runtime_dependency 'nokogiri', '~> 1.5.11'
|
36
|
+
spec.add_runtime_dependency 'logging'
|
36
37
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Netvisor
|
4
|
+
|
5
|
+
class Dummy
|
6
|
+
include HappyMapper
|
7
|
+
include ElementBase
|
8
|
+
|
9
|
+
attribute :foo, String
|
10
|
+
element :bar, String
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ElementBase do
|
14
|
+
describe "#initialize" do
|
15
|
+
it "Class values are nil on no parameters" do
|
16
|
+
dummy = Dummy.new
|
17
|
+
expect(dummy.foo).to be_nil
|
18
|
+
expect(dummy.bar).to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "Class attribute is set to specified value" do
|
22
|
+
dummy = Dummy.new(:foo => 'foo')
|
23
|
+
expect(dummy.foo).to eq 'foo'
|
24
|
+
expect(dummy.bar).to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netvisor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 3
|
10
|
+
version: 0.9.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Timo Sand
|
@@ -172,6 +172,20 @@ dependencies:
|
|
172
172
|
requirement: *id010
|
173
173
|
type: :runtime
|
174
174
|
name: nokogiri
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
hash: 3
|
182
|
+
segments:
|
183
|
+
- 0
|
184
|
+
version: "0"
|
185
|
+
prerelease: false
|
186
|
+
requirement: *id011
|
187
|
+
type: :runtime
|
188
|
+
name: logging
|
175
189
|
description: " This gem is a ruby implementation of the Netvisor invoicing API\n"
|
176
190
|
email:
|
177
191
|
- timo.j.sand@gmail.com
|
@@ -207,6 +221,7 @@ files:
|
|
207
221
|
- lib/netvisor/version.rb
|
208
222
|
- netvisor.gemspec
|
209
223
|
- spec/netvisor/configuration_spec.rb
|
224
|
+
- spec/netvisor/element_base_spec.rb
|
210
225
|
- spec/netvisor_spec.rb
|
211
226
|
- spec/spec_helper.rb
|
212
227
|
homepage: https://github.com/Eficode/netvisor
|
@@ -246,5 +261,6 @@ specification_version: 3
|
|
246
261
|
summary: WIP Implementation of Netvisor API in Ruby
|
247
262
|
test_files:
|
248
263
|
- spec/netvisor/configuration_spec.rb
|
264
|
+
- spec/netvisor/element_base_spec.rb
|
249
265
|
- spec/netvisor_spec.rb
|
250
266
|
- spec/spec_helper.rb
|