Shared functionality for SpreeCommerce Hub Endpoints.
Add this line to your application's Gemfile:
gem 'endpoint_base'
And then execute:
$ bundle
Or install it yourself as:
$ gem install endpoint_base
gem 'sinatra'
gem 'tilt', '~> 1.4.1'
gem 'tilt-jbuilder', require: 'sinatra/jbuilder'
# ...
gem 'endpoint_base'require "sinatra"
require "endpoint_base"
class SampleEndpoint < EndpointBase::Sinatra::Base
# optional security check, value supplied is compared against HTTP_X_HUB_TOKEN header
# which is included in all requests sent by the hub, header is unique per integration.
#
# to opt of out security check, do not include this line
endpoint_key 'abc123'
post '/sample' do
# Return an order object.
add_object :order, { id: 1, email: 'test@example.com' }
# Create or update the parameter sample.new.
add_parameter 'sample.new', '...'
# Return a customized key and value.
add_value 'my_customized_key', { ... }
#return the relevant HTTP status code, and set the notification summary.
result 200, 'The order was imported correctly'
end
post '/fail' do
#return the relevant HTTP status code, and set the notification summary.
result 500, 'The order failed to imported'
end
endgem 'rails'
# ...
gem 'endpoint_base'class SampleController < ApplicationController
include EndpointBase::Concerns::All
skip_before_filter :verify_authenticity_token
# optional security check, value supplied is compared against HTTP_X_HUB_TOKEN header
# which is included in all requests sent by the hub, header is unique per integration.
#
# to opt of out security check, do not include this line
endpoint_key 'abc123'
def sample
# Return an order object.
add_object :order, { id: 1, email: 'test@example.com' }
# Create or update the parameter sample.new.
add_parameter 'sample.new', '...'
# Return a customized key and value.
add_value 'my_customized_key', { ... }
#return the relevant HTTP status code, and set the notification summary.
result 200, 'The order was imported correctly'
end
def fail
#return the relevant HTTP status code, and set the notification summary.
result 500, 'The order failed to imported'
end
end# ...
require 'spree/testing_support/controllers'
# ...
RSpec.configure do |config|
config.include Rack::Test::Methods
config.include Spree::TestingSupport::Controllers
endSpree:TestingSupport::Controllers enables you to use json_response and auth in your Endpoint tests. It also sets ENV['ENDPOINT_KEY'] ||= '123'.
require 'spec_helper'
describe SampleEndpoint do
let(:request) { { request_id: '1234567',
order: {},
parameters: [] } }
describe '/sample' do
it 'notifies a new sample' do
post '/sample', request.to_json, auth
expect(last_response).to be_ok
expect(json_response['summary']).to eq "Order was successfully imported"
end
end
end- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
FlowLink allows you to connect to your own custom integrations. Feel free to modify the source code and host your own version of the integration or better yet, help to make the official integration better by submitting a pull request!
This integration is 100% open source an licensed under the terms of the New BSD License.
