Last active
December 22, 2015 18:39
-
-
Save marothstein/6513822 to your computer and use it in GitHub Desktop.
Boarding manager classes to work with the boarding APIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number::truncate = (decimal_places) -> | |
factor = Math.pow(10, decimal_places) | |
Number(Math.ceil(this * factor) / factor).toFixed decimal_places | |
String::sanitize = -> | |
@replace /[A-Za-z$-,]/g, "" | |
class Boarding.Helpers.BoardingManager extends Backbone.Events | |
token: null | |
permissions: null | |
triggerable: null | |
constructor: -> | |
@configurator = new Boarding.Helpers.Configurator() | |
true | |
authenticateNewUser: (email, password) => | |
@configurator.makeAuthenticationRequest email, password, "login" | |
getUserMaster: (userMasterId) => | |
@configurator.makeGetRequest "user_master/" + userMasterId | |
getUserData: => | |
@configurator.makeGetRequest "token/detail" | |
getCompanyData: (companyId) => | |
@configurator.makeGetRequest "company/" + companyId | |
updateCompanyData: (company) => | |
@configurator.makePutRequest "company/" + company.company_id, company | |
updateLocationData: (location) => | |
@configurator.makePutRequest "location/" + location.location_id, location | |
updateUserMasterData: (user_master) => | |
@configurator.makePutRequest "user_master/" + user_master.user_master_id, user_master | |
createBankAccount: (bankAccount) => | |
@configurator.makePostRequest "bank_account", bankAccount | |
createAccount: (userAccount) => | |
@configurator.makePostRequest "create_account", userAccount | |
createBoardingApplication: (boardingRequest) => | |
@configurator.makePostRequest "boarding/create_application", boardingRequest | |
submitBoardingAnswers: (boardingVerificationQuestions) => | |
@configurator.makePostRequest("boarding/submit_answers", boardingVerificationQuestions) | |
saveReaderPreference: (readerTypeCloudObject) => | |
@createCloudObject readerTypeCloudObject | |
createCloudObject: (cloudObject) => | |
@configurator.makePostRequest "cloud_object", cloudObject | |
purchaseUsbReader: (simplePayment) => | |
@configurator.makePostRequest "webstore/purchase_usb_reader", simplePayment | |
purchaseAudioReader: (simplePayment) => | |
@configurator.makePostRequest "webstore/purchase_audio_reader", simplePayment | |
getCompany: => | |
@configurator.makeGetRequest "company" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Boarding.Helpers.Configurator | |
token: null | |
# API_URL: "<%= APP_CONFIG['cube_api_url'] %>" | |
API_URL: "/api/" | |
ajaxSettings: | |
dataType: "json" | |
headers: | |
"content-type": "application/json" | |
'x-cube-application' : 'boarding' | |
'x-cube-uri' : window.location.href | |
global: true | |
timeout: 1000000 | |
constructor: -> | |
@jQuery = jQuery | |
@jQuery.ajaxSetup @ajaxSettings | |
@jQuery.support.cors = true | |
getjQuery: => | |
@jQuery | |
setLocalStorageObj: (key, value) => | |
if localStorage then localStorage.setItem key, value | |
getLocalStorageObj: (key) => | |
if localStorage then localStorage.getItem key | |
setTokenFromLocalStorage: => | |
token = @getLocalStorageObj('cubebright_token') | |
@setToken(token) | |
return @getToken() | |
setToken: (token) => | |
@token = token | |
@setLocalStorageObj "cubebright_token", @token | |
settings = | |
processData: false | |
contentType: "application/json" | |
headers: | |
"x-cube-token": @token | |
@jQuery.ajaxSetup settings | |
getToken: => | |
@token | |
makeAuthenticationRequest: (email, password, url_suffix) => | |
_this = this | |
settings = | |
url: @API_URL + url_suffix | |
headers: | |
"x-cube-email": email | |
"x-cube-password": password | |
request = @jQuery.ajax(settings).success((response) => | |
_this.setToken response.data | |
) | |
makeGetRequest: (url_suffix) => | |
request = @jQuery.ajax(@API_URL + url_suffix) | |
makePostRequest: (url_suffix, data) => | |
settings = | |
type: "POST" | |
url: @API_URL + url_suffix | |
data: JSON.stringify(data) | |
request = @jQuery.ajax(settings) | |
makePutRequest: (url_suffix, data) => | |
settings = | |
type: "PUT" | |
url: @API_URL + url_suffix | |
data: JSON.stringify(data) | |
request = @jQuery.ajax(settings) | |
makeDeleteRequest: (url_suffix) => | |
settings = | |
type: "DELETE" | |
url: @API_URL + url_suffix | |
request = @jQuery.ajax(settings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment