Ruby

Example of a custom Luckycycle® implementation in a Ruby environment.

There is a Luckycycle® gem hosted on Bitbucket
https://bitbucket.org/luckycycle/luckycycle_gem/overview

❗️

HTTP requests

In order to do HTTP requests, please install the gem "rest-client".

Depending on your Ruby framework, you may want to decouple the following code between controllers and views.

Here is an example that you would put in the controller handling the order confirmation page:

👍

Replace placeholders with real values

In the example below, replace all placeholders (in double brackets) with real data from your client's order. They way to achieve this depend on your store implementation.

# Fill the cart array with products informations
cart = []
for product in {{ORDER_CART}}
item = {
'price'=>{{PRODUCT_PRICE}},
'quantity'=>{{PRODUCT_QUANTITY}},
'product_id'=>{{PRODUCT_ID}}
}
cart.push(item)
end

# Fill the global informations
d = {}
d['item_value'] = {{ITEM_VALUE}}
d['segment'] = {{SEGMENT}}
d['lang'] = {{LANGUAGE}}
d['user_uid'] = {{USER_UID}}
d['item_uid'] = {{ORDER_UID}}
d['email'] = {{EMAIL}}
d['firstname'] = {{FIRSTNAME}}
d['lastname'] = {{LASTNAME}}
d['cart'] = cart

# Send the POST request
url = "https://www.luckycycle.com/api/v1/operations/{{OPERATION_ID}}/poke"
data = d.to_json
response = RestClient::Request.execute(
    :method => :post, 
    :url => url, 
    :payload => data, 
    :timeout => 9000000, 
    :headers => {'X-LuckyApiKey' => {{API_KEY}}, 'Content-Type' => 'application/json'}
)

@json_response = JSON.parse(response)

And display the Luckycycle® game in the confirmation page template, using something like this:

<%=  @json_response['html_data'].html_safe if @json_response['message'].to_s == 'OK' %>