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/lib/oas/api.rb DELETED
@@ -1,56 +0,0 @@
1
- require 'nokogiri'
2
- require 'httpclient'
3
- require 'savon'
4
-
5
- module Oas
6
- class Api
7
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
8
-
9
- def initialize(options={})
10
- options = Oas.options.merge(options)
11
- Configuration::VALID_OPTIONS_KEYS.each do |key|
12
- send("#{key}=", options[key])
13
- end
14
- end
15
-
16
- def request(request_type, &block)
17
- xml = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
18
- xml.AdXML {
19
- xml.Request(:type => request_type) {
20
- yield(xml) if block_given?
21
- }
22
- }
23
- end
24
- response = webservice.request :n1, :oas_xml_request, :"xmlns:n1" => "http://api.oas.tfsm.com/" do
25
- soap.body = {
26
- "String_1" => account.to_s,
27
- "String_2" => username.to_s,
28
- "String_3" => password.to_s,
29
- "String_4" => xml.to_xml
30
- }
31
- end
32
- response = Hash.from_xml(response.to_hash[:oas_xml_request_response][:result])[:AdXML][:Response]
33
- verify_errors(response)
34
- response
35
- end
36
-
37
- private
38
- def verify_errors(response)
39
- return if ((e = response[:Exception]).nil? && (!response[response.keys.first].is_a?(Hash) || (e = response[response.keys.first][:Exception]).nil?))
40
- error_code = e[:errorCode]
41
- error_msg = e[:content]
42
- case error_code
43
- when 550
44
- raise Oas::InvalidSite.new(error_msg, error_code)
45
- when 551
46
- raise Oas::InvalidPage.new(error_msg, error_code)
47
- else
48
- raise Oas::Error.new(error_msg, error_code)
49
- end
50
- end
51
-
52
- def webservice
53
- @webservice ||= Savon::Client.new(endpoint)
54
- end
55
- end
56
- end
@@ -1,25 +0,0 @@
1
- module Oas
2
- class Client
3
- # Defines methods related to oas campaigns
4
- module Campaigns
5
- def campaign(id)
6
- request("Campaign") do |xml|
7
- xml.Campaign(:action => "read") {
8
- xml.Overview {
9
- xml.Id id
10
- }
11
- }
12
- end
13
- end
14
-
15
- def creative(campaign_id, id)
16
- request("Creative") do |xml|
17
- xml.Creative(:action => "read") {
18
- xml.CampaignId campaign_id
19
- xml.Id id
20
- }
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,96 +0,0 @@
1
- module Oas
2
- class Client
3
- # Defines methods related to oas databases section
4
- module Databases
5
- def advertiser(id)
6
- request("Advertiser") do |xml|
7
- xml.Database(:action => "read") {
8
- xml.Advertiser {
9
- xml.Id id
10
- }
11
- }
12
- end
13
- end
14
-
15
- def agency(id)
16
- request("Agency") do |xml|
17
- xml.Database(:action => "read") {
18
- xml.Agency {
19
- xml.Id id
20
- }
21
- }
22
- end
23
- end
24
-
25
- def campaign_group(id)
26
- request("CampaignGroup") do |xml|
27
- xml.Database(:action => "read") {
28
- xml.CampaignGroup {
29
- xml.Id id
30
- }
31
- }
32
- end
33
- end
34
-
35
- def keyname(name)
36
- request("Keyname") do |xml|
37
- xml.Database(:action => "read") {
38
- xml.Keyname {
39
- xml.Name name
40
- }
41
- }
42
- end
43
- end
44
-
45
- def keyword(id)
46
- request("Keyword") do |xml|
47
- xml.Database(:action => "read") {
48
- xml.Keyword {
49
- xml.Id id
50
- }
51
- }
52
- end
53
- end
54
-
55
- def page(url)
56
- request("Page") do |xml|
57
- xml.Database(:action => "read") {
58
- xml.Page {
59
- xml.Url url
60
- }
61
- }
62
- end
63
- end
64
-
65
- def section(id)
66
- request("Section") do |xml|
67
- xml.Database(:action => "read") {
68
- xml.Section {
69
- xml.Id id
70
- }
71
- }
72
- end
73
- end
74
-
75
- def site(id)
76
- request("Site") do |xml|
77
- xml.Database(:action => "read") {
78
- xml.Site {
79
- xml.Id id
80
- }
81
- }
82
- end
83
- end
84
-
85
- def site_group(id)
86
- request("SiteGroup") do |xml|
87
- xml.Database(:action => "read") {
88
- xml.SiteGroup {
89
- xml.Id id
90
- }
91
- }
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,15 +0,0 @@
1
- module Oas
2
- class Client
3
- # Defines methods related to oas campaigns
4
- module Notifications
5
- def notification(campaign_id, event_name)
6
- request("Notification") do |xml|
7
- xml.Notification(:action => "read") {
8
- xml.CampaignId campaign_id
9
- xml.EventName event_name
10
- }
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,71 +0,0 @@
1
- module Oas
2
- class Client
3
- # Defines methods related to oas reports section
4
- module Reports
5
- class MissingTablesError < Client::Error; end
6
-
7
- def advertiser_report(advertiser_id, report_ids, start_date = nil, end_date = Date.today)
8
- report_request("Advertiser", advertiser_id, report_ids, start_date, end_date)
9
- end
10
-
11
- def campaign_report(campaign_id, report_ids, start_date, end_date = Date.today)
12
- report_request("Campaign", campaign_id, report_ids, start_date, end_date)
13
- end
14
-
15
- def section_report(section_id, report_ids, start_date = nil, end_date = Date.today)
16
- report_request("Section", site_id, report_ids, start_date, end_date)
17
- end
18
-
19
- def site_report(site_id, report_ids, start_date = nil, end_date = Date.today)
20
- report_request("Site", site_id, report_ids, start_date = Date.today, end_date)
21
- end
22
-
23
- def site_performance_report(site_ids = "", start_date = nil, end_date = Date.today)
24
- request("SitePerformanceReport") do |xml|
25
- xml.SitePerformanceReport {
26
- xml.Ids {
27
- site_ids.split(",").each do |s|
28
- xml.Id s
29
- end
30
- }
31
- xml.StartDate start_date
32
- xml.EndDate end_date
33
- xml.Table "Performance.Site.Base.T100.03"
34
- }
35
- end
36
- end
37
-
38
- def page_priority_report(page_url)
39
- request("PagePriorityReport") do |xml|
40
- xml.PagePriorityReport {
41
- xml.Id page_url
42
- xml.Table "Delivery.Page.Base.T100.05"
43
- }
44
- end
45
- end
46
-
47
- def campaign_status_report
48
- request("StatusReport") do |xml|
49
- xml.StatusReport(:type => "Campaign") {
50
- xml.Table "ImpressionCampaignStatusDetail"
51
- }
52
- end
53
- end
54
-
55
- private
56
- def report_request(type, id, report_ids, start_date, end_date)
57
- raise NoReportTablesError.new if report_ids.blank?
58
- request("Report") do |xml|
59
- xml.Report(:type => type) {
60
- xml.Id id
61
- xml.StartDate start_date
62
- xml.EndDate end_date
63
- report_ids.split(",").each do |r|
64
- xml.Table r
65
- end
66
- }
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,16 +0,0 @@
1
- module Oas
2
- class Client
3
- module Utils
4
- private
5
- def build_attributes(xml, attributes = {})
6
- attributes.each do |key,value|
7
- if value.is_a?(Hash)
8
- build_attributes(xml, value)
9
- else
10
- xml.send(key.to_sym, value)
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,57 +0,0 @@
1
- require 'nokogiri'
2
-
3
- class Hash
4
- class << self
5
- def from_xml(xml_io)
6
- result = Nokogiri::XML(xml_io)
7
- return { result.root.name.to_sym => xml_node_to_hash(result.root) }
8
- end
9
-
10
- def xml_node_to_hash(node)
11
- # If we are at the root of the document, start the hash
12
- if node.element?
13
- result_hash = {}
14
- if node.attributes != {}
15
- node.attributes.keys.each do |key|
16
- result_hash[node.attributes[key].name.to_sym] = prepare(node.attributes[key].value)
17
- end
18
- end
19
- if node.children.size > 0
20
- node.children.each do |child|
21
- result = xml_node_to_hash(child)
22
-
23
- if child.name == "text"
24
- unless child.next_sibling || child.previous_sibling
25
- result = prepare(result)
26
- return result if result_hash.empty?
27
- result_hash[:content] = result
28
- return result_hash
29
- end
30
- elsif result_hash[child.name.to_sym]
31
- if result_hash[child.name.to_sym].is_a?(Object::Array)
32
- result_hash[child.name.to_sym] << prepare(result)
33
- else
34
- result_hash[child.name.to_sym] = [result_hash[child.name.to_sym]] << prepare(result)
35
- end
36
- else
37
- result_hash[child.name.to_sym] = prepare(result)
38
- end
39
- end
40
- return result_hash
41
- else
42
- return nil
43
- end
44
- else
45
- return prepare(node.content.to_s)
46
- end
47
- end
48
-
49
- def prepare(data)
50
- (data.class == String && data.to_i.to_s == data) ? data.to_i : data
51
- end
52
- end
53
-
54
- def to_struct(struct_name)
55
- Struct.new(struct_name,*keys).new(*values)
56
- end
57
- end
@@ -1,6 +0,0 @@
1
- class Object
2
- # From activesupport/lib/active_support/core_ext/object/blank.rb, line 12
3
- def blank?
4
- respond_to?(:empty?) ? empty? : !self
5
- end
6
- end
data/lib/oas/error.rb DELETED
@@ -1,17 +0,0 @@
1
- module Oas
2
- # Custom error class for rescuing from all Oas errors
3
- class Error < StandardError
4
- attr_reader :error_code
5
-
6
- def initialize(message, error_code)
7
- @error_code = error_code
8
- super message
9
- end
10
- end
11
-
12
- # Raised when Oas returns the error code 550
13
- class InvalidSite < Error; end
14
-
15
- # Raised when Oas returns the error code 551
16
- class InvalidUrl < Error; end
17
- end
@@ -1,49 +0,0 @@
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>
11
- <Response>
12
- <Advertiser>
13
- <Id>advertiser_id</Id>
14
- <Organization>A Company Name</Organization>
15
- <Notes></Notes>
16
- <ContactFirstName></ContactFirstName>
17
- <ContactLastName></ContactLastName>
18
- <ContactTitle></ContactTitle>
19
- <Email></Email>
20
- <Phone></Phone>
21
- <Fax></Fax>
22
- <ExternalUsers/>
23
- <BillingInformation>
24
- <Method>
25
- <Code>O</Code>
26
- </Method>
27
- <Address>test address2</Address>
28
- <City>Philadelphia</City>
29
- <State>
30
- <Code>US:PA</Code>
31
- </State>
32
- <Country>
33
- <Code>US</Code>
34
- </Country>
35
- <Zip>20007</Zip>
36
- <Email>testmail@247realmeida.com</Email>
37
- </BillingInformation>
38
- <WhoCreated>realmedia</WhoCreated>
39
- <WhenCreated>01/20/2008 20:59:29</WhenCreated>
40
- <WhoModified>realmedia</WhoModified>
41
- <WhenModified>01/20/2008 21:22:33</WhenModified>
42
- </Advertiser>
43
- </Response>
44
- </AdXML>
45
- ]]>
46
- </result>
47
- </ns1:OasXmlRequestResponse>
48
- </soapenv:Body>
49
- </soapenv:Envelope>
@@ -1,49 +0,0 @@
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>
11
- <Response>
12
- <Agency>
13
- <Id>agency_id</Id>
14
- <Organization>A Company Name</Organization>
15
- <Notes>This Agency was added through the API.(With Billing Info)</Notes>
16
- <ContactFirstName>Nobody</ContactFirstName>
17
- <ContactLastName>Kim</ContactLastName>
18
- <ContactTitle>Senior Engineer</ContactTitle>
19
- <Email>nobody@247realmedia.com</Email>
20
- <Phone>123-123-1234</Phone>
21
- <Fax>123-123-1235</Fax>
22
- <ExternalUsers>
23
- <UserId>ExtUser1</UserId>
24
- <UserId>ExtUser2</UserId>
25
- </ExternalUsers>
26
- <BillingInformation>
27
- <Method>
28
- <Code>M</Code>
29
- </Method>
30
- <Address>51-12 BANPO 4-DONG SEOCHO-GU, SEOUL, SOUTH KOREA</Address>
31
- <City>SEOUL</City>
32
- <State>
33
- <Code>KR:SOULTUKPYOLS</Code>
34
- </State>
35
- <Country>
36
- <Code>KR</Code>
37
- </Country>
38
- <Zip>137-802</Zip>
39
- </BillingInformation>
40
- <InternalQuickReport>short</InternalQuickReport>
41
- <ExternalQuickReport>to-date</ExternalQuickReport>
42
- </Agency>
43
- </Response>
44
- </AdXML>
45
- ]]>
46
- </result>
47
- </ns1:OasXmlRequestResponse>
48
- </soapenv:Body>
49
- </soapenv:Envelope>