diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/accountListBox.js | 77 | ||||
-rw-r--r-- | src/application.js | 3 | ||||
-rw-r--r-- | src/checkIn.js | 174 | ||||
-rw-r--r-- | src/checkInDialog.js | 277 | ||||
-rw-r--r-- | src/foursquareBackend.js | 118 | ||||
-rw-r--r-- | src/org.gnome.Maps.src.gresource.xml.in | 5 | ||||
-rw-r--r-- | src/serviceBackend.js | 127 |
7 files changed, 0 insertions, 781 deletions
diff --git a/src/accountListBox.js b/src/accountListBox.js deleted file mode 100644 index 8a032f37..00000000 --- a/src/accountListBox.js +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */ -/* vim: set et ts=4 sw=4: */ -/* - * Copyright (c) 2014 Damián Nohales - * - * GNOME Maps is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * GNOME Maps is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>. - * - * Author: Damián Nohales <damiannohales@gmail.com> - */ - -const Gio = imports.gi.Gio; -const Goa = imports.gi.Goa; -const GObject = imports.gi.GObject; -const Gtk = imports.gi.Gtk; - -const Application = imports.application; - -var AccountRow = GObject.registerClass({ - Template: 'resource:///org/gnome/Maps/ui/account-row.ui', - InternalChildren: [ 'providerLabel', - 'identityLabel', - 'providerImage', - 'attentionNeededImage' ], -}, class AccountRow extends Gtk.ListBoxRow { - _init(params) { - this.account = params.account; - delete params.account; - - super._init(params); - - let account = this.account.get_account(); - - this._providerLabel.label = account.provider_name; - this._identityLabel.label = account.presentation_identity; - this._providerImage.gicon = Gio.Icon.new_for_string(account.provider_icon); - this._attentionNeededImage.visible = account.attention_needed; - } -}); - -var AccountListBox = GObject.registerClass({ - Signals: { - 'account-selected': { param_types: [Goa.Object] } - }, -}, class AccountListBox extends Gtk.ListBox { - _init(params) { - params.activate_on_single_click = true; - super._init(params); - - Application.checkInManager.connect('accounts-refreshed', () => this.refresh()); - - this.connect('row-activated', - (list, row) => this.emit('account-selected', row.account)); - - this.refresh(); - } - - refresh() { - let accounts = Application.checkInManager.accounts; - - this.foreach((row) => this.remove(row)); - - accounts.forEach((account) => { - this.insert(new AccountRow({ account: account }), -1); - }); - } -}); diff --git a/src/application.js b/src/application.js index 866bc69a..888fde61 100644 --- a/src/application.js +++ b/src/application.js @@ -29,7 +29,6 @@ const GtkClutter = imports.gi.GtkClutter; const Hdy = imports.gi.Handy; const WebKit2 = imports.gi.WebKit2; -const CheckIn = imports.checkIn; const ContactPlace = imports.contactPlace; const Format = imports.format; const Geoclue = imports.geoclue; @@ -51,7 +50,6 @@ var settings = null; var placeStore = null; var routingDelegator = null; var geoclue = null; -var checkInManager = null; var contactStore = null; var osmEdit = null; var normalStartup = true; @@ -264,7 +262,6 @@ var Application = GObject.registerClass({ routeQuery = new RouteQuery.RouteQuery(); routingDelegator = new RoutingDelegator.RoutingDelegator({ query: routeQuery }); geoclue = new Geoclue.Geoclue(); - checkInManager = new CheckIn.CheckInManager(); contactStore = new Maps.ContactStore(); contactStore.load(); osmEdit = new OSMEdit.OSMEdit(); diff --git a/src/checkIn.js b/src/checkIn.js deleted file mode 100644 index cc2f119c..00000000 --- a/src/checkIn.js +++ /dev/null @@ -1,174 +0,0 @@ -/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */ -/* vim: set et ts=4 sw=4: */ -/* - * Copyright (c) 2014 Damián Nohales - * - * GNOME Maps is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * GNOME Maps is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>. - * - * Author: Damián Nohales <damiannohales@gmail.com> - */ - -const GObject = imports.gi.GObject; -const Goa = imports.gi.Goa; -const Gtk = imports.gi.Gtk; - -const CheckInDialog = imports.checkInDialog; -const FoursquareBackend = imports.foursquareBackend; - -var CheckInManager = GObject.registerClass({ - Signals: { - 'accounts-refreshed': { } - }, - Properties: { - 'hasCheckIn': GObject.ParamSpec.boolean('hasCheckIn', - '', - '', - GObject.ParamFlags.READABLE) - } -}, class CheckInManager extends GObject.Object { - _init() { - super._init(); - - try { - this._goaClient = Goa.Client.new_sync(null); - } catch (e) { - log('Error creating GOA client: %s'.format(e.message)); - } - - this._accounts = []; - this._authorizers = {}; - this._backends = {}; - - this._initBackends(); - - if (this._goaClient) { - this._goaClient.connect('account-added', - this._refreshGoaAccounts.bind(this)); - this._goaClient.connect('account-changed', - this._refreshGoaAccounts.bind(this)); - this._goaClient.connect('account-removed', - this._refreshGoaAccounts.bind(this)); - } - - this._refreshGoaAccounts(); - } - - _initBackends() { - let foursquareBackend = new FoursquareBackend.FoursquareBackend(); - this._backends[foursquareBackend.name] = foursquareBackend; - } - - _refreshGoaAccounts() { - if (!this._goaClient) - return; - let accounts = this._goaClient.get_accounts(); - this._accounts = []; - this._accountsCount = 0; - this._authorizers = {}; - - accounts.forEach((object) => { - if (!object.get_account()) - return; - - if (!object.get_maps()) - return; - - let accountId = object.get_account().id; - this._accounts.push(object); - - this._authorizers[accountId] = this._getBackend(object).createAuthorizer(object); - }); - - this.emit('accounts-refreshed'); - this.notify('hasCheckIn'); - } - - get client() { - return this._goaClient; - } - - get accounts() { - return this._accounts; - } - - get hasCheckIn() { - return this._accounts.length > 0; - } - - _getAuthorizer(account) { - return this._authorizers[account.get_account().id]; - } - - _getBackend(account) { - return this._backends[account.get_account().provider_type]; - } - - performCheckIn(account, checkIn, callback, cancellable) { - this._getBackend(account) - .performCheckIn(this._getAuthorizer(account), checkIn, callback, cancellable); - } - - findPlaces(account, latitude, longitude, distance, callback, cancellable) { - this._getBackend(account) - .findPlaces(this._getAuthorizer(account), latitude, longitude, distance, callback, cancellable); - } - - showCheckInDialog(parentWindow, place, matchPlace) { - let dialog = new CheckInDialog.CheckInDialog({ transient_for: parentWindow, - matchPlace: matchPlace, - place: place }); - let response = dialog.run(); - dialog.destroy(); - - let message = null; - - switch (response) { - case CheckInDialog.Response.FAILURE_NO_PLACES: - if (matchPlace) - /* Translators: %s is the place name that user wanted to check-in */ - message = _("Cannot find “%s” in the social service").format(place.name); - else - message = _("Cannot find a suitable place to check-in in this location"); - break; - case CheckInDialog.Response.FAILURE_GET_PLACES: - if (dialog.error.code === 401) - message = _("Credentials have expired, please open Online Accounts to sign in and enable this account"); - else - message = dialog.error.message; - break; - } - - if (message) { - let messageDialog = new Gtk.MessageDialog({ transient_for: parentWindow, - destroy_with_parent: true, - message_type: Gtk.MessageType.ERROR, - buttons: Gtk.ButtonsType.OK, - modal: true, - text: _("An error has occurred"), - secondary_text: message }); - messageDialog.run(); - messageDialog.destroy(); - } - } -}); - -var CheckIn = class { - _init() { - this.message = null; - this.place = null; - this.privacy = null; - this.broadcastFacebook = false; - this.broadcastTwitter = false; - } -}; diff --git a/src/checkInDialog.js b/src/checkInDialog.js deleted file mode 100644 index 7ace6a7a..00000000 --- a/src/checkInDialog.js +++ /dev/null @@ -1,277 +0,0 @@ -/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */ -/* vim: set et ts=4 sw=4: */ -/* - * Copyright (c) 2014 Damián Nohales - * - * GNOME Maps is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * GNOME Maps is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>. - * - * Author: Damián Nohales <damiannohales@gmail.com> - */ - -const Gio = imports.gi.Gio; -const GObject = imports.gi.GObject; -const Gtk = imports.gi.Gtk; -const Mainloop = imports.mainloop; - -const AccountListBox = imports.accountListBox; -const Application = imports.application; -const CheckIn = imports.checkIn; -const SocialPlaceListBox = imports.socialPlaceListBox; -const SocialPlaceMatcher = imports.socialPlaceMatcher; - -var Response = { - SUCCESS: 0, - CANCELLED: 1, - FAILURE_NO_PLACES: 2, - FAILURE_GET_PLACES: 3, - FAILURE_ACCOUNT_DISABLED: 4, - FAILURE_CHECKIN_DISABLED: 5 -}; - -var CheckInDialog = GObject.registerClass({ - Template: 'resource:///org/gnome/Maps/ui/check-in-dialog.ui', - InternalChildren: [ 'cancelButton', - 'okButton', - 'stack', - 'accountFrame', - 'placeScrolledWindow', - 'placeNotFoundInfoBar', - 'placeNotFoundLabel', - 'messageInfoLabel', - 'messageInfoAccountImage', - 'messageTextView', - 'foursquareOptionsGrid', - 'foursquareOptionsPrivacyComboBox', - 'foursquareOptionsBroadcastFacebookCheckButton', - 'foursquareOptionsBroadcastTwitterCheckButton' ], -}, class CheckInDialog extends Gtk.Dialog { - _init(params) { - this._place = params.place; - delete params.place; - - this._matchPlace = params.matchPlace; - delete params.matchPlace; - - // This is a construct-only property and cannot be set by GtkBuilder - params.use_header_bar = true; - - super._init(params); - - this._account = null; - this._checkIn = new CheckIn.CheckIn(); - this.error = null; - - this._cancellable = new Gio.Cancellable(); - this._cancellable.connect(() => this.response(Response.CANCELLED)); - - this.connect('delete-event', () => this._cancellable.cancel()); - - Application.checkInManager.connect('accounts-refreshed', - () => this._onAccountRefreshed()); - - this._initHeaderBar(); - this._initWidgets(); - } - - _initHeaderBar() { - this._cancelButton.connect('clicked', - () => this._cancellable.cancel()); - - this._okButton.connect('clicked', () => this._startCheckInStep()); - } - - _initWidgets() { - // Limitations in Gjs means we can't do this in UI files yet - this._accountListBox = new AccountListBox.AccountListBox({ visible: true }); - this._accountFrame.add(this._accountListBox); - - this._placeListBox = new SocialPlaceListBox.SocialPlaceListBox({ visible: true }); - this._placeScrolledWindow.add(this._placeListBox); - - Application.settings.bind('checkin-foursquare-privacy', - this._foursquareOptionsPrivacyComboBox, - 'active_id', Gio.SettingsBindFlags.DEFAULT); - - Application.settings.bind('checkin-foursquare-broadcast-facebook', - this._foursquareOptionsBroadcastFacebookCheckButton, - 'active', Gio.SettingsBindFlags.DEFAULT); - - Application.settings.bind('checkin-foursquare-broadcast-twitter', - this._foursquareOptionsBroadcastTwitterCheckButton, - 'active', Gio.SettingsBindFlags.DEFAULT); - - this._accountListBox.connect('account-selected', (list, account) => { - this._account = account; - this._startPlaceStep(); - }); - - this._placeListBox.connect('place-selected', (list, place) => { - this._checkIn.place = place; - this._startMessageStep(); - }); - } - - vfunc_show() { - this._startup(); - super.vfunc_show(); - } - - _startup() { - let accounts = Application.checkInManager.accounts; - - if (accounts.length > 1) - this._startAccountStep(); - else if (accounts.length === 1) { - this._account = Application.checkInManager.accounts[0]; - this._startPlaceStep(); - } else { - Mainloop.idle_add(() => { - this.response(Response.FAILURE_CHECKIN_DISABLED); - }); - } - } - - _onAccountRefreshed() { - let accounts = Application.checkInManager.accounts; - - if (!Application.checkInManager.hasCheckIn) - this.response(Response.FAILURE_CHECKIN_DISABLED); - else if (this._account) { - for (let account of accounts) { - if (this._account.get_account().id === account.get_account().id) - return; - } - - this.response(Response.FAILURE_ACCOUNT_DISABLED); - } - } - - _startAccountStep() { - this.set_title(_("Select an account")); - this._stack.set_visible_child_name('account'); - } - - _startPlaceStep() { - this.set_title(_("Loading")); - this._stack.set_visible_child_name('loading'); - - Application.checkInManager.findPlaces(this._account, - this._place.location.latitude, - this._place.location.longitude, - 100, - this._onFindPlacesFinished.bind(this), - this._cancellable); - } - - _onFindPlacesFinished(account, places, error) { - if (!error) { - if (places.length === 0) { - this.response(Response.FAILURE_NO_PLACES); - return; - } - - let matches = SocialPlaceMatcher.match(this._place, places); - - if (matches.exactMatches.length === 1 && this._matchPlace) { - this._checkIn.place = matches.exactMatches[0]; - this._startMessageStep(); - } else { - this.set_title(_("Select a place")); - this._placeListBox.matches = matches; - - if (this._matchPlace) { - if (this._account.get_account().provider_type === 'foursquare') - this._placeNotFoundLabel.label = _("Maps cannot find the place to check in to with Foursquare. Please select one from this list."); - } else - this._placeNotFoundInfoBar.hide(); - - this._stack.set_visible_child_name('place'); - } - } else { - this.error = error; - this.response(Response.FAILURE_GET_PLACES); - } - } - - _startMessageStep() { - /* Translators: %s is the name of the place to check in. - */ - this.set_title(_("Check in to %s").format(this._checkIn.place.name)); - this._stack.set_visible_child_name('message'); - - this._messageTextView.grab_focus(); - this._okButton.show(); - - let account = this._account.get_account(); - - /* Translators: %s is the name of the place to check in. - */ - let labelMessageInfo = _("Write an optional message to check in to %s."); - this._messageInfoLabel.label = labelMessageInfo.format('<a href="%s">%s</a>'.format(this._checkIn.place.link, - this._checkIn.place.name)); - this._messageInfoAccountImage.gicon = Gio.Icon.new_for_string(account.provider_icon); - - let optionsGrids = { 'foursquare': this._foursquareOptionsGrid }; - - for (let provider in optionsGrids) - if (provider === account.provider_type) - optionsGrids[provider].show(); - else - optionsGrids[provider].hide(); - } - - _startCheckInStep() { - this.set_title(_("Loading")); - this._stack.set_visible_child_name('loading'); - - this._okButton.hide(); - - let message = this._messageTextView.buffer.text; - let privacy; - - if (this._account.get_account().provider_type === 'foursquare') - privacy = this._foursquareOptionsPrivacyComboBox.active_id; - - let broadcastFacebook = this._foursquareOptionsBroadcastFacebookCheckButton.active; - let broadcastTwitter = this._foursquareOptionsBroadcastTwitterCheckButton.active; - - this._checkIn.message = message; - this._checkIn.privacy = privacy; - this._checkIn.broadcastFacebook = broadcastFacebook; - this._checkIn.broadcastTwitter = broadcastTwitter; - - Application.checkInManager.performCheckIn(this._account, - this._checkIn, - this._onPerformCheckInFinished.bind(this), - this._cancellable); - } - - _onPerformCheckInFinished(account, data, error) { - if (!error) - this.response(Response.SUCCESS); - else { - let messageDialog = new Gtk.MessageDialog({ transient_for: this, - destroy_with_parent: true, - message_type: Gtk.MessageType.ERROR, - buttons: Gtk.ButtonsType.OK, - modal: true, - text: _("An error has occurred"), - secondary_text: error.message }); - messageDialog.run(); - messageDialog.destroy(); - - this._startMessageStep(); - } - } -}); diff --git a/src/foursquareBackend.js b/src/foursquareBackend.js deleted file mode 100644 index 164ddfb6..00000000 --- a/src/foursquareBackend.js +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */ -/* vim: set et ts=4 sw=4: */ -/* - * Copyright (c) 2014 Damián Nohales - * - * GNOME Maps is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * GNOME Maps is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>. - * - * Author: Damián Nohales <damiannohales@gmail.com> - */ - -const GObject = imports.gi.GObject; - -const FoursquareGoaAuthorizer = imports.foursquareGoaAuthorizer; -const ServiceBackend = imports.serviceBackend; -const SocialPlace = imports.socialPlace; - -const _PLACE_LINK_FORMAT = 'https://foursquare.com/v/foursquare-hq/%s'; - -var FoursquareBackend = GObject.registerClass( -class SocialServiceFoursquareBackend extends ServiceBackend.ServiceBackend { - - get name() { - return 'foursquare'; - } - - createRestCall(authorizer) { - return FoursquareGoaAuthorizer.newRestCall(authorizer); - } - - refreshAuthorization(authorizer, cancellable) { - return authorizer.refreshAuthorization(cancellable); - } - - getAuthorizerAccount(authorizer) { - return authorizer.goaObject; - } - - createAuthorizer(account) { - return new FoursquareGoaAuthorizer.FoursquareGoaAuthorizer({ goaObject: account }); - } - - isTokenInvalid(restCall, data) { - return data.meta.code === 401 || data.meta.code === 403; - } - - isInvalidCall(restCall, data) { - return !data || data.meta.code !== 200; - } - - getCallResultCode(restCall, data) { - return data ? data.meta.code : restCall.get_status_code(); - } - - getCallResultMessage(restCall, data) { - return data ? data.meta.errorDetail : restCall.get_status_message(); - } - - _realPerformCheckIn(authorizer, checkIn, callback, cancellable) { - let broadcast = checkIn.privacy; - - if (checkIn.broadcastFacebook) - broadcast += ',facebook'; - - if (checkIn.broadcastTwitter) - broadcast += ',twitter'; - - this.callAsync(authorizer, - 'POST', - 'checkins/add', - { - 'shout': checkIn.message, - 'venueId': checkIn.place.id, - 'broadcast': broadcast - }, - callback, - cancellable); - } - - _realFindPlaces(authorizer, latitude, longitude, distance, callback, cancellable) { - this.callAsync(authorizer, - 'GET', - 'venues/search', - { - 'll': latitude + ',' + longitude, - 'radius': distance, - 'intent': 'checkin' - }, - callback, - cancellable); - } - - createPlaces(rawData) { - return rawData.response.venues.map(function(place) { - let link = _PLACE_LINK_FORMAT.format(place.id); - - return new SocialPlace.SocialPlace({ id: place.id, - name: place.name, - latitude: place.location.lat, - longitude: place.location.lng, - category: place.categories.length > 0 ? - place.categories[0].name : - null, - link: link, - originalData: place }); - }); - } -}); diff --git a/src/org.gnome.Maps.src.gresource.xml.in b/src/org.gnome.Maps.src.gresource.xml.in index da8266e7..fd6e9bc4 100644 --- a/src/org.gnome.Maps.src.gresource.xml.in +++ b/src/org.gnome.Maps.src.gresource.xml.in @@ -1,12 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/org/gnome/Maps@suffix@/js"> - <file>accountListBox.js</file> <file>address.js</file> <file>application.js</file> <file>boundingBox.js</file> - <file>checkIn.js</file> - <file>checkInDialog.js</file> <file>color.js</file> <file>contactPlace.js</file> <file>contextMenu.js</file> @@ -14,7 +11,6 @@ <file>epaf.js</file> <file>exportViewDialog.js</file> <file>favoritesPopover.js</file> - <file>foursquareBackend.js</file> <file>foursquareGoaAuthorizer.js</file> <file>geoclue.js</file> <file>geocode.js</file> @@ -76,7 +72,6 @@ <file>routeQuery.js</file> <file>routingDelegator.js</file> <file>searchPopover.js</file> - <file>serviceBackend.js</file> <file>settings.js</file> <file>sendToDialog.js</file> <file>service.js</file> diff --git a/src/serviceBackend.js b/src/serviceBackend.js deleted file mode 100644 index edcfdebe..00000000 --- a/src/serviceBackend.js +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */ -/* vim: set et ts=4 sw=4: */ -/* - * Copyright (c) 2014 Damián Nohales - * - * GNOME Maps is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * GNOME Maps is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>. - * - * Author: Damián Nohales <damiannohales@gmail.com> - */ - -const GObject = imports.gi.GObject; - -const Utils = imports.utils; - -var ServiceBackend = GObject.registerClass({ - Abstract: true -}, class ServiceBackend extends GObject.Object { - - //Abstract - get name() { } - - //Abstract - createRestCall(authorizer) { } - - //Abstract - refreshAuthorization(authorizer, cancellable) { } - - //Abstract - getAuthorizerAccount(authorizer) { } - - //Abstract - createAuthorizer(account) { } - - //Abstract - isTokenInvalid(restCall, parsedPayload) { } - - //Abstract - isInvalidCall(restCall, parsedPayload) { } - - //Abstract - getCallResultCode(restCall, parsedPayload) { } - - //Abstract - getCallResultMessage(restCall, parsedPayload) { } - - callAsync(authorizer, method, func, params, callback, cancellable, mustRefreshToken) { - mustRefreshToken = mustRefreshToken || true; - cancellable = cancellable || null; - - let restCall = this.createRestCall(authorizer); - - method = method.toUpperCase(); - restCall.set_method(method); - - for (let key in params) - restCall.add_param(key, params[key].toString()); - - restCall.set_function(func); - - Utils.debug(this.name + ': ' + func); - - restCall.invoke_async(cancellable, (call, result) => { - let data = JSON.parse(call.get_payload()); - let account = this.getAuthorizerAccount(authorizer); - - if (data && this.isTokenInvalid(call, data)) - if (mustRefreshToken) { - //Unauthorized token error, we need to refresh the token - Utils.debug(this.name + ': The token is not authorized, refreshing token'); - try { - this.refreshAuthorization(authorizer, cancellable); - this.callAsync(authorizer, method, func, params, callback, cancellable, false); - } catch(error) { - callback(account, data, { code: 401, - message: null }); - } - } else - callback(account, data, { code: 401, - message: null }); - else if (this.isInvalidCall(call, data)) - callback(account, data, { code: this.getCallResultCode(call, data), - message: this.getCallResultMessage(call, data) }); - else - callback(account, data, null); - }); - } - - performCheckIn(authorizer, checkIn, callback, cancellable) { - callback = callback || function() {}; - this._realPerformCheckIn(authorizer, checkIn, callback, cancellable); - } - - //Abstract - _realPerformCheckIn(authorizer, checkIn, callback, cancellable) { } - - findPlaces(authorizer, latitude, longitude, distance, callback, cancellable) { - callback = callback || function() {}; - this._realFindPlaces(authorizer, - latitude, - longitude, - distance, - (account, data, error) => { - if (!error) - callback(account, this.createPlaces(data), error); - else - callback(account, [], error); - }, - cancellable); - } - - //Abstract - _realFindPlaces(authorizer, latitude, longitude, distance, callback, cancellable) { } - - //Abstract - createPlaces(rawData) { } -}); |