soapy_bing 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +19 -0
  4. data/lib/soapy_bing/ads/reports/base.rb +1 -1
  5. data/lib/soapy_bing/ads.rb +23 -0
  6. data/lib/soapy_bing/soap/request/get_ad_groups_by_campaign_id_request.rb +17 -0
  7. data/lib/soapy_bing/soap/request/get_ads_by_ad_group_id_request.rb +17 -0
  8. data/lib/soapy_bing/soap/request/get_targets_by_campaign_ids_request.rb +17 -0
  9. data/lib/soapy_bing/soap/request.rb +3 -0
  10. data/lib/soapy_bing/soap/response/get_ad_groups_by_campaign_id_response.rb +12 -0
  11. data/lib/soapy_bing/soap/response/get_ads_by_ad_group_id_response.rb +12 -0
  12. data/lib/soapy_bing/soap/response/get_targets_by_campaign_ids_response.rb +12 -0
  13. data/lib/soapy_bing/soap/response.rb +5 -0
  14. data/lib/soapy_bing/soap/templates/get_ad_groups_by_campaign_id.erb.xml +15 -0
  15. data/lib/soapy_bing/soap/templates/get_ads_by_ad_group_id.erb.xml +15 -0
  16. data/lib/soapy_bing/soap/templates/get_targets_by_campaign_ids.erb.xml +20 -0
  17. data/lib/soapy_bing/version.rb +1 -1
  18. data/spec/fixtures/get_ad_groups_by_campaign_id.json +587 -0
  19. data/spec/fixtures/get_ads_by_ad_group_id.json +218 -0
  20. data/spec/fixtures/get_targets_by_campaign_ids.json +81 -0
  21. data/spec/fixtures/vcr_cassettes/SoapyBing_Ads/_get_ad_groups_by_campaign_id/1_1_1.yml +150 -0
  22. data/spec/fixtures/vcr_cassettes/SoapyBing_Ads/_get_ads_by_ad_group_id/1_2_1.yml +141 -0
  23. data/spec/fixtures/vcr_cassettes/SoapyBing_Ads/_get_targets_by_campaign_ids/1_3_1.yml +111 -0
  24. data/spec/integration/soapy_bing/ads_spec.rb +32 -0
  25. data/spec/soapy_bing/oauth_credentials_spec.rb +1 -1
  26. data/spec/soapy_bing/soap/request/base_spec.rb +1 -1
  27. data/spec/soapy_bing/soap/request/poll_generate_report_request_spec.rb +2 -2
  28. metadata +25 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75bb3e63ec854d756a3d216b9ddcd0ad8742aa80
4
- data.tar.gz: 596a7c5f4d3c5f1f15611d7e98fbea0b0498d985
3
+ metadata.gz: ea5a6965e864eb014503ddafecb249e2effd9195
4
+ data.tar.gz: 50ea9e0645a6625676e7516abe118e72f9d05c06
5
5
  SHA512:
6
- metadata.gz: 44998a329b39fda44bff367952ee29ca0e0f5a1df9ee15b38fe8ded6137a98e3b152273cefe8c87c453ff9fd118f7716abe627c2ef94ed44708888f770ace2f1
7
- data.tar.gz: 11fe49b2c467a48dacfdc2d9b68cb296fc00759fefa4c867425fa531a0a19476220a661a10503439398adf0bbd125abdec78cab37733e8c88e6900ed5047673e
6
+ metadata.gz: 219d83ed3736b437e9840b5ad91dfda4e307ca282097ebfd0d37a4d5e4823036e6a1c4be81be73a75c0a632a463dd170695e0671e3b8b2e89b68eebcb24bf42e
7
+ data.tar.gz: 831a248fc27408938e8cbe7d22e91b4e1f7bb4ebb86dea0fb27493872757ae34b8c439a5f54bb9ec7dca9f92c16645f522822729b19384aded7264e64e634ff6
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
 
5
5
  .env.local
6
6
  .env.development
7
+ .bundle
data/README.md CHANGED
@@ -55,6 +55,25 @@ SoapyBing::Ads.new(
55
55
  )
56
56
  ```
57
57
 
58
+ ### Generate a refresh token
59
+
60
+ First go to the following url using your Client Id and Redirect Url.
61
+
62
+ https://login.live.com/oauth20_authorize.srf?client_id=<YOUR_CLIENT_ID>&scope=bingads.manage&response_type=code&redirect_uri=<YOUR_REDIRECT_URL>&state=ClientStateGoesHere
63
+
64
+ Make a note of the code parameter that is present in the redirect url. Execute the following curl command to get a new Refresh token.
65
+
66
+ ```sh
67
+ curl -v -XPOST \
68
+ -d client_id=<YOUR_CLIENT_ID> \
69
+ -d code=<THE_CODE_FROM_THE_FIRST_CALL>
70
+ -d grant_type=authorization_code \
71
+ -d redirect_uri=<YOUR_REDIRECT_URL> \
72
+ -d client_secret=<YOUR_CLIENT_SECRET> \
73
+ -H "Content-Type: application/x-www-form-urlencoded" \
74
+ https://login.live.com/oauth20_token.srf
75
+ ```
76
+
58
77
  ## Links
59
78
  * MS Live Applications [https://account.live.com/developers/applications](https://account.live.com/developers/applications)
60
79
  * Bing Ads User Authentication with OAuth [https://msdn.microsoft.com/en-us/library/bing-ads-user-authentication-oauth-guide.aspx](https://msdn.microsoft.com/en-us/library/bing-ads-user-authentication-oauth-guide.aspx)
@@ -17,7 +17,7 @@ module SoapyBing
17
17
  language: 'English',
18
18
  name: 'MyReport',
19
19
  aggregation: 'HourOfDay',
20
- columns: %w(TimePeriod CampaignName Impressions Clicks Spend)
20
+ columns: %w(TimePeriod CampaignName Impressions Clicks Spend CampaignId)
21
21
  }.freeze
22
22
 
23
23
  attr_reader :oauth_credentials, :account, :settings
@@ -19,5 +19,28 @@ module SoapyBing
19
19
  settings: settings
20
20
  )
21
21
  end
22
+
23
+ def get_ad_groups_by_campaign_id(campaign_id)
24
+ do_request(Soap::Request::GetAdGroupsByCampaignIdRequest, campaign_id: campaign_id)
25
+ end
26
+
27
+ def get_ads_by_ad_group_id(ad_group_id)
28
+ do_request(Soap::Request::GetAdsByAdGroupIdRequest, ad_group_id: ad_group_id)
29
+ end
30
+
31
+ def get_targets_by_campaign_ids(campaign_ids)
32
+ do_request(Soap::Request::GetTargetsByCampaignIdsRequest, campaign_ids: campaign_ids)
33
+ end
34
+
35
+ private
36
+
37
+ def do_request(klass, options)
38
+ klass.new(context: {
39
+ account: account,
40
+ authentication_token: oauth_credentials.access_token
41
+ }.merge(options))
42
+ .perform
43
+ .payload
44
+ end
22
45
  end
23
46
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module SoapyBing
3
+ module Soap
4
+ module Request
5
+ class GetAdGroupsByCampaignIdRequest < Base
6
+ API_BASE_URL = 'https://campaign.api.bingads.microsoft.com'
7
+ API_VERSION = 10
8
+ API_ENDPOINT = "#{API_BASE_URL}/Api/Advertiser/CampaignManagement/" \
9
+ "V#{API_VERSION}/CampaignManagementService.svc"
10
+
11
+ def perform
12
+ Response::GetAdGroupsByCampaignIdResponse.new(post(API_ENDPOINT))
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module SoapyBing
3
+ module Soap
4
+ module Request
5
+ class GetAdsByAdGroupIdRequest < Base
6
+ API_BASE_URL = 'https://campaign.api.bingads.microsoft.com'
7
+ API_VERSION = 10
8
+ API_ENDPOINT = "#{API_BASE_URL}/Api/Advertiser/CampaignManagement/" \
9
+ "V#{API_VERSION}/CampaignManagementService.svc"
10
+
11
+ def perform
12
+ Response::GetAdsByAdGroupIdResponse.new(post(API_ENDPOINT))
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module SoapyBing
3
+ module Soap
4
+ module Request
5
+ class GetTargetsByCampaignIdsRequest < Base
6
+ API_BASE_URL = 'https://campaign.api.bingads.microsoft.com'
7
+ API_VERSION = 10
8
+ API_ENDPOINT = "#{API_BASE_URL}/Api/Advertiser/CampaignManagement/" \
9
+ "V#{API_VERSION}/CampaignManagementService.svc"
10
+
11
+ def perform
12
+ Response::GetTargetsByCampaignIdsResponse.new(post(API_ENDPOINT))
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,3 +2,6 @@
2
2
  require 'soapy_bing/soap/request/base'
3
3
  require 'soapy_bing/soap/request/submit_generate_report_request'
4
4
  require 'soapy_bing/soap/request/poll_generate_report_request'
5
+ require 'soapy_bing/soap/request/get_ad_groups_by_campaign_id_request'
6
+ require 'soapy_bing/soap/request/get_ads_by_ad_group_id_request'
7
+ require 'soapy_bing/soap/request/get_targets_by_campaign_ids_request'
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module SoapyBing
3
+ module Soap
4
+ module Response
5
+ class GetAdGroupsByCampaignIdResponse < Base
6
+ def extract_payload
7
+ Array.wrap(body['Envelope']['Body'][class_name]['AdGroups']['AdGroup'])
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module SoapyBing
3
+ module Soap
4
+ module Response
5
+ class GetAdsByAdGroupIdResponse < Base
6
+ def extract_payload
7
+ Array.wrap(body['Envelope']['Body'][class_name]['Ads']['Ad'])
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module SoapyBing
3
+ module Soap
4
+ module Response
5
+ class GetTargetsByCampaignIdsResponse < Base
6
+ def extract_payload
7
+ Array.wrap(body['Envelope']['Body'][class_name]['Targets']['Target']).first
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
+ require 'active_support/core_ext/array/wrap'
3
+
2
4
  require 'soapy_bing/soap/response/payload'
3
5
  require 'soapy_bing/soap/response/report_status'
4
6
  require 'soapy_bing/soap/response/base'
5
7
  require 'soapy_bing/soap/response/submit_generate_report_response'
6
8
  require 'soapy_bing/soap/response/poll_generate_report_response'
9
+ require 'soapy_bing/soap/response/get_ad_groups_by_campaign_id_response'
10
+ require 'soapy_bing/soap/response/get_ads_by_ad_group_id_response'
11
+ require 'soapy_bing/soap/response/get_targets_by_campaign_ids_response'
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <env:Envelope xmlns:tns="https://bingads.microsoft.com/CampaignManagement/v10"
3
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
4
+ <env:Header>
5
+ <tns:CustomerAccountId><%= account.account_id %></tns:CustomerAccountId>
6
+ <tns:CustomerId><%= account.customer_id %></tns:CustomerId>
7
+ <tns:DeveloperToken><%= account.developer_token %></tns:DeveloperToken>
8
+ <tns:AuthenticationToken><%= authentication_token %></tns:AuthenticationToken>
9
+ </env:Header>
10
+ <env:Body>
11
+ <tns:GetAdGroupsByCampaignIdRequest>
12
+ <tns:CampaignId><%= campaign_id %></tns:CampaignId>
13
+ </tns:GetAdGroupsByCampaignIdRequest>
14
+ </env:Body>
15
+ </env:Envelope>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <env:Envelope xmlns:tns="https://bingads.microsoft.com/CampaignManagement/v10"
3
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
4
+ <env:Header>
5
+ <tns:CustomerAccountId><%= account.account_id %></tns:CustomerAccountId>
6
+ <tns:CustomerId><%= account.customer_id %></tns:CustomerId>
7
+ <tns:DeveloperToken><%= account.developer_token %></tns:DeveloperToken>
8
+ <tns:AuthenticationToken><%= authentication_token %></tns:AuthenticationToken>
9
+ </env:Header>
10
+ <env:Body>
11
+ <tns:GetAdsByAdGroupIdRequest>
12
+ <tns:AdGroupId><%= ad_group_id %></tns:AdGroupId>
13
+ </tns:GetAdsByAdGroupIdRequest>
14
+ </env:Body>
15
+ </env:Envelope>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <env:Envelope xmlns:tns="https://bingads.microsoft.com/CampaignManagement/v10"
3
+ xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
4
+ xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
5
+ <env:Header>
6
+ <tns:CustomerAccountId><%= account.account_id %></tns:CustomerAccountId>
7
+ <tns:CustomerId><%= account.customer_id %></tns:CustomerId>
8
+ <tns:DeveloperToken><%= account.developer_token %></tns:DeveloperToken>
9
+ <tns:AuthenticationToken><%= authentication_token %></tns:AuthenticationToken>
10
+ </env:Header>
11
+ <env:Body>
12
+ <tns:GetTargetsByCampaignIdsRequest>
13
+ <tns:CampaignIds>
14
+ <% campaign_ids.each do |campaign_id| %>
15
+ <arr:long><%= campaign_id %></arr:long>
16
+ <% end %>
17
+ </tns:CampaignIds>
18
+ </tns:GetTargetsByCampaignIdsRequest>
19
+ </env:Body>
20
+ </env:Envelope>
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SoapyBing
3
- VERSION = '0.0.5'
3
+ VERSION = '0.1.0'
4
4
  end