adroller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ module AdRoll
2
+ module Api
3
+ class Campaign < AdRoll::Api::Service
4
+ class << self
5
+ def create(advertisable:, budget:, is_retargeting: nil, is_fbx_newsfeed: nil,
6
+ adgroups: nil, cpc: nil, cpm: nil, start_date: nil, end_date: nil,
7
+ name: nil, status: nil, max_cpm: nil, networks: nil)
8
+
9
+ params = {
10
+ advertisable: advertisable,
11
+ budget: budget,
12
+ is_retargeting: is_retargeting,
13
+ is_fbx_newsfeed: is_fbx_newsfeed,
14
+ adgroups: adgroups,
15
+ cpc: cpc,
16
+ cpm: cpm,
17
+ start_date: start_date,
18
+ end_date: end_date,
19
+ name: name,
20
+ status: status,
21
+ max_cpm: max_cpm,
22
+ networks: networks
23
+ }.reject { |_, value| value.nil? }
24
+
25
+ call_api(:post, __method__, params)
26
+ end
27
+
28
+ def edit(campaign:, budget: nil, is_retargeting: nil,
29
+ cpc: nil, cpm: nil, start_date: nil, end_date: nil,
30
+ name: nil)
31
+
32
+ params = {
33
+ campaign: campaign,
34
+ budget: budget,
35
+ is_retargeting: is_retargeting,
36
+ cpc: cpc,
37
+ cpm: cpm,
38
+ start_date: start_date,
39
+ end_date: end_date,
40
+ name: name
41
+ }.reject { |_, value| value.nil? }
42
+
43
+ call_api(:put, __method__, params)
44
+ end
45
+
46
+ def get(campaign:)
47
+ params = {
48
+ campaign: campaign
49
+ }.reject { |_, value| value.nil? }
50
+
51
+ call_api(:get, __method__, params)
52
+ end
53
+
54
+ def get_adgroups(campaign:)
55
+ params = {
56
+ campaign: campaign
57
+ }.reject { |_, value| value.nil? }
58
+
59
+ call_api(:get, __method__, params)
60
+ end
61
+
62
+ def get_ip_range_exclusions(campaign:)
63
+ params = {
64
+ campaign: campaign
65
+ }.reject { |_, value| value.nil? }
66
+
67
+ call_api(:get, __method__, params)
68
+ end
69
+
70
+ def pause(campaign:)
71
+ params = {
72
+ campaign: campaign
73
+ }.reject { |_, value| value.nil? }
74
+
75
+ call_api(:get, __method__, params)
76
+ end
77
+
78
+ def pause_ads(campaign:, ads:)
79
+ params = {
80
+ campaign: campaign,
81
+ ads: ads
82
+ }.reject { |_, value| value.nil? }
83
+
84
+ call_api(:get, __method__, params)
85
+ end
86
+
87
+ def unpause(campaign:)
88
+ params = {
89
+ campaign: campaign
90
+ }.reject { |_, value| value.nil? }
91
+
92
+ call_api(:get, __method__, params)
93
+ end
94
+
95
+ def unpause_ads(campaign:, ads:)
96
+ params = {
97
+ campaign: campaign,
98
+ ads: ads
99
+ }.reject { |_, value| value.nil? }
100
+
101
+ call_api(:get, __method__, params)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,8 @@
1
+ require 'adroll/service'
2
+
3
+ module AdRoll
4
+ module Api
5
+ class Event < Service
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module AdRoll
2
+ module Api
3
+ class Invoice < AdRoll::Api::Service
4
+ class << self
5
+ def get(invoice:)
6
+ params = {
7
+ invoice: invoice
8
+ }.reject { |_, value| value.nil? }
9
+
10
+ call_api(:get, __method__, params)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,69 @@
1
+ module AdRoll
2
+ module Api
3
+ class MobileApp < AdRoll::Api::Service
4
+ class << self
5
+ def create(pixel:, app_name:, os:, app_identifier:, source_type:, source_variant:,
6
+ verbosity:, mission_elapsed_event_name:, mission_elapsed_time_threshold:)
7
+
8
+ params = {
9
+ pixel: pixel,
10
+ app_name: app_name,
11
+ os: os,
12
+ app_identifier: app_indentifier,
13
+ source_type: source_type,
14
+ source_variant: source_variant,
15
+ verbosity: verbosity,
16
+ mission_elapsed_event_name: mission_elapsed_event_name,
17
+ mission_elapsed_time_threshold: mission_elapsed_time_threshold
18
+ }.reject { |_, value| value.nil? }
19
+
20
+ call_api(:post, __method__, params)
21
+ end
22
+
23
+ def delete(mobile_app:)
24
+ params = {
25
+ mobile_app: mobile_app
26
+ }.reject { |_, value| value.nil? }
27
+
28
+ call_api(:delete, __method__, params)
29
+ end
30
+
31
+ def edit(mobile_app:, app_name:, os:, app_identifier:, source_type:, source_variant:,
32
+ verbosity:, mission_elapsed_event_name:, mission_elapsed_time_threshold:)
33
+
34
+ params = {
35
+ mobile_app: mobile_app,
36
+ app_name: app_name,
37
+ os: os,
38
+ app_identifier: app_indentifier,
39
+ source_type: source_type,
40
+ source_variant: source_variant,
41
+ verbosity: verbosity,
42
+ mission_elapsed_event_name: mission_elapsed_event_name,
43
+ mission_elapsed_time_threshold: mission_elapsed_time_threshold
44
+ }.reject { |_, value| value.nil? }
45
+
46
+ call_api(:put, __method__, params)
47
+ end
48
+
49
+ def get(mobile_app:, pixel:, eid:, app_name:, os:, app_identifier:, source_type:, source_variant:,
50
+ configuration:)
51
+
52
+ params = {
53
+ mobile_app: mobile_app,
54
+ pixel: pixel,
55
+ eid: eid,
56
+ app_name: app_name,
57
+ os: os,
58
+ app_identifier: app_indentifier,
59
+ source_type: source_type,
60
+ source_variant: source_variant,
61
+ configuration: configuration
62
+ }.reject { |_, value| value.nil? }
63
+
64
+ call_api(:get, __method__, params)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+
2
+ module AdRoll
3
+ module Api
4
+ class MobileRule < AdRoll::Api::Service
5
+ class << self
6
+ def edit(rule:, app_identifier:, event:, os:, device_type:)
7
+ params = {
8
+ rule: rule,
9
+ app_identifier: app_identifier,
10
+ event: event,
11
+ os: os,
12
+ device_type: device_type
13
+ }.reject { |_, value| value.nil? }
14
+
15
+ call_api(:put, __method__, params)
16
+ end
17
+
18
+ def get(rule:, pixel:, os:, device_type:, app_identifier:, event:, name:)
19
+ params = {
20
+ rule: rule,
21
+ pixel: pixel,
22
+ os: os,
23
+ device_type: device_type,
24
+ app_identifier: app_identifier,
25
+ event: event,
26
+ name: name
27
+ }.reject { |_, value| value.nil? }
28
+
29
+ call_api(:get, __method__, params)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,47 @@
1
+ module AdRoll
2
+ module Api
3
+ class Organization < AdRoll::Api::Service
4
+ class << self
5
+ def get(organization: nil)
6
+ params = {
7
+ organization: organization
8
+ }
9
+
10
+ call_api(:get, __method__, params)
11
+ end
12
+
13
+ def get_advertisables(organization: nil)
14
+ params = {
15
+ organization: organization
16
+ }
17
+
18
+ call_api(:get, __method__, params)
19
+ end
20
+
21
+ def get_billing_methods(organization: nil)
22
+ params = {
23
+ organization: organization
24
+ }
25
+
26
+ call_api(:get, __method__, params)
27
+ end
28
+
29
+ def get_users(organization: nil)
30
+ params = {
31
+ organization: organization
32
+ }
33
+
34
+ call_api(:get, __method__, params)
35
+ end
36
+
37
+ def reset(organization:)
38
+ params = {
39
+ organization: organization
40
+ }
41
+
42
+ call_api(:get, __method__, params)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ require 'adroll/service'
2
+
3
+ module AdRoll
4
+ module Api
5
+ class PaymentMethod < Service
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,40 @@
1
+ module AdRoll
2
+ module Api
3
+ class Pixel < AdRoll::Api::Service
4
+ class << self
5
+ def get(pixel:)
6
+ params = {
7
+ pixel: pixel
8
+ }.reject { |_, value| value.nil? }
9
+
10
+ call_api(:get, __method__, params)
11
+ end
12
+
13
+ def get_rules(pixel:)
14
+ params = {
15
+ pixel: pixel
16
+ }.reject { |_, value| value.nil? }
17
+
18
+ call_api(:get, __method__, params)
19
+ end
20
+
21
+ def get_segments(pixel:)
22
+ params = {
23
+ pixel: pixel
24
+ }.reject { |_, value| value.nil? }
25
+
26
+ call_api(:get, __method__, params)
27
+ end
28
+
29
+ def reorder_rules(pixel:, rules:)
30
+ params = {
31
+ pixel: pixel,
32
+ rules: rules
33
+ }.reject { |_, value| value.nil? }
34
+
35
+ call_api(:get, __method__, params)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,59 @@
1
+ module AdRoll
2
+ module Api
3
+ class Report < AdRoll::Api::Service
4
+ class << self
5
+ def ad(campaigns: nil, adgroups: nil, ads: nil, advertisables: nil,
6
+ data_format:, past_days: nil, start_date: nil, end_date: nil)
7
+
8
+ params = {
9
+ campaigns: campaigns,
10
+ adgroups: adgroups,
11
+ ads: ads,
12
+ advertisables: advertisables,
13
+ data_format: data_format,
14
+ past_days: past_days,
15
+ start_date: start_date,
16
+ end_date: end_date
17
+ }.reject { |_, value| value.nil? }
18
+
19
+ call_api(:get, __method__, params)
20
+ end
21
+
22
+ def advertisable(campaigns: nil, adgroups: nil, ads: nil, advertisables: nil,
23
+ data_format:, past_days: nil, start_date: nil, end_date: nil)
24
+
25
+ params = {
26
+ campaigns: campaigns,
27
+ adgroups: adgroups,
28
+ ads: ads,
29
+ advertisables: advertisables,
30
+ data_format: data_format,
31
+ past_days: past_days,
32
+ start_date: start_date,
33
+ end_date: end_date
34
+ }.reject { |_, value| value.nil? }
35
+
36
+ call_api(:get, __method__, params)
37
+ end
38
+
39
+ def campaign(campaigns: nil, adgroups: nil, ads: nil, advertisables: nil,
40
+ data_format:, past_days: nil, start_date: nil, end_date: nil, attributions: nil)
41
+
42
+ params = {
43
+ campaigns: campaigns,
44
+ adgroups: adgroups,
45
+ ads: ads,
46
+ advertisables: advertisables,
47
+ data_format: data_format,
48
+ past_days: past_days,
49
+ start_date: start_date,
50
+ end_date: end_date,
51
+ attributions: attributions
52
+ }.reject { |_, value| value.nil? }
53
+
54
+ call_api(:get, __method__, params)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,50 @@
1
+ module AdRoll
2
+ module Api
3
+ class Rule < AdRoll::Api::Service
4
+ class << self
5
+ def create(pixel:, type:, order:, name:, display_name:, pattern:, source:)
6
+ params = {
7
+ pixel: pixel,
8
+ type: type,
9
+ order: order,
10
+ name: name,
11
+ display_name: display_name,
12
+ pattern: pattern,
13
+ source: source
14
+ }.reject { |_, value| value.nil? }
15
+
16
+ call_api(:post, __method__, params)
17
+ end
18
+
19
+ def edit(rule:, order:, name:, display_name:, pattern:, source:)
20
+ params = {
21
+ rule: rule,
22
+ order: order,
23
+ name: name,
24
+ display_name: display_name,
25
+ pattern: pattern,
26
+ source: source
27
+ }.reject { |_, value| value.nil? }
28
+
29
+ call_api(:put, __method__, params)
30
+ end
31
+
32
+ def get(rule:)
33
+ params = {
34
+ rule: rule
35
+ }.reject { |_, value| value.nil? }
36
+
37
+ call_api(:get, __method__, params)
38
+ end
39
+
40
+ def get_segments(rule:)
41
+ params = {
42
+ rule: rule
43
+ }.reject { |_, value| value.nil? }
44
+
45
+ call_api(:get, __method__, params)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,24 @@
1
+ module AdRoll
2
+ module Api
3
+ class Segment < AdRoll::Api::Service
4
+ class << self
5
+ def edit(conversion_value:, duration:)
6
+ params = {
7
+ conversion_value: conversion_value,
8
+ duration: duration
9
+ }.reject { |_, value| value.nil? }
10
+
11
+ call_api(:post, __method__, params)
12
+ end
13
+
14
+ def get(segment:)
15
+ params = {
16
+ segment: segment
17
+ }.reject { |_, value| value.nil? }
18
+
19
+ call_api(:get, __method__, params)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module AdRoll
2
+ module Api
3
+ class Service
4
+ def self.service_url
5
+ File.join(AdRoll::Api.base_url, to_s.demodulize.downcase)
6
+ end
7
+
8
+ def self.basic_auth
9
+ { username: AdRoll::Api.user_name, password: AdRoll::Api.password }
10
+ end
11
+
12
+ def self.call_api(request_method, endpoint, query_params)
13
+ request_uri = File.join(service_url, endpoint.to_s)
14
+
15
+ response = HTTParty.send(request_method, request_uri,
16
+ basic_auth: basic_auth, query: query_params)
17
+
18
+ begin
19
+ JSON.parse(response.body).fetch('results', {})
20
+ rescue JSON::ParserError
21
+ {error: 'JSON::ParserError', response: response.body}
22
+ end
23
+ end
24
+
25
+ private_class_method :service_url, :basic_auth, :call_api
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ module AdRoll
2
+ module Api
3
+ class User < AdRoll::Api::Service
4
+ class << self
5
+ def deactivate(user:)
6
+ params = {
7
+ user: user
8
+ }.reject { |_, value| value.nil? }
9
+
10
+ call_api(:get, __method__, params)
11
+ end
12
+
13
+ def edit(u:, username:, first_name:, last_name:, email_preference_general:,
14
+ email_preference_payment:, email_preference_campaign_notifications:)
15
+ params = {
16
+ u: u,
17
+ username: username,
18
+ first_name: first_name,
19
+ last_name: last_name,
20
+ email_preference_general: email_preference_general,
21
+ email_preference_payment: email_preference_payment,
22
+ email_preference_campaign_notifications: email_preference_campaign_notifications
23
+ }.reject { |_, value| value.nil? }
24
+
25
+ call_api(:put, __method__, params)
26
+ end
27
+
28
+ def get(user:)
29
+ params = {
30
+ user: user
31
+ }.reject { |_, value| value.nil? }
32
+
33
+ call_api(:get, __method__, params)
34
+ end
35
+
36
+ def grant(u:, advertisables:, organization_role:)
37
+ params = {
38
+ u: u,
39
+ advertisables: advertisables,
40
+ organization_role: organization_role
41
+ }.reject { |_, value| value.nil? }
42
+
43
+ call_api(:get, __method__, params)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
data/lib/adroll.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'httparty'
2
+
3
+ Dir[File.dirname(__FILE__) + '/adroll/*.rb'].each do |file|
4
+ require file
5
+ end
6
+
7
+ module AdRoll
8
+ module Api
9
+ def self.user_name
10
+ ENV['ADROLL_USERNAME']
11
+ end
12
+
13
+ def self.password
14
+ ENV['ADROLL_PASSWORD']
15
+ end
16
+
17
+ def self.organization_eid
18
+ ENV['ADROLL_ORGANIZATION_EID']
19
+ end
20
+
21
+ def self.base_url
22
+ 'https://api.adroll.com/v1'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ require 'factory_girl'
2
+
3
+ FactoryGirl.define do
4
+ factory :service, class: 'AdRoll::Api::Service' do
5
+ end
6
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe AdRoll::Api::Ad do
4
+
5
+ let!(:basic_auth) { "#{AdRoll::Api.user_name}:#{AdRoll::Api.password}" }
6
+
7
+ subject { described_class }
8
+
9
+ describe '::clone' do
10
+ let!(:request_uri) { "https://#{basic_auth}@api.adroll.com/v1/ad/clone" }
11
+
12
+ let!(:params) do
13
+ {
14
+ name: 'name',
15
+ headline: 'headline',
16
+ body: 'body'
17
+ }
18
+ end
19
+
20
+ it 'calls the api with the correct params' do
21
+ subject.clone(name: 'name', headline: 'headline', body: 'body')
22
+ expect(WebMock).to have_requested(:post, request_uri).with(query: params)
23
+ end
24
+ end
25
+
26
+ describe '::create' do
27
+ let!(:request_uri) { "https://#{basic_auth}@api.adroll.com/v1/ad/create" }
28
+ let!(:params) do
29
+ { advertisable: 'advertisable',
30
+ file: 'ANBLE5432'
31
+ }
32
+ end
33
+
34
+ it 'calls the api with the correct params' do
35
+ subject.create(advertisable: 'advertisable', file: 'ANBLE5432')
36
+ expect(WebMock).to have_requested(:post, request_uri).with(query: params)
37
+ end
38
+ end
39
+
40
+ describe '::edit' do
41
+ let!(:request_uri) { "https://#{basic_auth}@api.adroll.com/v1/ad/edit" }
42
+ let!(:params) do
43
+ { ad: 'AD123' }
44
+ end
45
+
46
+ it 'calls the api with the correct params' do
47
+ subject.edit(ad: 'AD123')
48
+ expect(WebMock).to have_requested(:put, request_uri).with(query: params)
49
+ end
50
+ end
51
+
52
+ describe '::get' do
53
+ let!(:request_uri) { "https://#{basic_auth}@api.adroll.com/v1/ad/get" }
54
+ let!(:params) do
55
+ { ad: 'AD123' }
56
+ end
57
+
58
+ it 'calls the api with the correct params' do
59
+ subject.get(ad: 'AD123')
60
+ expect(WebMock).to have_requested(:get, request_uri).with(query: params)
61
+ end
62
+ end
63
+
64
+ describe '::set_outline' do
65
+ let!(:request_uri) { "https://#{basic_auth}@api.adroll.com/v1/ad/set_outline" }
66
+ let!(:params) do
67
+ { ad: 'AD123' }
68
+ end
69
+
70
+ it 'calls the api with the correct params' do
71
+ subject.set_outline(ad: 'AD123')
72
+ expect(WebMock).to have_requested(:get, request_uri).with(query: params)
73
+ end
74
+ end
75
+ end