soapy_cake 0.3.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/api_versions.yml +110 -110
  4. data/lib/soapy_cake.rb +10 -2
  5. data/lib/soapy_cake/admin.rb +34 -46
  6. data/lib/soapy_cake/affiliate.rb +5 -17
  7. data/lib/soapy_cake/client.rb +33 -3
  8. data/lib/soapy_cake/error.rb +4 -0
  9. data/lib/soapy_cake/helper.rb +16 -0
  10. data/lib/soapy_cake/request.rb +61 -0
  11. data/lib/soapy_cake/response.rb +48 -0
  12. data/lib/soapy_cake/version.rb +1 -1
  13. data/soapy_cake.gemspec +4 -4
  14. data/spec/fixtures/vcr_cassettes/Integration_test/raises_if_there_is_an_error.yml +50 -0
  15. data/spec/fixtures/vcr_cassettes/Integration_test/returns_an_affiliate_with_correct_data_types.yml +114 -0
  16. data/spec/lib/soapy_cake/admin_spec.rb +87 -199
  17. data/spec/lib/soapy_cake/affiliate_spec.rb +19 -39
  18. data/spec/lib/soapy_cake/integration_spec.rb +25 -0
  19. data/spec/spec_helper.rb +2 -0
  20. metadata +14 -55
  21. data/lib/soapy_cake/advertiser.rb +0 -21
  22. data/lib/soapy_cake/client/cake_client.rb +0 -157
  23. data/lib/soapy_cake/client/http_client.rb +0 -14
  24. data/spec/fixtures/vcr_cassettes/client_new_account_statuses.yml +0 -1200
  25. data/spec/fixtures/vcr_cassettes/client_new_advertisers.yml +0 -1202
  26. data/spec/fixtures/vcr_cassettes/client_new_affiliate_tags.yml +0 -1200
  27. data/spec/fixtures/vcr_cassettes/client_new_affiliate_tiers.yml +0 -1201
  28. data/spec/fixtures/vcr_cassettes/client_new_billing_cycles.yml +0 -1200
  29. data/spec/fixtures/vcr_cassettes/client_new_cap_intervals.yml +0 -1201
  30. data/spec/fixtures/vcr_cassettes/client_new_cap_types.yml +0 -1199
  31. data/spec/fixtures/vcr_cassettes/client_new_countries.yml +0 -1515
  32. data/spec/fixtures/vcr_cassettes/client_new_currencies.yml +0 -1199
  33. data/spec/fixtures/vcr_cassettes/client_new_empty_response.yml +0 -1200
  34. data/spec/fixtures/vcr_cassettes/client_new_empty_response_offer_summary.yml +0 -865
  35. data/spec/fixtures/vcr_cassettes/client_new_languages.yml +0 -1199
  36. data/spec/fixtures/vcr_cassettes/client_new_media_types.yml +0 -1215
  37. data/spec/fixtures/vcr_cassettes/client_new_offer_statuses.yml +0 -1202
  38. data/spec/fixtures/vcr_cassettes/client_new_offer_types.yml +0 -1201
  39. data/spec/fixtures/vcr_cassettes/client_new_payment_settings.yml +0 -1203
  40. data/spec/fixtures/vcr_cassettes/client_new_payment_types.yml +0 -1204
  41. data/spec/fixtures/vcr_cassettes/client_new_price_formats.yml +0 -1202
  42. data/spec/fixtures/vcr_cassettes/client_new_roles.yml +0 -1203
  43. data/spec/fixtures/vcr_cassettes/client_new_verticals.yml +0 -1197
  44. data/spec/fixtures/vcr_cassettes/client_new_with_username_and_password.yml +0 -1198
  45. data/spec/fixtures/vcr_cassettes/client_sekken_client_caches_results.yml +0 -1261
  46. data/spec/lib/soapy_cake/advertiser_spec.rb +0 -14
  47. data/spec/lib/soapy_cake/client/cake_client_spec.rb +0 -197
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8732d48ca3f901cc1b9d41ffd88c7a39125107ca
4
- data.tar.gz: 5b305d529fc2ef46dfcea3fb504abc8467a86619
3
+ metadata.gz: b6f7d62babdfc4fc4fe15e18b73cddf9438950f6
4
+ data.tar.gz: ebb81a5b7ebc9605520231f04bc2bc84f9ba552e
5
5
  SHA512:
6
- metadata.gz: f37161f549166fd0f232da0d179cf882bd269c1525a1c9e2fa94e9c414cc3c15c1a1bbceff741e8d4877ba39a8b89f7d287587f95055fd4029aadeb2e0ca31a0
7
- data.tar.gz: b43c4761abe84cd46188465581af5a9f1944a4f2fb2b5e190a283692480116f2f56ee7bf109789ab87e901fb6f37a8327b4f799c7e804184900d2566a4721ad7
6
+ metadata.gz: 106f6be2db7835ead031a090cbce6a241451a8907af245347cb964d70d3000341d1c7447864c97ce6aee26d9e57c967c9a80a62ddb22fec468a678cfe7e05cc0
7
+ data.tar.gz: 87ecc1739c0b32da04b2c2da8b4990193f9624c013d0f234180817ab069d34f7b0eeaa383d65bf4d91e12a2f95867a6dd658113f7fd95b306e3ea72c13669e97
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format progress
3
+ --require spec_helper
@@ -1,111 +1,111 @@
1
1
  ---
2
- :admin:
3
- :accounting:
4
- :mark_affiliate_bill_as_received: 1
5
- :export_advertiser_bills: 1
6
- :export_affiliate_bills: 1
7
- :mark_affiliate_bill_as_paid: 1
8
- :add:
9
- :advertiser_credit: 1
10
- :creative: 1
11
- :manual_credit: 1
12
- :addedit:
13
- :advertiser: 1
14
- :advertiser_credit_limit: 1
15
- :affiliate: 2
16
- :apply_suppression_list_to_offer: 1
17
- :campaign: 2
18
- :caps: 1
19
- :contact: 1
20
- :creative: 1
21
- :creative_files: 1
22
- :exchange_rates: 1
23
- :geo_targets: 1
24
- :offer: 4
25
- :offer_contract: 1
26
- :suppresion_list: 1
27
- :vertical: 1
28
- :auth:
29
- :login: 2
30
- :doc:
31
- :posting_doc: 1
32
- :edit:
33
- :buyer: 1
34
- :export:
35
- :advertisers: 5
36
- :affiliate_referrals: 1
37
- :affiliates: 5
38
- :buyer_contracts: 1
39
- :buyers: 1
40
- :campaigns: 6
41
- :creatives: 3
42
- :offers: 5
43
- :rules_targets: 3
44
- :schedules: 1
45
- :get:
46
- :account_statuses: 1
47
- :advertisers: 1
48
- :affiliate_tags: 1
49
- :affiliate_tiers: 1
50
- :billing_cycles: 1
51
- :cap_intervals: 1
52
- :cap_types: 1
53
- :countries: 1
54
- :currencies: 1
55
- :departments: 1
56
- :exchange_rates: 1
57
- :get_api_key: 1
58
- :inactive_reasons: 1
59
- :languages: 1
60
- :offer_statuses: 1
61
- :offer_types: 1
62
- :payment_settings: 1
63
- :payment_types: 1
64
- :price_formats: 1
65
- :roles: 1
66
- :tracking_domains: 1
67
- :verticals: 2
68
- :reports:
69
- :advertiser_summary: 2
70
- :affiliate_summary: 2
71
- :campaign_summary: 2
72
- :creative_summary: 2
73
- :caps: 4
74
- :clicks: 7
75
- :conversion_changes: 10
76
- :conversions: 11
77
- :daily_summary_export: 1
78
- :leads_by_affiliate_export: 1
79
- :leads_by_buyer: 4
80
- :login_export: 1
81
- :offer_summary: 2
82
- :traffic_export: 1
83
- :signup:
84
- :advertiser: 1
85
- :affiliate: 4
86
- :get_media_types: 1
87
- :get_price_formats: 1
88
- :get_traffic_types: 1
89
- :get_vertical_categories: 1
90
- :track:
91
- :accepted_dispositions: 1
92
- :conversion_dispositions: 2
93
- :decrypt_affiliate_link: 1
94
- :mass_conversion_adjustment: 2
95
- :mass_conversion_insert: 2
96
- :rejected_dispositions: 1
97
- :update_conversion: 2
98
- :update_conversion_disposition: 2
99
- :update_conversion_price: 2
100
- :update_conversion_revenue: 1
101
- :update_lead_price: 2
102
- :update_sale_revenue: 1
103
- :advertisers:
104
- :reports:
105
- :bills: 1
106
- :affiliates:
107
- :reports:
108
- :bills: 3
109
- :offers:
110
- :offer_feed: 4
111
- :get_campaign: 2
2
+ admin:
3
+ accounting:
4
+ mark_affiliate_bill_as_received: 1
5
+ export_advertiser_bills: 1
6
+ export_affiliate_bills: 1
7
+ mark_affiliate_bill_as_paid: 1
8
+ add:
9
+ advertiser_credit: 1
10
+ creative: 1
11
+ manual_credit: 1
12
+ addedit:
13
+ advertiser: 1
14
+ advertiser_credit_limit: 1
15
+ affiliate: 2
16
+ apply_suppression_list_to_offer: 1
17
+ campaign: 2
18
+ caps: 1
19
+ contact: 1
20
+ creative: 1
21
+ creative_files: 1
22
+ exchange_rates: 1
23
+ geo_targets: 1
24
+ offer: 4
25
+ offer_contract: 1
26
+ suppresion_list: 1
27
+ vertical: 1
28
+ auth:
29
+ login: 2
30
+ doc:
31
+ posting_doc: 1
32
+ edit:
33
+ buyer: 1
34
+ export:
35
+ advertisers: 5
36
+ affiliate_referrals: 1
37
+ affiliates: 5
38
+ buyer_contracts: 1
39
+ buyers: 1
40
+ campaigns: 6
41
+ creatives: 3
42
+ offers: 5
43
+ rules_targets: 3
44
+ schedules: 1
45
+ get:
46
+ account_statuses: 1
47
+ advertisers: 1
48
+ affiliate_tags: 1
49
+ affiliate_tiers: 1
50
+ billing_cycles: 1
51
+ cap_intervals: 1
52
+ cap_types: 1
53
+ countries: 1
54
+ currencies: 1
55
+ departments: 1
56
+ exchange_rates: 1
57
+ get_api_key: 1
58
+ inactive_reasons: 1
59
+ languages: 1
60
+ offer_statuses: 1
61
+ offer_types: 1
62
+ payment_settings: 1
63
+ payment_types: 1
64
+ price_formats: 1
65
+ roles: 1
66
+ tracking_domains: 1
67
+ verticals: 2
68
+ reports:
69
+ advertiser_summary: 2
70
+ affiliate_summary: 2
71
+ campaign_summary: 2
72
+ creative_summary: 2
73
+ caps: 4
74
+ clicks: 7
75
+ conversion_changes: 10
76
+ conversions: 11
77
+ daily_summary_export: 1
78
+ leads_by_affiliate_export: 1
79
+ leads_by_buyer: 4
80
+ login_export: 1
81
+ offer_summary: 2
82
+ traffic_export: 1
83
+ signup:
84
+ advertiser: 1
85
+ affiliate: 4
86
+ get_media_types: 1
87
+ get_price_formats: 1
88
+ get_traffic_types: 1
89
+ get_vertical_categories: 1
90
+ track:
91
+ accepted_dispositions: 1
92
+ conversion_dispositions: 2
93
+ decrypt_affiliate_link: 1
94
+ mass_conversion_adjustment: 2
95
+ mass_conversion_insert: 2
96
+ rejected_dispositions: 1
97
+ update_conversion: 2
98
+ update_conversion_disposition: 2
99
+ update_conversion_price: 2
100
+ update_conversion_revenue: 1
101
+ update_lead_price: 2
102
+ update_sale_revenue: 1
103
+ advertisers:
104
+ reports:
105
+ bills: 1
106
+ affiliates:
107
+ reports:
108
+ bills: 3
109
+ offers:
110
+ offer_feed: 4
111
+ get_campaign: 2
@@ -1,9 +1,17 @@
1
- require 'active_support/core_ext/string'
1
+ require 'nokogiri'
2
+ require 'saxerator'
3
+ require 'httparty'
2
4
  require 'active_support/core_ext/date'
5
+ require 'active_support/core_ext/numeric/time'
6
+ require 'active_support/core_ext/time/zones'
7
+
3
8
  require 'soapy_cake/version'
9
+ require 'soapy_cake/helper'
10
+ require 'soapy_cake/error'
11
+ require 'soapy_cake/request'
12
+ require 'soapy_cake/response'
4
13
  require 'soapy_cake/client'
5
14
  require 'soapy_cake/admin'
6
- require 'soapy_cake/advertiser'
7
15
  require 'soapy_cake/affiliate'
8
16
 
9
17
  module SoapyCake
@@ -1,91 +1,79 @@
1
1
  module SoapyCake
2
- class Admin
3
- def initialize(_opts = {})
4
- end
5
-
2
+ class Admin < Client
6
3
  def affiliate_bills(opts = {})
7
- Client::CakeClient.accounting.export_affiliate_bills(opts)
4
+ run Request.new(:admin, :accounting, :export_affiliate_bills, opts)
8
5
  end
9
6
 
10
7
  def advertiser_bills(opts = {})
11
- Client::CakeClient.accounting.export_advertiser_bills(opts)
8
+ run Request.new(:admin, :accounting, :export_advertiser_bills, opts)
9
+ end
10
+
11
+ def mark_affiliate_bill_as_received(opts = {})
12
+ run Request.new(:admin, :accounting, :mark_affiliate_bill_as_received, opts)
12
13
  end
13
14
 
14
- def affiliate_bill_received!(opts = {})
15
- Client::CakeClient.accounting.mark_affiliate_bill_as_received(opts)
15
+ def mark_affiliate_bill_as_paid(opts = {})
16
+ run Request.new(:admin, :accounting, :mark_affiliate_bill_as_paid, opts)
16
17
  end
17
18
 
18
19
  def advertisers(opts = {})
19
- Client::CakeClient.export.advertisers(opts)
20
+ run Request.new(:admin, :export, :advertisers, opts)
20
21
  end
21
22
 
22
23
  def affiliates(opts = {})
23
- Client::CakeClient.export.affiliates(opts)
24
+ run Request.new(:admin, :export, :affiliates, opts)
24
25
  end
25
26
 
26
27
  def campaigns(opts = {})
27
- Client::CakeClient.export.campaigns(opts)
28
+ run Request.new(:admin, :export, :campaigns, opts)
28
29
  end
29
30
 
30
31
  def offers(opts = {})
31
- Client::CakeClient.export.offers(opts)
32
+ run Request.new(:admin, :export, :offers, opts)
32
33
  end
33
34
 
34
- def campaign_summary(opts)
35
- Client::CakeClient.reports.campaign_summary(opts_with_date_range(opts))
35
+ def creatives(opts = {})
36
+ run Request.new(:admin, :export, :creatives, opts)
36
37
  end
37
38
 
38
- def offer_summary(opts)
39
- Client::CakeClient.reports.offer_summary(opts_with_date_range(opts))
39
+ def campaign_summary(opts = {})
40
+ run Request.new(:admin, :reports, :campaign_summary, opts)
40
41
  end
41
42
 
42
- def affiliate_summary(opts)
43
- Client::CakeClient.reports.affiliate_summary(opts_with_date_range(opts))
43
+ def offer_summary(opts = {})
44
+ run Request.new(:admin, :reports, :offer_summary, opts)
44
45
  end
45
46
 
46
- def advertiser_summary(opts)
47
- Client::CakeClient.reports.advertiser_summary(opts_with_date_range(opts))
47
+ def affiliate_summary(opts = {})
48
+ run Request.new(:admin, :reports, :affiliate_summary, opts)
48
49
  end
49
50
 
50
- def clicks(opts)
51
- Client::CakeClient.reports.conversions(opts)
51
+ def advertiser_summary(opts = {})
52
+ run Request.new(:admin, :reports, :advertiser_summary, opts)
52
53
  end
53
54
 
54
- def conversions(opts)
55
- Client::CakeClient.reports.conversions(opts.merge(conversion_type: 'conversions'))
55
+ def clicks(opts = {})
56
+ run Request.new(:admin, :reports, :clicks, opts)
56
57
  end
57
58
 
58
- def events(opts)
59
- Client::CakeClient.reports.conversions(opts.merge(conversion_type: 'events'))
59
+ def conversions(opts = {})
60
+ run Request.new(:admin, :reports, :conversions, opts.merge(conversion_type: 'conversions'))
60
61
  end
61
62
 
62
- def currencies
63
- Client::CakeClient.get.currencies
63
+ def events(opts = {})
64
+ run Request.new(:admin, :reports, :conversions, opts.merge(conversion_type: 'events'))
64
65
  end
65
66
 
66
- def mark_affiliate_bill_as_paid(opts)
67
- Client::CakeClient.accounting.mark_affiliate_bill_as_paid(opts)
67
+ def traffic(opts = {})
68
+ run Request.new(:admin, :reports, :traffic_export, opts)
68
69
  end
69
70
 
70
- def creatives(opts = {})
71
- Client::CakeClient.export.creatives(opts)
71
+ def currencies(*)
72
+ run Request.new(:admin, :get, :currencies, {})
72
73
  end
73
74
 
74
75
  def update_creative(opts = {})
75
- Client::CakeClient.addedit.creative(opts)
76
- end
77
-
78
- def traffic(opts)
79
- Client::CakeClient.reports.traffic_export(opts_with_date_range(opts))
80
- end
81
-
82
- private
83
-
84
- def opts_with_date_range(opts)
85
- start_date = opts[:start_date].to_date
86
- end_date = opts[:end_date] || start_date + 1
87
-
88
- opts.merge(start_date: start_date, end_date: end_date)
76
+ run Request.new(:admin, :addedit, :creative, opts)
89
77
  end
90
78
  end
91
79
  end
@@ -1,29 +1,17 @@
1
1
  module SoapyCake
2
- class Affiliate
3
- attr_reader :api_key, :affiliate_id
4
-
5
- def initialize(opts = {})
6
- @api_key = opts[:api_key]
7
- @affiliate_id = opts[:affiliate_id]
8
- end
9
-
2
+ class Affiliate < Client
10
3
  def bills(opts = {})
11
- cake_client(:reports, :bills, opts)
4
+ run Request.new(:affiliate, :reports, :bills, affiliate_opts(opts))
12
5
  end
13
6
 
14
7
  def offer_feed(opts = {})
15
- cake_client(:offers, :offer_feed, opts)
16
- end
17
-
18
- def campaign(opts = {})
19
- cake_client(:offers, :get_campaign, opts)
8
+ run Request.new(:affiliate, :offers, :offer_feed, affiliate_opts(opts))
20
9
  end
21
10
 
22
11
  private
23
12
 
24
- def cake_client(api, method, opts = {})
25
- Client::CakeClient.send(api, role: :affiliates)
26
- .send(method, opts.merge(affiliate_id: affiliate_id, api_key: api_key))
13
+ def affiliate_opts(opts)
14
+ { affiliate_id: self.opts[:affiliate_id] }.merge(opts)
27
15
  end
28
16
  end
29
17
  end
@@ -1,5 +1,35 @@
1
- require 'soapy_cake/client/http_client'
2
- require 'soapy_cake/client/cake_client'
1
+ module SoapyCake
2
+ class Client
3
+ attr_reader :domain, :api_key, :time_offset
3
4
 
4
- module SoapyCake::Client
5
+ def initialize(opts = {})
6
+ @domain = opts.fetch(:domain, ENV['CAKE_DOMAIN']) || fail(Error, 'Cake domain missing')
7
+ @api_key = opts.fetch(:domain, ENV['CAKE_API_KEY']) || fail(Error, 'Cake API key missing')
8
+ @time_offset = opts.fetch(:time_offset, ENV['CAKE_TIME_OFFSET']) \
9
+ || fail(Error, 'Cake time offset missing')
10
+ @opts = opts
11
+ end
12
+
13
+ protected
14
+
15
+ attr_reader :opts
16
+
17
+ def run(request)
18
+ request.api_key = api_key
19
+ request.time_offset = time_offset
20
+
21
+ url = "https://#{domain}#{request.path}"
22
+ body = HTTParty.post(url, headers: headers, body: request.xml).body
23
+
24
+ response = Response.new(body)
25
+ response.time_offset = time_offset
26
+ response.collection
27
+ end
28
+
29
+ private
30
+
31
+ def headers
32
+ { 'Content-Type' => 'application/soap+xml;charset=UTF-8' }
33
+ end
34
+ end
5
35
  end