Skip to content

Integration with Spree

Miguel Sancho Fernandez edited this page Sep 1, 2017 · 1 revision

https://github.com/wombat/wombat-ruby

Overview

Our project Cenit IO started in 2014 just after Spree Conference where was presented Spree Hub, later named Wombat.

Wombat was a privative integration platform for storefronts builds by Spree Commerce company. Wombat product was discontinued on March 31, 2016.

We used Wombat as inspiration in the initial steps of Cenit.

Spree is a complete open source e-commerce solution for Ruby on Rails.

We tested recently Spree using the API.

But we recommend use spree wombat gem to send created or updated objects to Cenit IO https://github.com/spree/spree_wombat

spree_wombat gem allows connecting your SpreeCommerce Storefront to Wombat, providing push API. We did a minor change in this gem to push objects to Cenit IO.

Now the next steps show how is possible send objects from Spree to Cenit IO.

running Spree sandbox

git clone [email protected]:spree/spree.git
cd spree
bundle install
bundle exec rake sandbox
cd sandbox
rails s

Add spree_wombat gem to Spree

Add spree_wombat cenit-io fork to your Gemfile:

gem 'spree_wombat', git: '[email protected]:cenit-io/spree_wombat.git', branch: 'master'

Bundle your dependencies and run the installation generator:

bundle bundle exec rails g spree_wombat:install

Add your Cenit IO credentials to config/initializers/wombat.rb:

Spree::Wombat::Config.configure do |config|     
  config.connection_token = "YOUR CENIT AUTHENTICATION TOKEN"     
  config.connection_id = "YOUR CENIT AUTHENTICATION KEY"    
  ...
end

Modified 'config/initializers/wombat.rb'

Spree::Wombat::Config.configure do |config|   
    config.connection_token = "YOUR CENIT AUTHENTICATION TOKEN"     
    config.connection_id = "YOUR CENIT AUTHENTICATION KEY"        
    config.push_objects = ["Spree::Order","Spree::Product"]       
    config.payload_builder = {        
       
# By default we filter orders to only push if they are completed.  You can remove the filter to send incomplete orders as well.        
       "Spree::Order" => { 
         serializer: "Spree::Wombat::OrderSerializer",  
         root: "orders",   
         filter: "complete"    
       },        
       "Spree::Product" => {       
         serializer: "Spree::Wombat::ProductSerializer",       
         root: "products"    
       },        
       "Spree::StockItem" => {       
         serializer: "Spree::Wombat::StockItemSerializer",
         root: "inventories"
        }     
    }        
   config.push_url = "https://cenit.io/api/v2/ecommerce/push"  
end

Notice that Cenit IO included out the box a namespace ecommerce, but you can push objects to any custom namespace

Please review more details in the readme of

https://github.com/spree/spree_wombat

Test send object to cenit io

> bundle exec rake wombat:push_it

Then output should look like:

Starting pushing objects to Wombat Pushed 2 Spree::Order to Wombat Pushed 17 Spree::Product to Wombat

Here you can see the minimal differences with the original spree_wombat gem, that we added in order to be compatible with Cenit IO

https://github.com/spree/spree_wombat/compare/master...cenit-io:master
https://github.com/spree/spree_wombat/compare/master...cenit-io:master

How this work

Client rb 'spree_wombat/lib/spree/wombat/client.rb' use

HTTParty.post(
  Spree::Wombat::Config[:push_url], {
    body: json_payload,
    headers: headers
  }               
)

headers are

headers = { 
  'Content-Type' => 'application/json',
  'X-User-Access-Key' => Spree::Wombat::Config[:connection_id],
  'X-User-Access-Token' => Spree::Wombat::Config[:connection_token],
  'X-User-Timestamp' => Time.now.utc.to_i.to_s
}

and JSON Payload is generated by spree_wombat, in see the complete JSON payload in this example visit the next gist:

https://gist.github.com/sanchojaf/81edb0ef7e8bec996a8283e9fb5b12a8

Clone this wiki locally