oas 1.2.0 → 2.1.0
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/README.md +74 -32
- data/Rakefile +1 -1
- data/lib/oas.rb +4 -1
- data/lib/oas/adxml.rb +75 -0
- data/lib/oas/client.rb +33 -19
- data/lib/oas/configuration.rb +4 -2
- data/lib/oas/error.rb +9 -0
- data/lib/oas/version.rb +1 -1
- data/oas.gemspec +4 -6
- data/test/fixtures/{successful_response.xml → response.xml} +0 -0
- data/test/helper.rb +0 -4
- data/test/test_adxml.rb +69 -0
- data/test/test_client.rb +69 -27
- data/test/test_configuration.rb +12 -0
- data/test/test_response.rb +28 -16
- metadata +16 -51
- data/lib/oas/response.rb +0 -31
- data/test/test_oas.rb +0 -15
data/README.md
CHANGED
@@ -1,47 +1,89 @@
|
|
1
|
-
OAS Ruby Client [][travis] [][gemnasium]
|
2
|
-
================
|
1
|
+
# OAS Ruby Client [][travis] [][gemnasium]
|
3
2
|
Ruby client for the OpenAdstream API
|
4
3
|
|
5
4
|
[travis]: http://travis-ci.org/realmedia/oas-ruby-client
|
6
5
|
[gemnasium]: https://gemnasium.com/realmedia/oas-ruby-client
|
7
6
|
|
8
|
-
Installation
|
9
|
-
------------
|
7
|
+
## Installation
|
10
8
|
|
11
9
|
`oas` is available through [Rubygems](http://rubygems.org/gems/oas) and can be installed via:
|
12
10
|
|
13
11
|
gem install oas
|
14
12
|
|
15
|
-
Usage
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Applications that make requests on behalf a single user to a single account can pass configuration options as a block to the `OAS.configure` method.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
OAS.configure do |config|
|
19
|
+
config.endpoint = OAS_ENDPOINT
|
20
|
+
config.account = OAS_ACCOUNT
|
21
|
+
config.username = OAS_USERNAME
|
22
|
+
config.password = OAS_PASSWORD
|
23
|
+
end
|
24
|
+
```
|
25
|
+
Applications that make requests on behalf of multiple users to multiple accounts should avoid using the global configuration and instantiate `OAS::Client` objects. If the endpoint is the same, you can specify it globally.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
OAS.configure do |config|
|
29
|
+
config.endpoint = OAS_ENDPOINT
|
30
|
+
end
|
31
|
+
|
32
|
+
client = OAS::Client.new(
|
33
|
+
:account => "oas_account",
|
34
|
+
:username => "oas_username",
|
35
|
+
:password => "oas_password"
|
36
|
+
)
|
37
|
+
```
|
38
|
+
Requests should be created using an `OAS::AdXML` object. Each request type will yield a `Nokogiri::XML::Builder` object.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
doc = OAS::AdXML.new
|
42
|
+
doc.request do |req|
|
43
|
+
req.Advertiser do |xml|
|
44
|
+
xml.Database(:action => 'read') {
|
45
|
+
xml.Advertiser {
|
46
|
+
xml.Id "DPadvtest"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
Multiple requests can be sent in the same call.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
doc = OAS::AdXML.new
|
56
|
+
doc.request do |req|
|
57
|
+
req.Site do |xml|
|
58
|
+
xml.Database(:action => "read") {
|
59
|
+
xml.Site {
|
60
|
+
xml.Id "247media"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
end
|
64
|
+
req.Site do |xml|
|
65
|
+
xml.Database(:action => "read") {
|
66
|
+
xml.Site {
|
67
|
+
xml.Id "realmedia"
|
38
68
|
}
|
39
|
-
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
Executing the request
|
40
74
|
|
41
|
-
|
42
|
-
|
75
|
+
```ruby
|
76
|
+
adxml = OAS.execute(doc) # or client.execute(doc)
|
77
|
+
adxml.each_response do |res|
|
78
|
+
if res.success?
|
79
|
+
# res.to_hash
|
80
|
+
else
|
81
|
+
# res.error_code
|
82
|
+
# res.error_text
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
43
86
|
|
44
|
-
Copyright
|
45
|
-
---------
|
87
|
+
## Copyright
|
46
88
|
Copyright (c) 2011 Realmedia Latin America.
|
47
89
|
See [LICENSE](https://github.com/realmedia/oas-ruby-client/blob/master/LICENSE) for details.
|
data/Rakefile
CHANGED
data/lib/oas.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
+
require 'oas/error'
|
1
2
|
require 'oas/configuration'
|
2
3
|
require 'oas/client'
|
4
|
+
require 'oas/version'
|
3
5
|
|
4
6
|
module OAS
|
5
7
|
extend Configuration
|
6
8
|
|
7
9
|
def self.client(options={})
|
8
|
-
@client
|
10
|
+
@client = OAS::Client.new(options) unless defined?(@client)
|
11
|
+
@client
|
9
12
|
end
|
10
13
|
|
11
14
|
def self.method_missing(method, *args, &block)
|
data/lib/oas/adxml.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module OAS
|
4
|
+
class AdXML
|
5
|
+
def self.parse(str)
|
6
|
+
new Nokogiri.XML(str)
|
7
|
+
end
|
8
|
+
|
9
|
+
module Utils
|
10
|
+
def parser
|
11
|
+
@parser ||= Nori.new(:advanced_typecasting => false, :convert_tags_to => lambda { |tag| tag.to_sym })
|
12
|
+
end
|
13
|
+
attr_writer :parser
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@doc.to_xml
|
17
|
+
end
|
18
|
+
alias_method :to_xml, :to_s
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
@hash ||= parser.parse(@doc.to_xml)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Request
|
26
|
+
def initialize(root)
|
27
|
+
@root = root
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_missing method, *args, &block # :nodoc:
|
31
|
+
Nokogiri::XML::Builder.with(@root) do |xml|
|
32
|
+
xml.Request(:type => method.to_s) { |xml| block.call(xml) if block_given? }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Response
|
38
|
+
include Utils
|
39
|
+
|
40
|
+
attr_reader :error_code
|
41
|
+
attr_reader :error_text
|
42
|
+
|
43
|
+
def initialize(doc)
|
44
|
+
@doc = doc
|
45
|
+
@error_code = @error_text = nil
|
46
|
+
error = @doc.xpath('/Response//Exception').first rescue nil
|
47
|
+
if error
|
48
|
+
@error_code = error['errorCode'].to_i
|
49
|
+
@error_text = error.text
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def success?
|
54
|
+
!error_code
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
include Utils
|
59
|
+
|
60
|
+
def initialize(doc = nil)
|
61
|
+
@doc = doc
|
62
|
+
@doc = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') { |xml| xml.AdXML }.doc if @doc.nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
def request
|
66
|
+
yield Request.new(@doc.root)
|
67
|
+
end
|
68
|
+
|
69
|
+
def each_response
|
70
|
+
@doc.xpath('/AdXML/Response').each do |node|
|
71
|
+
yield Response.new(node)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/oas/client.rb
CHANGED
@@ -1,39 +1,53 @@
|
|
1
|
-
require '
|
1
|
+
require 'oas/adxml'
|
2
2
|
require 'savon'
|
3
|
-
require 'oas/response'
|
4
3
|
|
5
4
|
module OAS
|
6
|
-
class Client
|
5
|
+
class Client
|
7
6
|
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
8
|
-
attr_accessor :driver
|
9
7
|
|
10
|
-
def initialize(
|
11
|
-
options = OAS.options.merge(
|
8
|
+
def initialize(opts={})
|
9
|
+
options = OAS.options.merge(opts)
|
12
10
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
13
11
|
send("#{key}=", options[key])
|
14
12
|
end
|
15
|
-
end
|
16
13
|
|
17
|
-
|
18
|
-
@driver ||= Savon::Client.new do |client|
|
14
|
+
@savon = Savon::Client.new do |client|
|
19
15
|
client.endpoint endpoint.to_s
|
20
16
|
client.namespace "http://api.oas.tfsm.com/"
|
21
17
|
client.namespace_identifier :n1
|
22
18
|
client.convert_request_keys_to :camelcase
|
23
|
-
client.
|
19
|
+
client.logger logger
|
20
|
+
client.log !!logger
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
27
|
-
def request
|
28
|
-
|
29
|
-
|
30
|
-
OAS::Response.new(res.body[:oas_xml_request_response][:result])
|
31
|
-
rescue Savon::SOAPFault => e
|
32
|
-
raise e.to_hash[:fault][:faultstring]
|
24
|
+
def execute(request)
|
25
|
+
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]
|
26
|
+
OAS::AdXML.parse response.body[:oas_xml_request_response][:result]
|
33
27
|
rescue Savon::HTTPError => e
|
34
|
-
|
35
|
-
rescue Savon::InvalidResponseError
|
36
|
-
raise
|
28
|
+
_raise_http_error!(e)
|
29
|
+
rescue Savon::InvalidResponseError => e
|
30
|
+
raise OAS::Error.new(e.message)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def _raise_http_error!(e)
|
36
|
+
case e.http.code
|
37
|
+
when 403
|
38
|
+
raise OAS::Error::HTTP::Forbidden.new
|
39
|
+
when 500
|
40
|
+
raise OAS::Error::HTTP::InternalServerError.new
|
41
|
+
when 502
|
42
|
+
raise OAS::Error::HTTP::BadGateway.new
|
43
|
+
when 503
|
44
|
+
raise OAS::Error::HTTP::ServiceUnavailable.new
|
45
|
+
when 504
|
46
|
+
raise OAS::Error::HTTP::GatewayTimeout.new
|
47
|
+
else
|
48
|
+
raise OAS::Error::HTTP.new(e.to_s)
|
49
|
+
end
|
37
50
|
end
|
51
|
+
|
38
52
|
end
|
39
53
|
end
|
data/lib/oas/configuration.rb
CHANGED
@@ -5,7 +5,8 @@ module OAS
|
|
5
5
|
:endpoint,
|
6
6
|
:account,
|
7
7
|
:username,
|
8
|
-
:password
|
8
|
+
:password,
|
9
|
+
:logger].freeze
|
9
10
|
|
10
11
|
# The endpoint that will be used to connect if none is set
|
11
12
|
DEFAULT_ENDPOINT = "https://oas.realmediadigital.com/oasapi/OaxApi".freeze
|
@@ -40,6 +41,7 @@ module OAS
|
|
40
41
|
self.account = DEFAULT_ACCOUNT
|
41
42
|
self.username = DEFAULT_USERNAME
|
42
43
|
self.password = DEFAULT_PASSWORD
|
44
|
+
self.logger = nil
|
43
45
|
end
|
44
46
|
end
|
45
|
-
end
|
47
|
+
end
|
data/lib/oas/error.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
module OAS
|
2
|
+
class Error < StandardError; end
|
3
|
+
class Error::HTTP < Error; end
|
4
|
+
class Error::HTTP::Forbidden < Error::HTTP; end
|
5
|
+
class Error::HTTP::BadGateway < Error::HTTP; end
|
6
|
+
class Error::HTTP::GatewayTimeout < Error::HTTP; end
|
7
|
+
class Error::HTTP::InternalServerError < Error::HTTP; end
|
8
|
+
class Error::HTTP::ServiceUnavailable < Error::HTTP; end
|
9
|
+
end
|
data/lib/oas/version.rb
CHANGED
data/oas.gemspec
CHANGED
@@ -19,12 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency "
|
23
|
-
s.add_dependency "
|
24
|
-
s.add_dependency "
|
22
|
+
s.add_dependency "nokogiri", "~> 1.5"
|
23
|
+
s.add_dependency "nori", "~> 2.0"
|
24
|
+
s.add_dependency "savon", "~> 2.0"
|
25
25
|
|
26
|
-
s.add_development_dependency "
|
26
|
+
s.add_development_dependency "rake", "~> 0.9"
|
27
27
|
s.add_development_dependency "webmock", "~> 1.9"
|
28
|
-
s.add_development_dependency "rake"
|
29
|
-
s.add_development_dependency "simplecov"
|
30
28
|
end
|
File without changes
|
data/test/helper.rb
CHANGED
data/test/test_adxml.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAdXML < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@doc = OAS::AdXML.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_set_encoding
|
9
|
+
assert_match 'UTF-8', @doc.to_xml
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_set_root_node
|
13
|
+
new_doc = Nokogiri.XML @doc.to_xml
|
14
|
+
assert_equal 'AdXML', new_doc.root.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_convert_to_hash
|
18
|
+
assert @doc.to_hash.has_key?(:AdXML)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_adxml_parsing
|
22
|
+
assert_kind_of OAS::AdXML, OAS::AdXML.parse("<AdXML></AdXML>")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_response_iterator
|
26
|
+
str = <<-EOXML
|
27
|
+
<AdXML>
|
28
|
+
<Response>
|
29
|
+
<Campaign/>
|
30
|
+
</Response>
|
31
|
+
<Response>
|
32
|
+
<Campaign/>
|
33
|
+
</Response>
|
34
|
+
</AdXML>
|
35
|
+
EOXML
|
36
|
+
responses = []
|
37
|
+
doc = OAS::AdXML.new Nokogiri.XML(str)
|
38
|
+
doc.each_response do |res|
|
39
|
+
responses << res
|
40
|
+
assert_kind_of OAS::AdXML::Response, res
|
41
|
+
assert_equal 'Response', Nokogiri.XML(res.to_xml).root.name
|
42
|
+
end
|
43
|
+
assert_equal 2, responses.size
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_request_builder
|
47
|
+
@doc.request do |req|
|
48
|
+
req.Site do |xml|
|
49
|
+
assert_kind_of Nokogiri::XML::Builder, xml
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
new_doc = Nokogiri.XML(@doc.to_xml)
|
54
|
+
assert_equal 1, new_doc.xpath("/AdXML/Request[@type='Site']").length
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_chain_request_blocks
|
58
|
+
@doc.request do |req|
|
59
|
+
req.Site
|
60
|
+
req.Site
|
61
|
+
end
|
62
|
+
@doc.request do |req|
|
63
|
+
req.Campaign
|
64
|
+
end
|
65
|
+
|
66
|
+
new_doc = Nokogiri.XML(@doc.to_xml)
|
67
|
+
assert_equal 3, new_doc.xpath('/AdXML/Request').length
|
68
|
+
end
|
69
|
+
end
|
data/test/test_client.rb
CHANGED
@@ -5,45 +5,87 @@ class TestClient < MiniTest::Unit::TestCase
|
|
5
5
|
include WebMock::API
|
6
6
|
|
7
7
|
def setup
|
8
|
-
OAS.
|
9
|
-
|
8
|
+
@client = OAS::Client.new(
|
9
|
+
:account => "test_account",
|
10
|
+
:username => "test_user",
|
11
|
+
:password => "test_password"
|
12
|
+
)
|
13
|
+
@request = Class.new do
|
14
|
+
def to_xml; '<AdXML></AdXML>' end
|
15
|
+
end.new
|
10
16
|
end
|
11
17
|
|
12
18
|
def teardown
|
19
|
+
OAS.reset!
|
13
20
|
WebMock.reset!
|
14
21
|
end
|
15
22
|
|
16
23
|
def fixture(file)
|
17
|
-
File.new(File.join(File.expand_path(
|
24
|
+
File.new(File.join(File.expand_path('../fixtures', __FILE__), file))
|
18
25
|
end
|
19
26
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@client.
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def test_execute_request
|
28
|
+
stub_request(:post, @client.endpoint.to_s)
|
29
|
+
.to_return(:status => 200, :body => fixture('response.xml'))
|
30
|
+
|
31
|
+
assert_kind_of OAS::AdXML, @client.execute(@request)
|
32
|
+
assert_requested(:post, @client.endpoint.to_s, :times => 1) do |req|
|
33
|
+
doc = Nokogiri.XML(req.body)
|
34
|
+
node = doc.xpath("/env:Envelope/env:Body/n1:OasXmlRequest").first
|
35
|
+
return false unless !!node
|
36
|
+
node.xpath("./String_1").first.text == @client.account &&
|
37
|
+
node.xpath("./String_2").first.text == @client.username &&
|
38
|
+
node.xpath("./String_3").first.text == @client.password &&
|
39
|
+
node.xpath("./String_4").first.text == @request.to_xml
|
40
|
+
end
|
28
41
|
end
|
29
42
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
@client.driver = MiniTest::Mock.new
|
38
|
-
@client.driver.expect :call, res, [:oas_xml_request, message: Hash["String_1", @client.account.to_s, "String_2", @client.username.to_s, "String_3", @client.password.to_s, "String_4", doc.to_xml]]
|
39
|
-
@client.request(doc)
|
40
|
-
@client.driver.verify
|
43
|
+
|
44
|
+
def test_raise_http_error
|
45
|
+
stub_request(:post, @client.endpoint.to_s).to_return(:status => 599)
|
46
|
+
|
47
|
+
assert_raises OAS::Error::HTTP do
|
48
|
+
@client.execute(@request)
|
49
|
+
end
|
41
50
|
end
|
42
51
|
|
43
|
-
def
|
44
|
-
stub_request(:post, @client.endpoint.to_s)
|
45
|
-
|
46
|
-
|
47
|
-
|
52
|
+
def test_raise_http_forbidden_error
|
53
|
+
stub_request(:post, @client.endpoint.to_s).to_return(:status => 403)
|
54
|
+
|
55
|
+
assert_raises OAS::Error::HTTP::Forbidden do
|
56
|
+
@client.execute(@request)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_raise_http_internal_server_error_error
|
61
|
+
stub_request(:post, @client.endpoint.to_s).to_return(:status => 500)
|
62
|
+
|
63
|
+
assert_raises OAS::Error::HTTP::InternalServerError do
|
64
|
+
@client.execute(@request)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_raise_http_bad_gateway_error
|
69
|
+
stub_request(:post, @client.endpoint.to_s).to_return(:status => 502)
|
70
|
+
|
71
|
+
assert_raises OAS::Error::HTTP::BadGateway do
|
72
|
+
@client.execute(@request)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_raise_http_service_unavailable_error
|
77
|
+
stub_request(:post, @client.endpoint.to_s).to_return(:status => 503)
|
78
|
+
|
79
|
+
assert_raises OAS::Error::HTTP::ServiceUnavailable do
|
80
|
+
@client.execute(@request)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_raise_http_gateway_timeout_error
|
85
|
+
stub_request(:post, @client.endpoint.to_s).to_return(:status => 504)
|
86
|
+
|
87
|
+
assert_raises OAS::Error::HTTP::GatewayTimeout do
|
88
|
+
@client.execute(@request)
|
89
|
+
end
|
48
90
|
end
|
49
91
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestConfiguration < MiniTest::Unit::TestCase
|
4
|
+
def test_should_set_configuration_keys
|
5
|
+
OAS::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
6
|
+
OAS.configure do |config|
|
7
|
+
config.send("#{key}=", key)
|
8
|
+
assert_equal key, OAS.send(key)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/test/test_response.rb
CHANGED
@@ -1,22 +1,34 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
def
|
5
|
-
|
6
|
-
<
|
7
|
-
<
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
class TestAdXMLResponse < MiniTest::Unit::TestCase
|
4
|
+
def test_successful_response
|
5
|
+
node = <<-EOXML
|
6
|
+
<Response>
|
7
|
+
<Campaign>
|
8
|
+
<Overview>
|
9
|
+
<Id>DPtestcampaign-01</Id>
|
10
|
+
</Overview>
|
11
|
+
</Campaign>
|
12
|
+
</Response>
|
13
|
+
EOXML
|
14
|
+
res = OAS::AdXML::Response.new Nokogiri.XML(node)
|
15
|
+
assert res.to_hash.has_key?(:Response)
|
16
|
+
assert res.success?
|
17
|
+
assert_nil res.error_code
|
18
|
+
assert_nil res.error_text
|
12
19
|
end
|
13
20
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
def test_unsuccessful_response
|
22
|
+
node = <<-EOXML
|
23
|
+
<Response>
|
24
|
+
<Campaign>
|
25
|
+
<Exception errorCode="512">Campaign ID already exists in Open AdStream</Exception>
|
26
|
+
</Campaign>
|
27
|
+
</Response>
|
28
|
+
EOXML
|
29
|
+
res = OAS::AdXML::Response.new Nokogiri.XML(node)
|
30
|
+
refute res.success?
|
31
|
+
assert_equal 512, res.error_code
|
32
|
+
assert_equal 'Campaign ID already exists in Open AdStream', res.error_text
|
21
33
|
end
|
22
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: nokogiri
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '1.5'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,9 +26,9 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '1.5'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: nori
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '2.0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: savon
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,13 +60,13 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '0.9'
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
77
|
+
version: '0.9'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: webmock
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,38 +91,6 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '1.9'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: rake
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: simplecov
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ! '>='
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ! '>='
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: '0'
|
126
94
|
description: Ruby client for the OpenAdstream API
|
127
95
|
email:
|
128
96
|
- damian.caruso@gmail.com
|
@@ -137,15 +105,17 @@ files:
|
|
137
105
|
- README.md
|
138
106
|
- Rakefile
|
139
107
|
- lib/oas.rb
|
108
|
+
- lib/oas/adxml.rb
|
140
109
|
- lib/oas/client.rb
|
141
110
|
- lib/oas/configuration.rb
|
142
|
-
- lib/oas/
|
111
|
+
- lib/oas/error.rb
|
143
112
|
- lib/oas/version.rb
|
144
113
|
- oas.gemspec
|
145
|
-
- test/fixtures/
|
114
|
+
- test/fixtures/response.xml
|
146
115
|
- test/helper.rb
|
116
|
+
- test/test_adxml.rb
|
147
117
|
- test/test_client.rb
|
148
|
-
- test/
|
118
|
+
- test/test_configuration.rb
|
149
119
|
- test/test_response.rb
|
150
120
|
homepage: http://github.com/realmedia/oas-ruby-client
|
151
121
|
licenses: []
|
@@ -159,18 +129,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
129
|
- - ! '>='
|
160
130
|
- !ruby/object:Gem::Version
|
161
131
|
version: '0'
|
162
|
-
segments:
|
163
|
-
- 0
|
164
|
-
hash: 67502451
|
165
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
133
|
none: false
|
167
134
|
requirements:
|
168
135
|
- - ! '>='
|
169
136
|
- !ruby/object:Gem::Version
|
170
137
|
version: '0'
|
171
|
-
segments:
|
172
|
-
- 0
|
173
|
-
hash: 67502451
|
174
138
|
requirements: []
|
175
139
|
rubyforge_project: oas
|
176
140
|
rubygems_version: 1.8.24
|
@@ -178,3 +142,4 @@ signing_key:
|
|
178
142
|
specification_version: 3
|
179
143
|
summary: Ruby client for the OpenAdstream API
|
180
144
|
test_files: []
|
145
|
+
has_rdoc:
|
data/lib/oas/response.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'nori'
|
2
|
-
|
3
|
-
module OAS
|
4
|
-
class Response
|
5
|
-
attr_writer :parser
|
6
|
-
|
7
|
-
def initialize(doc)
|
8
|
-
@doc = doc
|
9
|
-
end
|
10
|
-
|
11
|
-
def parser
|
12
|
-
@parser ||= Nori.new(:advanced_typecasting => false, :convert_tags_to => lambda { |tag| tag.to_sym })
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_s
|
16
|
-
raw
|
17
|
-
end
|
18
|
-
|
19
|
-
def raw
|
20
|
-
@raw ||= begin
|
21
|
-
raw = ""
|
22
|
-
@doc.each_line { |l| raw << l.strip }
|
23
|
-
raw
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_hash
|
28
|
-
parser.parse(raw)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/test/test_oas.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestOas < MiniTest::Unit::TestCase
|
4
|
-
|
5
|
-
describe "#configure" do
|
6
|
-
OAS::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
7
|
-
it "should set the #{key}" do
|
8
|
-
OAS.configure do |config|
|
9
|
-
config.send("#{key}=", key)
|
10
|
-
assert_equal key, OAS.send(key)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|