Skip to content

Instantly share code, notes, and snippets.

@pikender
Last active May 18, 2016 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikender/277868dcd03309774b492f5271c50b91 to your computer and use it in GitHub Desktop.
Save pikender/277868dcd03309774b492f5271c50b91 to your computer and use it in GitHub Desktop.
Understanding SaaS Flow with Wombat Integrations and Cangaroo

Shopify Integration Test

2.2.1 :005 > Cangaroo::ProductJob.perform_now
Performing Cangaroo::ProductJob from Inline(cangaroo)
  Cangaroo::Connection Load (0.3ms)  SELECT  "cangaroo_connections".* FROM "cangaroo_connections" WHERE "cangaroo_connections"."name" = ? LIMIT 1  [["name", "Shopify"]]
Performed Cangaroo::ProductJob from Inline(cangaroo) in 4333.08ms
 => #<Interactor::Context source_connection=#<Cangaroo::Connection id: 1, name: "Shopify", url: "http://127.0.0.1:4000", key: "123", token: "123", created_at: "2016-05-06 09:23:15", updated_at: "2016-05-06 09:23:15", parameters: {:shopify_apikey=>"xxxx", :shopify_password=>"xxxx", :shopify_host=>"pik-s.myshopify.com"}>, json_body="{\"request_id\":\"0c3d14f4-9aa5-459d-9899-f8dfe0b5e3a0\",\"summary\":\"Product added with Shopify ID of 6453577219 was added.\",\"products\":[{\"id\":\"SKUPRODUCT\",\"shopify_id\":\"6453577219\"}]}", jobs=[], request_id="{\"\":\"0c314f4-9aa5-459-9899-f8f0b53a0\",\"mmay\":\"Poc a wh Shopfy ID of 6453577219 wa a.\",\"poc\":[{\"\":\"SKUPRODUCT\",\"hopfy\":\"6453577219\"}]}", summary="{\"eqet_id\":\"0c3d14f4-95-459d-9899-f8dfe0b5e30\",\"\":\"Podct dded with Shopif ID of 6453577219 w dded.\",\"podct\":[{\"id\":\"SKUPRODUCT\",\"hopif_id\":\"6453577219\"}]}", message="wrong json schema", error_code=500> 
# Route - "add", "product"
{"request_id"=>"0c3d14f4-9aa5-459d-9899-f8dfe0b5e3a0", "parameters"=>{"shopify_apikey"=>"xxxxx", "shopify_password"=>"xxxxx", "shopify_host"=>"pik-s.myshopify.com"}, "product"=>{"id"=>"SKUPRODUCT", "name"=>"Burton Custom Freestlye 153", "description"=>"Descrizione", "meta_description"=>"<strong>Good snowboard!</strong>", "options"=>["Snowboard"]}}
{"shopify_apikey"=>"xxxxx", "shopify_password"=>"xxxxx", "shopify_host"=>"pik-s.myshopify.com"}
#<Product:0x00000003289760 @shopify_id=nil, @wombat_id="SKUPRODUCT", @name="Burton Custom Freestlye 153", @description="Descrizione", @options=[#<Option:0x000000032895f8 @name="Snowboard">], @variants=[], @images=[]>
"Response {\"objects\"=>{\"product\"=>{\"id\"=>6453577219, \"title\"=>\"Burton Custom Freestlye 153\", \"body_html\"=>\"Descrizione\", \"vendor\"=>\"pik.s\", \"product_type\"=>\"None\", \"created_at\"=>\"2016-05-06T15:36:49+05:30\", \"handle\"=>\"burton-custom-freestlye-153\", \"updated_at\"=>\"2016-05-06T15:36:49+05:30\", \"published_at\"=>\"2016-05-06T15:36:49+05:30\", \"template_suffix\"=>nil, \"published_scope\"=>\"global\", \"tags\"=>\"\", \"variants\"=>[{\"id\"=>19820168899, \"product_id\"=>6453577219, \"title\"=>\"Default Title\", \"price\"=>\"0.00\", \"sku\"=>\"\", \"position\"=>1, \"grams\"=>0, \"inventory_policy\"=>\"deny\", \"compare_at_price\"=>nil, \"fulfillment_service\"=>\"manual\", \"inventory_management\"=>nil, \"option1\"=>\"Default Title\", \"option2\"=>nil, \"option3\"=>nil, \"created_at\"=>\"2016-05-06T15:36:49+05:30\", \"updated_at\"=>\"2016-05-06T15:36:49+05:30\", \"taxable\"=>true, \"barcode\"=>nil, \"image_id\"=>nil, \"inventory_quantity\"=>1, \"weight\"=>0.0, \"weight_unit\"=>\"kg\", \"old_inventory_quantity\"=>1, \"requires_shipping\"=>true}], \"options\"=>[{\"id\"=>7689393731, \"product_id\"=>6453577219, \"name\"=>\"Snowboard\", \"position\"=>1, \"values\"=>[\"Default Title\"]}], \"images\"=>[], \"image\"=>nil}}, \"message\"=>\"Product added with Shopify ID of 6453577219 was added.\"}"
127.0.0.1 - - [06/May/2016 15:36:51] "POST /add_product HTTP/1.1" 200 179 4.3213

Spree Wombat

  • There are different webhooks handlers which are initiated and created using single end-point.
  • Webhook handlers are found based on path-params and other params are passed as JSON Body
module Spree
  module Wombat
    class WebhookController < ActionController::Base
      # Applications can use error_notifier to forward errors to tools like
      # airbrake, honeybadger, rollbar, etc.
      # This should be an object that responds to `call` and accepts the
      # responder as an argument.
      class_attribute :error_notifier

      before_filter :save_request_data, :authorize
      rescue_from Exception, :with => :exception_handler

      def consume
        handler = Handler::Base.build_handler(@called_hook, @webhook_body)
        responder = handler.process
        render_responder(responder)
      end
      ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment