/SearsAPIs.js

https://github.com/littlelazer/SearsAPIs · JavaScript · 501 lines · 268 code · 147 blank · 86 comment · 4 complexity · 640fd4d939af364d9dd4cb71b4f5af9c MD5 · raw file

  1. /*
  2. other things to add: caching option
  3. */
  4. function SearsAPI ( initObj ) {
  5. var apiKey = initObj.apiKey,
  6. searsAppID = initObj.appID,
  7. searsAuthID = initObj.authID,
  8. rApiURL = 'http://api.developer.sears.com/v1/',
  9. sApiURL = 'https://webservices.sears.com/shcapi/',
  10. webApiURL = 'http://webservices.sears.com/shcapi/',
  11. apiRequestCache = {},
  12. clientSessionKey,
  13. // Helper functions
  14. saveCSKey = function ( key ) {
  15. clientSessionKey = key;
  16. },
  17. prepareString = function ( obj ) {
  18. var i = 0, data = [];
  19. for ( var j in obj ) {
  20. data[i++] = j + '=' + obj[j] + '&';
  21. }
  22. return data.join('');
  23. };
  24. /*****************************/
  25. /* Store & Product Functions */
  26. /*****************************/
  27. // Product Search API
  28. this.productSearch = function ( opts ) {
  29. var apiURL,
  30. searchOpts = {
  31. store: 'Sears',
  32. catalogId: '12605',
  33. authID: searsAuthID,
  34. appID: searsAppID,
  35. contentType: 'json'
  36. };
  37. apiURL = webApiURL + 'productsearch?' + prepareString( $.extend(searchOpts, opts) );
  38. if ( ! apiRequestCache[ apiURL ] ) {
  39. apiRequestCache[ apiURL ] = $.Deferred(function( defer ) {
  40. $.ajax({
  41. url : apiURL,
  42. dataType : 'json'
  43. }).then( defer.resolve, defer.reject );
  44. }).promise();
  45. }
  46. return apiRequestCache[ apiURL ];
  47. };
  48. // Store Locator API
  49. this.storeLocator = function ( opts ) {
  50. var apiURL,
  51. searchOpts = {
  52. store : 'Sears',
  53. authID: searsAuthID,
  54. appID: searsAppID,
  55. contentType : 'json'
  56. };
  57. apiURL = webApiURL + 'StoreLocator?' + prepareString( $.extend(searchOpts, opts) );
  58. if ( ! apiRequestCache[ apiURL ] ) {
  59. apiRequestCache[ apiURL ] = $.Deferred(function( defer ) {
  60. $.ajax({
  61. url : apiURL,
  62. dataType : 'json'
  63. }).then( defer.resolve, defer.reject );
  64. }).promise();
  65. }
  66. return apiRequestCache[ apiURL ];
  67. };
  68. // Pass-through API
  69. this.passThrough = function ( ) {
  70. };
  71. // Compare Products API
  72. this.compareProducts = function ( ) {
  73. };
  74. // Main-in Rebate API
  75. this.mailRebate = function ( ) {
  76. };
  77. // Top Sellers API
  78. this.topSellers = function ( ) {
  79. };
  80. // Real-time Inventory API
  81. this.realInventory = function ( ) {
  82. };
  83. // Sales & Deals API
  84. this.salesDeals = function ( ) {
  85. };
  86. // Product Details API
  87. this.productDetails = function ( opts ) {
  88. var apiURL,
  89. searchOpts = {
  90. store : 'Sears',
  91. catalogId : 12605,
  92. textOnly : 'false',
  93. showSpec : 'true',
  94. appID : searsAppID,
  95. authID : searsAuthID,
  96. contentType : 'json'
  97. };
  98. apiURL = webApiURL + 'productdetails?' + prepareString( $.extend(searchOpts, opts) );
  99. if ( ! apiRequestCache[ apiURL ] ) {
  100. apiRequestCache[ apiURL ] = $.Deferred(function( defer ) {
  101. $.ajax({
  102. url : apiURL,
  103. dataType : 'json'
  104. }).then( defer.resolve, defer.reject );
  105. }).promise();
  106. }
  107. return apiRequestCache[ apiURL ];
  108. };
  109. // Check Product Availability for Delivery
  110. this.checkDeliveryAvailability = function ( ) {
  111. };
  112. /***************************/
  113. /* Gift Registry Functions */
  114. /***************************/
  115. // Get Gift Registry Event Ids
  116. this.giftRegistryEvents = function ( ) {
  117. };
  118. // Create Gift Regustry
  119. this.createRegistry = function ( ) {
  120. };
  121. // Gift Registry Search
  122. this.searchRegistries = function ( ) {
  123. };
  124. // Add Items to Gift Registry
  125. this.addItemsToRegistry = function ( ) {
  126. };
  127. // Add to Cart from Gift Registry
  128. this.addCartFromRegistry = function ( ) {
  129. };
  130. // Delete Gift Registry Item
  131. this.deleteRegistryItem = function ( ) {
  132. };
  133. // View Gift Registry Items
  134. this.viewRegistry = function ( ) {
  135. };
  136. // Update Registry Item Info
  137. this.updateRegistryItemInfo = function ( ) {
  138. };
  139. // View ALl Gift Registries
  140. this.viewRegistries = function ( ) {
  141. };
  142. // Delete a Gift Registry
  143. this.deleteRegistry = function ( ) {
  144. };
  145. // Email a Gift Registry
  146. this.emailRegistry = function ( ) {
  147. };
  148. // Edit a Gift Registry
  149. this.editRegistry = function ( ) {
  150. };
  151. // Record a Gift Registry Purchase
  152. this.recordRegistryPurchase = function ( ) {
  153. };
  154. /**************************/
  155. /* User Profile Functions */
  156. /**************************/
  157. // ToDo: Figure out what the AutoSignOn API is/does
  158. // User Registration API
  159. this.register = function ( ) {
  160. }
  161. // Login Service API
  162. this.login = function ( userInfo ) {
  163. var serviceURL = sApiURL + 'Login';
  164. return $.ajax({
  165. cache: false,
  166. type: 'POST',
  167. url: serviceURL,
  168. data: {
  169. catalogId : '12605',
  170. loginId : userInfo.username,
  171. logonPassword : userInfo.password,
  172. store : 'Sears',
  173. appID : searsAppID,
  174. authID : searsAuthID
  175. },
  176. dataType: 'xml'
  177. });
  178. };
  179. // Logout Service API
  180. this.logout = function ( ) {
  181. };
  182. // View Gift Card API
  183. this.viewGiftCard = function ( ) {
  184. };
  185. // Add Gift Card API
  186. this.addGiftCard = function ( ) {
  187. };
  188. // Add to Cart API
  189. this.addToCart = function ( ) {
  190. };
  191. // Delete from Cart API
  192. this.deleteFromCart = function ( ) {
  193. };
  194. // Update Item Quantity
  195. this.updateQuantity = function ( ) {
  196. };
  197. // View Cart
  198. this.viewCart = function ( ) {
  199. };
  200. // Empty Cart
  201. this.emptyCart = function ( ) {
  202. };
  203. // Checkout Redirect
  204. this.checkoutredirect = function ( ) {
  205. };
  206. // Installation Continue
  207. this.installContinue = function ( ) {
  208. };
  209. // Create Universal List
  210. this.createList = function ( ) {
  211. };
  212. // View Universal List
  213. this.viewList = function ( ) {
  214. };
  215. // Add Item to Universal List
  216. this.addToList = function ( ) {
  217. };
  218. // Remove Item from Universal List
  219. this.removeFromList = function ( ) {
  220. };
  221. // View All Universal Lists
  222. this.viewLists = function ( ) {
  223. };
  224. // Delete Universal List
  225. this.deleteList = function ( ) {
  226. };
  227. // Copy Item from One Universal List to Another
  228. this.copyListItem = function ( ) {
  229. };
  230. // Follow AdYourWay
  231. this.followAdYourWay = function ( ) {
  232. };
  233. // View AdYourWay
  234. this.viewAdYourWay = function ( ) {
  235. };
  236. // Unfollow AdYourWay
  237. this.unfollowAdYourWay = function ( ) {
  238. };
  239. // Save for Later to Cart
  240. this.saveLaterToCart = function ( ) {
  241. };
  242. // Get My Vehicle Info
  243. this.getVehiclesInfo = function ( ) {
  244. var serviceURL = sApiURL + 'GetMyVehicleInfo';
  245. return $.ajax({
  246. cache : false,
  247. type : 'POST',
  248. url : serviceURL,
  249. data : {
  250. store : 'Sears',
  251. catalogId : '12605',
  252. langId : '-1',
  253. appID : searsAppID,
  254. authID : searsAuthID,
  255. sessionKey : clientSessionKey
  256. },
  257. dataType : 'xml'
  258. });
  259. };
  260. // Forgot Password
  261. this.forgotPassword = function ( ) {
  262. };
  263. /**************************/
  264. /* Car Fitment Functions */
  265. /**************************/
  266. // Get Fitment Products API
  267. this.getFitmentProducts = function ( ) {
  268. };
  269. // Get Fitment Data for Year
  270. this.getFitmentYear = function ( ) {
  271. var serviceURL = webApiURL + 'GetFitMentData'
  272. return $.ajax({
  273. url : serviceURL,
  274. data : {
  275. requestedField : 'year',
  276. appID : searsAppID,
  277. authID : searsAuthID,
  278. store : 'Sears',
  279. catalogId : '12605',
  280. langId : '-1'
  281. }
  282. });
  283. };
  284. // Get Fitment Data for Make
  285. this.getFitmentMake = function ( carYear ) {
  286. var serviceURL = webApiURL + 'GetFitMentData'
  287. return $.ajax({
  288. url : serviceURL,
  289. data : {
  290. requestedField : 'make',
  291. year : carYear,
  292. appID : searsAppID,
  293. authID : searsAuthID,
  294. store : 'Sears',
  295. catalogId : '12605',
  296. langId : '-1'
  297. }
  298. });
  299. };
  300. // Get Fitment Data for Model
  301. this.getFitmentModel = function ( carYear, carMake ) {
  302. var serviceURL = webApiURL + 'GetFitMentData'
  303. return $.ajax({
  304. url : serviceURL,
  305. data : {
  306. requestedField : 'model',
  307. make : carMake,
  308. year : carYear,
  309. appID : searsAppID,
  310. authID : searsAuthID,
  311. store : 'Sears',
  312. catalogId : '12605',
  313. langId : '-1'
  314. }
  315. });
  316. };
  317. // Get Fitment Data for Engine Size
  318. this.getFitmentEngine = function ( ) {
  319. };
  320. // Get Fitment Vehicle for a Product ID
  321. this.getVehicleForId = function ( ) {
  322. };
  323. /**********************************/
  324. /* MyGofer3 & Craftsman Functions */
  325. /**********************************/
  326. // Reset Password
  327. this.resetPassword = function ( ) {
  328. };
  329. // Order Details
  330. this.orderDetails = function ( ) {
  331. };
  332. /**********************************/
  333. /* E-Circular Weekly Ad Functions */
  334. /**********************************/
  335. // Not sure if they mean "Cart" when the say "List" here
  336. // View Weekly Ad Categories
  337. this.weeklyAdListCategories = function ( ) {
  338. };
  339. // View Weekly Ad Departments
  340. this.weeklyAdDepartment = function ( ) {
  341. };
  342. // Add Weekly Ad Item to List
  343. this.weeklyAdToList = function ( ) {
  344. };
  345. // View Weekly Ad Items in List
  346. this.weeklyAdInList = function ( ) {
  347. };
  348. // Delete Weekly Ad Item from List
  349. this.weeklyAdDeleteFromList = function ( ) {
  350. };
  351. // Email the Weekly Ad List
  352. this.weeklyAdEmailList = function ( ) {
  353. };
  354. }