oas 0.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +6 -6
  2. data/.travis.yml +9 -3
  3. data/Gemfile +4 -4
  4. data/LICENSE +20 -20
  5. data/README.md +47 -0
  6. data/Rakefile +11 -8
  7. data/lib/oas.rb +19 -31
  8. data/lib/oas/client.rb +39 -17
  9. data/lib/oas/configuration.rb +45 -45
  10. data/lib/oas/response.rb +31 -0
  11. data/lib/oas/version.rb +3 -3
  12. data/oas.gemspec +30 -29
  13. data/test/fixtures/successful_response.xml +15 -0
  14. data/test/helper.rb +6 -0
  15. data/test/test_client.rb +49 -0
  16. data/test/test_oas.rb +15 -0
  17. data/test/test_response.rb +22 -0
  18. metadata +85 -61
  19. data/.rspec +0 -2
  20. data/README.markdown +0 -103
  21. data/lib/oas/api.rb +0 -56
  22. data/lib/oas/client/campaigns.rb +0 -25
  23. data/lib/oas/client/databases.rb +0 -96
  24. data/lib/oas/client/notifications.rb +0 -15
  25. data/lib/oas/client/reports.rb +0 -71
  26. data/lib/oas/client/utils.rb +0 -16
  27. data/lib/oas/core_ext/hash.rb +0 -57
  28. data/lib/oas/core_ext/object.rb +0 -6
  29. data/lib/oas/error.rb +0 -17
  30. data/spec/fixtures/read_advertiser.xml +0 -49
  31. data/spec/fixtures/read_agency.xml +0 -49
  32. data/spec/fixtures/read_campaign.xml +0 -121
  33. data/spec/fixtures/read_campaign_group.xml +0 -31
  34. data/spec/fixtures/read_creative.xml +0 -52
  35. data/spec/fixtures/read_keyname.xml +0 -29
  36. data/spec/fixtures/read_keyword.xml +0 -27
  37. data/spec/fixtures/read_notification.xml +0 -31
  38. data/spec/fixtures/read_page.xml +0 -33
  39. data/spec/fixtures/read_section.xml +0 -30
  40. data/spec/fixtures/read_site.xml +0 -32
  41. data/spec/fixtures/read_site_group.xml +0 -33
  42. data/spec/fixtures/wsdl.xml +0 -37
  43. data/spec/oas/client/campaigns_spec.rb +0 -30
  44. data/spec/oas/client/databases_spec.rb +0 -111
  45. data/spec/oas/client/notifications_spec.rb +0 -16
  46. data/spec/oas_spec.rb +0 -14
  47. data/spec/spec_helper.rb +0 -29
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- *.gem
2
- .bundle
3
- .redcar
4
- .rvmrc
5
- Gemfile.lock
6
- pkg/*
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ coverage/
5
+ doc/
6
+ pkg/
data/.travis.yml CHANGED
@@ -1,3 +1,9 @@
1
- rvm:
2
- - 1.9.2
3
- - 1.9.3
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ notifications:
8
+ email:
9
+ - dev@realmediadigital.com
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in ruby-oas.gemspec
4
- gemspec
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-oas.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2011 Realmedia LatinAmerica
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2011 Realmedia Latin America
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ OAS Ruby Client [![Build Status](https://secure.travis-ci.org/realmedia/oas-ruby-client.png)][travis] [![Dependency Status](https://gemnasium.com/realmedia/oas-ruby-client.png?travis)][gemnasium]
2
+ ================
3
+ Ruby client for the OpenAdstream API
4
+
5
+ [travis]: http://travis-ci.org/realmedia/oas-ruby-client
6
+ [gemnasium]: https://gemnasium.com/realmedia/oas-ruby-client
7
+
8
+ Installation
9
+ ------------
10
+
11
+ `oas` is available through [Rubygems](http://rubygems.org/gems/oas) and can be installed via:
12
+
13
+ gem install oas
14
+
15
+ Usage Example
16
+ --------------
17
+ require "oas"
18
+ require "pp"
19
+
20
+ # Configure OAS
21
+ OAS.configure do |config|
22
+ config.endpoint = OAS_ENDPOINT
23
+ config.account = OAS_ACCOUNT
24
+ config.username = OAS_USERNAME
25
+ config.password = OAS_PASSWORD
26
+ end
27
+
28
+ # Build OAS message (Ex: Nokogiri)
29
+ msg = Nokogiri::XML::Builder.new(:encoding => "utf-8") do |xml|
30
+ xml.AdXML {
31
+ xml.Request(:type => 'Site') {
32
+ xml.Database(:action => 'list') {
33
+ xml.SearchCriteria {
34
+ xml.Id "%"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ end
40
+
41
+ # Make request
42
+ pp OAS.client.request(msg).to_hash
43
+
44
+ Copyright
45
+ ---------
46
+ Copyright (c) 2011 Realmedia Latin America.
47
+ See [LICENSE](https://github.com/realmedia/oas-ruby-client/blob/master/LICENSE) for details.
data/Rakefile CHANGED
@@ -1,8 +1,11 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new('spec')
6
-
7
- task :test => :spec
8
- task :default => :spec
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new do |t|
6
+ t.libs = ["test"]
7
+ t.verbose = true
8
+ t.test_files = FileList['test/**/test_*.rb']
9
+ end
10
+
11
+ task :default => :test
data/lib/oas.rb CHANGED
@@ -1,31 +1,19 @@
1
- Dir[File.join(File.dirname(__FILE__),'oas/core_ext/**/*.rb')].each {|f| require f}
2
-
3
- require 'oas/version'
4
- require 'oas/error'
5
- require 'oas/configuration'
6
- require 'oas/api'
7
- require 'oas/client'
8
-
9
- module Oas
10
- extend Configuration
11
-
12
- # Alias for Oas::Client.new
13
- #
14
- # @return [Oas::Client]
15
- def self.client(options={})
16
- Oas::Client.new(options)
17
- end
18
-
19
- # Delegate to Oas::Client
20
- def self.method_missing(method, *args, &block)
21
- return super unless client.respond_to?(method)
22
- client.send(method, *args, &block)
23
- end
24
-
25
- def self.respond_to?(method, include_private = false)
26
- client.respond_to?(method, include_private) || super(method, include_private)
27
- end
28
-
29
- HTTPI.log = false
30
- Savon.configure { |c| c.log = false }
31
- end
1
+ require 'oas/configuration'
2
+ require 'oas/client'
3
+
4
+ module OAS
5
+ extend Configuration
6
+
7
+ def self.client(options={})
8
+ @client ||= OAS::Client.new(options)
9
+ end
10
+
11
+ def self.method_missing(method, *args, &block)
12
+ return super unless client.respond_to?(method)
13
+ client.send(method, *args, &block)
14
+ end
15
+
16
+ def self.respond_to_missing?(method, include_private = false)
17
+ client.respond_to?(method, include_private)
18
+ end
19
+ end
data/lib/oas/client.rb CHANGED
@@ -1,17 +1,39 @@
1
- module Oas
2
- class Client < Api
3
- class Error < StandardError; end
4
-
5
- require 'oas/client/utils'
6
- require 'oas/client/campaigns'
7
- require 'oas/client/databases'
8
- require 'oas/client/notifications'
9
- require 'oas/client/reports'
10
-
11
- include Oas::Client::Utils
12
- include Oas::Client::Campaigns
13
- include Oas::Client::Databases
14
- include Oas::Client::Notifications
15
- include Oas::Client::Reports
16
- end
17
- end
1
+ require 'httpclient'
2
+ require 'savon'
3
+ require 'oas/response'
4
+
5
+ module OAS
6
+ class Client
7
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
+ attr_accessor :driver
9
+
10
+ def initialize(options={})
11
+ options = OAS.options.merge(options)
12
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
13
+ send("#{key}=", options[key])
14
+ end
15
+ end
16
+
17
+ def driver
18
+ @driver ||= Savon::Client.new do |client|
19
+ client.endpoint endpoint.to_s
20
+ client.namespace "http://api.oas.tfsm.com/"
21
+ client.namespace_identifier :n1
22
+ client.convert_request_keys_to :camelcase
23
+ client.log false
24
+ end
25
+ end
26
+
27
+ def request(msg)
28
+ doc = msg.respond_to?(:to_xml) ? msg.to_xml : msg
29
+ res = driver.call :oas_xml_request, message: Hash["String_1", account.to_s, "String_2", username.to_s, "String_3", password.to_s, "String_4", doc.to_s]
30
+ OAS::Response.new(res.body[:oas_xml_request_response][:result])
31
+ rescue Savon::SOAPFault => e
32
+ raise e.to_hash[:fault][:faultstring]
33
+ rescue Savon::HTTPError => e
34
+ raise "Something went wrong. HTTP #{e.http.code}"
35
+ rescue Savon::InvalidResponseError
36
+ raise "Invalid server response"
37
+ end
38
+ end
39
+ end
@@ -1,45 +1,45 @@
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].freeze
9
-
10
- # The endpoint that will be used to connect if none is set
11
- DEFAULT_ENDPOINT = "https://oas.realmediadigital.com/oasapi/OaxApi?wsdl".freeze
12
-
13
- # The account that will be used to connect if none is set
14
- DEFAULT_ACCOUNT = "OasDefault"
15
-
16
- # By default, don't set a username
17
- DEFAULT_USERNAME = nil
18
-
19
- # By default, don't set a password
20
- DEFAULT_PASSWORD = nil
21
-
22
- attr_accessor *VALID_OPTIONS_KEYS
23
-
24
- def self.extended(base)
25
- base.reset
26
- end
27
-
28
- def configure
29
- yield self if block_given?
30
- end
31
-
32
- def options
33
- options = {}
34
- VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
35
- options
36
- end
37
-
38
- def reset
39
- self.endpoint = DEFAULT_ENDPOINT
40
- self.account = DEFAULT_ACCOUNT
41
- self.username = DEFAULT_USERNAME
42
- self.password = DEFAULT_PASSWORD
43
- end
44
- end
45
- 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].freeze
9
+
10
+ # The endpoint that will be used to connect if none is set
11
+ DEFAULT_ENDPOINT = "https://oas.realmediadigital.com/oasapi/OaxApi".freeze
12
+
13
+ # The account that will be used to connect if none is set
14
+ DEFAULT_ACCOUNT = "OasDefault"
15
+
16
+ # By default, don't set a username
17
+ DEFAULT_USERNAME = nil
18
+
19
+ # By default, don't set a password
20
+ DEFAULT_PASSWORD = nil
21
+
22
+ attr_accessor *VALID_OPTIONS_KEYS
23
+
24
+ def self.extended(base)
25
+ base.reset!
26
+ end
27
+
28
+ def configure
29
+ yield self if block_given?
30
+ end
31
+
32
+ def options
33
+ options = {}
34
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
35
+ options
36
+ end
37
+
38
+ def reset!
39
+ self.endpoint = DEFAULT_ENDPOINT
40
+ self.account = DEFAULT_ACCOUNT
41
+ self.username = DEFAULT_USERNAME
42
+ self.password = DEFAULT_PASSWORD
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
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/lib/oas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Oas
2
- VERSION = "0.1.2"
3
- end
1
+ module OAS
2
+ VERSION = "1.2.0"
3
+ end
data/oas.gemspec CHANGED
@@ -1,29 +1,30 @@
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/ruby-oas"
12
- s.summary = %q{Ruby wrapper for the OAS 7.4 API}
13
- s.description = %q{Ruby wrapper for the OAS 7.4 API}
14
-
15
- s.rubyforge_project = "oas"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
-
22
- s.add_dependency "httpclient", "~> 2.2.0.2"
23
- s.add_dependency "nokogiri", "~> 1.4.4"
24
- s.add_dependency "savon", "~> 0.9.2"
25
-
26
- s.add_development_dependency "rake", "~> 0.9.2.2"
27
- s.add_development_dependency "rspec", "~> 2.5.0"
28
- s.add_development_dependency "webmock", "~> 1.6.2"
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
+
15
+ s.rubyforge_project = "oas"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "httpclient", "~> 2.3"
23
+ s.add_dependency "savon", "~> 2.0"
24
+ s.add_dependency "nori", "~> 2.0"
25
+
26
+ s.add_development_dependency "minitest", "~> 4.3"
27
+ s.add_development_dependency "webmock", "~> 1.9"
28
+ s.add_development_dependency "rake"
29
+ s.add_development_dependency "simplecov"
30
+ end