epom_rails 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/epom_rails/acts_as.rb +36 -32
- data/lib/epom_rails/config.rb +36 -0
- data/lib/epom_rails/version.rb +1 -1
- data/lib/epom_rails.rb +3 -1
- data/lib/generators/epom_rails/config/USAGE +0 -0
- data/lib/generators/epom_rails/config/config_generator.rb +16 -0
- data/lib/generators/epom_rails/config/templates/epom_rails.rb +3 -0
- data/test/epom_rails/acts_as_advertiser_test.rb +19 -13
- data/test/epom_rails/acts_as_banner_test.rb +15 -9
- data/test/epom_rails/acts_as_campaign_test.rb +14 -9
- data/test/epom_rails/acts_as_placement_test.rb +10 -4
- data/test/epom_rails/acts_as_site_test.rb +13 -7
- data/test/epom_rails/acts_as_zone_test.rb +11 -5
- data/test/test_helper.rb +4 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 881de5d92f0a20370cdb8d5f59af872d2c0db131
|
4
|
+
data.tar.gz: 6e06828f0a38e0f12a4a43818eb6b3af99eb2043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ffd073e01ea28bfbf262c81a28a59d8dc3ac833228a05a6f7d27659719850a6546f3af881904b5ec73ad2b56ddec3cbe60d489e5c7f7009a2ea6d95f7018f37
|
7
|
+
data.tar.gz: 3a12c1c79cf720461179c74eb8ba58113a1df28c5f21155b52e69aefda6ee7123210122bc7b80f3fddd48cea860c3d047a9da8a7a759352381e6a2a627b8d758
|
data/lib/epom_rails/acts_as.rb
CHANGED
@@ -37,45 +37,49 @@ class ActiveRecord::Base
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.define_before_save
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
unless EpomRails.config.offline
|
41
|
+
klass = self.epom_klass
|
42
|
+
fields = self.epom_fields
|
43
|
+
before_save do
|
44
|
+
klass_name = klass.name.include?('::') ? klass.name.split('::').last : klass.name
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
method = if self.send fields.key('id') then "update_#{klass_name.downcase}" else "create_#{klass_name.downcase}" end
|
47
|
+
|
48
|
+
url_params = {}
|
49
|
+
if klass.extended_methods[method.to_sym][:url_parameters]
|
50
|
+
klass.extended_methods[method.to_sym][:url_parameters].each do |parameter|
|
51
|
+
url_params[parameter] = self.send(fields.key(parameter.to_s)) if fields.key(parameter.to_s)
|
52
|
+
end
|
51
53
|
end
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
body_params = {}
|
56
|
+
if klass.extended_methods[method.to_sym][:body_parameters]
|
57
|
+
klass.extended_methods[method.to_sym][:body_parameters].each do |parameter|
|
58
|
+
body_params[parameter] = self.send(fields.key(parameter.to_s)) if fields.key(parameter.to_s)
|
59
|
+
end
|
58
60
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
|
62
|
+
epom_response = klass.send method, url_params, body_params
|
63
|
+
|
64
|
+
unless self.send fields.key('id')
|
65
|
+
# save id value returned from Epom in an Advertiser column
|
66
|
+
self.send "#{fields.key('id')}=", epom_response['id']
|
67
|
+
end
|
68
|
+
epom_response['success']
|
69
|
+
end
|
70
|
+
end
|
69
71
|
end
|
70
72
|
|
71
73
|
def self.define_before_destroy
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
unless EpomRails.config.offline
|
75
|
+
klass = self.epom_klass
|
76
|
+
fields = self.epom_fields
|
77
|
+
before_destroy do
|
78
|
+
if self.send fields.key('id')
|
79
|
+
klass_name = klass.name.include?('::') ? klass.name.split('::').last : klass.name
|
80
|
+
epom_response = klass.send "delete_#{klass_name.downcase}", {"#{klass_name.downcase}Id" => self.send(fields.key('id'))}, {}
|
81
|
+
epom_response['success'] if epom_response
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module EpomRails
|
4
|
+
# Configures global settings for EpomRails
|
5
|
+
# EpomRails.configure do |config|
|
6
|
+
# config.offline = false
|
7
|
+
# end
|
8
|
+
def self.configure(&block)
|
9
|
+
yield @config ||= EpomRails::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Global settings for EpomRails
|
13
|
+
def self.config
|
14
|
+
@config
|
15
|
+
end
|
16
|
+
|
17
|
+
# need a Class for 3.0
|
18
|
+
class Configuration #:nodoc:
|
19
|
+
include ActiveSupport::Configurable
|
20
|
+
config_accessor :offline
|
21
|
+
|
22
|
+
def param_name
|
23
|
+
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
24
|
+
end
|
25
|
+
|
26
|
+
# define param_name writer (copied from AS::Configurable)
|
27
|
+
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
28
|
+
singleton_class.class_eval writer, __FILE__, line
|
29
|
+
class_eval writer, __FILE__, line
|
30
|
+
end
|
31
|
+
|
32
|
+
# this is ugly. why can't we pass the default value to config_accessor...?
|
33
|
+
EpomRails.configure do |config|
|
34
|
+
config.offline = false
|
35
|
+
end
|
36
|
+
end
|
data/lib/epom_rails/version.rb
CHANGED
data/lib/epom_rails.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'epom'
|
2
2
|
require 'epom_rails/acts_as'
|
3
3
|
|
4
|
+
require 'epom_rails/config'
|
5
|
+
|
4
6
|
module EpomRails
|
5
7
|
attr_accessor :epom_klass, :epom_fields
|
6
8
|
|
7
9
|
Epom::EpomElement.login(ENV['username'], ENV['password'])
|
8
10
|
|
9
11
|
def method_missing(method_name, *args)
|
10
|
-
if epom_klass.respond_to?(method_name)
|
12
|
+
if not EpomRails.config.offline and epom_klass.respond_to?(method_name)
|
11
13
|
epom_klass.send(method_name, args[0], args[1])
|
12
14
|
else
|
13
15
|
super
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EpomRails
|
2
|
+
class ConfigGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
|
5
|
+
def copy_epom_rails_file
|
6
|
+
template 'epom_rails.rb', 'config/initializers/epom_rails.rb'
|
7
|
+
if File.exist?('.gitignore')
|
8
|
+
inject_into_file '.gitignore', after: "/.bundle" do "\nconfig/initializers/epom_rails.rb" end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def epom_generator
|
13
|
+
generate 'epom:config'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -10,7 +10,8 @@ class ActsAsAdvertiserTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'save an advertiser' do
|
13
|
-
|
13
|
+
unless EpomRails.config.offline
|
14
|
+
advertiser = advertisers(:one)
|
14
15
|
|
15
16
|
assert advertiser.save
|
16
17
|
assert_instance_of Fixnum, advertiser.send(epom_field('id'))
|
@@ -29,36 +30,41 @@ class ActsAsAdvertiserTest < ActiveSupport::TestCase
|
|
29
30
|
epom_advertiser = epom_response.find{|a| a['id'] == advertiser.send(epom_field('id'))}
|
30
31
|
assert_equal advertiser.send(epom_field('name')), epom_advertiser['name']
|
31
32
|
assert_equal "Is Owner", epom_advertiser['shareType']
|
33
|
+
end
|
32
34
|
end
|
33
35
|
|
34
36
|
test 'delete an advertiser' do
|
35
|
-
|
37
|
+
unless EpomRails.config.offline
|
38
|
+
advertiser = advertisers(:one)
|
36
39
|
|
37
40
|
assert advertiser.save
|
38
41
|
assert_instance_of Fixnum, advertiser.send(epom_field('id'))
|
39
42
|
|
40
43
|
epom_id = advertiser.send(epom_field('id'))
|
41
44
|
assert advertiser.destroy
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
44
48
|
test 'epom methods' do
|
45
|
-
|
49
|
+
unless EpomRails.config.offline
|
50
|
+
response = Advertiser.get_advertisers_tree({}, {})
|
46
51
|
|
47
|
-
assert_instance_of Array, response
|
48
|
-
if response.count > 0
|
49
|
-
first = response[0]
|
50
|
-
assert_instance_of Fixnum, first['id']
|
51
|
-
assert_instance_of Array, first['category']
|
52
|
-
assert_instance_of String, first['name']
|
53
|
-
assert_instance_of Array, first['campaigns']
|
54
|
-
|
55
|
-
advertiser = first
|
56
|
-
response = Advertiser.get_campaigns_for_advertiser({:advertiserId => advertiser['id']}, {})
|
57
52
|
assert_instance_of Array, response
|
58
53
|
if response.count > 0
|
59
54
|
first = response[0]
|
60
55
|
assert_instance_of Fixnum, first['id']
|
56
|
+
assert_instance_of Array, first['category']
|
61
57
|
assert_instance_of String, first['name']
|
58
|
+
assert_instance_of Array, first['campaigns']
|
59
|
+
|
60
|
+
advertiser = first
|
61
|
+
response = Advertiser.get_campaigns_for_advertiser({:advertiserId => advertiser['id']}, {})
|
62
|
+
assert_instance_of Array, response
|
63
|
+
if response.count > 0
|
64
|
+
first = response[0]
|
65
|
+
assert_instance_of Fixnum, first['id']
|
66
|
+
assert_instance_of String, first['name']
|
67
|
+
end
|
62
68
|
end
|
63
69
|
end
|
64
70
|
end
|
@@ -10,33 +10,39 @@ class ActsAsBannerTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'save an banner' do
|
13
|
-
|
13
|
+
unless EpomRails.config.offline
|
14
|
+
banner = banners(:one)
|
14
15
|
|
15
16
|
assert banner.save
|
16
17
|
assert_instance_of Fixnum, banner.send(epom_field('id'))
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
test 'delete an banner' do
|
20
|
-
|
22
|
+
unless EpomRails.config.offline
|
23
|
+
banner = banners(:one)
|
21
24
|
|
22
25
|
assert banner.save
|
23
26
|
assert_instance_of Fixnum, banner.send(epom_field('id'))
|
24
27
|
|
25
28
|
epom_id = banner.send(epom_field('id'))
|
26
29
|
assert banner.destroy
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
test 'epom methods' do
|
30
|
-
|
34
|
+
unless EpomRails.config.offline
|
35
|
+
banner = banners(:one)
|
31
36
|
|
32
37
|
assert banner.save
|
33
38
|
assert_instance_of Fixnum, banner.send(epom_field('id'))
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
response = Banner.get_banner({:bannerId => banner.send(epom_field('id'))}, {})
|
41
|
+
assert_equal banner.campaign_id, response['campaignId']
|
42
|
+
assert_equal banner.weight, response['weight']
|
43
|
+
assert_equal banner.url, response['url']
|
44
|
+
assert_equal banner.name, response['name']
|
45
|
+
assert_equal banner.image_banner_link, response['imageBannerLink']
|
46
|
+
end
|
41
47
|
end
|
42
48
|
end
|
@@ -10,31 +10,36 @@ class ActsAsCampaignTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'save an campaign' do
|
13
|
-
|
13
|
+
unless EpomRails.config.offline
|
14
|
+
campaign = campaigns(:one)
|
14
15
|
|
15
16
|
assert campaign.save
|
16
17
|
assert_instance_of Fixnum, campaign.send(epom_field('id'))
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
test 'delete an campaign' do
|
20
|
-
|
22
|
+
unless EpomRails.config.offline
|
23
|
+
campaign = campaigns(:one)
|
21
24
|
|
22
25
|
assert campaign.save
|
23
26
|
assert_instance_of Fixnum, campaign.send(epom_field('id'))
|
24
27
|
|
25
28
|
epom_id = campaign.send(epom_field('id'))
|
26
29
|
assert campaign.destroy
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
test 'epom methods' do
|
30
|
-
|
34
|
+
unless EpomRails.config.offline
|
35
|
+
campaign = campaigns(:one)
|
31
36
|
|
32
|
-
|
33
|
-
|
37
|
+
assert campaign.save
|
38
|
+
assert_instance_of Fixnum, campaign.send(epom_field('id'))
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
response = Campaign.get_campaign({:campaignId => campaign.send(epom_field('id'))}, {})
|
41
|
+
assert_equal campaign.send(epom_field('id')), response['id']
|
42
|
+
assert_equal campaign.send(epom_field('name')), response['name']
|
43
|
+
end
|
39
44
|
end
|
40
45
|
end
|
@@ -10,7 +10,8 @@ class ActsAsPlacementTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'save an placement' do
|
13
|
-
|
13
|
+
unless EpomRails.config.offline
|
14
|
+
placement = placements(:one)
|
14
15
|
|
15
16
|
assert placement.save
|
16
17
|
assert_instance_of Fixnum, placement.send(epom_field('id'))
|
@@ -27,25 +28,30 @@ class ActsAsPlacementTest < ActiveSupport::TestCase
|
|
27
28
|
assert_instance_of Array, epom_response
|
28
29
|
epom_placement = epom_response.find{|a| a['id'] == placement.send(epom_field('id'))}
|
29
30
|
assert_equal placement.send(epom_field('name')), epom_placement['name']
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
34
|
test 'delete an placement' do
|
33
|
-
|
35
|
+
unless EpomRails.config.offline
|
36
|
+
placement = placements(:one)
|
34
37
|
|
35
38
|
assert placement.save
|
36
39
|
assert_instance_of Fixnum, placement.send(epom_field('id'))
|
37
40
|
|
38
41
|
epom_id = placement.send(epom_field('id'))
|
39
42
|
assert placement.destroy
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
test 'epom methods' do
|
43
|
-
|
47
|
+
unless EpomRails.config.offline
|
48
|
+
placement = placements(:one)
|
44
49
|
|
45
50
|
assert placement.save
|
46
51
|
assert_instance_of Fixnum, placement.send(epom_field('id'))
|
47
52
|
|
48
|
-
|
53
|
+
epom_response = Epom::Placement.get_placement_summary({}, {:placementIds => placement.send(epom_field('id'))})
|
49
54
|
assert_instance_of Array, epom_response
|
55
|
+
end
|
50
56
|
end
|
51
57
|
end
|
@@ -10,7 +10,8 @@ class ActsAsSiteTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'save an site' do
|
13
|
-
|
13
|
+
unless EpomRails.config.offline
|
14
|
+
site = sites(:one)
|
14
15
|
|
15
16
|
assert site.save
|
16
17
|
assert_instance_of Fixnum, site.send(epom_field('id'))
|
@@ -27,25 +28,30 @@ class ActsAsSiteTest < ActiveSupport::TestCase
|
|
27
28
|
assert_instance_of Array, epom_response
|
28
29
|
epom_site = epom_response.find{|a| a['id'] == site.send(epom_field('id'))}
|
29
30
|
assert_equal site.send(epom_field('name')), epom_site['name']
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
34
|
test 'delete an site' do
|
33
|
-
|
35
|
+
unless EpomRails.config.offline
|
36
|
+
site = sites(:one)
|
34
37
|
|
35
38
|
assert site.save
|
36
39
|
assert_instance_of Fixnum, site.send(epom_field('id'))
|
37
40
|
|
38
41
|
epom_id = site.send(epom_field('id'))
|
39
42
|
assert site.destroy
|
43
|
+
end
|
40
44
|
end
|
41
45
|
|
42
46
|
test 'epom methods' do
|
43
|
-
|
47
|
+
unless EpomRails.config.offline
|
48
|
+
site = sites(:one)
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
assert site.save
|
51
|
+
assert_instance_of Fixnum, site.send(epom_field('id'))
|
47
52
|
|
48
|
-
|
49
|
-
|
53
|
+
response = Site.get_sites_zones({:siteId => site.send(epom_field('id'))}, {})
|
54
|
+
assert_instance_of Array, response
|
55
|
+
end
|
50
56
|
end
|
51
57
|
end
|
@@ -10,32 +10,38 @@ class ActsAsZoneTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'save an zone' do
|
13
|
-
|
13
|
+
unless EpomRails.config.offline
|
14
|
+
zone = zones(:one)
|
14
15
|
|
15
16
|
assert zone.save
|
16
17
|
assert_instance_of Fixnum, zone.send(epom_field('id'))
|
17
18
|
|
18
19
|
# testing update_zone
|
19
20
|
assert zone.update name: 'otro string'
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
24
|
test 'delete an zone' do
|
23
|
-
|
25
|
+
unless EpomRails.config.offline
|
26
|
+
zone = zones(:one)
|
24
27
|
|
25
28
|
assert zone.save
|
26
29
|
assert_instance_of Fixnum, zone.send(epom_field('id'))
|
27
30
|
|
28
31
|
epom_id = zone.send(epom_field('id'))
|
29
32
|
assert zone.destroy
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
test 'epom methods' do
|
33
|
-
|
37
|
+
unless EpomRails.config.offline
|
38
|
+
zone = zones(:one)
|
34
39
|
|
35
40
|
assert zone.save
|
36
41
|
assert_instance_of Fixnum, zone.send(epom_field('id'))
|
37
42
|
|
38
|
-
|
39
|
-
|
43
|
+
response = Zone.get_zone_placements({:zoneId => zone.send(epom_field('id'))}, {})
|
44
|
+
assert_instance_of Array, response
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epom_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Chang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -64,7 +64,11 @@ files:
|
|
64
64
|
- Rakefile
|
65
65
|
- lib/epom_rails.rb
|
66
66
|
- lib/epom_rails/acts_as.rb
|
67
|
+
- lib/epom_rails/config.rb
|
67
68
|
- lib/epom_rails/version.rb
|
69
|
+
- lib/generators/epom_rails/config/USAGE
|
70
|
+
- lib/generators/epom_rails/config/config_generator.rb
|
71
|
+
- lib/generators/epom_rails/config/templates/epom_rails.rb
|
68
72
|
- lib/tasks/epom_rails_tasks.rake
|
69
73
|
- test/dummy/README.rdoc
|
70
74
|
- test/dummy/Rakefile
|