oas 2.1.2 → 2.1.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.
- checksums.yaml +7 -0
- data/.gitignore +7 -6
- data/.travis.yml +8 -8
- data/Gemfile +4 -4
- data/LICENSE +20 -20
- data/README.md +89 -89
- data/Rakefile +10 -10
- data/lib/oas.rb +22 -22
- data/lib/oas/adxml.rb +91 -74
- data/lib/oas/client.rb +58 -55
- data/lib/oas/configuration.rb +51 -51
- data/lib/oas/error.rb +18 -8
- data/lib/oas/version.rb +3 -3
- data/oas.gemspec +29 -29
- data/test/fixtures/response.xml +14 -14
- data/test/helper.rb +1 -1
- data/test/test_adxml.rb +72 -68
- data/test/test_client.rb +89 -90
- data/test/test_configuration.rb +11 -11
- data/test/test_response.rb +37 -37
- metadata +19 -37
data/lib/oas/client.rb
CHANGED
@@ -1,56 +1,59 @@
|
|
1
|
-
require 'oas/adxml'
|
2
|
-
require 'savon'
|
3
|
-
|
4
|
-
module OAS
|
5
|
-
class Client
|
6
|
-
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
7
|
-
|
8
|
-
def initialize(opts={})
|
9
|
-
options = OAS.options.merge(opts)
|
10
|
-
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
11
|
-
send("#{key}=", options[key])
|
12
|
-
end
|
13
|
-
|
14
|
-
@savon = Savon::Client.new do |client|
|
15
|
-
client.endpoint endpoint.to_s
|
16
|
-
client.namespace "http://api.oas.tfsm.com/"
|
17
|
-
client.namespace_identifier :n1
|
18
|
-
client.convert_request_keys_to :camelcase
|
19
|
-
client.open_timeout timeout.to_i
|
20
|
-
client.read_timeout timeout.to_i
|
21
|
-
client.ssl_verify_mode :none
|
22
|
-
client.logger logger
|
23
|
-
client.log !!logger
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def execute(request)
|
28
|
-
response = @savon.call :oas_xml_request, message: Hash["String_1", account.to_s, "String_2", username.to_s, "String_3", password.to_s, "String_4", request.to_xml.to_s]
|
29
|
-
OAS::AdXML.parse
|
30
|
-
|
31
|
-
|
32
|
-
rescue Savon::
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when
|
43
|
-
|
44
|
-
when
|
45
|
-
|
46
|
-
when
|
47
|
-
|
48
|
-
when
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
require 'oas/adxml'
|
2
|
+
require 'savon'
|
3
|
+
|
4
|
+
module OAS
|
5
|
+
class Client
|
6
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
7
|
+
|
8
|
+
def initialize(opts={})
|
9
|
+
options = OAS.options.merge(opts)
|
10
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
11
|
+
send("#{key}=", options[key])
|
12
|
+
end
|
13
|
+
|
14
|
+
@savon = Savon::Client.new do |client|
|
15
|
+
client.endpoint endpoint.to_s
|
16
|
+
client.namespace "http://api.oas.tfsm.com/"
|
17
|
+
client.namespace_identifier :n1
|
18
|
+
client.convert_request_keys_to :camelcase
|
19
|
+
client.open_timeout timeout.to_i
|
20
|
+
client.read_timeout timeout.to_i
|
21
|
+
client.ssl_verify_mode :none
|
22
|
+
client.logger logger
|
23
|
+
client.log !!logger
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute(request)
|
28
|
+
response = @savon.call :oas_xml_request, message: Hash["String_1", account.to_s, "String_2", username.to_s, "String_3", password.to_s, "String_4", request.to_xml.to_s]
|
29
|
+
doc = OAS::AdXML.parse(response.body[:oas_xml_request_response][:result])
|
30
|
+
doc.http_headers = response.http.headers
|
31
|
+
doc
|
32
|
+
rescue Savon::HTTPError => e
|
33
|
+
_raise_http_error!(e)
|
34
|
+
rescue Savon::InvalidResponseError => e
|
35
|
+
raise OAS::Error.new(e.message)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def _raise_http_error!(e)
|
41
|
+
case e.http.code
|
42
|
+
when 403
|
43
|
+
klass = OAS::Error::HTTP::Forbidden
|
44
|
+
when 500
|
45
|
+
klass = OAS::Error::HTTP::InternalServerError
|
46
|
+
when 502
|
47
|
+
klass = OAS::Error::HTTP::BadGateway
|
48
|
+
when 503
|
49
|
+
klass = OAS::Error::HTTP::ServiceUnavailable
|
50
|
+
when 504
|
51
|
+
klass = OAS::Error::HTTP::GatewayTimeout
|
52
|
+
else
|
53
|
+
klass = OAS::Error::HTTP
|
54
|
+
end
|
55
|
+
raise klass.new(e.http.code, e.http.headers, e.http.body)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
56
59
|
end
|
data/lib/oas/configuration.rb
CHANGED
@@ -1,52 +1,52 @@
|
|
1
|
-
module OAS
|
2
|
-
module Configuration
|
3
|
-
# An array of valid keys in the options hash when configuring a {OAS::Client}
|
4
|
-
VALID_OPTIONS_KEYS = [
|
5
|
-
:endpoint,
|
6
|
-
:account,
|
7
|
-
:username,
|
8
|
-
:password,
|
9
|
-
:timeout,
|
10
|
-
:logger].freeze
|
11
|
-
|
12
|
-
# The endpoint that will be used to connect if none is set
|
13
|
-
DEFAULT_ENDPOINT = "https://oas.realmediadigital.com/oasapi/OaxApi".freeze
|
14
|
-
|
15
|
-
# The account that will be used to connect if none is set
|
16
|
-
DEFAULT_ACCOUNT = "OasDefault"
|
17
|
-
|
18
|
-
# By default, don't set a username
|
19
|
-
DEFAULT_USERNAME = nil
|
20
|
-
|
21
|
-
# By default, don't set a password
|
22
|
-
DEFAULT_PASSWORD = nil
|
23
|
-
|
24
|
-
# By default, set open and read timeout to 300
|
25
|
-
DEFAULT_TIMEOUT = 300
|
26
|
-
|
27
|
-
attr_accessor *VALID_OPTIONS_KEYS
|
28
|
-
|
29
|
-
def self.extended(base)
|
30
|
-
base.reset!
|
31
|
-
end
|
32
|
-
|
33
|
-
def configure
|
34
|
-
yield self if block_given?
|
35
|
-
end
|
36
|
-
|
37
|
-
def options
|
38
|
-
options = {}
|
39
|
-
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
|
40
|
-
options
|
41
|
-
end
|
42
|
-
|
43
|
-
def reset!
|
44
|
-
self.endpoint = DEFAULT_ENDPOINT
|
45
|
-
self.account = DEFAULT_ACCOUNT
|
46
|
-
self.username = DEFAULT_USERNAME
|
47
|
-
self.password = DEFAULT_PASSWORD
|
48
|
-
self.timeout = DEFAULT_TIMEOUT
|
49
|
-
self.logger = nil
|
50
|
-
end
|
51
|
-
end
|
1
|
+
module OAS
|
2
|
+
module Configuration
|
3
|
+
# An array of valid keys in the options hash when configuring a {OAS::Client}
|
4
|
+
VALID_OPTIONS_KEYS = [
|
5
|
+
:endpoint,
|
6
|
+
:account,
|
7
|
+
:username,
|
8
|
+
:password,
|
9
|
+
:timeout,
|
10
|
+
:logger].freeze
|
11
|
+
|
12
|
+
# The endpoint that will be used to connect if none is set
|
13
|
+
DEFAULT_ENDPOINT = "https://oas.realmediadigital.com/oasapi/OaxApi".freeze
|
14
|
+
|
15
|
+
# The account that will be used to connect if none is set
|
16
|
+
DEFAULT_ACCOUNT = "OasDefault"
|
17
|
+
|
18
|
+
# By default, don't set a username
|
19
|
+
DEFAULT_USERNAME = nil
|
20
|
+
|
21
|
+
# By default, don't set a password
|
22
|
+
DEFAULT_PASSWORD = nil
|
23
|
+
|
24
|
+
# By default, set open and read timeout to 300
|
25
|
+
DEFAULT_TIMEOUT = 300
|
26
|
+
|
27
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
28
|
+
|
29
|
+
def self.extended(base)
|
30
|
+
base.reset!
|
31
|
+
end
|
32
|
+
|
33
|
+
def configure
|
34
|
+
yield self if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
def options
|
38
|
+
options = {}
|
39
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
|
40
|
+
options
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset!
|
44
|
+
self.endpoint = DEFAULT_ENDPOINT
|
45
|
+
self.account = DEFAULT_ACCOUNT
|
46
|
+
self.username = DEFAULT_USERNAME
|
47
|
+
self.password = DEFAULT_PASSWORD
|
48
|
+
self.timeout = DEFAULT_TIMEOUT
|
49
|
+
self.logger = nil
|
50
|
+
end
|
51
|
+
end
|
52
52
|
end
|
data/lib/oas/error.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
-
module OAS
|
2
|
-
class Error < StandardError; end
|
3
|
-
|
4
|
-
class Error::HTTP
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module OAS
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class Error::HTTP < Error
|
5
|
+
attr_reader :code, :headers, :body
|
6
|
+
|
7
|
+
def initialize(code, headers, body)
|
8
|
+
@code = code
|
9
|
+
@headers = headers
|
10
|
+
@body = body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Error::HTTP::Forbidden < Error::HTTP; end
|
15
|
+
class Error::HTTP::BadGateway < Error::HTTP; end
|
16
|
+
class Error::HTTP::GatewayTimeout < Error::HTTP; end
|
17
|
+
class Error::HTTP::InternalServerError < Error::HTTP; end
|
18
|
+
class Error::HTTP::ServiceUnavailable < Error::HTTP; end
|
9
19
|
end
|
data/lib/oas/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module OAS
|
2
|
-
VERSION = '2.1.
|
3
|
-
end
|
1
|
+
module OAS
|
2
|
+
VERSION = '2.1.3'
|
3
|
+
end
|
data/oas.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "oas/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "oas"
|
7
|
-
s.version = OAS::VERSION
|
8
|
-
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = ["Damian Caruso"]
|
10
|
-
s.email = ["damian.caruso@gmail.com"]
|
11
|
-
s.homepage = "http://github.com/realmedia/oas-ruby-client"
|
12
|
-
s.summary = %q{Ruby client for the OpenAdstream API}
|
13
|
-
s.description = %q{Ruby client for the OpenAdstream API}
|
14
|
-
s.licenses = ['MIT']
|
15
|
-
|
16
|
-
s.rubyforge_project = "oas"
|
17
|
-
|
18
|
-
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
-
s.require_paths = ["lib"]
|
22
|
-
|
23
|
-
s.add_dependency "nokogiri", "~> 1.5"
|
24
|
-
s.add_dependency "nori", "~> 2.0"
|
25
|
-
s.add_dependency "savon", "~> 2.0"
|
26
|
-
|
27
|
-
s.add_development_dependency "rake", "~> 0.9"
|
28
|
-
s.add_development_dependency "webmock", "~> 1.9"
|
29
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "oas/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "oas"
|
7
|
+
s.version = OAS::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Damian Caruso"]
|
10
|
+
s.email = ["damian.caruso@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/realmedia/oas-ruby-client"
|
12
|
+
s.summary = %q{Ruby client for the OpenAdstream API}
|
13
|
+
s.description = %q{Ruby client for the OpenAdstream API}
|
14
|
+
s.licenses = ['MIT']
|
15
|
+
|
16
|
+
s.rubyforge_project = "oas"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_dependency "nokogiri", "~> 1.5"
|
24
|
+
s.add_dependency "nori", "~> 2.0"
|
25
|
+
s.add_dependency "savon", "~> 2.0"
|
26
|
+
|
27
|
+
s.add_development_dependency "rake", "~> 0.9"
|
28
|
+
s.add_development_dependency "webmock", "~> 1.9"
|
29
|
+
end
|
data/test/fixtures/response.xml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
3
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
4
|
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
5
|
-
<soapenv:Body>
|
6
|
-
<ns1:OasXmlRequestResponse xmlns:ns1="http://api.oas.tfsm.com/">
|
7
|
-
<result>
|
8
|
-
<![CDATA[
|
9
|
-
<?xml version="1.0"?>
|
10
|
-
<AdXML><Response></Response></AdXML>
|
11
|
-
]]>
|
12
|
-
</result>
|
13
|
-
</ns1:OasXmlRequestResponse>
|
14
|
-
</soapenv:Body>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
|
3
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
4
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
5
|
+
<soapenv:Body>
|
6
|
+
<ns1:OasXmlRequestResponse xmlns:ns1="http://api.oas.tfsm.com/">
|
7
|
+
<result>
|
8
|
+
<![CDATA[
|
9
|
+
<?xml version="1.0"?>
|
10
|
+
<AdXML><Response></Response></AdXML>
|
11
|
+
]]>
|
12
|
+
</result>
|
13
|
+
</ns1:OasXmlRequestResponse>
|
14
|
+
</soapenv:Body>
|
15
15
|
</soapenv:Envelope>
|
data/test/helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'minitest/autorun'
|
1
|
+
require 'minitest/autorun'
|
2
2
|
require 'oas'
|
data/test/test_adxml.rb
CHANGED
@@ -1,69 +1,73 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestAdXML < MiniTest::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@doc = OAS::AdXML.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
@doc.request do |req|
|
63
|
-
req.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAdXML < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@doc = OAS::AdXML.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_http_headers
|
9
|
+
assert_kind_of Hash, @doc.http_headers
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_set_encoding
|
13
|
+
assert_match 'UTF-8', @doc.to_xml
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_set_root_node
|
17
|
+
new_doc = Nokogiri.XML @doc.to_xml
|
18
|
+
assert_equal 'AdXML', new_doc.root.name
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_convert_to_hash
|
22
|
+
assert @doc.to_hash.has_key?(:AdXML)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_adxml_parsing
|
26
|
+
assert_kind_of OAS::AdXML, OAS::AdXML.parse("<AdXML></AdXML>")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_response_iterator
|
30
|
+
str = <<-EOXML
|
31
|
+
<AdXML>
|
32
|
+
<Response>
|
33
|
+
<Campaign/>
|
34
|
+
</Response>
|
35
|
+
<Response>
|
36
|
+
<Campaign/>
|
37
|
+
</Response>
|
38
|
+
</AdXML>
|
39
|
+
EOXML
|
40
|
+
responses = []
|
41
|
+
doc = OAS::AdXML.new Nokogiri.XML(str)
|
42
|
+
doc.each_response do |res|
|
43
|
+
responses << res
|
44
|
+
assert_kind_of OAS::AdXML::Response, res
|
45
|
+
assert_equal 'Response', Nokogiri.XML(res.to_xml).root.name
|
46
|
+
end
|
47
|
+
assert_equal 2, responses.size
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_request_builder
|
51
|
+
@doc.request do |req|
|
52
|
+
req.Site do |xml|
|
53
|
+
assert_kind_of Nokogiri::XML::Builder, xml
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
new_doc = Nokogiri.XML(@doc.to_xml)
|
58
|
+
assert_equal 1, new_doc.xpath("/AdXML/Request[@type='Site']").length
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_chain_request_blocks
|
62
|
+
@doc.request do |req|
|
63
|
+
req.Site
|
64
|
+
req.Site
|
65
|
+
end
|
66
|
+
@doc.request do |req|
|
67
|
+
req.Campaign
|
68
|
+
end
|
69
|
+
|
70
|
+
new_doc = Nokogiri.XML(@doc.to_xml)
|
71
|
+
assert_equal 3, new_doc.xpath('/AdXML/Request').length
|
72
|
+
end
|
69
73
|
end
|