Skip to content

Instantly share code, notes, and snippets.

@goodbedford
Created October 10, 2016 18:40
Show Gist options
  • Save goodbedford/e664b842fc21b9c604e378719ac5f45d to your computer and use it in GitHub Desktop.
Save goodbedford/e664b842fc21b9c604e378719ac5f45d to your computer and use it in GitHub Desktop.
sprinkler example
// app.js
var htmlTarget = document.querySelector("#target");
var resultDiv1 = document.createElement("div");
SprinklrTest.Send(new SprinklrTest.ReviewListRequest({
ItemsPerPage: 5,
OneBasedOnPage: 2,
Sort: "TimeStampAscending"
}), function callback(responseData) {
console.log("ima result", responseData)
// in the callback function we accept the returned val from request and we pass in a results variable to hold the response
// inspect this response data you get back an array of objects. you will need to go iterate through array and print out users
// console.log("these are the results for search" + results);
//next you need to manipulate the response data to get on screean
//this way will return an array that is then joined in a string seperated by two line breaks
// resultDiv1.innerHTML = responseData.Items.map(function(item) {
// var answer = [];
// answer.push("Title:" + item.Title, "Name:" + item.Owner.Name, "Body:" + item.Body);
// // console.log(answer.join(" ------------"));
// return answer.join("<br>");
// }).join("<br><br>");
// htmlTarget.appendChild(resultDiv1);
// this way for each item in the responseData.Items
// make a new empty div and put what you want inside then append to the end of the target
responseData.Items.forEach(function(item) {
var answer = [];
var div = document.createElement("div");
answer.push("Title:" + item.Title, "Name:" + item.Owner.Name, "Body:" + item.Body);
console.log(answer.join("\n"));
div.innerHTML = answer.join("<br>");
htmlTarget.appendChild(div);
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>SprinklrTest</h1>
<div id="target"></div>
<script src="jquery-1.7.1.min.js"></script>
<!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.1/jquery.min.js" integrity="sha256-iBcUE/x23aI6syuqF7EeT/+JFBxjPs5zeFJEXxumwb0=" crossorigin="anonymous"></script> -->
<script src="sprinklrtest.js"></script>
<script src="app.js"></script>
</body>
</html>
// SprinklrTest.User object model
// Id - string - the unique ID of the user
// Name - string - the displayed name of the user
// Url - string - the URL to the user's home page. You do NOT have to create this page.
// AvatarImage - string - the URL to the user's avatar image. The avatar image is always 40x40 pixels.
// IsFeaturedReviewer - boolean - if true, the user is a featured reviewer in our system.
// CreateDate - Date - the date on which the user joined the system.
//
// SprinklrTest.Review object model
// Id - string - the unique ID of the review
// Title - string - the title of the review
// Rating - int - the star rating of the review. Will always be a whole number.
// Body - string - the text body of the review. This is raw text, not HTML. Returns must be maintained when viewed on the page.
// CreateDate - Date - the date on which the review was created.
// Owner - SprinklrTest.User - the person who created the review.
//
// SprinklrTest.ReviewListRequest request model
// Input object model:
// ItemsPerPage - int - the number of items per page to be returned. Default is 5
// OneBasedOnPage - int - the one-based page number to be viewed. Default is 1
// Sort - string - the sort to be applied to the list. Valid values are "TimeStampAscending", "TimeStampDescending", "RatingAscending", "RatingDescending". Default is "TimeStampAscending"
// Return object model:
// Items - array of Reviews - the reviews for the page and sort.
// TotalCount - int - the total number of reviews available.
//
// Send function
// SprinklrTest.Send(new SprinklrTest.ReviewListRequest({}), callback)
// request - a request model
// callback - a function to be called asynchronously with the data. It takes a single input, as a return object model.
//
var SprinklrTest = (function() {
var reviews = [{
Id: "ajjhwejkssl",
Title: "5.0 out of 5 starsRack up the miles with this shoe",
Rating: 5,
Body: "The shoe immediately impressed with their comfort, especially the snug fit around the heel and bridge of my feet with the tongue providing good padding on top so the laces don't dug into my feet. The toe box feels roomy and comfortable and with no seams running through that area there are no worries about chafing or discomfort during a long run. There is also a less apparent heel to toe drop compared to the Pegasus 31 which made the step transition from heel to toe feel really super smooth. It is probably what I like most about the shoe as it just encourages you to eat up the miles as you glide through your stride. After running a half marathon with them this past weekend included an undulating 2 mile section of gravel road and the shoe handled the conditions very well providing good support for my ankles. As we also had a light drizzle the road conditions were treacherous and the shoe provided excellent grip",
CreateDate: new Date(2012, 5, 23, 14, 12, 10, 0),
Owner: {
Id: "kwergiueerwq",
Name: "Bugs Bunny",
Url: "./users.html?id=kwergiueerwq",
AvatarImage: "./avatars/bugsbunny.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2012, 2, 12, 9, 44, 0, 0)
}
}, {
Id: "gqergnuioqr",
Title: "Great Running Shoes",
Rating: 5,
Body: "Love this brand and this shoe is no exception. Great support and great cushioning if you are a bigger guy like me. I run 3 to 5 miles, 5 or 6 times a week and these shoes do great for me. These are one of the few running shoes that come in both regular and wide widths. If you have wider feet like me, I recommend you get the EE width.",
CreateDate: new Date(2012, 7, 4, 21, 32, 14, 0),
Owner: {
Id: "qrgqertqwert",
Name: "Chimchim Monkey",
Url: "./users.html?id=qrgqertqwert",
AvatarImage: "./avatars/chimchim.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2012, 7, 4, 21, 16, 0, 0)
}
}, {
Id: "sqqerqerhh",
Title: "My all-around running shoe",
Rating: 4,
Body: "I've been running on these for several years now, including two marathons and several halfs. I never get blisters or have any foot/knee problems. I have a high arch and never needed any extra support but recently I developed pain in my left foot. So now, I do use a doctor prescribed and custom designed insert. Pain seems to be due to a mal-alignment of some bones in my left foot. Doc says its from my stride. He said he likes this brand for this because they have extra room for the inserts. I'm not an avid runner nor do I know all the ins and outs of shoe types, I just know these work for me.",
CreateDate: new Date(2011, 12, 21, 2, 55, 41, 0),
Owner: {
Id: "wthyetyjsdh",
Name: "Santa's Little Helper",
Url: "./users.html?id=wthyetyjsdh",
AvatarImage: "./avatars/christmastree.jpg",
IsFeaturedReviewer: true,
CreateDate: new Date(2011, 11, 19, 11, 1, 34, 0)
}
}, {
Id: "efjhetykety",
Title: "First pair",
Rating: 5,
Body: "These are my first pair of running shoes by this company and I must say what a difference they make. I am 6ft 212lbs 47year old male that is new to the running program. The shoes I was using before were from another brand that did not provide enough cushion when running on asphalt and my knees would get sore. A noticeable difference with these! No more sore knees and as one could expect, my endurance and stamina have increased. Runs consist of 4 to 6 miles and I am really enjoying my runs now - thanks to Brooks! I have wide feet and these shoes were available in 2E but only in the Metallic Charcoal/Lime which is okay but wish other colors were also available in 2E widths.The crash pad on these shoes is amazing - they make the landings easier by lessening the impact - great feature, by design, for running on asphalt. The heel support is great by really cradling your heels which helps me keep my form. The pad under the shoe strings is thick and the laces lay flat which keeps them from digging into your feet without compromising their hold.",
CreateDate: new Date(2012, 8, 12, 20, 33, 14, 0),
Owner: {
Id: "tyjkfthwtds",
Name: "Princess4ADay",
Url: "./users.html?id=tyjkfthwtds",
AvatarImage: "./avatars/princess.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2012, 4, 2, 13, 8, 0, 0)
}
}, {
Id: "jytywerthryrj",
Title: "the fit is great but they are wearing really quickly on the sole",
Rating: 3,
Body: "the fit is great but they are wearing really quickly on the sole...much quicker than the last pair I bought. They feel great but they are going to have to be replaced in about half the mileage as my previous pair",
CreateDate: new Date(2012, 0, 2, 9, 3, 55, 0),
Owner: {
Id: "kwrtqadthee",
Name: "I Wear Square Pants",
Url: "./users.html?id=kwrtqadthee",
AvatarImage: "./avatars/squarepants.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2011, 5, 26, 15, 18, 0, 0)
}
}, {
Id: "gn21ouieqrrr",
Title: "Poor quality. A disappointment",
Rating: 1,
Body: "Terrible. I wore the previous release of this shoe and loved it. But this time I was not at all impressed. Completely different design and not recommended for anyone who has the slightest bit of supination. Less than a month later I am on the search for a new pair of shoes due to the excessive heel, knee and back pain. These shoes are design much wider then the previous model and wear out incredibly fast.",
CreateDate: new Date(2012, 1, 5, 3, 39, 0, 0),
Owner: {
Id: "cwdfttrthth",
Name: "Yosemite Sam",
Url: "./users.html?id=cwdfttrthth",
AvatarImage: "./avatars/yosemite.jpg",
IsFeaturedReviewer: true,
CreateDate: new Date(2011, 10, 3, 10, 51, 0, 0)
}
}, {
Id: "hwweohhgowkdfds",
Title: "Best fit for me",
Rating: 5,
Body: "I run road and trail marathons annually. I had a running company size and measure my feet four years ago. This shoe was the best fit for me! The best decision I made was not the purchase of the shoes it was my decision to have my feet measured for best fit. I've worn these shoes for four years. I typically get 2 half marathons and 1 full marathon to include all of the training for each out of a pair before I have to retire the shoe. No issues with anything in these shoes. Would recommend to all runners if they are the proper fit.",
CreateDate: new Date(2012, 2, 7, 18, 33, 21, 0),
Owner: {
Id: "gertoiqwtoijgh",
Name: "Wilma Flintstone",
Url: "./users.html?id=gertoiqwtoijgh",
AvatarImage: "./avatars/wilma.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2012, 2, 4, 12, 13, 0, 0)
}
}, {
Id: "ergjbnwerggw",
Title: "Support and cushion are just right",
Rating: 4,
Body: "This is my first pair of these running shoes and I have to say they fit and feel great on my feet. I wear a 10 wide and the size and width were perfect. I am 5'-11\" and 185 lbs for reference. The support and cushion are also just right. I am not a \"Major Runner\", but my feet really can stay comfortable for a long time....all day in fact. I will buy this pair again.",
CreateDate: new Date(2012, 7, 1, 6, 33, 51, 0),
Owner: {
Id: "2qergooqehrgoij",
Name: "Office Worker",
Url: "./users.html?id=2qergooqehrgoij",
AvatarImage: "./avatars/coatandtie.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2012, 0, 29, 15, 28, 0, 0)
}
}, {
Id: "4rrhotihoiert",
Title: "very comfortable",
Rating: 5,
Body: "I bought these for my husband for jogging. They were referred to him by a friend. I asked how he liked them after a week of wearing them and he says they are the best jogging sneakers he has ever had. He raves how comfortable they are.",
CreateDate: new Date(2012, 1, 29, 23, 48, 3, 0),
Owner: {
Id: "qwergqiouerhg",
Name: "Lily from Mockingbird Lane",
Url: "./users.html?id=qwergqiouerhg",
AvatarImage: "./avatars/lilymunster.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2011, 3, 19, 11, 4, 0, 0)
}
}, {
Id: "qerognopnqerg",
Title: "3.0 out of 5 starsGreat arch support and comfortable fit, but perhaps not as durable as other models",
Rating: 3,
Body: "I really love this brand. My last pair were my go-to pair for a long while, but they have become increasingly difficult to find these days. After a little research, I decided to go with this one. I am glad I went with these -- they provide very good arch support and they fit as expected (it's always a gamble when buying shoes online). They are very comfortable and they can easily be worn all day or for long runs. Unfortunately, my pair has already started to fray a bit at the toe. This happened after probably 4-5 weeks of fairly light use. My last pair took an untold amount of abuse and stayed relatively intact for significantly longer. As of right now, it looks like the fraying is just cosmetic and will not affect the overall structure or stitching of the shoe. I love the fit and support, but I have some doubts about their longevity.",
CreateDate: new Date(2012, 6, 29, 8, 3, 40, 0),
Owner: {
Id: "eqropignundafg",
Name: "George Jetson",
Url: "./users.html?id=eqropignundafg",
AvatarImage: "./avatars/georgejetson.jpg",
IsFeaturedReviewer: false,
CreateDate: new Date(2012, 6, 29, 7, 41, 12, 0)
}
}, {
Id: "erohqthoihqt",
Title: "What is up with their sizing?!",
Rating: 2,
Body: "I don't understand the sizing on shoes at all. I bought these through Amazon because I like the previous iteration so much. I normally wear 12's but on the previous ones that I bought (in a store), the size that felt best was a US 13, so when those wore out and I couldn't find the same model anywhere new, I decided to take a shot on the newest model. Generally it's the same just different colors. I ordered the 13 assuming it would fit the same as the others did. Surprise! They're a little too big. Oy. I guess I just can't buy shoes in the mail.",
CreateDate: new Date(2012, 5, 26, 21, 32, 10, 0),
Owner: {
Id: "ljasdfasdfh",
Name: "I Thought I Saw a Puddy Tat",
Url: "./users.html?id=ljasdfasdfh",
AvatarImage: "./avatars/tweety.jpg",
IsFeaturedReviewer: true,
CreateDate: new Date(2011, 10, 3, 18, 43, 0, 0)
}
}, {
Id: "qwitoiqrogng",
Title: "Disappointed",
Rating: 1,
Body: "I usually don't post to many reviews but I felt it necessary to discuss why I would never recommend this shoe to anyone. Due to the abnormally large heel cushion on this shoe and because your heel is raised up so high it is virtually impossible to gain a solid mid-strike while running. They're soft as pillows while walking but after my 12 mile venture in them I swore off them and quickly ordered a new pair from another brand. Running with proper form is eons more important than a pillow like cushion. Heel striking will, in the long run, be detrimental to staying healthy and will result in excessive lower back and IT band pain or injury. Please consider something else, a shoe that will keep a focus on healthy strides.",
CreateDate: new Date(2012, 8, 11, 9, 46, 0, 0),
Owner: {
Id: "aldkjlkjaglkjag",
Name: "Cleveland Rocks",
Url: "./users.html?id=aldkjlkjaglkjag",
AvatarImage: "./avatars/cleveland.jpg",
IsFeaturedReviewer: true,
CreateDate: new Date(2011, 2, 31, 22, 9, 0, 0)
}
}];
var f1 = function(a, b) {
for (var v in b) {
a[v] = b[v];
}
return a;
};
function f2(a, b) {
if (!(a instanceof b)) {
throw "The 'new' keyword must be used when creating a new sdk object";
}
}
var sdk = {
ReviewListRequest: function(a) {
f2(this, arguments.callee);
this.ObjectType = 'Requests.ReviewList';
return f1(this, a);
},
Send: function(a, b) {
if (a.ObjectType == 'Requests.ReviewList') {
var st = a.Sort || "TimeStampDescending";
var ipp = a.ItemsPerPage || 5;
var pg = (a.OneBasedOnPage || 1) - 1;
var r = {};
var s = pg * ipp;
if (ipp <= 0) {
r.Exception = "ItemsPerPage must be greater than 0";
} else if (pg < 0) {
r.Exception = "OneBasedOnPage must be greater than 0";
} else if (s >= reviews.length) {
r.Exception = "The page of reviews does not exist";
} else {
var w = [];
for (var i = 0; i < reviews.length; i++) {
w.push(reviews[i]);
}
if (st == "TimeStampAscending") w.sort(function(a1, b1) {
return a1.CreateDate.getTime() - b1.CreateDate.getTime();
});
else if (st == "TimeStampDescending") w.sort(function(a1, b1) {
return b1.CreateDate.getTime() - a1.CreateDate.getTime();
});
else if (st == "RatingAscending") w.sort(function(a1, b1) {
var u = a1.Rating - b1.Rating;
if (u == 0) u = a1.CreateDate.getTime() - b1.CreateDate.getTime();
return u;
});
else if (st == "RatingDescending") w.sort(function(a1, b1) {
var u = b1.Rating - a1.Rating;
if (u == 0) u = a1.CreateDate.getTime() - b1.CreateDate.getTime();
return u;
});
r.Items = w.slice(s, s + ipp);
r.TotalCount = w.length;
window.setTimeout(function() {
b(r);
}, 500);
}
}
}
};
return sdk;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment