SingtelSdp
The core of this gem its on SingtelSdp::BaseAdapter and SingtelSdp::BaseAdapterController.
Implementing these 2 classes will let you decide what to do with each request received from the sdp.
SingtelSdp let you forget about the xml connections, result codes and messages. It gives you the chance to focus on the implementation of the actions for each request.
This gem solves most of the hard problems with the integration with singtel.
Installing
Get the gem
Add this to your Gemfile.
gem 'singtel_sdp', '~>1.0.0', git: 'git://github.com/dropmyemail/singtel_sdp.git'
Create the adapter
Use the provided generator to create the model, controller and initializer file for SingtelSdp.
rails g singtel_sdp
Customize the models
SingtelSdp::BaseAdapter is an abstract class, You need to implement the abstract methods.
# app/models/singtel_Adapter.rb
#
class SingtelAdapter < SingtelSdp::BaseAdapter
def roles
# here you should return a list of the possible roles. eg ['ADMIN','DEFAULT']
end
def find_singtel_customer(isvcustno)
# Find and return a singtel customer here, can be an instances of any class that represents an active customer.
end
def find_singtel_product(isvsubsid)
# Find and return a singtel product subscription here, can be an instances of any class that represents an active subscription to a product in your domain.
end
def find_singtel_user(isvuserid)
# Find and return your singtel user here, can be an instances of any class that represents your active user.
end
def on_create_customer
#create your singtel customer here. in arguments variable you ll find a hash with the params received in the request. eg: arguments[:ISVCUSTNO], return the ivcustno as a string if everything went fine, if not nil.
end
def on_update_customer
#update your singtel customer here. in arguments variable you ll find a hash with the params received in the request. eg: arguments[:ISVCUSTNO], return the ivcustno as a string if everything went fine, if not nil.
end
def on_delete_customer
#delete your singtel customer here. in arguments variable you ll find a hash with the params received in the request. eg: arguments[:ISVCUSTNO], return the ivcustno as a string if everything went fine, if not nil.
end
def on_create_product
# Create your singtel product here. In arguments variable you ll find a hash with the params received in the request. eg arguments[:ISVSUBSID], return the isvsubsid as a string if everything went fine, if not nil.
end
def on_update_product
# Update your singtel product here. In arguments variable you ll find a hash with the params received in the request. eg: arguments[:NEWISVSUBSID], return the newisvsubsid as a string if everything went fine, if not nil.
end
def on_delete_product
# Update your singtel product here. In arguments variable you ll find a hash with the params received in the request. eg: arguments[:NEWISVSUBSID], return the newisvsubsid as a string if everything went fine, if not nil.
end
def on_create_user
end
def on_update_user
end
def on_delete_user
end
end
Customize the controller
The SintelSdp::BaseAdapterController should be overriden. You have to override SingtelSdp::SingtelBaseAdapterController#sign\_in\_singtel\_user #sign\_in\_singtel\_user.
Optionally you can override SingtelSdp::SingtelBaseAdapterController#on\_singtel\_login\_success #on\_singtel\_login\_success and SingtelSdp::SingtelBaseAdapterController#on\_singtel\_login\_failure #on\_singtel\_login\_failure
# app/controller/singtel_controller.rb
class SingtelController < SingtelSdp::BaseAdapterController
def sign_in_singtel_user(isvuserid)
# this is an implementation :P
end
end
Mounting the routes
We provide a shortcut so you can add the SingtelSdp::BaseAdapterController BaseAdapterController to your routes.rb.
Here's a snippet showing two different ways of mounting the routes:
# your routes.rb
YourApp::Application.routes.draw do
# Will mount the default SingtelSdp:BaseAdapterController in the
# /singtel path.
add_singtel_sdp_routes
end
Customize the invalid session template
SingtelSdp will redirect to invalid session template if an sso login fails:
- problems with the otp.
- problems with the conextion.
You can copy the the built in template into your app's directory structure and customize them:
$ rails g singtel_sdp_views
LICENSE
MIT-LICENSE. Check LICENSE for more details