oas 2.1.2 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
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 response.body[:oas_xml_request_response][:result]
30
- rescue Savon::HTTPError => e
31
- _raise_http_error!(e)
32
- rescue Savon::InvalidResponseError => e
33
- raise OAS::Error.new(e.message)
34
- end
35
-
36
- private
37
-
38
- def _raise_http_error!(e)
39
- case e.http.code
40
- when 403
41
- raise OAS::Error::HTTP::Forbidden.new
42
- when 500
43
- raise OAS::Error::HTTP::InternalServerError.new
44
- when 502
45
- raise OAS::Error::HTTP::BadGateway.new
46
- when 503
47
- raise OAS::Error::HTTP::ServiceUnavailable.new
48
- when 504
49
- raise OAS::Error::HTTP::GatewayTimeout.new
50
- else
51
- raise OAS::Error::HTTP.new(e.to_s)
52
- end
53
- end
54
-
55
- end
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
@@ -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
- 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
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.2'
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
@@ -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 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
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