Best JavaScript code snippet using qawolf
themoviedb.js
Source:themoviedb.js
1var theMovieDb = {};2theMovieDb.common = {3 api_key: "YOUR_KEY",4 base_uri: "http://api.themoviedb.org/3/",5 images_uri: "http://image.tmdb.org/t/p/",6 timeout: 5000,7 generateQuery: function (options) {8 'use strict';9 var myOptions, query, option;10 myOptions = options || {};11 query = "?api_key=" + theMovieDb.common.api_key;12 if (Object.keys(myOptions).length > 0) {13 for (option in myOptions) {14 if (myOptions.hasOwnProperty(option) && option !== "id" && option !== "body") {15 query = query + "&" + option + "=" + myOptions[option];16 }17 }18 }19 return query;20 },21 validateCallbacks: function (callbacks) {22 'use strict';23 if (typeof callbacks[0] !== "function" || typeof callbacks[1] !== "function") {24 throw "Success and error parameters must be functions!";25 }26 },27 validateRequired: function (args, argsReq, opt, optReq, allOpt) {28 'use strict';29 var i, allOptional;30 allOptional = allOpt || false;31 if (args.length !== argsReq) {32 throw "The method requires " + argsReq + " arguments and you are sending " + args.length + "!";33 }34 if (allOptional) {35 return;36 }37 if (argsReq > 2) {38 for (i = 0; i < optReq.length; i = i + 1) {39 if (!opt.hasOwnProperty(optReq[i])) {40 throw optReq[i] + " is a required parameter and is not present in the options!";41 }42 }43 }44 },45 getImage: function (options) {46 'use strict';47 return theMovieDb.common.images_uri + options.size + "/" + options.file;48 },49 client: function (options, success, error) {50 'use strict';51 var method, status, xhr;52 method = options.method || "GET";53 status = options.status || 200;54 xhr = new XMLHttpRequest();55 xhr.ontimeout = function () {56 error('{"status_code":408,"status_message":"Request timed out"}');57 };58 xhr.open(method, theMovieDb.common.base_uri + options.url, true);59 if(options.method === "POST") {60 xhr.setRequestHeader("Content-Type", "application/json");61 xhr.setRequestHeader("Accept", "application/json");62 }63 xhr.timeout = theMovieDb.common.timeout;64 xhr.onload = function (e) {65 if (xhr.readyState === 4) {66 if (xhr.status === status) {67 success(xhr.responseText);68 } else {69 error(xhr.responseText);70 }71 } else {72 error(xhr.responseText);73 }74 };75 xhr.onerror = function (e) {76 error(xhr.responseText);77 };78 if (options.method === "POST") {79 xhr.send(JSON.stringify(options.body));80 } else {81 xhr.send(null);82 }83 }84};85theMovieDb.configurations = {86 getConfiguration: function (success, error) {87 'use strict';88 theMovieDb.common.validateRequired(arguments, 2);89 theMovieDb.common.validateCallbacks([success, error]);90 theMovieDb.common.client(91 {92 url: "configuration" + theMovieDb.common.generateQuery()93 },94 success,95 error96 );97 }98};99theMovieDb.account = {100 getInformation: function (options, success, error) {101 'use strict';102 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id"]);103 theMovieDb.common.validateCallbacks([success, error]);104 theMovieDb.common.client(105 {106 url: "account" + theMovieDb.common.generateQuery(options)107 },108 success,109 error110 );111 },112 getLists: function (options, success, error) {113 'use strict';114 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);115 theMovieDb.common.validateCallbacks([success, error]);116 theMovieDb.common.client(117 {118 url: "account/" + options.id + "/lists" + theMovieDb.common.generateQuery(options)119 },120 success,121 error122 );123 },124 getFavoritesMovies: function (options, success, error) {125 'use strict';126 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);127 theMovieDb.common.validateCallbacks([success, error]);128 theMovieDb.common.client(129 {130 url: "account/" + options.id + "/favorite_movies" + theMovieDb.common.generateQuery(options)131 },132 success,133 error134 );135 },136 addFavorite: function (options, success, error) {137 'use strict';138 var body;139 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "movie_id", "favorite"]);140 theMovieDb.common.validateCallbacks([success, error]);141 body = {142 "movie_id": options.movie_id,143 "favorite": options.favorite144 }145 theMovieDb.common.client(146 {147 url: "account/" + options.id + "/favorite" + theMovieDb.common.generateQuery(options),148 status: 201,149 method: "POST",150 body: body151 },152 success,153 error154 );155 },156 getRatedMovies: function (options, success, error) {157 'use strict';158 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);159 theMovieDb.common.validateCallbacks([success, error]);160 theMovieDb.common.client(161 {162 url: "account/" + options.id + "/rated_movies" + theMovieDb.common.generateQuery(options)163 },164 success,165 error166 );167 },168 getWatchlist: function (options, success, error) {169 'use strict';170 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);171 theMovieDb.common.validateCallbacks([success, error]);172 theMovieDb.common.client(173 {174 url: "account/" + options.id + "/movie_watchlist" + theMovieDb.common.generateQuery(options)175 },176 success,177 error178 );179 },180 addMovieToWatchlist: function (options, success, error) {181 'use strict';182 var body;183 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "movie_id", "movie_watchlist"]);184 theMovieDb.common.validateCallbacks([success, error]);185 body = {186 "movie_id": options.movie_id,187 "movie_watchlist": options.movie_watchlist188 }189 theMovieDb.common.client(190 {191 url: "account/" + options.id + "/movie_watchlist" + theMovieDb.common.generateQuery(options),192 method: "POST",193 status: 201,194 body: body195 },196 success,197 error198 );199 }200};201theMovieDb.authentication = {202 generateToken: function (success, error) {203 'use strict';204 theMovieDb.common.validateRequired(arguments, 2);205 theMovieDb.common.validateCallbacks([success, error]);206 theMovieDb.common.client(207 {208 url: "authentication/token/new" + theMovieDb.common.generateQuery()209 },210 success,211 error212 );213 },214 askPermissions: function(options){215 'use strict';216 window.open("https://www.themoviedb.org/authenticate/" + options.token + "?redirect_to=" + options.redirect_to);217 },218 validateUser: function (options, success, error) {219 'use strict';220 theMovieDb.common.validateRequired(arguments, 3, options, ["request_token", "username", "password"]);221 theMovieDb.common.validateCallbacks([success, error]);222 theMovieDb.common.client(223 {224 url: "authentication/token/validate_with_login" + theMovieDb.common.generateQuery(options)225 },226 success,227 error228 );229 },230 generateSession: function (options, success, error) {231 'use strict';232 theMovieDb.common.validateRequired(arguments, 3, options, ["request_token"]);233 theMovieDb.common.validateCallbacks([success, error]);234 theMovieDb.common.client(235 {236 url: "authentication/session/new" + theMovieDb.common.generateQuery(options)237 },238 success,239 error240 );241 },242 generateGuestSession: function (success, error) {243 'use strict';244 theMovieDb.common.validateRequired(arguments, 2);245 theMovieDb.common.validateCallbacks([success, error]);246 theMovieDb.common.client(247 {248 url: "authentication/guest_session/new" + theMovieDb.common.generateQuery()249 },250 success,251 error252 );253 }254};255theMovieDb.certifications = {256 getList: function (success, error) {257 'use strict';258 theMovieDb.common.validateRequired(arguments, 2);259 theMovieDb.common.validateCallbacks([success, error]);260 theMovieDb.common.client(261 {262 url: "certification/movie/list" + theMovieDb.common.generateQuery()263 },264 success,265 error266 );267 }268};269theMovieDb.changes = {270 getMovieChanges: function (options, success, error) {271 'use strict';272 theMovieDb.common.validateRequired(arguments, 3, "", "", true);273 theMovieDb.common.validateCallbacks([success, error]);274 theMovieDb.common.client(275 {276 url: "movie/changes" + theMovieDb.common.generateQuery(options)277 },278 success,279 error280 );281 },282 getPersonChanges: function (options, success, error) {283 'use strict';284 theMovieDb.common.validateRequired(arguments, 3, "", "", true);285 theMovieDb.common.validateCallbacks([success, error]);286 theMovieDb.common.client(287 {288 url: "person/changes" + theMovieDb.common.generateQuery(options)289 },290 success,291 error292 );293 }294};295theMovieDb.collections = {296 getCollection: function (options, success, error) {297 'use strict';298 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);299 theMovieDb.common.validateCallbacks([success, error]);300 theMovieDb.common.client(301 {302 url: "collection/" + options.id + theMovieDb.common.generateQuery(options)303 },304 success,305 error306 );307 },308 getCollectionImages: function (options, success, error) {309 'use strict';310 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);311 theMovieDb.common.validateCallbacks([success, error]);312 theMovieDb.common.client(313 {314 url: "collection/" + options.id + "/images" + theMovieDb.common.generateQuery(options)315 },316 success,317 error318 );319 }320};321theMovieDb.companies = {322 getCompany: function (options, success, error) {323 'use strict';324 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);325 theMovieDb.common.validateCallbacks([success, error]);326 theMovieDb.common.client(327 {328 url: "company/" + options.id + theMovieDb.common.generateQuery(options)329 },330 success,331 error332 );333 },334 getCompanyMovies: function (options, success, error) {335 'use strict';336 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);337 theMovieDb.common.validateCallbacks([success, error]);338 theMovieDb.common.client(339 {340 url: "company/" + options.id + "/movies" + theMovieDb.common.generateQuery(options)341 },342 success,343 error344 );345 }346};347theMovieDb.credits = {348 getCredit: function (options, success, error) {349 'use strict';350 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);351 theMovieDb.common.validateCallbacks([success, error]);352 theMovieDb.common.client(353 {354 url: "credit/" + options.id + theMovieDb.common.generateQuery(options)355 },356 success,357 error358 );359 }360};361theMovieDb.discover = {362 getMovies: function (options, success, error) {363 'use strict';364 theMovieDb.common.validateRequired(arguments, 3, "", "", true);365 theMovieDb.common.validateCallbacks([success, error]);366 theMovieDb.common.client(367 {368 url: "discover/movie" + theMovieDb.common.generateQuery(options)369 },370 success,371 error372 );373 },374 getTvShows: function (options, success, error) {375 'use strict';376 theMovieDb.common.validateRequired(arguments, 3, "", "", true);377 theMovieDb.common.validateCallbacks([success, error]);378 theMovieDb.common.client(379 {380 url: "discover/tv" + theMovieDb.common.generateQuery(options)381 },382 success,383 error384 );385 }386};387theMovieDb.find = {388 getById: function (options, success, error) {389 'use strict';390 theMovieDb.common.validateRequired(arguments, 3, options, ["id", "external_source"]);391 theMovieDb.common.validateCallbacks([success, error]);392 theMovieDb.common.client(393 {394 url: "find/" + options.id + theMovieDb.common.generateQuery(options)395 },396 success,397 error398 );399 }400};401theMovieDb.genres = {402 getList: function (options, success, error) {403 'use strict';404 theMovieDb.common.validateRequired(arguments, 3, "", "", true);405 theMovieDb.common.validateCallbacks([success, error]);406 theMovieDb.common.client(407 {408 url: "genre/list" + theMovieDb.common.generateQuery(options)409 },410 success,411 error412 );413 },414 getMovies: function (options, success, error) {415 'use strict';416 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);417 theMovieDb.common.validateCallbacks([success, error]);418 theMovieDb.common.client(419 {420 url: "genre/" + options.id + "/movies" + theMovieDb.common.generateQuery(options)421 },422 success,423 error424 );425 }426};427theMovieDb.jobs = {428 getList: function (success, error) {429 'use strict';430 theMovieDb.common.validateRequired(arguments, 2);431 theMovieDb.common.validateCallbacks([success, error]);432 theMovieDb.common.client(433 {434 url: "job/list" + theMovieDb.common.generateQuery()435 },436 success,437 error438 );439 }440};441theMovieDb.keywords = {442 getById: function (options, success, error) {443 'use strict';444 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);445 theMovieDb.common.validateCallbacks([success, error]);446 theMovieDb.common.client(447 {448 url: "keyword/" + options.id + theMovieDb.common.generateQuery(options)449 },450 success,451 error452 );453 },454 getMovies: function (options, success, error) {455 'use strict';456 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);457 theMovieDb.common.validateCallbacks([success, error]);458 theMovieDb.common.client(459 {460 url: "keyword/" + options.id + "/movies" + theMovieDb.common.generateQuery(options)461 },462 success,463 error464 );465 }466};467theMovieDb.lists = {468 getById: function (options, success, error) {469 'use strict';470 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);471 theMovieDb.common.validateCallbacks([success, error]);472 theMovieDb.common.client(473 {474 url: "list/" + options.id + theMovieDb.common.generateQuery(options)475 },476 success,477 error478 );479 },480 getStatusById: function (options, success, error) {481 'use strict';482 theMovieDb.common.validateRequired(arguments, 3, options, ["id", "movie_id"]);483 theMovieDb.common.validateCallbacks([success, error]);484 theMovieDb.common.client(485 {486 url: "list/" + options.id + "/item_status" + theMovieDb.common.generateQuery(options)487 },488 success,489 error490 );491 },492 addList: function (options, success, error) {493 'use strict';494 var body;495 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "name", "description"]);496 theMovieDb.common.validateCallbacks([success, error]);497 body = {498 "name": options.name,499 "description": options.description500 };501 delete options.name;502 delete options.description;503 if(options.hasOwnProperty("language")) {504 body["language"] = options.language;505 delete options.language;506 }507 theMovieDb.common.client(508 {509 method: "POST",510 status: 201,511 url: "list" + theMovieDb.common.generateQuery(options),512 body: body513 },514 success,515 error516 );517 },518 addItem: function (options, success, error) {519 'use strict';520 var body;521 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "media_id"]);522 theMovieDb.common.validateCallbacks([success, error]);523 body = {524 "media_id": options.media_id525 };526 theMovieDb.common.client(527 {528 method: "POST",529 status: 201,530 url: "list/" + options.id + "/add_item" + theMovieDb.common.generateQuery(options),531 body: body532 },533 success,534 error535 );536 },537 removeItem: function (options, success, error) {538 'use strict';539 var body;540 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "media_id"]);541 theMovieDb.common.validateCallbacks([success, error]);542 body = {543 "media_id": options.media_id544 };545 theMovieDb.common.client(546 {547 method: "POST",548 status: 201,549 url: "list/" + options.id + "/remove_item" + theMovieDb.common.generateQuery(options),550 body: body551 },552 success,553 error554 );555 },556 removeList: function (options, success, error) {557 'use strict';558 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);559 theMovieDb.common.validateCallbacks([success, error]);560 theMovieDb.common.client(561 {562 method: "DELETE",563 status: 204,564 url: "list/" + options.id + theMovieDb.common.generateQuery(options)565 },566 success,567 error568 );569 },570 clearList: function (options, success, error) {571 'use strict';572 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id", "confirm"]);573 theMovieDb.common.validateCallbacks([success, error]);574 theMovieDb.common.client(575 {576 method: "POST",577 status: 204,578 body: {},579 url: "list/" + options.id + "/clear" + theMovieDb.common.generateQuery(options)580 },581 success,582 error583 );584 }585};586theMovieDb.movies = {587 getById: function (options, success, error) {588 'use strict';589 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);590 theMovieDb.common.validateCallbacks([success, error]);591 theMovieDb.common.client(592 {593 url: "movie/" + options.id + theMovieDb.common.generateQuery(options)594 },595 success,596 error597 );598 },599 getAlternativeTitles: function (options, success, error) {600 'use strict';601 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);602 theMovieDb.common.validateCallbacks([success, error]);603 theMovieDb.common.client(604 {605 url: "movie/" + options.id + "/alternative_titles" + theMovieDb.common.generateQuery(options)606 },607 success,608 error609 );610 },611 getCredits: function (options, success, error) {612 'use strict';613 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);614 theMovieDb.common.validateCallbacks([success, error]);615 theMovieDb.common.client(616 {617 url: "movie/" + options.id + "/credits" + theMovieDb.common.generateQuery(options)618 },619 success,620 error621 );622 },623 getImages: function (options, success, error) {624 'use strict';625 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);626 theMovieDb.common.validateCallbacks([success, error]);627 theMovieDb.common.client(628 {629 url: "movie/" + options.id + "/images" + theMovieDb.common.generateQuery(options)630 },631 success,632 error633 );634 },635 getKeywords: function (options, success, error) {636 'use strict';637 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);638 theMovieDb.common.validateCallbacks([success, error]);639 theMovieDb.common.client(640 {641 url: "movie/" + options.id + "/keywords" + theMovieDb.common.generateQuery(options)642 },643 success,644 error645 );646 },647 getReleases: function (options, success, error) {648 'use strict';649 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);650 theMovieDb.common.validateCallbacks([success, error]);651 theMovieDb.common.client(652 {653 url: "movie/" + options.id + "/releases" + theMovieDb.common.generateQuery(options)654 },655 success,656 error657 );658 },659 getTrailers: function (options, success, error) {660 'use strict';661 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);662 theMovieDb.common.validateCallbacks([success, error]);663 theMovieDb.common.client(664 {665 url: "movie/" + options.id + "/trailers" + theMovieDb.common.generateQuery(options)666 },667 success,668 error669 );670 },671 getVideos: function (options, success, error) {672 'use strict';673 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);674 theMovieDb.common.validateCallbacks([success, error]);675 theMovieDb.common.client(676 {677 url: "movie/" + options.id + "/videos" + theMovieDb.common.generateQuery(options)678 },679 success,680 error681 );682 },683 getTranslations: function (options, success, error) {684 'use strict';685 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);686 theMovieDb.common.validateCallbacks([success, error]);687 theMovieDb.common.client(688 {689 url: "movie/" + options.id + "/translations" + theMovieDb.common.generateQuery(options)690 },691 success,692 error693 );694 },695 getSimilarMovies: function (options, success, error) {696 'use strict';697 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);698 theMovieDb.common.validateCallbacks([success, error]);699 theMovieDb.common.client(700 {701 url: "movie/" + options.id + "/similar_movies" + theMovieDb.common.generateQuery(options)702 },703 success,704 error705 );706 },707 getReviews: function (options, success, error) {708 'use strict';709 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);710 theMovieDb.common.validateCallbacks([success, error]);711 theMovieDb.common.client(712 {713 url: "movie/" + options.id + "/reviews" + theMovieDb.common.generateQuery(options)714 },715 success,716 error717 );718 },719 getLists: function (options, success, error) {720 'use strict';721 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);722 theMovieDb.common.validateCallbacks([success, error]);723 theMovieDb.common.client(724 {725 url: "movie/" + options.id + "/lists" + theMovieDb.common.generateQuery(options)726 },727 success,728 error729 );730 },731 getChanges: function (options, success, error) {732 'use strict';733 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);734 theMovieDb.common.validateCallbacks([success, error]);735 theMovieDb.common.client(736 {737 url: "movie/" + options.id + "/changes" + theMovieDb.common.generateQuery(options)738 },739 success,740 error741 );742 },743 getLatest: function (success, error) {744 'use strict';745 theMovieDb.common.validateRequired(arguments, 2);746 theMovieDb.common.validateCallbacks([success, error]);747 theMovieDb.common.client(748 {749 url: "movie/latest" + theMovieDb.common.generateQuery()750 },751 success,752 error753 );754 },755 getUpcoming: function (options, success, error) {756 'use strict';757 theMovieDb.common.validateRequired(arguments, 3, "", "", true);758 theMovieDb.common.validateCallbacks([success, error]);759 theMovieDb.common.client(760 {761 url: "movie/upcoming" + theMovieDb.common.generateQuery(options)762 },763 success,764 error765 );766 },767 getNowPlaying: function (options, success, error) {768 'use strict';769 theMovieDb.common.validateRequired(arguments, 3, "", "", true);770 theMovieDb.common.validateCallbacks([success, error]);771 theMovieDb.common.client(772 {773 url: "movie/now_playing" + theMovieDb.common.generateQuery(options)774 },775 success,776 error777 );778 },779 getPopular: function (options, success, error) {780 'use strict';781 theMovieDb.common.validateRequired(arguments, 3, "", "", true);782 theMovieDb.common.validateCallbacks([success, error]);783 theMovieDb.common.client(784 {785 url: "movie/popular" + theMovieDb.common.generateQuery(options)786 },787 success,788 error789 );790 },791 getTopRated: function (options, success, error) {792 'use strict';793 theMovieDb.common.validateRequired(arguments, 3, "", "", true);794 theMovieDb.common.validateCallbacks([success, error]);795 theMovieDb.common.client(796 {797 url: "movie/top_rated" + theMovieDb.common.generateQuery(options)798 },799 success,800 error801 );802 },803 getStatus: function (options, success, error) {804 'use strict';805 theMovieDb.common.validateRequired(arguments, 3, options, ["session_id", "id"]);806 theMovieDb.common.validateCallbacks([success, error]);807 theMovieDb.common.client(808 {809 url: "movie/" + options.id + "/account_states" + theMovieDb.common.generateQuery(options)810 },811 success,812 error813 );814 },815 rate: function (options, rate, success, error) {816 'use strict';817 theMovieDb.common.validateRequired(arguments, 4, options, ["session_id", "id"]);818 theMovieDb.common.validateCallbacks([success, error]);819 theMovieDb.common.client(820 {821 method: "POST",822 status: 201,823 url: "movie/" + options.id + "/rating" + theMovieDb.common.generateQuery(options),824 body: { "value": rate }825 },826 success,827 error828 );829 },830 rateGuest: function (options, rate, success, error) {831 'use strict';832 theMovieDb.common.validateRequired(arguments, 4, options, ["guest_session_id", "id"]);833 theMovieDb.common.validateCallbacks([success, error]);834 theMovieDb.common.client(835 {836 method: "POST",837 status: 201,838 url: "movie/" + options.id + "/rating" + theMovieDb.common.generateQuery(options),839 body: { "value": rate }840 },841 success,842 error843 );844 }845};846theMovieDb.networks = {847 getById: function (options, success, error) {848 'use strict';849 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);850 theMovieDb.common.validateCallbacks([success, error]);851 theMovieDb.common.client(852 {853 url: "network/" + options.id + theMovieDb.common.generateQuery(options)854 },855 success,856 error857 );858 }859};860theMovieDb.people = {861 getById: function (options, success, error) {862 'use strict';863 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);864 theMovieDb.common.validateCallbacks([success, error]);865 theMovieDb.common.client(866 {867 url: "person/" + options.id + theMovieDb.common.generateQuery(options)868 },869 success,870 error871 );872 },873 getMovieCredits: function (options, success, error) {874 'use strict';875 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);876 theMovieDb.common.validateCallbacks([success, error]);877 theMovieDb.common.client(878 {879 url: "person/" + options.id + "/movie_credits" + theMovieDb.common.generateQuery(options)880 },881 success,882 error883 );884 },885 getTvCredits: function (options, success, error) {886 'use strict';887 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);888 theMovieDb.common.validateCallbacks([success, error]);889 theMovieDb.common.client(890 {891 url: "person/" + options.id + "/tv_credits" + theMovieDb.common.generateQuery(options)892 },893 success,894 error895 );896 },897 getCredits: function (options, success, error) {898 'use strict';899 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);900 theMovieDb.common.validateCallbacks([success, error]);901 theMovieDb.common.client(902 {903 url: "person/" + options.id + "/combined_credits" + theMovieDb.common.generateQuery(options)904 },905 success,906 error907 );908 },909 getExternalIds: function (options, success, error) {910 'use strict';911 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);912 theMovieDb.common.validateCallbacks([success, error]);913 theMovieDb.common.client(914 {915 url: "person/" + options.id + "/external_ids" + theMovieDb.common.generateQuery(options)916 },917 success,918 error919 );920 },921 getImages: function (options, success, error) {922 'use strict';923 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);924 theMovieDb.common.validateCallbacks([success, error]);925 theMovieDb.common.client(926 {927 url: "person/" + options.id + "/images" + theMovieDb.common.generateQuery(options)928 },929 success,930 error931 );932 },933 getTaggedImages: function(options, sucess, error) {934 'use strict';935 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);936 theMovieDb.common.validateCallbacks([success, error]);937 theMovieDb.common.client(938 {939 url: "person/" + options.id + "/tagged_images" + theMovieDb.common.generateQuery(options)940 },941 success,942 error943 );944 },945 getChanges: function (options, success, error) {946 'use strict';947 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);948 theMovieDb.common.validateCallbacks([success, error]);949 theMovieDb.common.client(950 {951 url: "person/" + options.id + "/changes" + theMovieDb.common.generateQuery(options)952 },953 success,954 error955 );956 },957 getPopular: function (options, success, error) {958 'use strict';959 theMovieDb.common.validateRequired(arguments, 3, "", "", true);960 theMovieDb.common.validateCallbacks([success, error]);961 theMovieDb.common.client(962 {963 url: "person/popular" + theMovieDb.common.generateQuery(options)964 },965 success,966 error967 );968 },969 getLatest: function (success, error) {970 'use strict';971 theMovieDb.common.validateRequired(arguments, 2);972 theMovieDb.common.validateCallbacks([success, error]);973 theMovieDb.common.client(974 {975 url: "person/latest" + theMovieDb.common.generateQuery()976 },977 success,978 error979 );980 }981};982theMovieDb.reviews = {983 getById: function (options, success, error) {984 'use strict';985 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);986 theMovieDb.common.validateCallbacks([success, error]);987 theMovieDb.common.client(988 {989 url: "review/" + options.id + theMovieDb.common.generateQuery(options)990 },991 success,992 error993 );994 }995};996theMovieDb.search = {997 getMovie: function (options, success, error) {998 'use strict';999 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1000 theMovieDb.common.validateCallbacks([success, error]);1001 theMovieDb.common.client(1002 {1003 url: "search/movie" + theMovieDb.common.generateQuery(options)1004 },1005 success,1006 error1007 );1008 },1009 getCollection: function (options, success, error) {1010 'use strict';1011 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1012 theMovieDb.common.validateCallbacks([success, error]);1013 theMovieDb.common.client(1014 {1015 url: "search/collection" + theMovieDb.common.generateQuery(options)1016 },1017 success,1018 error1019 );1020 },1021 getTv: function (options, success, error) {1022 'use strict';1023 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1024 theMovieDb.common.validateCallbacks([success, error]);1025 theMovieDb.common.client(1026 {1027 url: "search/tv" + theMovieDb.common.generateQuery(options)1028 },1029 success,1030 error1031 );1032 },1033 getPerson: function (options, success, error) {1034 'use strict';1035 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1036 theMovieDb.common.validateCallbacks([success, error]);1037 theMovieDb.common.client(1038 {1039 url: "search/person" + theMovieDb.common.generateQuery(options)1040 },1041 success,1042 error1043 );1044 },1045 getList: function (options, success, error) {1046 'use strict';1047 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1048 theMovieDb.common.validateCallbacks([success, error]);1049 theMovieDb.common.client(1050 {1051 url: "search/list" + theMovieDb.common.generateQuery(options)1052 },1053 success,1054 error1055 );1056 },1057 getCompany: function (options, success, error) {1058 'use strict';1059 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1060 theMovieDb.common.validateCallbacks([success, error]);1061 theMovieDb.common.client(1062 {1063 url: "search/company" + theMovieDb.common.generateQuery(options)1064 },1065 success,1066 error1067 );1068 },1069 getKeyword: function (options, success, error) {1070 'use strict';1071 theMovieDb.common.validateRequired(arguments, 3, options, ["query"]);1072 theMovieDb.common.validateCallbacks([success, error]);1073 theMovieDb.common.client(1074 {1075 url: "search/keyword" + theMovieDb.common.generateQuery(options)1076 },1077 success,1078 error1079 );1080 }1081};1082theMovieDb.timezones = {1083 getList: function (success, error) {1084 'use strict';1085 theMovieDb.common.validateRequired(arguments, 2);1086 theMovieDb.common.validateCallbacks([success, error]);1087 theMovieDb.common.client(1088 {1089 url: "timezones/list" + theMovieDb.common.generateQuery()1090 },1091 success,1092 error1093 );1094 }1095};1096theMovieDb.tv = {1097 getById: function (options, success, error) {1098 'use strict';1099 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1100 theMovieDb.common.validateCallbacks([success, error]);1101 theMovieDb.common.client(1102 {1103 url: "tv/" + options.id + theMovieDb.common.generateQuery(options)1104 },1105 success,1106 error1107 );1108 },1109 getSimilar: function (options, success, error) {1110 'use strict';1111 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1112 theMovieDb.common.validateCallbacks([success, error]);1113 theMovieDb.common.client(1114 {1115 url: "tv/" + options.id + "/similar" + theMovieDb.common.generateQuery(options)1116 },1117 success,1118 error1119 );1120 },1121 getCredits: function (options, success, error) {1122 'use strict';1123 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1124 theMovieDb.common.validateCallbacks([success, error]);1125 theMovieDb.common.client(1126 {1127 url: "tv/" + options.id + "/credits" + theMovieDb.common.generateQuery(options)1128 },1129 success,1130 error1131 );1132 },1133 getExternalIds: function (options, success, error) {1134 'use strict';1135 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1136 theMovieDb.common.validateCallbacks([success, error]);1137 theMovieDb.common.client(1138 {1139 url: "tv/" + options.id + "/external_ids" + theMovieDb.common.generateQuery(options)1140 },1141 success,1142 error1143 );1144 },1145 getImages: function (options, success, error) {1146 'use strict';1147 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1148 theMovieDb.common.validateCallbacks([success, error]);1149 theMovieDb.common.client(1150 {1151 url: "tv/" + options.id + "/images" + theMovieDb.common.generateQuery(options)1152 },1153 success,1154 error1155 );1156 },1157 getTranslations: function (options, success, error) {1158 'use strict';1159 theMovieDb.common.validateRequired(arguments, 3, options, ["id"]);1160 theMovieDb.common.validateCallbacks([success, error]);1161 theMovieDb.common.client(1162 {1163 url: "tv/" + options.id + "/translations" + theMovieDb.common.generateQuery(options)1164 },1165 success,1166 error1167 );1168 },1169 getOnTheAir: function (options, success, error) {1170 'use strict';1171 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1172 theMovieDb.common.validateCallbacks([success, error]);1173 theMovieDb.common.client(1174 {1175 url: "tv/on_the_air" + theMovieDb.common.generateQuery(options)1176 },1177 success,1178 error1179 );1180 },1181 getAiringToday: function (options, success, error) {1182 'use strict';1183 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1184 theMovieDb.common.validateCallbacks([success, error]);1185 theMovieDb.common.client(1186 {1187 url: "tv/airing_today" + theMovieDb.common.generateQuery(options)1188 },1189 success,1190 error1191 );1192 },1193 getTopRated: function (options, success, error) {1194 'use strict';1195 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1196 theMovieDb.common.validateCallbacks([success, error]);1197 theMovieDb.common.client(1198 {1199 url: "tv/top_rated" + theMovieDb.common.generateQuery(options)1200 },1201 success,1202 error1203 );1204 },1205 getPopular: function (options, success, error) {1206 'use strict';1207 theMovieDb.common.validateRequired(arguments, 3, "", "", true);1208 theMovieDb.common.validateCallbacks([success, error]);1209 theMovieDb.common.client(1210 {1211 url: "tv/popular" + theMovieDb.common.generateQuery(options)1212 },1213 success,1214 error1215 );1216 }1217};1218theMovieDb.tvSeasons = {1219 getById: function (options, success, error) {1220 'use strict';1221 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1222 theMovieDb.common.validateCallbacks([success, error]);1223 theMovieDb.common.client(1224 {1225 url: "tv/" + options.id + "/season/" + options.season_number + theMovieDb.common.generateQuery(options)1226 },1227 success,1228 error1229 );1230 },1231 getCredits: function (options, success, error) {1232 'use strict';1233 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1234 theMovieDb.common.validateCallbacks([success, error]);1235 theMovieDb.common.client(1236 {1237 url: "tv/" + options.id + "/season/" + options.season_number + "/credits" + theMovieDb.common.generateQuery(options)1238 },1239 success,1240 error1241 );1242 },1243 getExternalIds: function (options, success, error) {1244 'use strict';1245 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1246 theMovieDb.common.validateCallbacks([success, error]);1247 theMovieDb.common.client(1248 {1249 url: "tv/" + options.id + "/season/" + options.season_number + "/external_ids" + theMovieDb.common.generateQuery(options)1250 },1251 success,1252 error1253 );1254 },1255 getImages: function (options, success, error) {1256 'use strict';1257 theMovieDb.common.validateRequired(arguments, 3, options, ["season_number", "id"]);1258 theMovieDb.common.validateCallbacks([success, error]);1259 theMovieDb.common.client(1260 {1261 url: "tv/" + options.id + "/season/" + options.season_number + "/images" + theMovieDb.common.generateQuery(options)1262 },1263 success,1264 error1265 );1266 }1267};1268theMovieDb.tvEpisodes = {1269 getById: function (options, success, error) {1270 'use strict';1271 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1272 theMovieDb.common.validateCallbacks([success, error]);1273 theMovieDb.common.client(1274 {1275 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + theMovieDb.common.generateQuery(options)1276 },1277 success,1278 error1279 );1280 },1281 getCredits: function (options, success, error) {1282 'use strict';1283 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1284 theMovieDb.common.validateCallbacks([success, error]);1285 theMovieDb.common.client(1286 {1287 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + "/credits" + theMovieDb.common.generateQuery(options)1288 },1289 success,1290 error1291 );1292 },1293 getExternalIds: function (options, success, error) {1294 'use strict';1295 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1296 theMovieDb.common.validateCallbacks([success, error]);1297 theMovieDb.common.client(1298 {1299 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + "/external_ids" + theMovieDb.common.generateQuery(options)1300 },1301 success,1302 error1303 );1304 },1305 getImages: function (options, success, error) {1306 'use strict';1307 theMovieDb.common.validateRequired(arguments, 3, options, ["episode_number", "season_number", "id"]);1308 theMovieDb.common.validateCallbacks([success, error]);1309 theMovieDb.common.client(1310 {1311 url: "tv/" + options.id + "/season/" + options.season_number + "/episode/" + options.episode_number + "/images" + theMovieDb.common.generateQuery(options)1312 },1313 success,1314 error1315 );1316 }1317};1318// browserified with just one line of code...
test_defaultStorageUpgrade.js
Source:test_defaultStorageUpgrade.js
1/**2 * Any copyright is dedicated to the Public Domain.3 * http://creativecommons.org/publicdomain/zero/1.0/4 */5var testGenerator = testSteps();6function testSteps()7{8 const openParams = [9 // This one lives in storage/default/http+++localhost10 { url: "http://localhost", dbName: "dbA", dbVersion: 1 },11 // This one lives in storage/default/http+++www.mozilla.org12 { url: "http://www.mozilla.org", dbName: "dbB", dbVersion: 1 },13 // This one lives in storage/default/http+++www.mozilla.org+808014 { url: "http://www.mozilla.org:8080", dbName: "dbC", dbVersion: 1 },15 // This one lives in storage/default/https+++www.mozilla.org16 { url: "https://www.mozilla.org", dbName: "dbD", dbVersion: 1 },17 // This one lives in storage/default/https+++www.mozilla.org+808018 { url: "https://www.mozilla.org:8080", dbName: "dbE", dbVersion: 1 },19 // This one lives in storage/permanent/indexeddb+++fx-devtools20 { url: "indexeddb://fx-devtools", dbName: "dbF",21 dbOptions: { version: 1, storage: "persistent" } },22 // This one lives in storage/permanent/moz-safe-about+home23 { url: "moz-safe-about:home", dbName: "dbG",24 dbOptions: { version: 1, storage: "persistent" } },25 // This one lives in storage/default/file++++Users+joe+26 { url: "file:///Users/joe/", dbName: "dbH", dbVersion: 1 },27 // This one lives in storage/default/file++++Users+joe+index.html28 { url: "file:///Users/joe/index.html", dbName: "dbI", dbVersion: 1 },29 // This one lives in storage/default/file++++c++Users+joe+30 { url: "file:///c:/Users/joe/", dbName: "dbJ", dbVersion: 1 },31 // This one lives in storage/default/file++++c++Users+joe+index.html32 { url: "file:///c:/Users/joe/index.html", dbName: "dbK", dbVersion: 1 },33 // This one lives in storage/permanent/chrome34 { dbName: "dbL", dbVersion: 1 },35 // This one lives in storage/default/1007+t+https+++developer.cdn.mozilla.net36 { appId: 1007, inIsolatedMozBrowser: true, url: "https://developer.cdn.mozilla.net",37 dbName: "dbN", dbVersion: 1 },38 // This one lives in storage/default/http+++127.0.0.139 { url: "http://127.0.0.1", dbName: "dbO", dbVersion: 1 },40 // This one lives in storage/default/file++++41 { url: "file:///", dbName: "dbP", dbVersion: 1 },42 // This one lives in storage/default/file++++c++43 { url: "file:///c:/", dbName: "dbQ", dbVersion: 1 },44 // This one lives in storage/default/file++++Users+joe+c+++index.html45 { url: "file:///Users/joe/c++/index.html", dbName: "dbR", dbVersion: 1 },46 // This one lives in storage/default/file++++Users+joe+c+++index.html47 { url: "file:///Users/joe/c///index.html", dbName: "dbR", dbVersion: 1 },48 // This one lives in storage/default/file++++++index.html49 { url: "file:///+/index.html", dbName: "dbS", dbVersion: 1 },50 // This one lives in storage/default/file++++++index.html51 { url: "file://///index.html", dbName: "dbS", dbVersion: 1 },52 // This one lives in storage/permanent/resource+++fx-share-addon-at-mozilla-dot-org-fx-share-addon-data53 { url: "resource://fx-share-addon-at-mozilla-dot-org-fx-share-addon-data",54 dbName: "dbU", dbOptions: { version: 1, storage: "persistent" } },55 // This one lives in storage/temporary/http+++localhost+8156 // The .metadata file was intentionally removed for this origin directory57 // to test restoring during upgrade.58 { url: "http://localhost:81", dbName: "dbV",59 dbOptions: { version: 1, storage: "temporary" } },60 // This one lives in storage/temporary/http+++localhost+8261 // The .metadata file was intentionally truncated for this origin directory62 // to test restoring during upgrade.63 { url: "http://localhost:82", dbName: "dbW",64 dbOptions: { version: 1, storage: "temporary" } },65 // This one lives in storage/temporary/1007+t+https+++developer.cdn.mozilla.net66 { appId: 1007, inIsolatedMozBrowser: true, url: "https://developer.cdn.mozilla.net",67 dbName: "dbY", dbOptions: { version: 1, storage: "temporary" } },68 // This one lives in storage/temporary/http+++localhost69 { url: "http://localhost", dbName: "dbZ",70 dbOptions: { version: 1, storage: "temporary" } }71 ];72 let ios = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]73 .getService(SpecialPowers.Ci.nsIIOService);74 let ssm = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]75 .getService(SpecialPowers.Ci.nsIScriptSecurityManager);76 function openDatabase(params) {77 let request;78 if ("url" in params) {79 let uri = ios.newURI(params.url, null, null);80 let principal =81 ssm.createCodebasePrincipal(uri,82 {appId: params.appId || ssm.NO_APPID,83 inIsolatedMozBrowser: params.inIsolatedMozBrowser});84 if ("dbVersion" in params) {85 request = indexedDB.openForPrincipal(principal, params.dbName,86 params.dbVersion);87 } else {88 request = indexedDB.openForPrincipal(principal, params.dbName,89 params.dbOptions);90 }91 } else {92 if ("dbVersion" in params) {93 request = indexedDB.open(params.dbName, params.dbVersion);94 } else {95 request = indexedDB.open(params.dbName, params.dbOptions);96 }97 }98 return request;99 }100 clearAllDatabases(continueToNextStepSync);101 yield undefined;102 installPackagedProfile("defaultStorageUpgrade_profile");103 for (let params of openParams) {104 let request = openDatabase(params);105 request.onerror = errorHandler;106 request.onupgradeneeded = unexpectedSuccessHandler;107 request.onsuccess = grabEventAndContinueHandler;108 let event = yield undefined;109 is(event.type, "success", "Correct event type");110 }111 resetAllDatabases(continueToNextStepSync);112 yield undefined;113 for (let params of openParams) {114 let request = openDatabase(params);115 request.onerror = errorHandler;116 request.onupgradeneeded = unexpectedSuccessHandler;117 request.onsuccess = grabEventAndContinueHandler;118 let event = yield undefined;119 is(event.type, "success", "Correct event type");120 }121 finishTest();122 yield undefined;...
aboutuser.js
Source:aboutuser.js
1const fs = require('fs')2exports.isLimit = function(sender, isPremium, isOwner, limitawal, _db){3 if (isOwner) return false4 if (isPremium) return false5 let found = false6 for (let i of _db) {7 if (i.id === sender) {8 let limits = i.limit9 if (limits >= limitawal) {10 found = true11 return true12 } else {13 found = true14 return false15 }16 }17 }18 if (found === false) {19 const obj = { id: sender, limit: 0 }20 _db.push(obj)21 fs.writeFileSync('./database/limit.json', JSON.stringify(_db))22 return false23 }24}25exports.limitAdd = function(sender, _db){26 let found = false27 Object.keys(_db).forEach((i) => {28 if (_db[i].id === sender) {29 found = i30 }31 })32 if (found !== false) {33 _db[found].limit += 134 fs.writeFileSync('./database/limit.json', JSON.stringify(_db))35 }36}37exports.getLimit = function(sender, limitawal, _db){38 let found = false39 Object.keys(_db).forEach((i) => {40 if (_db[i].id === sender) {41 found = i42 }43 })44 if (found !== false) {45 return limitawal - _db[found].limit46 } else {47 return limitawal48 }49}50exports.giveLimit = function(pemain, duit, _db){51 let position = false52 Object.keys(_db).forEach((i) => {53 if (_db[i].id === pemain) {54 position = i55 }56 })57 if (position !== false) {58 _db[position].limit -= duit59 fs.writeFileSync('./database/limit.json', JSON.stringify(_db))60 } else {61 const njt = duit - duit - duit62 const bulim = ({63 id: pemain,64 limit: njt65 })66 _db.push(bulim)67 fs.writeFileSync('./database/limit.json', JSON.stringify(_db))68 }69}70exports.addBalance = function(sender, duit, _db){71 let position = false72 Object.keys(_db).forEach((i) => {73 if (_db[i].id === sender) {74 position = i75 }76 })77 if (position !== false) {78 _db[position].balance += duit79 fs.writeFileSync('./database/balance.json', JSON.stringify(_db))80 } else {81 const bulin = ({82 id: sender,83 balance: duit84 })85 _db.push(bulin)86 fs.writeFileSync('./database/balance.json', JSON.stringify(_db))87 }88}89exports.kurangBalance = function(sender, duit, _db){90 let position = false91 Object.keys(_db).forEach((i) => {92 if (_db[i].id === sender) {93 position = i94 }95 })96 if (position !== false) {97 _db[position].balance -= duit98 fs.writeFileSync('./database/balance.json', JSON.stringify(_db))99 }100}101exports.getBalance = function(sender, _db){102 let position = false103 Object.keys(_db).forEach((i) => {104 if (_db[i].id === sender) {105 position = i106 }107 })108 if (position !== false) {109 return _db[position].balance110 } else {111 return 0112 }113}114exports.isGame = function(sender, isOwner, gcount, _db){115 if (isOwner) {return false;}116 let found = false;117 for (let i of _db){118 if(i.id === sender){119 let limits = i.glimit;120 if (limits >= gcount) {121 found = true;122 return true;123 }else{124 found = true;125 return false;126 }127 }128 }129 if (found === false){130 let obj = {id: sender, glimit:0};131 _db.push(obj);132 fs.writeFileSync('./database/glimit.json',JSON.stringify(_db));133 return false;134 }135}136exports.gameAdd = function(sender, _db){137 var found = false;138 Object.keys(_db).forEach((i) => {139 if(_db[i].id == sender){140 found = i141 }142 })143 if (found !== false) {144 _db[found].glimit += 1;145 fs.writeFileSync('./database/glimit.json',JSON.stringify(_db));146 }147}148exports.givegame = function(pemain, duit, _db){149 let position = false150 Object.keys(_db).forEach((i) => {151 if (_db[i].id === pemain) {152 position = i153 }154 })155 if (position !== false) {156 _db[position].glimit -= duit157 fs.writeFileSync('./database/glimit.json', JSON.stringify(_db))158 } else {159 const njti = duit - duit - duit160 const bulimi = ({161 id: pemain,162 glimit: njti163 })164 _db.push(bulimi)165 fs.writeFileSync('./database/glimit.json', JSON.stringify(_db))166 }167}168exports.cekGLimit = function(sender, gcount, _db){169 let position = false170 Object.keys(_db).forEach((i) => {171 if(_db[i].id === sender) {172 position = i173 }174 })175 if (position !== false) {176 return gcount - _db[position].glimit177 } else {178 return gcount179 }180}181exports.createHit = function(sender, _db){182 const anohoh = { id: sender, hit: 0}183 _db.push(anohoh);184 fs.writeFileSync('./database/userhit.json',JSON.stringify(_db));''185}186exports.AddHit = function(sender, _db){187 var found = false;188 Object.keys(_db).forEach((i) => {189 if(_db[i].id == sender){190 found = i191 }192 })193 if (found !== false) {194 _db[found].hit += 1;195 fs.writeFileSync('./database/userhit.json',JSON.stringify(_db));196 }197}198exports.gethitUser = function(sender, _db){199 let position = false200 Object.keys(_db).forEach((i) => {201 if (_db[i].id === sender) {202 position = i203 }204 })205 if (position !== false) {206 return _db[position].hit207 }...
exports.js
Source:exports.js
1/**2 * @fileoverview Exports for ydn-db crud module.3 *4 */5goog.provide('ydn.db.crud.exports');6goog.require('ydn.db.Key');7goog.require('ydn.db.KeyRange');8goog.require('ydn.db.crud.Storage');9goog.require('ydn.db.tr.exports');10goog.exportProperty(ydn.db.crud.Storage.prototype, 'branch',11 ydn.db.crud.Storage.prototype.branch);12goog.exportProperty(ydn.db.crud.Storage.prototype, 'add',13 ydn.db.crud.Storage.prototype.add);14goog.exportProperty(ydn.db.crud.Storage.prototype, 'addAll',15 ydn.db.crud.Storage.prototype.addAll);16goog.exportProperty(ydn.db.crud.Storage.prototype, 'get',17 ydn.db.crud.Storage.prototype.get);18goog.exportProperty(ydn.db.crud.Storage.prototype, 'keys',19 ydn.db.crud.Storage.prototype.keys);20goog.exportProperty(ydn.db.crud.Storage.prototype, 'keysByIndex',21 ydn.db.crud.Storage.prototype.keysByIndex);22goog.exportProperty(ydn.db.crud.Storage.prototype, 'values',23 ydn.db.crud.Storage.prototype.values);24goog.exportProperty(ydn.db.crud.Storage.prototype, 'valuesByIndex',25 ydn.db.crud.Storage.prototype.valuesByIndex);26goog.exportProperty(ydn.db.crud.Storage.prototype, 'put',27 ydn.db.crud.Storage.prototype.put);28goog.exportProperty(ydn.db.crud.Storage.prototype, 'putAll',29 ydn.db.crud.Storage.prototype.putAll);30goog.exportProperty(ydn.db.crud.Storage.prototype, 'clear',31 ydn.db.crud.Storage.prototype.clear);32goog.exportProperty(ydn.db.crud.Storage.prototype, 'remove',33 ydn.db.crud.Storage.prototype.remove);34goog.exportProperty(ydn.db.crud.Storage.prototype, 'count',35 ydn.db.crud.Storage.prototype.count);36goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'add',37 ydn.db.crud.DbOperator.prototype.add);38goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'addAll',39 ydn.db.crud.DbOperator.prototype.addAll);40goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'get',41 ydn.db.crud.DbOperator.prototype.get);42goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'keys',43 ydn.db.crud.DbOperator.prototype.keys);44goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'keysByIndex',45 ydn.db.crud.DbOperator.prototype.keysByIndex);46goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'values',47 ydn.db.crud.DbOperator.prototype.values);48goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'valuesByIndex',49 ydn.db.crud.DbOperator.prototype.valuesByIndex);50goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'put',51 ydn.db.crud.DbOperator.prototype.put);52goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'putAll',53 ydn.db.crud.DbOperator.prototype.putAll);54goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'clear',55 ydn.db.crud.DbOperator.prototype.clear);56goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'remove',57 ydn.db.crud.DbOperator.prototype.remove);58goog.exportProperty(ydn.db.crud.DbOperator.prototype, 'count',59 ydn.db.crud.DbOperator.prototype.count);60goog.exportSymbol('ydn.db.Key', ydn.db.Key);61goog.exportProperty(ydn.db.Key.prototype, 'id', ydn.db.Key.prototype.getId);62goog.exportProperty(ydn.db.Key.prototype, 'parent',63 ydn.db.Key.prototype.getParent);64goog.exportProperty(ydn.db.Key.prototype, 'storeName',65 ydn.db.Key.prototype.getStoreName);66goog.exportSymbol('ydn.db.KeyRange', ydn.db.KeyRange);67goog.exportProperty(ydn.db.KeyRange, 'upperBound', ydn.db.KeyRange.upperBound);68goog.exportProperty(ydn.db.KeyRange, 'lowerBound', ydn.db.KeyRange.lowerBound);69goog.exportProperty(ydn.db.KeyRange, 'bound', ydn.db.KeyRange.bound);70goog.exportProperty(ydn.db.KeyRange, 'only', ydn.db.KeyRange.only);71goog.exportProperty(ydn.db.KeyRange, 'starts', ydn.db.KeyRange.starts);72goog.exportProperty(ydn.db.events.Event.prototype, 'store_name',73 ydn.db.events.Event.prototype.store_name); // this don't work, why?74goog.exportProperty(ydn.db.events.Event.prototype, 'getStoreName',75 ydn.db.events.Event.prototype.getStoreName);76goog.exportProperty(ydn.db.events.RecordEvent.prototype, 'name',77 ydn.db.events.RecordEvent.prototype.name);78goog.exportProperty(ydn.db.events.RecordEvent.prototype, 'getKey',79 ydn.db.events.RecordEvent.prototype.getKey);80goog.exportProperty(ydn.db.events.RecordEvent.prototype, 'getValue',81 ydn.db.events.RecordEvent.prototype.getValue);82goog.exportProperty(ydn.db.events.StoreEvent.prototype, 'name',83 ydn.db.events.StoreEvent.prototype.name);84goog.exportProperty(ydn.db.events.StoreEvent.prototype, 'getKeys',85 ydn.db.events.StoreEvent.prototype.getKeys);86goog.exportProperty(ydn.db.events.StoreEvent.prototype, 'getValues',...
Using AI Code Generation
1const { launch, type, click, closeBrowser } = require('qawolf');2describe('test', () => {3 let browser;4 beforeAll(async () => {5 });6 afterAll(async () => {7 await closeBrowser(browser);8 });9 it('test', async () => {10 const page = await browser.newPage();11 await type(page, '#root > div > d
Using AI Code Generation
1const { launch } = require("@qawolf/browser");2const { test, expect } = require("@qawolf/jest");3const { db } = require("@qawolf/web");4test("test", async () => {5 const browser = await launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.click("text=Login");9 await page.click("input[name=\"email\"]");10 await page.fill("input[name=\"email\"]", "
Using AI Code Generation
1const { launch } = require('qawolf');2const selectors = require('../selectors/test');3const config = require('../qawolf.config.js');4const { db } = require('qawolf');5describe('test', () => {6 let browser;7 let page;8 beforeAll(async () => {9 page = await browser.newPage();10 });11 afterAll(async () => {12 await browser.close();13 });14 it('test',
Using AI Code Generation
1const { create } = require('qawolf');2const { launch } = require('qawolf');3const { test } = require('qawolf');4const { create } = require('qawolf');5const { launch } = require('qawolf');6const { test } = require('qawolf');7const { create } = require('qawolf');8const { launch } = require('qawolf');9const { test } = require('qawolf');10const { create } = require('qawolf');11const { launch } = require('qawolf');12const { test } = require('qawolf');13const { create } = require('qawolf');14const { launch } = require('qawolf');15const { test } = require('qawolf');16const { create } = require('qawolf');17const { launch } = require('qawolf');18const { test } = require('qawolf');19const { create } = require('qawolf');20const { launch } = require('qawolf');21const { test } = require('qawolf');22const { create } = require('qawolf');23const { launch } = require('qawolf');24const { test } = require('qawolf');25const { create } = require('qawolf');26const { launch } = require('qawolf');27const { test } = require('qawolf');28const { create } = require('qawolf');29const { launch } = require('qawolf');30const { test } = require('qawolf');31const { create } = require('qawolf');32const { launch } = require('qawolf');33const { test } = require('qawolf');34const { create } = require('qawolf');35const { launch }
Using AI Code Generation
1const { db } = require('qawolf');2const { test } = require('qawolf');3describe('test', () => {4 let browser;5 beforeAll(async () => {6 browser = await test.setupBrowser();7 });8 afterAll(async () => {9 await test.teardownBrowser(browser);10 });11 it('test', async () => {12 const context = await browser.newContext();13 const page = await context.newPage();14 await test.step('step 1', async () => {15 await page.click('text=About');16 });17 await test.step('step 2', async () => {18 await page.click('text=Privacy');19 });20 await test.step('step 3', async () => {21 await page.click('text=Terms');22 });23 await test.step('step 4', async () => {24 await page.click('text=Settings');25 });26 await test.step('step 5', async () => {27 await page.click('text=Sign in');28 });29 await test.step('step 6', async () => {30 await page.click('text=Sign up');31 });32 await test.step('step 7', async () => {33 await page.click('text=Advertising');34 });35 await test.step('step 8', async () => {36 await page.click('text=Business');37 });38 await test.step('step 9', async () => {39 await page.click('text=How Search works');40 });41 await test.step('step 10', async () => {42 await page.click('text=Google.com');43 });44 await test.step('step 11', async () => {45 await page.click('text=About');46 });47 await test.step('step 12', async () => {48 await page.click('text=Privacy');49 });50 await test.step('step 13', async () => {51 await page.click('text=Terms');52 });53 await test.step('step 14', async () => {54 await page.click('text=Settings');55 });56 await test.step('step 15', async () => {57 await page.click('text=Sign in');58 });59 await test.step('step 16', async () => {60 await page.click('text=Sign up');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!