promonizr 1.13.2
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.
- checksums.yaml +7 -0
- data/Rakefile +1 -0
- data/config/configuration.rb +1 -0
- data/config/locales/br.yml +103 -0
- data/config/locales/cl.yml +102 -0
- data/config/locales/co.yml +102 -0
- data/config/locales/en.yml +102 -0
- data/config/promotion_api.yml +19 -0
- data/lib/promonizr/campaigns.rb +73 -0
- data/lib/promonizr/companies.rb +23 -0
- data/lib/promonizr/contests.rb +63 -0
- data/lib/promonizr/engine.rb +4 -0
- data/lib/promonizr/evaluations.rb +41 -0
- data/lib/promonizr/factories.rb +2 -0
- data/lib/promonizr/products.rb +48 -0
- data/lib/promonizr/promotion.rb +63 -0
- data/lib/promonizr/railtie.rb +7 -0
- data/lib/promonizr/request.rb +32 -0
- data/lib/promonizr/search.rb +54 -0
- data/lib/promonizr/special_events.rb +63 -0
- data/lib/promonizr/utils.rb +47 -0
- data/lib/promonizr/version.rb +3 -0
- data/lib/promonizr.rb +15 -0
- data/spec/factories/promotion_factory.rb +29 -0
- data/spec/i18n_spec.rb +13 -0
- data/spec/promonizr/campaigns_spec.rb +130 -0
- data/spec/promonizr/evaluations_spec.rb +59 -0
- data/spec/promonizr/products_spec.rb +33 -0
- data/spec/promonizr/promotion_spec.rb +155 -0
- data/spec/promonizr/request_spec.rb +23 -0
- data/spec/promonizr/search_spec.rb +343 -0
- data/spec/promonizr/utils_spec.rb +94 -0
- data/spec/promonizr_spec.rb +7 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/factory_girl.rb +9 -0
- metadata +220 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fed309f65e8324d77b60af02b5175fb67e5b98121106bb0960b95c3e9668c129
|
4
|
+
data.tar.gz: 30a328b823f945fceeaaaf7f29ad7f3d2ce1037e262f1a568bd0ba2b8b64c0b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf43239476710236ed5c5692520176e803f2380cc90ef4716e62729e4894fa55d21e425a1caa027b4f938b5f99f8764e5a0cea140b29983c85e059382ff34f8b
|
7
|
+
data.tar.gz: 554e4409828c3f2e836d8a179c3943a1860eaa072b5d2125ac73d83959eee030dd3ead4d6a43863dc8b3dde19d90cba14d0b4ba746b21e710a35a888e6d7190f
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
load 'promotion_api'
|
@@ -0,0 +1,103 @@
|
|
1
|
+
---
|
2
|
+
br:
|
3
|
+
promonizr:
|
4
|
+
actions: Acciones
|
5
|
+
add: Añadir
|
6
|
+
add_condition: Añadir condición
|
7
|
+
already_applied: ¿El beneficio ya fue aplicado?
|
8
|
+
amount: Cantidad
|
9
|
+
amount_hint: Cuántos 2x1 hay disponibles. Déjalo en blanco si no hay limites
|
10
|
+
applies:
|
11
|
+
from: Desde
|
12
|
+
to: Hasta
|
13
|
+
applies_to_installments: Aplica a las cuotas
|
14
|
+
applies_to_passengers: Aplica a los pasajeros
|
15
|
+
applies_to_passengers_hint: El primer pasajero es el %{first} y el último %{last}
|
16
|
+
benefits:
|
17
|
+
discount: Descuento
|
18
|
+
discount_percentage: Porcentaje de descuento
|
19
|
+
campaigns: Campañas
|
20
|
+
check_all: Marcar todas
|
21
|
+
clone: Clonar campaña
|
22
|
+
companies: Compañías
|
23
|
+
condition: Condición
|
24
|
+
condition_value: Valor
|
25
|
+
conditions:
|
26
|
+
between: Entre
|
27
|
+
eq: Igual a
|
28
|
+
gt: Mayor a
|
29
|
+
gte: Mayor o igual a
|
30
|
+
in: Dentro de
|
31
|
+
lt: Menor a
|
32
|
+
lte: Menor o igual a
|
33
|
+
neq: Distinto a
|
34
|
+
notIn: Fuera de
|
35
|
+
confirm_delete: "¿Estás seguro?"
|
36
|
+
countries:
|
37
|
+
br: Brasil
|
38
|
+
cl: Chile
|
39
|
+
co: Colombia
|
40
|
+
country: País
|
41
|
+
destroy: Borrar
|
42
|
+
discount_type: Tipo descuento
|
43
|
+
discount_value: Valor descuento
|
44
|
+
display_config: Configuración de visualización
|
45
|
+
edit: Editar campaña
|
46
|
+
end_date: Fecha de término
|
47
|
+
exclusions: Exclusiones
|
48
|
+
exclusions_hint: La promoción no se mostrará en estas páginas
|
49
|
+
featured_image: Imagen destacada
|
50
|
+
featured_label: "¿Es destacada?"
|
51
|
+
from_service: Procedencia
|
52
|
+
from_service_label: "¿La promoción proviene de un Web Service?"
|
53
|
+
gift_description: Descripción del regalo
|
54
|
+
gift_hint: Opcional, una breve descripción sobre el regalo
|
55
|
+
image: Imagen
|
56
|
+
kind: Tipo
|
57
|
+
kinds:
|
58
|
+
discount: Descuento
|
59
|
+
gift: Regalo
|
60
|
+
two_x_one: 2x1
|
61
|
+
new_campaign: Nueva campaña
|
62
|
+
not_rules_yet: No hay reglas aún
|
63
|
+
not_rules_yet_product_country: No hay reglas para esta combinación de país y producto
|
64
|
+
operator: Operador lógico
|
65
|
+
operators:
|
66
|
+
and: Y
|
67
|
+
or: O
|
68
|
+
payment_method: Medio de pago
|
69
|
+
payment_methods:
|
70
|
+
any: Cualquiera
|
71
|
+
product: Producto
|
72
|
+
products:
|
73
|
+
car_insurance: Seguro de auto
|
74
|
+
travel_assistance: Asistencia en viaje
|
75
|
+
remaining_characters: Caracteres restantes
|
76
|
+
required_dimensions: 'Dimensión requerida: %{height}×%{width} px'
|
77
|
+
rules: Reglas
|
78
|
+
save: Guardar
|
79
|
+
saving: Guardando...
|
80
|
+
simple_rules: Reglas simples
|
81
|
+
stage_pages:
|
82
|
+
landing: Landing
|
83
|
+
results: Página de resultados
|
84
|
+
sale: Sale page
|
85
|
+
start_date: Fecha de inicio
|
86
|
+
subtitle: Bajada
|
87
|
+
terms_of_service: Términos y condiciones
|
88
|
+
title: Título
|
89
|
+
uncheck_all: Desmarcar todas
|
90
|
+
update: Actualizar
|
91
|
+
hour: Hora
|
92
|
+
name: Nombre
|
93
|
+
short_description: Descripción breve
|
94
|
+
long_description: Descripción larga
|
95
|
+
special_event: Evento especial
|
96
|
+
special_events: Eventos especiales
|
97
|
+
new_special_event: Nuevo evento especial
|
98
|
+
edit_special_event: Editar evento especial
|
99
|
+
contest: Concurso
|
100
|
+
contests: Concursos
|
101
|
+
new_contest: Nuevo concurso
|
102
|
+
edit_contest: Editar concurso
|
103
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
---
|
2
|
+
cl:
|
3
|
+
promonizr:
|
4
|
+
actions: Acciones
|
5
|
+
add: Añadir
|
6
|
+
add_condition: Añadir condición
|
7
|
+
already_applied: "¿El beneficio ya fue aplicado?"
|
8
|
+
amount: Cantidad
|
9
|
+
amount_hint: Cuántos 2x1 hay disponibles. Déjalo en blanco si no hay limites
|
10
|
+
applies:
|
11
|
+
from: Desde
|
12
|
+
to: Hasta
|
13
|
+
applies_to_installments: Aplica a las cuotas
|
14
|
+
applies_to_passengers: Aplica a los pasajeros
|
15
|
+
applies_to_passengers_hint: El primer pasajero es el %{first} y el último %{last}
|
16
|
+
benefits:
|
17
|
+
discount: Descuento
|
18
|
+
discount_percentage: Porcentaje de descuento
|
19
|
+
campaigns: Campañas
|
20
|
+
check_all: Marcar todas
|
21
|
+
clone: Clonar campaña
|
22
|
+
companies: Compañías
|
23
|
+
condition: Condición
|
24
|
+
condition_value: Valor
|
25
|
+
conditions:
|
26
|
+
between: Entre
|
27
|
+
eq: Igual a
|
28
|
+
gt: Mayor a
|
29
|
+
gte: Mayor o igual a
|
30
|
+
in: Dentro de
|
31
|
+
lt: Menor a
|
32
|
+
lte: Menor o igual a
|
33
|
+
neq: Distinto a
|
34
|
+
notIn: Fuera de
|
35
|
+
confirm_delete: "¿Estás seguro?"
|
36
|
+
countries:
|
37
|
+
br: Brasil
|
38
|
+
cl: Chile
|
39
|
+
co: Colombia
|
40
|
+
country: País
|
41
|
+
destroy: Borrar
|
42
|
+
discount_type: Tipo descuento
|
43
|
+
discount_value: Valor descuento
|
44
|
+
display_config: Configuración de visualización
|
45
|
+
edit: Editar campaña
|
46
|
+
end_date: Fecha de término
|
47
|
+
exclusions: Exclusiones
|
48
|
+
exclusions_hint: La promoción no se mostrará en estas páginas
|
49
|
+
featured_image: Imagen destacada
|
50
|
+
featured_label: "¿Es destacada?"
|
51
|
+
from_service: Procedencia
|
52
|
+
from_service_label: "¿La promoción proviene de un Web Service?"
|
53
|
+
gift_description: Descripción del regalo
|
54
|
+
gift_hint: Opcional, una breve descripción sobre el regalo
|
55
|
+
image: Imagen
|
56
|
+
kind: Tipo
|
57
|
+
kinds:
|
58
|
+
discount: Descuento
|
59
|
+
gift: Regalo
|
60
|
+
two_x_one: 2x1
|
61
|
+
new_campaign: Nueva campaña
|
62
|
+
not_rules_yet: No hay reglas aún
|
63
|
+
not_rules_yet_product_country: No hay reglas para esta combinación de país y producto
|
64
|
+
operator: Operador lógico
|
65
|
+
operators:
|
66
|
+
and: Y
|
67
|
+
or: O
|
68
|
+
payment_method: Medio de pago
|
69
|
+
payment_methods:
|
70
|
+
any: Cualquiera
|
71
|
+
product: Producto
|
72
|
+
products:
|
73
|
+
car_insurance: Seguro de auto
|
74
|
+
travel_assistance: Asistencia en viaje
|
75
|
+
remaining_characters: Caracteres restantes
|
76
|
+
required_dimensions: 'Dimensión requerida: %{height}×%{width} px'
|
77
|
+
rules: Reglas
|
78
|
+
save: Guardar
|
79
|
+
saving: Guardando...
|
80
|
+
simple_rules: Reglas simples
|
81
|
+
stage_pages:
|
82
|
+
landing: Landing
|
83
|
+
results: Página de resultados
|
84
|
+
sale: Sale page
|
85
|
+
start_date: Fecha de inicio
|
86
|
+
subtitle: Bajada
|
87
|
+
terms_of_service: Términos y condiciones
|
88
|
+
title: Título
|
89
|
+
uncheck_all: Desmarcar todas
|
90
|
+
update: Actualizar
|
91
|
+
hour: Hora
|
92
|
+
name: Nombre
|
93
|
+
short_description: Descripción breve
|
94
|
+
long_description: Descripción larga
|
95
|
+
special_event: Evento especial
|
96
|
+
special_events: Eventos especiales
|
97
|
+
new_special_event: Nuevo evento especial
|
98
|
+
edit_special_event: Editar evento especial
|
99
|
+
contest: Concurso
|
100
|
+
contests: Concursos
|
101
|
+
new_contest: Nuevo concurso
|
102
|
+
edit_contest: Editar concurso
|
@@ -0,0 +1,102 @@
|
|
1
|
+
---
|
2
|
+
co:
|
3
|
+
promonizr:
|
4
|
+
actions: Acciones
|
5
|
+
add: Añadir
|
6
|
+
add_condition: Añadir condición
|
7
|
+
already_applied: ¿El beneficio ya fue aplicado?
|
8
|
+
amount: Cantidad
|
9
|
+
amount_hint: Cuántos 2x1 hay disponibles. Déjalo en blanco si no hay limites
|
10
|
+
applies:
|
11
|
+
from: Desde
|
12
|
+
to: Hasta
|
13
|
+
applies_to_installments: Aplica a las cuotas
|
14
|
+
applies_to_passengers: Aplica a los pasajeros
|
15
|
+
applies_to_passengers_hint: El primer pasajero es el %{first} y el último %{last}
|
16
|
+
benefits:
|
17
|
+
discount: Descuento
|
18
|
+
discount_percentage: Porcentaje de descuento
|
19
|
+
campaigns: Campañas
|
20
|
+
check_all: Marcar todas
|
21
|
+
clone: Clonar campaña
|
22
|
+
companies: Compañías
|
23
|
+
condition: Condición
|
24
|
+
condition_value: Valor
|
25
|
+
conditions:
|
26
|
+
between: Entre
|
27
|
+
eq: Igual a
|
28
|
+
gt: Mayor a
|
29
|
+
gte: Mayor o igual a
|
30
|
+
in: Dentro de
|
31
|
+
lt: Menor a
|
32
|
+
lte: Menor o igual a
|
33
|
+
neq: Distinto a
|
34
|
+
notIn: Fuera de
|
35
|
+
confirm_delete: "¿Estás seguro?"
|
36
|
+
countries:
|
37
|
+
br: Brasil
|
38
|
+
cl: Chile
|
39
|
+
co: Colombia
|
40
|
+
country: País
|
41
|
+
destroy: Borrar
|
42
|
+
discount_type: Tipo descuento
|
43
|
+
discount_value: Valor descuento
|
44
|
+
display_config: Configuración de visualización
|
45
|
+
edit: Editar campaña
|
46
|
+
end_date: Fecha de término
|
47
|
+
exclusions: Exclusiones
|
48
|
+
exclusions_hint: La promoción no se mostrará en estas páginas
|
49
|
+
featured_image: Imagen destacada
|
50
|
+
featured_label: "¿Es destacada?"
|
51
|
+
from_service: Procedencia
|
52
|
+
from_service_label: "¿La promoción proviene de un Web Service?"
|
53
|
+
gift_description: Descripción del regalo
|
54
|
+
gift_hint: Opcional, una breve descripción sobre el regalo
|
55
|
+
image: Imagen
|
56
|
+
kind: Tipo
|
57
|
+
kinds:
|
58
|
+
discount: Descuento
|
59
|
+
gift: Regalo
|
60
|
+
two_x_one: 2x1
|
61
|
+
new_campaign: Nueva campaña
|
62
|
+
not_rules_yet: No hay reglas aún
|
63
|
+
not_rules_yet_product_country: No hay reglas para esta combinación de país y producto
|
64
|
+
operator: Operador lógico
|
65
|
+
operators:
|
66
|
+
and: Y
|
67
|
+
or: O
|
68
|
+
payment_method: Medio de pago
|
69
|
+
payment_methods:
|
70
|
+
any: Cualquiera
|
71
|
+
product: Producto
|
72
|
+
products:
|
73
|
+
car_insurance: Seguro de auto
|
74
|
+
travel_assistance: Asistencia en viaje
|
75
|
+
remaining_characters: Caracteres restantes
|
76
|
+
required_dimensions: 'Dimensión requerida: %{height}×%{width} px'
|
77
|
+
rules: Reglas
|
78
|
+
save: Guardar
|
79
|
+
saving: Guardando...
|
80
|
+
simple_rules: Reglas simples
|
81
|
+
stage_pages:
|
82
|
+
landing: Landing
|
83
|
+
results: Página de resultados
|
84
|
+
sale: Sale page
|
85
|
+
start_date: Fecha de inicio
|
86
|
+
subtitle: Bajada
|
87
|
+
terms_of_service: Términos y condiciones
|
88
|
+
title: Título
|
89
|
+
uncheck_all: Desmarcar todas
|
90
|
+
update: Actualizar
|
91
|
+
hour: Hora
|
92
|
+
name: Nombre
|
93
|
+
short_description: Descripción breve
|
94
|
+
long_description: Descripción larga
|
95
|
+
special_event: Evento especial
|
96
|
+
special_events: Eventos especiales
|
97
|
+
new_special_event: Nuevo evento especial
|
98
|
+
edit_special_event: Editar evento especial
|
99
|
+
contest: Concurso
|
100
|
+
contests: Concursos
|
101
|
+
new_contest: Nuevo concurso
|
102
|
+
edit_contest: Editar concurso
|
@@ -0,0 +1,102 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
promonizr:
|
4
|
+
actions: Actions
|
5
|
+
add: Add
|
6
|
+
add_condition: Add condition
|
7
|
+
already_applied: is benefit already applied?
|
8
|
+
amount: Amount
|
9
|
+
amount_hint: How many 2x1 are available. Leave it blank if there is no limits.
|
10
|
+
applies:
|
11
|
+
from: From
|
12
|
+
to: To
|
13
|
+
applies_to_installments: Applies to instalments
|
14
|
+
applies_to_passengers: Applies to passengers
|
15
|
+
applies_to_passengers_hint: El primer pasajero es el %{first} y el último %{last}
|
16
|
+
benefits:
|
17
|
+
discount: Discount
|
18
|
+
discount_percentage: Percentage discount
|
19
|
+
campaigns: Campaign
|
20
|
+
check_all: Check all
|
21
|
+
clone: Clone campaign
|
22
|
+
companies: Companies
|
23
|
+
condition: Condition
|
24
|
+
condition_value: Value
|
25
|
+
conditions:
|
26
|
+
between: Between
|
27
|
+
eq: Equal
|
28
|
+
gt: Greater than
|
29
|
+
gte: Great than or equal to
|
30
|
+
in: In
|
31
|
+
lt: Less than
|
32
|
+
lte: Less than or equal to
|
33
|
+
neq: Not equal
|
34
|
+
notIn: Not in
|
35
|
+
confirm_delete: Are you sure?
|
36
|
+
countries:
|
37
|
+
br: Brazil
|
38
|
+
cl: Chile
|
39
|
+
co: Colombia
|
40
|
+
country: Country
|
41
|
+
destroy: Destroy
|
42
|
+
discount_type: Discount type
|
43
|
+
discount_value: Discount value
|
44
|
+
display_config: Display config
|
45
|
+
edit: Edit campaign
|
46
|
+
end_date: End date
|
47
|
+
exclusions: Exclusions
|
48
|
+
exclusions_hint: La promoción no se mostrará en estas páginas
|
49
|
+
featured_image: Featured image
|
50
|
+
featured_label: Is it featured ?
|
51
|
+
from_service: From service
|
52
|
+
from_service_label: "¿La promoción proviene de un Web Service?"
|
53
|
+
gift_description: Gift description
|
54
|
+
gift_hint: Optional, a brief description about the gift
|
55
|
+
image: Image
|
56
|
+
kind: Type
|
57
|
+
kinds:
|
58
|
+
discount: Discount
|
59
|
+
gift: Gift
|
60
|
+
two_x_one: 2x1
|
61
|
+
new_campaign: New Campaign
|
62
|
+
not_rules_yet: There are not rules yet
|
63
|
+
not_rules_yet_product_country: There are not simple rules for this combination of product and country
|
64
|
+
operator: Logical operator
|
65
|
+
operators:
|
66
|
+
and: And
|
67
|
+
or: Or
|
68
|
+
payment_method: Payment method
|
69
|
+
payment_methods:
|
70
|
+
any: Any
|
71
|
+
product: Product
|
72
|
+
products:
|
73
|
+
car_insurance: Car insurance
|
74
|
+
travel_assistance: Travel assistance
|
75
|
+
remaining_characters: Remaining characters
|
76
|
+
required_dimensions: 'Required dimensions: %{height}×%{width} px'
|
77
|
+
rules: Rules
|
78
|
+
save: Save
|
79
|
+
saving: Saving...
|
80
|
+
simple_rules: Simple rules
|
81
|
+
stage_pages:
|
82
|
+
landing: Landing page
|
83
|
+
results: Results page
|
84
|
+
sale: Sale page
|
85
|
+
start_date: Start date
|
86
|
+
subtitle: Subtitle
|
87
|
+
terms_of_service: Terms of service
|
88
|
+
title: Title
|
89
|
+
uncheck_all: Uncheck all
|
90
|
+
update: Update
|
91
|
+
hour: Hour
|
92
|
+
name: Name
|
93
|
+
short_description: Short description
|
94
|
+
long_description: Long description
|
95
|
+
special_event: Special Event
|
96
|
+
special_events: Special Events
|
97
|
+
new_special_event: New Special Event
|
98
|
+
edit_special_event: Edit Special Event
|
99
|
+
contest: Contest
|
100
|
+
contests: Contests
|
101
|
+
new_contest: New contest
|
102
|
+
edit_contest: Edit contest
|
@@ -0,0 +1,19 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
url: https://ms-staging.comparaonline.com/promotions
|
3
|
+
cdn: https://webimg.comparaonline.com
|
4
|
+
|
5
|
+
development:
|
6
|
+
<<: *defaults
|
7
|
+
cdn: ''
|
8
|
+
|
9
|
+
qc:
|
10
|
+
<<: *defaults
|
11
|
+
cdn: https://qc.webimg.comparaonline.com
|
12
|
+
|
13
|
+
staging:
|
14
|
+
<<: *defaults
|
15
|
+
cdn: https://staging.webimg.comparaonline.com
|
16
|
+
|
17
|
+
production:
|
18
|
+
<<: *defaults
|
19
|
+
url: https://ms.comparaonline.com/promotions
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Promonizr
|
2
|
+
# Campaigns implements CRUD methods on the Campaign resource from the
|
3
|
+
# Promotions web service.
|
4
|
+
module Campaigns
|
5
|
+
JSON_ATTRIBUTES = %i(rules conditions benefits display_config companies).freeze
|
6
|
+
|
7
|
+
STAGE_CODES = %w(landing results).freeze
|
8
|
+
COUNTRY_CODES = %w(cl br co).freeze
|
9
|
+
KIND_CODES = %w(two_x_one discount gift).freeze
|
10
|
+
BENEFITS_BY_PRODUCT = {
|
11
|
+
car_insurance: %w(discount gift),
|
12
|
+
travel_assistance: %w(two_x_one discount)
|
13
|
+
}.freeze
|
14
|
+
RULE_OPERATORS = %w(and or).freeze
|
15
|
+
RULE_CONDITIONS = %w(eq neq lt gt lte gte in notIn between).freeze
|
16
|
+
|
17
|
+
VALIDATION_RULES = {
|
18
|
+
title: {
|
19
|
+
max_length: 62
|
20
|
+
},
|
21
|
+
subtitle: {
|
22
|
+
max_length: 200
|
23
|
+
}
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
module_function
|
27
|
+
|
28
|
+
def api_url
|
29
|
+
CoConfig::PROMOTION_API[:url] + '/campaigns'
|
30
|
+
end
|
31
|
+
|
32
|
+
def all
|
33
|
+
@campaigns = Request.execute(:get, api_url)
|
34
|
+
@campaigns.is_a?(Array) ? @campaigns : []
|
35
|
+
end
|
36
|
+
|
37
|
+
def create(params)
|
38
|
+
Request.execute(:post, api_url, sanitized_params(params))
|
39
|
+
end
|
40
|
+
|
41
|
+
def update(id, params)
|
42
|
+
Request.execute(:put, url_with_id(id), sanitized_params(params))
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy(id)
|
46
|
+
Request.execute(:delete, url_with_id(id))
|
47
|
+
end
|
48
|
+
|
49
|
+
def get(id)
|
50
|
+
Request.execute(:get, url_with_id(id))
|
51
|
+
end
|
52
|
+
|
53
|
+
def url_with_id(id)
|
54
|
+
"#{api_url}/#{id}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Ensures that columns defined in JSON_ATTRIBUTES are json strings.
|
58
|
+
# boolean values will be casted
|
59
|
+
def sanitized_params(params)
|
60
|
+
JSON_ATTRIBUTES.each do |json_column|
|
61
|
+
next unless params.key?(json_column)
|
62
|
+
|
63
|
+
if params[json_column].is_a?(String)
|
64
|
+
params[json_column] = JSON.parse(params[json_column])
|
65
|
+
end
|
66
|
+
|
67
|
+
params[json_column] = Utils.cast_values(params[json_column]).to_json
|
68
|
+
end
|
69
|
+
|
70
|
+
params
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Promonizr
|
2
|
+
module Companies
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# The gem's client must implement this in order to
|
6
|
+
# provide its own way to fetch all companies names.
|
7
|
+
# Returns: Array[String]
|
8
|
+
# Example:
|
9
|
+
# def all(...); Company.pluck(:name); end
|
10
|
+
def all(country_code, product_code_name)
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
# The gem's client must implement this in order to
|
15
|
+
# provide its own way to fetch companies using its url_name
|
16
|
+
# Returns: Array[String]
|
17
|
+
# Example:
|
18
|
+
# def by_url_names(...); Company.where(url_name: url_names); end
|
19
|
+
def by_url_names(url_names, country_code, product_code_name)
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Promonizr
|
2
|
+
# Campaigns implements CRUD methods on the Campaign resource from the
|
3
|
+
# Promotions web service.
|
4
|
+
module Contests
|
5
|
+
JSON_ATTRIBUTES = %i(images).freeze
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def api_url
|
10
|
+
CoConfig::PROMOTION_API[:url] + '/contests'
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
@contests = Request.execute(:get, api_url)
|
15
|
+
@contests.is_a?(Array) ?@contests : []
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(params)
|
19
|
+
Request.execute(:post, api_url, sanitized_params(params))
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(id, params)
|
23
|
+
Request.execute(:put, url_with_id(id), sanitized_params(params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy(id)
|
27
|
+
Request.execute(:delete, url_with_id(id))
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(id)
|
31
|
+
Request.execute(:get, url_with_id(id))
|
32
|
+
end
|
33
|
+
|
34
|
+
def url_with_id(id)
|
35
|
+
"#{api_url}/#{id}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def search(params)
|
39
|
+
Request.execute(:post, url_with_id('search'), sanitized_params(params))
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_current(params)
|
43
|
+
events = search(params)
|
44
|
+
events.empty? ? nil : events[0]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Ensures that columns defined in JSON_ATTRIBUTES are json strings.
|
48
|
+
# boolean values will be casted
|
49
|
+
def sanitized_params(params)
|
50
|
+
JSON_ATTRIBUTES.each do |json_column|
|
51
|
+
next unless params.key?(json_column)
|
52
|
+
|
53
|
+
if params[json_column].is_a?(String)
|
54
|
+
params[json_column] = JSON.parse(params[json_column])
|
55
|
+
end
|
56
|
+
|
57
|
+
params[json_column] = params[json_column].to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
params
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Promonizr
|
2
|
+
module Evaluations
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def api_url(rest)
|
6
|
+
"#{CoConfig::PROMOTION_API[:url]}/#{rest}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def headers
|
10
|
+
{content_type: :json}
|
11
|
+
end
|
12
|
+
|
13
|
+
def evaluate(product, country_code, attributes = {})
|
14
|
+
attributes = attributes.with_indifferent_access
|
15
|
+
|
16
|
+
params = {
|
17
|
+
countryCode: country_code,
|
18
|
+
product: product,
|
19
|
+
form: attributes,
|
20
|
+
companyName: attributes[:company_name]
|
21
|
+
}.to_json
|
22
|
+
|
23
|
+
campaigns = Request.execute(:post, api_url('evaluate'), params, headers)
|
24
|
+
build_promotions(campaigns)
|
25
|
+
end
|
26
|
+
|
27
|
+
def evaluate_in_bulk(url, form_data, offers_data)
|
28
|
+
params = {
|
29
|
+
form: form_data,
|
30
|
+
offers: offers_data
|
31
|
+
}.to_json
|
32
|
+
Request.execute(:post, api_url("#{url}/campaigns_for_offers"), params, headers)
|
33
|
+
.map { |offer_id, campaigns| [offer_id, build_promotions(campaigns)] }
|
34
|
+
.to_h
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_promotions(campaigns)
|
38
|
+
campaigns.map { |c| Promotion.new(c) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|