epom 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +28 -0
  5. data/config/application.yml +41 -0
  6. data/lib/epom.rb +22 -0
  7. data/lib/epom/ad_unit_size.rb +15 -0
  8. data/lib/epom/advertiser.rb +45 -0
  9. data/lib/epom/auth.rb +31 -0
  10. data/lib/epom/banner.rb +525 -0
  11. data/lib/epom/banner_type.rb +15 -0
  12. data/lib/epom/campaign.rb +508 -0
  13. data/lib/epom/day_of_week.rb +11 -0
  14. data/lib/epom/epom_element.rb +61 -0
  15. data/lib/epom/limit_counters.rb +10 -0
  16. data/lib/epom/payment_model.rb +9 -0
  17. data/lib/epom/period_type.rb +9 -0
  18. data/lib/epom/placement.rb +56 -0
  19. data/lib/epom/placement_type.rb +7 -0
  20. data/lib/epom/publisher.rb +6 -0
  21. data/lib/epom/relation.rb +9 -0
  22. data/lib/epom/site.rb +84 -0
  23. data/lib/epom/version.rb +3 -0
  24. data/lib/epom/zone.rb +38 -0
  25. data/lib/tasks/epom_tasks.rake +4 -0
  26. data/test/IMG_5457-128x128.JPG +0 -0
  27. data/test/dummy/README.rdoc +28 -0
  28. data/test/dummy/Rakefile +6 -0
  29. data/test/dummy/app/assets/javascripts/application.js +13 -0
  30. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  31. data/test/dummy/app/controllers/application_controller.rb +5 -0
  32. data/test/dummy/app/helpers/application_helper.rb +2 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/test/dummy/bin/bundle +3 -0
  35. data/test/dummy/bin/rails +4 -0
  36. data/test/dummy/bin/rake +4 -0
  37. data/test/dummy/bin/setup +29 -0
  38. data/test/dummy/config.ru +4 -0
  39. data/test/dummy/config/application.rb +26 -0
  40. data/test/dummy/config/boot.rb +5 -0
  41. data/test/dummy/config/database.yml +25 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/development.rb +41 -0
  44. data/test/dummy/config/environments/production.rb +79 -0
  45. data/test/dummy/config/environments/test.rb +42 -0
  46. data/test/dummy/config/initializers/assets.rb +11 -0
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/dummy/config/initializers/inflections.rb +16 -0
  51. data/test/dummy/config/initializers/mime_types.rb +4 -0
  52. data/test/dummy/config/initializers/session_store.rb +3 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +23 -0
  55. data/test/dummy/config/routes.rb +56 -0
  56. data/test/dummy/config/secrets.yml +22 -0
  57. data/test/dummy/db/development.sqlite3 +0 -0
  58. data/test/dummy/db/schema.rb +16 -0
  59. data/test/dummy/db/test.sqlite3 +0 -0
  60. data/test/dummy/log/development.log +4 -0
  61. data/test/dummy/log/test.log +17350 -0
  62. data/test/dummy/public/404.html +67 -0
  63. data/test/dummy/public/422.html +67 -0
  64. data/test/dummy/public/500.html +66 -0
  65. data/test/dummy/public/favicon.ico +0 -0
  66. data/test/epom/advertiser_test.rb +85 -0
  67. data/test/epom/auth_test.rb +50 -0
  68. data/test/epom/banner_test.rb +194 -0
  69. data/test/epom/campaign_test.rb +65 -0
  70. data/test/epom/placement_test.rb +53 -0
  71. data/test/epom/site_test.rb +136 -0
  72. data/test/epom/zone_test.rb +67 -0
  73. data/test/epom_test.rb +38 -0
  74. data/test/logo-128x128.png +0 -0
  75. data/test/test.php +51 -0
  76. data/test/test.rb +21 -0
  77. data/test/test_helper.rb +55 -0
  78. metadata +256 -0
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+ require 'epom/campaign'
3
+
4
+ class CampaignTest < ActiveSupport::TestCase
5
+ test "truth" do
6
+ assert_kind_of Class, Epom::Campaign
7
+ end
8
+
9
+ define_get_tests_auto(Epom::Campaign)
10
+
11
+ test "get_actions" do
12
+ timestamp = Time.now.to_i * 1000
13
+ url_params = {
14
+ :campaignId => ENV['campaign_id'],
15
+ }
16
+ body_params = {
17
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
18
+ :timestamp => timestamp,
19
+ :username => ENV['username'],
20
+ }
21
+
22
+ response = Epom::Campaign.get_actions(url_params, body_params)
23
+ assert_instance_of Array, response
24
+ if response.count > 0
25
+ first = response[0]
26
+ assert_instance_of String, first['key']
27
+ end
28
+ end
29
+
30
+ test "get_targetings" do
31
+ timestamp = Time.now.to_i * 1000
32
+ url_params = {
33
+ :campaignId => ENV['campaign_id'],
34
+ }
35
+ body_params = {
36
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
37
+ :timestamp => timestamp,
38
+ :username => ENV['username'],
39
+ }
40
+
41
+ response = Epom::Campaign.get_targetings(url_params, body_params)
42
+ assert_instance_of Array, response
43
+ if response.count > 0
44
+ first = response[0]
45
+ assert_instance_of Fixnum, first['id']
46
+ end
47
+ end
48
+
49
+ test "create_campaign" do
50
+ timestamp = Time.now.to_i * 1000
51
+ body_params = {
52
+ :advertiserId => ENV['advertiser_id'],
53
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
54
+ :timestamp => timestamp,
55
+ :username => ENV['username'],
56
+ :name => "campaign #{timestamp}",
57
+ :description => "description for campaign #{timestamp}",
58
+ :active => true}
59
+
60
+ response = Epom::Campaign.create_campaign({}, body_params)
61
+ assert_instance_of Hash, response
62
+ assert_instance_of Fixnum, response['id']
63
+ assert_instance_of String, response['name']
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+ require 'epom/placement'
3
+
4
+ class PlacementTest < ActiveSupport::TestCase
5
+ test "truth" do
6
+ assert_kind_of Class, Epom::Placement
7
+ end
8
+
9
+ test "get_placement_summary" do
10
+ timestamp = Time.now.to_i * 1000
11
+ body_params = {
12
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
13
+ :timestamp => timestamp,
14
+ :username => ENV['username'],
15
+ :placementIds => ENV['placement_id']
16
+ }
17
+ url_params = {}
18
+
19
+ response = Epom::Placement.get_placement_summary(url_params, body_params)
20
+ assert_instance_of Array, response
21
+ if response.count > 0
22
+ first = response.first
23
+ assert_instance_of Hash, first
24
+ assert_instance_of Fixnum, first['id']
25
+ assert_instance_of Array, first['category']
26
+ assert_instance_of String, first['name']
27
+ assert_instance_of String, first['key']
28
+ assert_instance_of String, first['size']
29
+ assert_instance_of Fixnum, first['zoneId']
30
+ end
31
+ end
32
+
33
+ test "create_standard_placement" do
34
+ timestamp = Time.now.to_i * 1000
35
+ body_params = {
36
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
37
+ :timestamp => timestamp,
38
+ :username => ENV['username'],
39
+ :zoneId => ENV['zone_id'],
40
+ :type => Epom::PlacementType::SITE_PLACEMENT,
41
+ :name => "placement #{timestamp}",
42
+ :adUnitId => 10,
43
+ 'size.height' => 200,
44
+ 'size.width' => 350,
45
+ }
46
+ url_params = {}
47
+
48
+ response = Epom::Placement.create_standard_placement(url_params, body_params)
49
+ assert_instance_of Hash, response
50
+ assert_instance_of Fixnum, response['id']
51
+ assert response['success']
52
+ end
53
+ end
@@ -0,0 +1,136 @@
1
+ require 'test_helper'
2
+ require 'epom/site'
3
+
4
+ class SiteTest < ActiveSupport::TestCase
5
+ test "truth" do
6
+ assert_kind_of Class, Epom::Site
7
+ end
8
+
9
+ define_get_tests_auto(Epom::Site)
10
+
11
+ test "get_sites" do
12
+ timestamp = Time.now.to_i * 1000
13
+ body_params = {
14
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
15
+ :timestamp => timestamp,
16
+ :username => ENV['username'],
17
+ }
18
+ url_params = {}
19
+
20
+ response = Epom::Site.get_sites(url_params, body_params)
21
+ assert_instance_of Array, response
22
+ if response.count > 0
23
+ first = response.first
24
+ assert_instance_of Hash, first
25
+ assert_instance_of Fixnum, first['id']
26
+ assert_instance_of String, first['name']
27
+ end
28
+ end
29
+
30
+ test "get_site_cpm_threshold_summary" do
31
+ timestamp = Time.now.to_i * 1000
32
+ body_params = {
33
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
34
+ :timestamp => timestamp,
35
+ :username => ENV['username'],
36
+ }
37
+ url_params = {
38
+ :siteId => ENV['site_id']
39
+ }
40
+
41
+ response = Epom::Site.get_site_cpm_threshold_summary(url_params, body_params)
42
+ assert_instance_of Array, response
43
+ if response.count > 0
44
+ first = response.first
45
+ assert_instance_of Hash, first
46
+ assert_instance_of Float, first['cpmThreshold']
47
+ end
48
+ end
49
+
50
+ test "get_site_pricing" do
51
+ timestamp = Time.now.to_i * 1000
52
+ body_params = {
53
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
54
+ :timestamp => timestamp,
55
+ :username => ENV['username'],
56
+ }
57
+ url_params = {
58
+ :siteId => ENV['site_id']
59
+ }
60
+
61
+ response = Epom::Site.get_site_pricing(url_params, body_params)
62
+ assert_instance_of Hash, response
63
+ assert_instance_of String, response['paymentModel']
64
+ assert_instance_of Float, response['price']
65
+ assert_instance_of String, response['pricingType']
66
+ end
67
+
68
+ test "set_site_pricing" do
69
+ timestamp = Time.now.to_i * 1000
70
+ url_params = {
71
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
72
+ :timestamp => timestamp,
73
+ :username => ENV['username'],
74
+ :siteId => ENV['site_id']
75
+ }
76
+ body_params = '{"paymentModel":"FIXED_PRICE","pricingType":"CPM","price":4.2}'
77
+
78
+ response = Epom::Site.set_site_pricing(url_params, body_params)
79
+ assert_instance_of Hash, response
80
+ assert response['success']
81
+ end
82
+
83
+ test "set_placement_pricing" do
84
+ timestamp = Time.now.to_i * 1000
85
+ url_params = {
86
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
87
+ :timestamp => timestamp,
88
+ :username => ENV['username'],
89
+ :placementId => ENV['placement_id'],
90
+ }
91
+ body_params = '{"paymentModel":"FIXED_PRICE","pricingType":"CPC","price":1.2}'
92
+
93
+ response = Epom::Site.set_placement_pricing(url_params, body_params)
94
+ assert_instance_of Hash, response
95
+ assert response['success']
96
+ end
97
+
98
+ test "create_site" do
99
+ timestamp = Time.now.to_i * 1000
100
+ body_params = {
101
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
102
+ :timestamp => timestamp,
103
+ :username => ENV['username'],
104
+ :name => "publisher_#{timestamp}",
105
+ :url => 'http://www.publisher.com',
106
+ :email => "publisher@example.com",
107
+ :categoryId => 2
108
+ }
109
+
110
+ response = Epom::Site.create_site({}, body_params)
111
+ assert_instance_of Hash, response
112
+ assert_instance_of Fixnum, response['id']
113
+ assert response['success']
114
+ end
115
+
116
+ test "get_sites_zones" do
117
+ timestamp = Time.now.to_i * 1000
118
+ body_params = {
119
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
120
+ :timestamp => timestamp,
121
+ :username => ENV['username'],
122
+ }
123
+ url_params = {
124
+ :siteId => ENV['site_id']
125
+ }
126
+
127
+ response = Epom::Site.get_sites_zones(url_params, body_params)
128
+ assert_instance_of Array, response
129
+ if response.count > 0
130
+ first = response[0]
131
+ assert_instance_of Fixnum, first['id']
132
+ assert_instance_of String, first['name']
133
+ end
134
+ end
135
+
136
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+ require 'epom/zone'
3
+
4
+ class ZoneTest < ActiveSupport::TestCase
5
+ test "truth" do
6
+ assert_kind_of Class, Epom::Zone
7
+ end
8
+
9
+ test "create_zone" do
10
+ timestamp = Time.now.to_i * 1000
11
+ body_params = {
12
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
13
+ :timestamp => timestamp,
14
+ :username => ENV['username'],
15
+ :name => "zone #{timestamp}",
16
+ :description => "description",
17
+ :siteId => ENV['site_id']
18
+ }
19
+ url_params = {
20
+ }
21
+
22
+ response = Epom::Zone.create_zone(url_params, body_params)
23
+ assert_instance_of Hash, response
24
+ assert_instance_of Fixnum, response['id']
25
+ assert response['success']
26
+ end
27
+
28
+ test "update_zone" do
29
+ timestamp = Time.now.to_i * 1000
30
+ body_params = {
31
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
32
+ :timestamp => timestamp,
33
+ :username => ENV['username'],
34
+ :name => "zone #{timestamp}",
35
+ :description => "description",
36
+ :zoneId => ENV['zone_id'],
37
+ :siteId => ENV['site_id']
38
+ }
39
+ url_params = {
40
+ }
41
+
42
+ response = Epom::Zone.update_zone(url_params, body_params)
43
+ assert_instance_of Hash, response
44
+ assert_instance_of Fixnum, response['id']
45
+ assert response['success']
46
+ end
47
+
48
+ test "get_zone_placement" do
49
+ timestamp = Time.now.to_i * 1000
50
+ body_params = {
51
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
52
+ :timestamp => timestamp,
53
+ :username => ENV['username'],
54
+ }
55
+ url_params = {
56
+ :zoneId => ENV['zone_id']
57
+ }
58
+
59
+ response = Epom::Zone.get_zone_placement(url_params, body_params)
60
+ assert_instance_of Array, response
61
+ if response.count > 0
62
+ first = response[0]
63
+ assert_instance_of Fixnum, first['id']
64
+ assert_instance_of String, first['name']
65
+ end
66
+ end
67
+ end
data/test/epom_test.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class EpomTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, Epom
6
+ end
7
+
8
+ test "get_targeting" do
9
+ timestamp = Time.now.to_i * 1000
10
+ body_params = {
11
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
12
+ :timestamp => timestamp,
13
+ :username => ENV['username'],
14
+ }
15
+ url_params = {
16
+ :bannerId => ENV['banner_id'],
17
+ :targetId => ENV['target_id']
18
+ }
19
+
20
+ response = Epom::Banner.get_targeting(url_params, body_params)
21
+ assert_instance_of Hash, response
22
+ end
23
+
24
+ test "set_site_pricing" do
25
+ timestamp = Time.now.to_i * 1000
26
+ url_params = {
27
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
28
+ :timestamp => timestamp,
29
+ :username => ENV['username'],
30
+ :siteId => ENV['site_id']
31
+ }
32
+ body_params = '{"paymentModel":"FIXED_PRICE","pricingType":"CPM","price":4.2}'
33
+
34
+ response = Epom::Site.set_site_pricing(url_params, body_params)
35
+ assert_instance_of Hash, response
36
+ assert response['success']
37
+ end
38
+ end
Binary file
data/test/test.php ADDED
@@ -0,0 +1,51 @@
1
+ <?php
2
+ define("DEBUG",false);
3
+
4
+ $username = "kewelta";
5
+ $password = "kewelta";
6
+ $timestamp = round(microtime(true) * 1000);
7
+ $hash = md5(md5($password).$timestamp);
8
+
9
+ $url = "https://n29.epom.com/rest-api/banner/create.do";
10
+ /*Getting the full path to your file*/
11
+ $file_name_with_full_path = realpath('300x250.gif');
12
+ /*Specifying MIME type of the file*/
13
+ $filetype = "image/gif";
14
+
15
+ $post_data = array(
16
+ "hash" => $hash,
17
+ "timestamp" => $timestamp,
18
+ "username" => $username,
19
+ "placementType" => "SITE_PLACEMENT",
20
+ "campaignId" => "1261",
21
+ "active" => "true",
22
+ "name" => "test_banner_1",
23
+ "weight" => "1",
24
+ "bannerType" => "LOCAL_FILE",
25
+ "imageBannerLink" => "http://qwe.com",
26
+ "imageFile" => "@$file_name_with_full_path;type=$filetype",
27
+ "url" => "http://qwe.com",
28
+ "adUnitId" => "1"
29
+ );
30
+
31
+ $options = array(
32
+ CURLOPT_URL => $url,
33
+ CURLOPT_SSL_VERIFYPEER => false,
34
+ CURLOPT_POST => true,
35
+ CURLOPT_POSTFIELDS => $post_data,
36
+ CURLOPT_HTTPHEADER => array("Content-type: multipart/form-data"),
37
+ CURLOPT_RETURNTRANSFER => true
38
+ );
39
+
40
+ $curl = curl_init();
41
+
42
+ curl_setopt_array($curl,$options);
43
+
44
+ echo curl_exec($curl);
45
+
46
+ if(DEBUG){
47
+ echo "\n\n";
48
+ echo $url;
49
+ print_r($post_data);
50
+ }
51
+ ?>
data/test/test.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'pathname'
2
+ require 'yaml'
3
+
4
+ env_file = File.join(Pathname.new(__FILE__).parent.parent, 'config', 'application.yml')
5
+ YAML.load(File.open(env_file)).each do |key, value|
6
+ ENV[key.to_s] = value.to_s
7
+ end if File.exists?(env_file)
8
+
9
+ require 'epom'
10
+
11
+ timestamp = Time.now.to_i * 1000
12
+ body_params = {
13
+ :hash => Epom.create_hash(Epom.create_hash(ENV['password']), timestamp),
14
+ :timestamp => timestamp,
15
+ :username => ENV['username'],
16
+ }
17
+ url_params = {}
18
+
19
+ response = Epom::Site.get_sites(url_params, body_params)
20
+
21
+ puts response
@@ -0,0 +1,55 @@
1
+ require 'yaml'
2
+
3
+ require "codeclimate-test-reporter"
4
+ CodeClimate::TestReporter.start
5
+
6
+ # Configure Rails Environment
7
+ ENV["RAILS_ENV"] = "test"
8
+
9
+ env_file = File.join(Pathname.new(__FILE__).parent.parent, 'config', 'application.yml')
10
+ YAML.load(File.open(env_file)).each do |key, value|
11
+ ENV[key.to_s] = value.to_s
12
+ end if File.exists?(env_file)
13
+
14
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
15
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
16
+ require "rails/test_help"
17
+
18
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
19
+ # to be shown.
20
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
21
+
22
+ # Load support files
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
24
+
25
+ # Load fixtures from the engine
26
+ if ActiveSupport::TestCase.respond_to?(:fixture_path=)
27
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
28
+ end
29
+
30
+ def define_get_tests_auto(klass)
31
+ klass.extended_methods.keys.grep(/^get_/).each do |extended_method|
32
+ define_method("test_#{extended_method}_auto") do
33
+ url_parameters_signature = klass.extended_methods[extended_method][:url_parameters]
34
+ body_parameters_signature = klass.extended_methods[extended_method][:body_parameters]
35
+
36
+ url_params = {}
37
+ if url_parameters_signature
38
+ url_parameters_signature.each do |url_parameter|
39
+ url_params[url_parameter] = ENV[url_parameter.to_s.underscore]
40
+ end
41
+ end
42
+
43
+ body_params = {}
44
+ body_parameters_signature.each do |body_parameter|
45
+ body_params[body_parameter] = ENV[body_parameter.to_s.underscore]
46
+ end
47
+ timestamp = Time.now.to_i * 1000
48
+ body_params[:timestamp] = timestamp
49
+ body_params[:hash] = Epom.create_hash(Epom.create_hash(ENV['password']), timestamp)
50
+
51
+ response = klass.send(extended_method, url_params, body_params)
52
+ assert_not_instance_of Fixnum, response
53
+ end
54
+ end
55
+ end