lime_light_platform 1.0.0.3 → 1.0.0.4
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 +4 -4
- data/lib/lime_light_platform.rb +267 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51d9415c838946dba28413a0a6228e04faa9bc9a997cc047d77287b57a837f03
|
4
|
+
data.tar.gz: 5d9290d1b86281869969a28c5e8938037ae49ec1041499ece72f2409e239ce9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d7ed5b6e8d8c821b145dbd9ac7b9d780d283655cd1599e3ced165291e12351d31c382252da90c7d5ea495995703271fba9f3c1328ff11cdd69a1c59983fd76e
|
7
|
+
data.tar.gz: d454a7d559bf78946c0bf131da91798c60ab9c945bdae352609b195326a57d4cf8e601a035123ae2110bff2075a014104b32745187d663c7f993b6afd7945fae
|
data/lib/lime_light_platform.rb
CHANGED
@@ -1,2 +1,268 @@
|
|
1
|
-
class LimeLightPlatform <
|
1
|
+
class LimeLightPlatform < AppBase
|
2
|
+
include Helpers::Accessor
|
3
|
+
|
4
|
+
URL_TEMPLATE = 'https://<APP_KEY>.limelightcrm.com/<DEV_SUB>api/v1/<METHOD>.php'
|
5
|
+
|
6
|
+
attr_reader :app_key,
|
7
|
+
:api_username,
|
8
|
+
:api_password,
|
9
|
+
:dev_subdirectory
|
10
|
+
|
11
|
+
def initialize app_key, api_username, api_password, dev_subdirectory=''
|
12
|
+
if app_key.blank?
|
13
|
+
raise ApiError.new 'App Key is required'
|
14
|
+
end
|
15
|
+
|
16
|
+
if api_username.blank?
|
17
|
+
raise ApiError.new 'API username is required'
|
18
|
+
end
|
19
|
+
|
20
|
+
if api_password.blank?
|
21
|
+
raise ApiError.new 'API password is required'
|
22
|
+
end
|
23
|
+
|
24
|
+
@app_key = app_key
|
25
|
+
@api_username = api_username
|
26
|
+
@api_password = api_password
|
27
|
+
@dev_subdirectory = dev_subdirectory
|
28
|
+
|
29
|
+
if !@dev_subdirectory.blank?
|
30
|
+
@dev_subdirectory = @dev_subdirectory + '/'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def campaign_find_active
|
35
|
+
response = default_response
|
36
|
+
api_response = perform_api_call base_call_params(__method__)
|
37
|
+
|
38
|
+
if !api_response.blank?
|
39
|
+
parsed = JSON.parse(response)
|
40
|
+
response_code = parsed['response'].to_i
|
41
|
+
response[:code] = response_code
|
42
|
+
campaigns = []
|
43
|
+
|
44
|
+
if response_code == 100
|
45
|
+
response[:success] = true
|
46
|
+
campaign_ids = parsed['campaign_id']
|
47
|
+
campaign_names = parsed['campaign_name']
|
48
|
+
|
49
|
+
campaign_ids.each_with_index {|campaign_id, i|
|
50
|
+
campaigns << {
|
51
|
+
'id' => campaign_id,
|
52
|
+
'name' => campaign_names[i]
|
53
|
+
}
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
response[:data] = campaigns
|
58
|
+
end
|
59
|
+
|
60
|
+
response
|
61
|
+
end
|
62
|
+
|
63
|
+
def campaign_view campaign_id
|
64
|
+
call_params = base_call_params __method__
|
65
|
+
call_params[:body]['campaign_id'] = campaign_id
|
66
|
+
common_perform_post call_params
|
67
|
+
end
|
68
|
+
|
69
|
+
def gateway_view gateway_id
|
70
|
+
call_params = base_call_params __method__
|
71
|
+
call_params[:body]['gateway_id'] = gateway_id
|
72
|
+
common_perform_post call_params
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_order request={}
|
76
|
+
method_name = __method__.to_s
|
77
|
+
call_params = base_call_params method_name.camelize
|
78
|
+
call_params[:body] = {
|
79
|
+
'firstName' => get_if_exists('first_name', request),
|
80
|
+
'lastName' => get_if_exists('last_name', request),
|
81
|
+
'shippingAddress1' => get_if_exists('shipping_address_1', request),
|
82
|
+
'shippingAddress2' => get_if_exists('shipping_address_2', request),
|
83
|
+
'shippingCity' => get_if_exists('shipping_city', request),
|
84
|
+
'shippingState' => get_if_exists('shipping_state', request),
|
85
|
+
'shippingZip' => get_if_exists('shipping_zip', request),
|
86
|
+
'shippingCountry' => get_if_exists('shipping_country', request),
|
87
|
+
'billingFirstName' => get_if_exists('billing_first_name', request),
|
88
|
+
'billingLastName' => get_if_exists('billing_last_name', request),
|
89
|
+
'billingAddress1' => get_if_exists('billing_address_1', request),
|
90
|
+
'billingAddress2' => get_if_exists('billing_address_2', request),
|
91
|
+
'billingCity' => get_if_exists('billing_city', request),
|
92
|
+
'billingState' => get_if_exists('billing_state', request),
|
93
|
+
'billingZip' => get_if_exists('billing_zip', request),
|
94
|
+
'billingCountry' => get_if_exists('billing_country', request),
|
95
|
+
'phone' => get_if_exists('phone', request),
|
96
|
+
'email' => get_if_exists('email', request),
|
97
|
+
'creditCardType' => get_if_exists('credit_card_type', request),
|
98
|
+
'creditCardNumber' => get_if_exists('credit_card_number', request),
|
99
|
+
'creditCardNumber' => get_if_exists('credit_card_number', request),
|
100
|
+
'expirationDate' => get_if_exists('expiration_date', request),
|
101
|
+
'CVV' => get_if_exists('cvv', request),
|
102
|
+
'shippingId' => get_if_exists('shipping_id', request),
|
103
|
+
'tranType' => get_if_exists('tran_type', request),
|
104
|
+
'ipAddress' => get_if_exists('ip_address', request),
|
105
|
+
'campaignId' => get_if_exists('campaign_id', request),
|
106
|
+
'notes' => get_if_exists('notes', request),
|
107
|
+
'utm_source' => get_if_exists('utm_source', request),
|
108
|
+
'utm_medium' => get_if_exists('utm_medium', request),
|
109
|
+
'utm_campaign' => get_if_exists('utm_campaign', request),
|
110
|
+
'utm_content' => get_if_exists('utm_content', request),
|
111
|
+
'utm_term' => get_if_exists('utm_term', request),
|
112
|
+
'products' => get_if_exists('products', request)
|
113
|
+
}
|
114
|
+
common_perform_post call_params
|
115
|
+
end
|
116
|
+
|
117
|
+
def product_create request={}
|
118
|
+
call_params = base_call_params __method__
|
119
|
+
call_params[:body] = {
|
120
|
+
'customer_purchase_limit' => get_if_exists('customer_purchase_limit', request, 0),
|
121
|
+
'taxable' => get_if_exists('taxable', request, 0),
|
122
|
+
'shippable' => get_if_exists('shippable', request, 0),
|
123
|
+
'signature_confirmation' => get_if_exists('signature_confirmation', request, 0),
|
124
|
+
'delivery_confirmation' => get_if_exists('delivery_confirmation', request, 0),
|
125
|
+
'preserve_quantity' => get_if_exists('preserve_quantity', request, 0),
|
126
|
+
'collections' => get_if_exists('collections', request, 0),
|
127
|
+
'shipping_declared_value' => get_if_exists('shipping_declared_value', request, 0),
|
128
|
+
'product_price' => get_if_exists('product_price', request, 0),
|
129
|
+
'product_restocking_fee' => get_if_exists('product_restocking_fee', request, 0),
|
130
|
+
'shipping_weight' => get_if_exists('shipping_weight', request, 0),
|
131
|
+
'product_sku' => get_if_exists('product_sku', request),
|
132
|
+
'shipping_digital_url' => get_if_exists('shipping_digital_url', request),
|
133
|
+
'recurring_discount_max' => get_if_exists('recurring_discount_max', request, 0),
|
134
|
+
'product_name' => get_if_exists('product_name', request),
|
135
|
+
'product_description' => get_if_exists('product_description', request),
|
136
|
+
'category_id' => get_if_exists('category_id', request, 0),
|
137
|
+
'vertical_id' => get_if_exists('vertical_id', request, 0),
|
138
|
+
'cost_of_goods_sold' => get_if_exists('cost_of_goods_sold', request, 0),
|
139
|
+
'product_max_quantity' => get_if_exists('product_max_quantity', request, 1)
|
140
|
+
}
|
141
|
+
common_perform_post call_params
|
142
|
+
end
|
143
|
+
|
144
|
+
def product_update request={}
|
145
|
+
response = default_response
|
146
|
+
call_params = base_call_params __method__
|
147
|
+
|
148
|
+
if key_exists('product_id', request)
|
149
|
+
call_params[:body]['product_ids'] = []
|
150
|
+
call_params[:body]['actions'] = []
|
151
|
+
call_params[:body]['values'] = []
|
152
|
+
keys = [
|
153
|
+
'customer_purchase_limit',
|
154
|
+
'taxable',
|
155
|
+
'shippable',
|
156
|
+
'signature_confirmation',
|
157
|
+
'delivery_confirmation',
|
158
|
+
'preserve_quantity',
|
159
|
+
'collections',
|
160
|
+
'shipping_declared_value',
|
161
|
+
'product_price',
|
162
|
+
'product_restocking_fee',
|
163
|
+
'shipping_weight',
|
164
|
+
'product_sku',
|
165
|
+
'shipping_digital_url',
|
166
|
+
'recurring_discount_max',
|
167
|
+
'product_name',
|
168
|
+
'product_description',
|
169
|
+
'category_id',
|
170
|
+
'vertical_id',
|
171
|
+
'cost_of_goods_sold',
|
172
|
+
'product_max_quantity'
|
173
|
+
]
|
174
|
+
|
175
|
+
# only update what is present
|
176
|
+
keys.each do |key|
|
177
|
+
if key_exists(key, request)
|
178
|
+
call_params[:body]['product_ids'] << request['product_id']
|
179
|
+
call_params[:body]['actions'] << key
|
180
|
+
call_params[:body]['values'] << get_by_key(key)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
if !call_params[:body]['product_ids'].empty?
|
185
|
+
api_response = perform_api_call call_params
|
186
|
+
|
187
|
+
if !api_response.nil?
|
188
|
+
parsed = JSON.parse(api_response)
|
189
|
+
|
190
|
+
if !parsed['response_code'].nil?
|
191
|
+
response_code = parsed['response_code'].to_i
|
192
|
+
response[:code] = response_code
|
193
|
+
|
194
|
+
if response_code == 100
|
195
|
+
response[:success] = true
|
196
|
+
response[:data] = parsed
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
response
|
204
|
+
end
|
205
|
+
|
206
|
+
def order_update
|
207
|
+
response = default_response
|
208
|
+
response
|
209
|
+
end
|
210
|
+
|
211
|
+
def subscription_order_update
|
212
|
+
response = default_response
|
213
|
+
response
|
214
|
+
end
|
215
|
+
|
216
|
+
def billing_model_view offer_id
|
217
|
+
call_params = base_call_params __method__
|
218
|
+
call_params[:body]['offer_id'] = offer_id
|
219
|
+
common_perform_post call_params
|
220
|
+
end
|
221
|
+
|
222
|
+
def offer_view campaign_id
|
223
|
+
call_params = base_call_params __method__
|
224
|
+
call_params[:body]['campaign_id'] = campaign_id
|
225
|
+
common_perform_post call_params
|
226
|
+
end
|
227
|
+
|
228
|
+
private
|
229
|
+
|
230
|
+
def crm_url method=''
|
231
|
+
URL_TEMPLATE.gsub('<APP_KEY>', @app_key).gsub('<DEV_SUB>', @dev_subdirectory).gsub('<METHOD>', method)
|
232
|
+
end
|
233
|
+
|
234
|
+
def base_call_params method
|
235
|
+
{
|
236
|
+
url: crm_url(method.to_s),
|
237
|
+
proto: POST,
|
238
|
+
format: BODY_F_QUERY_STR,
|
239
|
+
headers: [ "Authorization" => Base64.encode64("#{@api_username}:#{@api_password}") ],
|
240
|
+
body: {}
|
241
|
+
}
|
242
|
+
end
|
243
|
+
|
244
|
+
def default_response
|
245
|
+
{ success: false, code: nil, data: [] }
|
246
|
+
end
|
247
|
+
|
248
|
+
def common_perform_post call_params
|
249
|
+
response = default_response
|
250
|
+
api_response = perform_api_call call_params
|
251
|
+
|
252
|
+
if !api_response.nil?
|
253
|
+
parsed = JSON.parse(api_response)
|
254
|
+
|
255
|
+
if !parsed['response_code'].nil?
|
256
|
+
response_code = parsed['response_code'].to_i
|
257
|
+
response[:code] = response_code
|
258
|
+
|
259
|
+
if response_code == 100
|
260
|
+
response[:success] = true
|
261
|
+
response[:data] = parsed
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
response
|
267
|
+
end
|
2
268
|
end
|