adtech-api-client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +8 -0
  6. data/Gemfile.lock +42 -0
  7. data/README.md +130 -0
  8. data/adtech-api-client.gemspec +15 -0
  9. data/example/report_by_advertiser +34 -0
  10. data/example/report_by_customer +34 -0
  11. data/example/report_by_network +32 -0
  12. data/example/report_by_website +34 -0
  13. data/lib/adtech/HeliosWSClientSystem/HeliosWSClientSystem.jar +0 -0
  14. data/lib/adtech/HeliosWSClientSystem/lib/activation-1.1.jar +0 -0
  15. data/lib/adtech/HeliosWSClientSystem/lib/aopalliance-1.0.jar +0 -0
  16. data/lib/adtech/HeliosWSClientSystem/lib/asm-3.3.1.jar +0 -0
  17. data/lib/adtech/HeliosWSClientSystem/lib/commons-codec-1.6.jar +0 -0
  18. data/lib/adtech/HeliosWSClientSystem/lib/commons-collections-3.2.1.jar +0 -0
  19. data/lib/adtech/HeliosWSClientSystem/lib/commons-lang-2.4.jar +0 -0
  20. data/lib/adtech/HeliosWSClientSystem/lib/commons-logging-1.1.3.jar +0 -0
  21. data/lib/adtech/HeliosWSClientSystem/lib/cxf-api-2.7.6.jar +0 -0
  22. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-bindings-soap-2.7.6.jar +0 -0
  23. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-bindings-xml-2.7.6.jar +0 -0
  24. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-core-2.7.6.jar +0 -0
  25. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-databinding-jaxb-2.7.6.jar +0 -0
  26. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-frontend-jaxws-2.7.6.jar +0 -0
  27. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-frontend-simple-2.7.6.jar +0 -0
  28. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-transports-http-2.7.6.jar +0 -0
  29. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-transports-http-jetty-2.7.6.jar +0 -0
  30. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-ws-addr-2.7.6.jar +0 -0
  31. data/lib/adtech/HeliosWSClientSystem/lib/cxf-rt-ws-policy-2.7.6.jar +0 -0
  32. data/lib/adtech/HeliosWSClientSystem/lib/cxf-tools-common-2.7.6.jar +0 -0
  33. data/lib/adtech/HeliosWSClientSystem/lib/geronimo-javamail_1.4_spec-1.7.1.jar +0 -0
  34. data/lib/adtech/HeliosWSClientSystem/lib/geronimo-servlet_3.0_spec-1.0.jar +0 -0
  35. data/lib/adtech/HeliosWSClientSystem/lib/httpclient-4.3.3.jar +0 -0
  36. data/lib/adtech/HeliosWSClientSystem/lib/httpcore-4.3.2.jar +0 -0
  37. data/lib/adtech/HeliosWSClientSystem/lib/javax.annotation-api-1.2-b03.jar +0 -0
  38. data/lib/adtech/HeliosWSClientSystem/lib/javax.xml.soap-api-1.3.5.jar +0 -0
  39. data/lib/adtech/HeliosWSClientSystem/lib/jaxb-api-2.1.jar +0 -0
  40. data/lib/adtech/HeliosWSClientSystem/lib/jaxb-impl-2.2.6.jar +0 -0
  41. data/lib/adtech/HeliosWSClientSystem/lib/jaxb-xjc-2.2.6.jar +0 -0
  42. data/lib/adtech/HeliosWSClientSystem/lib/jaxws-api-2.2.11.jar +0 -0
  43. data/lib/adtech/HeliosWSClientSystem/lib/jetty-continuation-8.1.7.v20120910.jar +0 -0
  44. data/lib/adtech/HeliosWSClientSystem/lib/jetty-http-8.1.7.v20120910.jar +0 -0
  45. data/lib/adtech/HeliosWSClientSystem/lib/jetty-io-8.1.7.v20120910.jar +0 -0
  46. data/lib/adtech/HeliosWSClientSystem/lib/jetty-security-8.1.7.v20120910.jar +0 -0
  47. data/lib/adtech/HeliosWSClientSystem/lib/jetty-server-8.1.7.v20120910.jar +0 -0
  48. data/lib/adtech/HeliosWSClientSystem/lib/jetty-util-8.1.7.v20120910.jar +0 -0
  49. data/lib/adtech/HeliosWSClientSystem/lib/jsr181-api-1.0-MR1.jar +0 -0
  50. data/lib/adtech/HeliosWSClientSystem/lib/neethi-3.0.2.jar +0 -0
  51. data/lib/adtech/HeliosWSClientSystem/lib/spring-aop-4.0.3.RELEASE.jar +0 -0
  52. data/lib/adtech/HeliosWSClientSystem/lib/spring-beans-4.0.3.RELEASE.jar +0 -0
  53. data/lib/adtech/HeliosWSClientSystem/lib/spring-context-4.0.3.RELEASE.jar +0 -0
  54. data/lib/adtech/HeliosWSClientSystem/lib/spring-core-4.0.3.RELEASE.jar +0 -0
  55. data/lib/adtech/HeliosWSClientSystem/lib/spring-expression-4.0.3.RELEASE.jar +0 -0
  56. data/lib/adtech/HeliosWSClientSystem/lib/stax-api-1.0-2.jar +0 -0
  57. data/lib/adtech/HeliosWSClientSystem/lib/stax2-api-3.1.1.jar +0 -0
  58. data/lib/adtech/HeliosWSClientSystem/lib/velocity-1.7.jar +0 -0
  59. data/lib/adtech/HeliosWSClientSystem/lib/woodstox-core-asl-4.2.0.jar +0 -0
  60. data/lib/adtech/HeliosWSClientSystem/lib/wsdl4j-1.6.3.jar +0 -0
  61. data/lib/adtech/HeliosWSClientSystem/lib/xml-resolver-1.2.jar +0 -0
  62. data/lib/adtech/HeliosWSClientSystem/lib/xmlschema-core-2.0.3.jar +0 -0
  63. data/lib/adtech/api/admin.rb +29 -0
  64. data/lib/adtech/api/base.rb +23 -0
  65. data/lib/adtech/api/report.rb +152 -0
  66. data/lib/adtech/client.rb +43 -0
  67. data/lib/adtech-api-client.rb +26 -0
  68. data/spec/report_spec.rb +148 -0
  69. data/spec/spec_helper.rb +20 -0
  70. metadata +114 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61e475d1ca3ae838a378b620e0698676e78b26cb
4
+ data.tar.gz: 598ca7019d56a401be026373fd1cc342664307d9
5
+ SHA512:
6
+ metadata.gz: 45c2b8844d65ce24211e3340568bd54b5124cfbc34f6f4e456647e71386c0601c359eb0bd1588f6c7a1090fd92d6a1ff63d4e9db8bf6f0c0fdf88267ef06518a
7
+ data.tar.gz: 8e3f09615da44fafe15c9c38894ef1668c8e7943fe6c240c12ddcd83e033d6d3c569e5f29620ce107046ab88bccad1402ef08234ca9a23604f6faf8152e825f9
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ .bundle
3
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.22
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rspec', '~> 3.0'
7
+ gem 'simplecov', :require => false
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ adtech-api-client (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ docile (1.1.5)
11
+ json (1.8.3)
12
+ json (1.8.3-java)
13
+ rspec (3.4.0)
14
+ rspec-core (~> 3.4.0)
15
+ rspec-expectations (~> 3.4.0)
16
+ rspec-mocks (~> 3.4.0)
17
+ rspec-core (3.4.1)
18
+ rspec-support (~> 3.4.0)
19
+ rspec-expectations (3.4.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.4.0)
22
+ rspec-mocks (3.4.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.4.0)
25
+ rspec-support (3.4.1)
26
+ simplecov (0.11.1)
27
+ docile (~> 1.1.0)
28
+ json (~> 1.8)
29
+ simplecov-html (~> 0.10.0)
30
+ simplecov-html (0.10.0)
31
+
32
+ PLATFORMS
33
+ java
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ adtech-api-client!
38
+ rspec (~> 3.0)
39
+ simplecov
40
+
41
+ BUNDLED WITH
42
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # ADTech API Ruby Client
2
+
3
+ ## Getting Started
4
+
5
+ Install Java (JDK 1.8 Above)
6
+
7
+ ```
8
+ $ brew tap caskroom/cask
9
+ $ brew install brew-cask
10
+ $ brew cask install java
11
+ ```
12
+
13
+ Install JRuby with rbenv
14
+ ```
15
+ $ rbenv install jruby-1.7.22
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile
21
+
22
+ ```
23
+ gem 'adtech-api-client'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ ```
29
+ $ bundle install
30
+ ```
31
+
32
+ ## Tests
33
+ To run tests, please use:
34
+ ```
35
+ env JRUBY_OPTS="--debug -Xcli.debug=true" bundle exec rspec -f d
36
+ ```
37
+ You can see the coverate report with:
38
+ ```
39
+ open coverage/index.html
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ### Basic Usage
45
+
46
+ To use an API, we need to authenticate with the chosen region server with ADTech verified `username` / `password`
47
+ ```
48
+ require 'adtech-api-client'
49
+
50
+ ADTech::Client.region = ADTech::EU_SERVER # Set API server
51
+ ADTech::Client.user = 'tester' # API username
52
+ ADTech::Client.password = 'test' # API password
53
+ ```
54
+
55
+ ### Retrieving report
56
+
57
+ To retrieve a report, create an instance and pass relevant dates / `report_type_id`. `report_type_id` can be found from `Reports` menu in `adtech` portal.
58
+
59
+ ```
60
+ report = ADTech::API::Report.new
61
+ report_type_id = 1285 # Our test report type id by network
62
+ reporting_day = Date.today - 1 # Yesterday
63
+ # Retrieve a report url
64
+ report_url = report.get_report_url(report_type_id,
65
+ reporting_day,
66
+ reporting_day,
67
+ nil)
68
+ opts = {
69
+ encoding: "UTF-8",
70
+ col_sep:';',
71
+ headers: :first_row,
72
+ header_converters: [:symbol],
73
+ converters: [:numeric],
74
+ }
75
+
76
+ # Download the report and display each line
77
+ CSV.new(open(report_url) { |f| f.read }, opts).each do |r|
78
+ puts r.inspect
79
+ end
80
+ ```
81
+
82
+ ### Retrieving object list
83
+
84
+ A list of website
85
+ ```
86
+ # A list of website
87
+ Admin.new.websites
88
+
89
+ # A list of website ids
90
+ Admin.new.website_ids
91
+ ```
92
+ A list of customer
93
+ ```
94
+ # A list of customer
95
+ Admin.new.customers
96
+
97
+ # A list of customer ids
98
+ Admin.new.customer_ids
99
+ ```
100
+
101
+ A list of advertiser
102
+ ```
103
+ # A list of advertiser
104
+ Admin.new.advertisers
105
+
106
+ # A list of advertiser ids
107
+ Admin.new.advertiser_ids
108
+ ```
109
+
110
+ ## Examples
111
+
112
+ Examples can be found in the `example` directory.
113
+
114
+
115
+ ## Coding standard
116
+
117
+ This project has been following [Factory Media Ruby Standard](https://github.com/factorymedia/standards/tree/master/coding-styles/ruby) and [Factory Media Rspec Standard](https://github.com/factorymedia/standards/tree/master/testing/rspec)
118
+
119
+
120
+ ## License
121
+
122
+ (The MIT License)
123
+
124
+ Copyright (c) 2016 Factory Media Ltd
125
+
126
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
127
+
128
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
129
+
130
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ $: << File.expand_path('../lib', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'adtech-api-client'
5
+ s.version = '0.0.2'
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ['minsikzzang', 'ericescalante']
8
+ s.email = ['min.kim@factorymedia.com', 'eric.escalante@factorymedia.com', 'developers@factorymedia.com']
9
+ s.homepage = 'https://github.com/factorymedia/adtech-api-ruby-client'
10
+ s.summary = 'ADTech Classic API ruby client'
11
+ s.description = 'ADTech Classic API ruby client'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.require_paths = ['lib']
15
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'bundler'; Bundler.setup(:default)
6
+ require 'adtech-api-client'
7
+ require 'date'
8
+ require 'open-uri'
9
+ require 'csv'
10
+
11
+ ADTech::Client.region = ADTech::EU_SERVER
12
+ ADTech::Client.user = ''
13
+ ADTech::Client.password = ''
14
+
15
+ report = ADTech::API::Report.new
16
+ report_type_id = 92982 # Our test report type id by advertiser
17
+ # test_advertisers = [1, 2]
18
+ test_advertisers = []
19
+ reporting_day = Date.today - 1
20
+ report_url = report.get_report_url(report_type_id,
21
+ reporting_day,
22
+ reporting_day,
23
+ test_advertisers)
24
+ opts = {
25
+ encoding: "UTF-8",
26
+ col_sep:';',
27
+ headers: :first_row,
28
+ header_converters: [:symbol],
29
+ converters: [:numeric],
30
+ }
31
+
32
+ CSV.new(open(report_url) { |f| f.read }, opts).each do |r|
33
+ puts r.inspect
34
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'bundler'; Bundler.setup(:default)
6
+ require 'adtech-api-client'
7
+ require 'date'
8
+ require 'open-uri'
9
+ require 'csv'
10
+
11
+ ADTech::Client.region = ADTech::EU_SERVER
12
+ ADTech::Client.user = ''
13
+ ADTech::Client.password = ''
14
+
15
+ report = ADTech::API::Report.new
16
+ report_type_id = 32 # Our test report type id by customer
17
+ # test_customers = [1, 2]
18
+ test_customers = []
19
+ reporting_day = Date.today - 1
20
+ report_url = report.get_report_url(report_type_id,
21
+ reporting_day,
22
+ reporting_day,
23
+ test_customers)
24
+ opts = {
25
+ encoding: "UTF-8",
26
+ col_sep:';',
27
+ headers: :first_row,
28
+ header_converters: [:symbol],
29
+ converters: [:numeric],
30
+ }
31
+
32
+ CSV.new(open(report_url) { |f| f.read }, opts).each do |r|
33
+ puts r.inspect
34
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'bundler'; Bundler.setup(:default)
6
+ require 'adtech-api-client'
7
+ require 'date'
8
+ require 'open-uri'
9
+ require 'csv'
10
+
11
+ ADTech::Client.region = ADTech::EU_SERVER
12
+ ADTech::Client.user = ''
13
+ ADTech::Client.password = ''
14
+
15
+ report = ADTech::API::Report.new
16
+ report_type_id = 1285 # Our test report type id by network
17
+ reporting_day = Date.today - 1
18
+ report_url = report.get_report_url(report_type_id,
19
+ reporting_day,
20
+ reporting_day,
21
+ nil)
22
+ opts = {
23
+ encoding: "UTF-8",
24
+ col_sep:';',
25
+ headers: :first_row,
26
+ header_converters: [:symbol],
27
+ converters: [:numeric],
28
+ }
29
+
30
+ CSV.new(open(report_url) { |f| f.read }, opts).each do |r|
31
+ puts r.inspect
32
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'bundler'; Bundler.setup(:default)
6
+ require 'adtech-api-client'
7
+ require 'date'
8
+ require 'open-uri'
9
+ require 'csv'
10
+
11
+ ADTech::Client.region = ADTech::EU_SERVER
12
+ ADTech::Client.user = ''
13
+ ADTech::Client.password = ''
14
+
15
+ report = ADTech::API::Report.new
16
+ report_type_id = 1293 # Our test report type id by website, also 240
17
+ # testing_sites = [1185844, 1185854] <- to specify websites
18
+ testing_sites = [] # or nil for entire websites
19
+ reporting_day = Date.today - 1
20
+ report_url = report.get_report_url(report_type_id,
21
+ reporting_day,
22
+ reporting_day,
23
+ testing_sites)
24
+ opts = {
25
+ encoding: "UTF-8",
26
+ col_sep:';',
27
+ headers: :first_row,
28
+ header_converters: [:symbol],
29
+ converters: [:numeric],
30
+ }
31
+
32
+ CSV.new(open(report_url) { |f| f.read }, opts).each do |r|
33
+ puts r.inspect
34
+ end
@@ -0,0 +1,29 @@
1
+ module ADTech
2
+ module API
3
+ class Admin < Base
4
+ def website_ids(size = 9999)
5
+ websites(size).map { |website| website.getId }
6
+ end
7
+
8
+ def websites(size)
9
+ website_service.getWebsiteList(0, size, nil, nil)
10
+ end
11
+
12
+ def advertiser_ids(size = 9999)
13
+ advertisers(size).map { |advertiser| advertiser.getId }
14
+ end
15
+
16
+ def advertisers(size)
17
+ customer_service.getAdvertiserList(0, size, nil, nil)
18
+ end
19
+
20
+ def customer_ids(size = 9999)
21
+ customers(size).map { |customer| customer.getId }
22
+ end
23
+
24
+ def customers(size)
25
+ customer_service.getCustomerList(0, size, nil, nil)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module ADTech
2
+ module API
3
+ class Base
4
+ extend Forwardable
5
+
6
+ def_delegators :client, :reportService
7
+ def_delegators :client, :websiteService
8
+ def_delegators :client, :customerService
9
+
10
+ alias_method :report_service, :reportService
11
+ alias_method :website_service, :websiteService
12
+ alias_method :customer_service, :customerService
13
+
14
+ def initialize(client = nil)
15
+ @client = client if client
16
+ end
17
+
18
+ def client
19
+ @client ||= ADTech::Client.new.helios
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,152 @@
1
+ import 'java.util.Calendar'
2
+ import 'java.util.GregorianCalendar'
3
+
4
+ module ADTech
5
+ module API
6
+ class Report < Base
7
+ def get_report_url(report_type_id, start_date, end_date, entities)
8
+ report = report_service.getReportById(report_type_id)
9
+
10
+ ADTech.logger.info "Your report (#{report_type_id}) is of entity type: \
11
+ #{report.getEntityType} and report category: #{report.getReportCategory}"
12
+
13
+ start_cal = gregorian_calendar(start_date.year,
14
+ start_date.month - 1,
15
+ start_date.day,
16
+ 0, 0, 0)
17
+ ADTech.logger.info "Report start date set to: #{start_cal.getTime}";
18
+
19
+ end_cal = gregorian_calendar(end_date.year,
20
+ end_date.month - 1,
21
+ end_date.day,
22
+ 23, 59, 59)
23
+ ADTech.logger.info "Report end date set to: #{end_cal.getTime}";
24
+
25
+ entities = default_entities(report.getReportCategory) if !entities || entities.empty?
26
+
27
+ if entities
28
+ report_queue_entry = report_service.requestReportByEntities(
29
+ report_type_id,
30
+ start_cal.getTime,
31
+ end_cal.getTime,
32
+ report_entity(report.getEntityType),
33
+ report_category(report.getReportCategory),
34
+ entities
35
+ )
36
+ else
37
+ report_queue_entry = report_service.requestReport(
38
+ report_type_id,
39
+ start_cal.getTime,
40
+ end_cal.getTime
41
+ )
42
+ end
43
+
44
+ report_download_url(System.getProperty('line.separator'),
45
+ 'csv',
46
+ report_queue_entry)
47
+ end
48
+
49
+ def report_download_url(line_sep, extension, report_queue_entry)
50
+ ADTech.logger.info 'Start polling for report...'
51
+ report_url = ''
52
+
53
+ while (true)
54
+ report_queue_entry =
55
+ report_service.getReportQueueEntryById(report_queue_entry.getId())
56
+
57
+ status = ''
58
+ case report_queue_entry.getState()
59
+ when IReportQueueEntry::STATE_ENTERED
60
+ status = 'ENTERED'
61
+ when IReportQueueEntry::STATE_BUSY
62
+ status = 'BUSY'
63
+ when IReportQueueEntry::STATE_FINISHED
64
+ status = 'FINISHED'
65
+ when IReportQueueEntry::STATE_DELETED
66
+ status = 'DELETED'
67
+ when IReportQueueEntry::STATE_FAILED
68
+ status = 'FAILED'
69
+ end
70
+
71
+ if report_queue_entry.getState() == IReportQueueEntry::STATE_DELETED ||
72
+ report_queue_entry.getState() == IReportQueueEntry::STATE_FAILED
73
+ ADTech.logger.error "Report state is: #{status}"
74
+ ADTech.logger.info 'Exiting...'
75
+ break
76
+ elsif report_queue_entry.getState() == IReportQueueEntry::STATE_FINISHED
77
+ ADTech.logger.debug "Report state: #{status}"
78
+ report_url = "#{report_queue_entry.getResultURL()}&format=#{extension}"
79
+ ADTech.logger.info "ResultURL: '#{report_url}'"
80
+ break
81
+ end
82
+
83
+ # ADTech API sample code recommends this sleep never set below 10s
84
+ sleep(10)
85
+ end
86
+
87
+ report_url
88
+ end
89
+
90
+ private
91
+
92
+ def default_entities(category)
93
+ entities = case category
94
+ when 'website'
95
+ Admin.new(client).website_ids
96
+ when 'customer'
97
+ Admin.new(client).customer_ids
98
+ when 'advertiser'
99
+ Admin.new(client).advertiser_ids
100
+ end
101
+ end
102
+
103
+ def gregorian_calendar(year, month, day, hour, minute, second)
104
+ cal = GregorianCalendar.getInstance()
105
+ cal.set(Calendar::DAY_OF_MONTH, day)
106
+ cal.set(Calendar::MONTH, month)
107
+ cal.set(Calendar::YEAR, year)
108
+ cal.set(Calendar::HOUR, hour)
109
+ cal.set(Calendar::MINUTE, minute)
110
+ cal.set(Calendar::SECOND, second)
111
+ cal
112
+ end
113
+
114
+ def report_entity(entity)
115
+ case entity
116
+ when 'advertiser'
117
+ IReport::REPORT_ENTITY_TYPE_ADVERTISER
118
+ when 'customer'
119
+ IReport::REPORT_ENTITY_TYPE_CUSTOMER
120
+ when 'campaign'
121
+ IReport::REPORT_ENTITY_TYPE_CAMPAIGN
122
+ when 'mastercampaign'
123
+ IReport::REPORT_ENTITY_TYPE_MASTERCAMPAIGN
124
+ when 'network'
125
+ IReport::REPORT_ENTITY_TYPE_NETWORK
126
+ when 'website'
127
+ IReport::REPORT_ENTITY_TYPE_WEBSITE
128
+ end
129
+
130
+ end
131
+
132
+ def report_category(category)
133
+ case category
134
+ when 'campaign'
135
+ IReport::REPORT_CATEGORY_CAMPAIGN
136
+ when 'website'
137
+ IReport::REPORT_CATEGORY_WEBSITE
138
+ when 'page'
139
+ IReport::REPORT_CATEGORY_PAGE
140
+ when 'placement'
141
+ IReport::REPORT_CATEGORY_PLACEMENT
142
+ when 'customer'
143
+ IReport::REPORT_CATEGORY_CUSTOMER
144
+ when 'advertiser'
145
+ IReport::REPORT_CATEGORY_ADVERTISER
146
+ when 'bannersize'
147
+ IReport::REPORT_CATEGORY_BANNERSIZE
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,43 @@
1
+ java_package 'de.adtech.helios'
2
+ import 'de.adtech.helios.ReportManagement.Report'
3
+ import 'de.adtech.helios.ReportManagement.ReportQueueEntry'
4
+ import 'de.adtech.helios.ReportManagement.ReportAccessSettings'
5
+ import 'de.adtech.helios.NetworkManagement.NetworkInfo'
6
+ import 'de.adtech.webservices.helios.client.HeliosWSClientSystem'
7
+ import 'de.adtech.webservices.helios.client.auth.AuthenticationType'
8
+ import 'de.adtech.webservices.helios.lowLevel.constants.IReportAccessSettings'
9
+ import 'de.adtech.webservices.helios.lowLevel.constants.IReportQueueEntry'
10
+ import 'de.adtech.webservices.helios.lowLevel.constants.IReport'
11
+
12
+ module ADTech
13
+ EU_SERVER = 'https://ws-api.adtech.de'
14
+ US_SERVER = 'https://ws-api.adtechus.com'
15
+
16
+ class Client
17
+ attr_reader :helios
18
+ attr_accessor :verbose
19
+ attr_accessor :region
20
+
21
+ class << self
22
+ attr_accessor :region
23
+ attr_accessor :user
24
+ attr_accessor :password
25
+ end
26
+
27
+ def initialize
28
+ @helios = HeliosWSClientSystem.new
29
+ @helios.initServices(api_server_url,
30
+ Dir::tmpdir(),
31
+ Client.user,
32
+ Client.password,
33
+ AuthenticationType::SSO);
34
+ end
35
+
36
+ private
37
+
38
+ def api_server_url
39
+ return EU_SERVER unless Client.region
40
+ Client.region
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ require 'java'
2
+ require 'logger'
3
+
4
+ java_import java.lang.System
5
+ System.setProperty('http.nonProxyHosts', '')
6
+
7
+ $CLASSPATH << "adtech/HeliosWSClientSystem"
8
+ $CLASSPATH << "adtech/HeliosWSClientSystem/lib"
9
+
10
+ PROG_NAME = 'ADTechAPIClient'
11
+
12
+ module ADTech
13
+ class << self
14
+ attr_writer :logger
15
+
16
+ def logger
17
+ @logger ||= Logger.new($stdout).tap { |log| log.progname = PROG_NAME }
18
+ end
19
+ end
20
+ end
21
+
22
+ require "adtech/HeliosWSClientSystem/HeliosWSClientSystem"
23
+ require 'adtech/client'
24
+ require 'adtech/api/base'
25
+ require 'adtech/api/admin'
26
+ require 'adtech/api/report'
@@ -0,0 +1,148 @@
1
+ describe ADTech::API::Report do
2
+ before do
3
+ ADTech::Client.region = ADTech::EU_SERVER
4
+ ADTech::Client.user = ''
5
+ ADTech::Client.password = ''
6
+ @report = ADTech::API::Report.new
7
+ end
8
+
9
+ describe '.get_report_url' do
10
+ context 'when missing parameters' do
11
+ it 'raises ArgumentError if report type is missing' do
12
+ start_date = Date.today - 1
13
+ end_date = Date.today - 2
14
+ testing_sites = [1185844]
15
+ expect {
16
+ @report.get_report_url(start_date, end_date, testing_sites)
17
+ }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it 'raises ArgumentError if start date is missing' do
21
+ report_type_id = 1293
22
+ testing_sites = [1185844]
23
+ end_date = Date.today - 2
24
+ expect {
25
+ @report.get_report_url(report_type_id, end_date, testing_sites)
26
+ }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it 'raises ArgumentError if end date is missing' do
30
+ report_type_id = 1293
31
+ testing_sites = [1185844]
32
+ start_date = Date.today - 1
33
+ expect {
34
+ @report.get_report_url(report_type_id, start_date, testing_sites)
35
+ }.to raise_error(ArgumentError)
36
+ end
37
+
38
+ it 'raises ArgumentError if testing sites are missing' do
39
+ report_type_id = 1293
40
+ start_date = Date.today - 1
41
+ end_date = Date.today - 2
42
+ expect {
43
+ @report.get_report_url(report_type_id, start_date, end_date)
44
+ }.to raise_error(ArgumentError)
45
+ end
46
+ end
47
+
48
+ context 'when invoking get_report url correctly' do
49
+ before do
50
+ @report_double = double('report',
51
+ :getEntityType => 'test',
52
+ :getReportCategory => 'test'
53
+ )
54
+ @service_double = double('report_service',
55
+ :getReportById => @report_double,
56
+ :requestReportByEntities => '',
57
+ :requestReport => '',
58
+ )
59
+ allow(@report).to receive(:report_service) { @service_double }
60
+ allow(@report).to receive(:report_download_url) { true }
61
+ end
62
+
63
+ it 'calls requestReportByEntities if entities are present' do
64
+ report_type_id = 1293
65
+ testing_sites = [1185844]
66
+ reporting_day = Date.today - 1
67
+ expect(@service_double).to receive(:requestReportByEntities)
68
+ report_url = @report.get_report_url(report_type_id,
69
+ reporting_day,
70
+ reporting_day,
71
+ testing_sites)
72
+ end
73
+
74
+ it 'calls requestReport if no entities are present' do
75
+ report_type_id = 1293
76
+ testing_sites = nil
77
+ reporting_day = Date.today - 1
78
+ expect(@service_double).to receive(:requestReport)
79
+ report_url = @report.get_report_url(report_type_id,
80
+ reporting_day,
81
+ reporting_day,
82
+ testing_sites)
83
+ end
84
+ end
85
+ end
86
+
87
+ describe '.report_download_url' do
88
+ context 'when invoked with missing parameters' do
89
+ it 'raises ArgumentError when missing line separator' do
90
+ expect{
91
+ @report.report_download_url()
92
+ }.to raise_error(ArgumentError)
93
+ end
94
+ end
95
+
96
+ context 'when ivoked with all parameters' do
97
+ before do
98
+ @report_entry = double('report_queue_entry',
99
+ :getId => '123'
100
+ )
101
+ end
102
+
103
+ it 'pools AdTech every 10 seconds' do
104
+ entry_double = double('entry',
105
+ :getState => IReportQueueEntry::STATE_BUSY,
106
+ :getId => '123'
107
+ )
108
+ service_double = double('report_service',
109
+ :getReportQueueEntryById => entry_double
110
+ )
111
+ allow(@report).to receive(:report_service) { service_double }
112
+ allow(@report).to receive(:sleep) { true }
113
+ thread = Thread.new do
114
+ expect(@report).to receive(:sleep).with(10)
115
+ @report.report_download_url(nil, nil, @report_entry)
116
+ end
117
+ sleep(1)
118
+ thread.kill
119
+ end
120
+
121
+ it 'returns url once AdTech responds with finished state' do
122
+ entry_double = double('entry',
123
+ :getState => IReportQueueEntry::STATE_FINISHED,
124
+ :getResultURL => 'http://test/report-url'
125
+ )
126
+ service_double = double('report_service',
127
+ :getReportQueueEntryById => entry_double
128
+ )
129
+ allow(@report).to receive(:report_service) { service_double }
130
+ result_url = @report.report_download_url(nil, nil, @report_entry)
131
+ expect(result_url).to eq('http://test/report-url&format=')
132
+ end
133
+
134
+ it 'returns empty url once AdTech responds with failed state' do
135
+ entry_double = double('entry',
136
+ :getState => IReportQueueEntry::STATE_FAILED,
137
+ :getResultURL => 'http://test/report-url'
138
+ )
139
+ service_double = double('report_service',
140
+ :getReportQueueEntryById => entry_double
141
+ )
142
+ allow(@report).to receive(:report_service) { service_double }
143
+ result_url = @report.report_download_url(nil, nil, @report_entry)
144
+ expect(result_url).to eq('')
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,20 @@
1
+ require 'simplecov'
2
+ require 'adtech-api-client'
3
+ require 'date'
4
+
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
8
+ Dir['lib/*.rb', 'lib/adtech/api/*.rb'].each {|file| load file }
9
+
10
+ RSpec.configure do |config|
11
+ config.filter_run focus: true
12
+ config.run_all_when_everything_filtered = true
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
15
+ end
16
+
17
+ config.mock_with :rspec do |mocks|
18
+ mocks.verify_partial_doubles = true
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adtech-api-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - minsikzzang
8
+ - ericescalante
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-01-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ADTech Classic API ruby client
15
+ email:
16
+ - min.kim@factorymedia.com
17
+ - eric.escalante@factorymedia.com
18
+ - developers@factorymedia.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - .rspec
25
+ - .ruby-version
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - README.md
29
+ - adtech-api-client.gemspec
30
+ - example/report_by_advertiser
31
+ - example/report_by_customer
32
+ - example/report_by_network
33
+ - example/report_by_website
34
+ - lib/adtech-api-client.rb
35
+ - lib/adtech/HeliosWSClientSystem/HeliosWSClientSystem.jar
36
+ - lib/adtech/HeliosWSClientSystem/lib/activation-1.1.jar
37
+ - lib/adtech/HeliosWSClientSystem/lib/aopalliance-1.0.jar
38
+ - lib/adtech/HeliosWSClientSystem/lib/asm-3.3.1.jar
39
+ - lib/adtech/HeliosWSClientSystem/lib/commons-codec-1.6.jar
40
+ - lib/adtech/HeliosWSClientSystem/lib/commons-collections-3.2.1.jar
41
+ - lib/adtech/HeliosWSClientSystem/lib/commons-lang-2.4.jar
42
+ - lib/adtech/HeliosWSClientSystem/lib/commons-logging-1.1.3.jar
43
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-api-2.7.6.jar
44
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-bindings-soap-2.7.6.jar
45
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-bindings-xml-2.7.6.jar
46
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-core-2.7.6.jar
47
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-databinding-jaxb-2.7.6.jar
48
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-frontend-jaxws-2.7.6.jar
49
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-frontend-simple-2.7.6.jar
50
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-transports-http-2.7.6.jar
51
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-transports-http-jetty-2.7.6.jar
52
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-ws-addr-2.7.6.jar
53
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-rt-ws-policy-2.7.6.jar
54
+ - lib/adtech/HeliosWSClientSystem/lib/cxf-tools-common-2.7.6.jar
55
+ - lib/adtech/HeliosWSClientSystem/lib/geronimo-javamail_1.4_spec-1.7.1.jar
56
+ - lib/adtech/HeliosWSClientSystem/lib/geronimo-servlet_3.0_spec-1.0.jar
57
+ - lib/adtech/HeliosWSClientSystem/lib/httpclient-4.3.3.jar
58
+ - lib/adtech/HeliosWSClientSystem/lib/httpcore-4.3.2.jar
59
+ - lib/adtech/HeliosWSClientSystem/lib/javax.annotation-api-1.2-b03.jar
60
+ - lib/adtech/HeliosWSClientSystem/lib/javax.xml.soap-api-1.3.5.jar
61
+ - lib/adtech/HeliosWSClientSystem/lib/jaxb-api-2.1.jar
62
+ - lib/adtech/HeliosWSClientSystem/lib/jaxb-impl-2.2.6.jar
63
+ - lib/adtech/HeliosWSClientSystem/lib/jaxb-xjc-2.2.6.jar
64
+ - lib/adtech/HeliosWSClientSystem/lib/jaxws-api-2.2.11.jar
65
+ - lib/adtech/HeliosWSClientSystem/lib/jetty-continuation-8.1.7.v20120910.jar
66
+ - lib/adtech/HeliosWSClientSystem/lib/jetty-http-8.1.7.v20120910.jar
67
+ - lib/adtech/HeliosWSClientSystem/lib/jetty-io-8.1.7.v20120910.jar
68
+ - lib/adtech/HeliosWSClientSystem/lib/jetty-security-8.1.7.v20120910.jar
69
+ - lib/adtech/HeliosWSClientSystem/lib/jetty-server-8.1.7.v20120910.jar
70
+ - lib/adtech/HeliosWSClientSystem/lib/jetty-util-8.1.7.v20120910.jar
71
+ - lib/adtech/HeliosWSClientSystem/lib/jsr181-api-1.0-MR1.jar
72
+ - lib/adtech/HeliosWSClientSystem/lib/neethi-3.0.2.jar
73
+ - lib/adtech/HeliosWSClientSystem/lib/spring-aop-4.0.3.RELEASE.jar
74
+ - lib/adtech/HeliosWSClientSystem/lib/spring-beans-4.0.3.RELEASE.jar
75
+ - lib/adtech/HeliosWSClientSystem/lib/spring-context-4.0.3.RELEASE.jar
76
+ - lib/adtech/HeliosWSClientSystem/lib/spring-core-4.0.3.RELEASE.jar
77
+ - lib/adtech/HeliosWSClientSystem/lib/spring-expression-4.0.3.RELEASE.jar
78
+ - lib/adtech/HeliosWSClientSystem/lib/stax-api-1.0-2.jar
79
+ - lib/adtech/HeliosWSClientSystem/lib/stax2-api-3.1.1.jar
80
+ - lib/adtech/HeliosWSClientSystem/lib/velocity-1.7.jar
81
+ - lib/adtech/HeliosWSClientSystem/lib/woodstox-core-asl-4.2.0.jar
82
+ - lib/adtech/HeliosWSClientSystem/lib/wsdl4j-1.6.3.jar
83
+ - lib/adtech/HeliosWSClientSystem/lib/xml-resolver-1.2.jar
84
+ - lib/adtech/HeliosWSClientSystem/lib/xmlschema-core-2.0.3.jar
85
+ - lib/adtech/api/admin.rb
86
+ - lib/adtech/api/base.rb
87
+ - lib/adtech/api/report.rb
88
+ - lib/adtech/client.rb
89
+ - spec/report_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/factorymedia/adtech-api-ruby-client
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.8
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: ADTech Classic API ruby client
114
+ test_files: []