Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/couchbaselabs/mobile-travel-sample

Mobile Version of Travel sample App using Couchbase Lite 2.x
https://github.com/couchbaselabs/mobile-travel-sample

Last synced: 1 day ago
JSON representation

Mobile Version of Travel sample App using Couchbase Lite 2.x

Awesome Lists containing this project

README

        

The complete tutorial is available at https://docs.couchbase.com/tutorials/mobile-travel-tutorial/introduction.html. Please follow the tutorial for step-by-step installation instructions.

## Overview
This is a step-by-step tutorial describing a Travel application for mobile platforms that supports the following capabilities

* Users can search and make flight reservations via the Couchbase Lite enabled mobile/desktop applications or through the Python web application.
** Flight reservations made on the Couchbase Lite enabled mobile and desktop apps are available even when the app is disconnected from the server.
* Flight reservations made via any of the client apps will be automatically synced over to the remaining clients through the Sync Gateway
* Users will also be able to do a Full text Search for hotels via Couchbase Lite enabled mobile/desktop applications or through the Python web application

In addition, the Couchbase Lite enabled mobile/desktop applications mobile/desktop apps support the following functionality -

* Users can fetch listing of hotels from the Python web backend via a REST endpoint.
* Users can bookmark (and unbookmark) the hotels
* Bookmarked hotels stored locally and available even when the app is disconnected from the server.

## Installation
== Pre-requisites
*Windows Users* : If you are developing on Windows, use a Windows 10 machine.
Also, note that you should also have *administrative privileges on the Windows box* so you can authorize the installation and running of the required executables.

* Visual C++ 2017 (*only Windows Users*): must install the Microsoft Visual C++ Compiler for Python Downloadable from https://www.microsoft.com/en-us/download/details.aspx?id=44266[here].
* Python 3.4+: downloadable from https://www.python.org/downloads/[python.org]. This should come packaged with pip3
+
*Windows Users* : If you are developing on Windows, make sure that Python is included in your system's PATH environment variable.
You can follow instructions https://www.pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/[here] to set your PATH variable.
* Git: downloadable from https://git-scm.com/book/en/v2/Getting-Started-Installing-Git[git-scm.org].

=== Try it out

* Verify the python installation
** Run the following command from your terminal.
+
[source,bash]
----
bash python --version
----
You should see the version of python displayed.

** Confirm that pip3 is installed. pip is package management software for Python.
+
[source,bash]
----
pip3
----
You should see the command line options.

* Verify git installation
** Run the following command from your terminal.
+
[source,bash]
----
bash git --version
----
You should see the version of git installed.

== Workshop Repo
* Clone the "master" branch of the workshop source from GitHub. We are doing a shallow pull with `depth` as 1 to speed the cloning process.
+
[source,bash]
----
git clone -b master --depth 1 https://github.com/couchbaselabs/mobile-travel-sample.git
----

== Couchbase Server

In this lesson, you will install and launch v7.1.x of Couchbase Server.

Screenshots below apply to Couchbase Server 7.1.1 and there will be some variation with CBS 7.0.x. However, equivalent functionality is available in earlier versions of server. Refer to documentation for compatible server versions.

*Apple M1 Users:* Install and launch v7.1.1 or later

If there is a later version available, you can download it as well bearing in mind that the instructions have been validated with the version that is specified in instructions below.

* https://www.couchbase.com/downloads[Download and install] v7.1.1 of Couchbase Server.
Follow the instructions specified in the appropriate platform specific https://docs.couchbase.com/server/current/install/install-intro.html[install guide] to install the same.
* On the setup wizard, create an Administrator account with the user _Administrator_ and password as __password__.

* As you follow the download instructions and setup wizard, make sure you keep all the services (data, query, and index) selected.

* Install the sample bucket named _travel-sample_ because it contains the data used in this tutorial. You can add the bucket from the "Sample Buckets" tab in the "Settings" menu in the admin console.

* Create an RBAC user named *admin* with password *password* and *Application Access* to the travel-sample bucket. You can do this from the "Security" menu. These credentials will be used by the Sync Gateway to access the documents in this bucket.
* Create a Full text search index on travel-sample bucket called 'hotels'. You can do this from the "Search" menu. Just go with default index settings.

*Try it out*

* Launch Couchbase Server (if not already runnning)
* Log into the "Admin Console" (`http://localhost:8091`) with appropriate Administrator credentials you created during installation
* Select the "Buckets" option from the menu on the left
* Verify that you have around 31,000 documents in your travel-sample bucket

== Sync Gateway

In this section, you will install and launch version 3.0.3 of Sync Gateway.

* Download Sync Gateway 3.0.3 from https://www.couchbase.com/download[here] for your platform.
* The Sync Gateway will have to be launched with the config file named `sync-gateway-config-travelsample.json` that you should have downloaded as per the instructions in the <> section. The config file will be located in `/path/to/mobile-travel-sample`.
* Open the `sync-gateway-config-travelsample-`.json and confirm that the RBAC user credentials configured on the Couchbase Server are used by Sync Gateway for accessing the bucket
+
[source,json]
----
"username": "admin",
"password": "password",
----
* Launch the Sync Gateway.
+
*macOS*
+
[source,bash]
----
$ cd /path/to/couchbase-sync-gateway/bin
$ ./sync_gateway /path/to/mobile-travel-sample/sync-gateway-config-travelsample-.json
----
*Windows*
+
By default, the Sync Gateway service will install with _serviceconfig.json_ as the configuration file at *C:\Program%20Files\Couchbase\Sync%20Gateway\serviceconfig.json*.
+
The Sync Gateway will have to be launched with the config file named `sync-gateway-config-travelsample.json` that you should have downloaded as per the instructions in the <> section.
The config file will be located in ``C:/path/to/mobile-travel-sample``.
+
Open the sync-gateway-config-travelsample.json and confirm that the RBAC user credentials configured on the Couchbase Server are used by Sync Gateway for accessing the bucket.
+
[source,json]
----
"username": "admin",
"password": "password",
----
+
* Stop the Sync Gateway service (since it would be launched with the default version of config file). To stop the service, you can use the Services application (Control Panel --> Admin Tools --> Services).
* Replace the _serviceconfig.json_ file with the `sync-gateway-config-travelsample.json`
+
[source,bash]
----
$ copy c:/path/to/mobile-travel-sample/sync-gateway-config-travelsample.json "C:\Program Files\Couchbase\Sync Gateway\serviceconfig.json"
----
* Start the Sync Gateway service with the new version of _serviceconfig.json_ file. To start the service, you can use the Services application (Control Panel --> Admin Tools --> Services).

*Try it out*

* Access this URL `http://127.0.0.1:4984` in your browser
* Verify that you get JSON response _similar_ to one below `json {"couchdb":"Welcome","vendor":{"name":"Couchbase Sync Gateway","version":"2.7"},"version":"Couchbase Sync Gateway/2.7.0(271;bf3ddf6) EE"}`

== Python Travel Sample Web Backend

=== Clone repository

==== Apple M1 Users:

* Clone the `mobile-travel-sample-m1` branch of Travel Sample Python web app repo
+
[source,bash]
----
git clone -b mobile-travel-sample-m1 https://github.com/couchbaselabs/try-cb-python.git
cd try-cb-python
----

==== Other platforms:

* Clone the `mobile-travel-sample-tutorial` branch of Travel Sample Python web app repo
+
[source,bash]
----
git clone -b mobile-travel-sample-tutorial https://github.com/couchbaselabs/try-cb-python.git
cd try-cb-python
----

=== Install Python

==== Windows Users Only

* Verify the pip installation. +
If you are developing on Windows, *pip.exe* will be found in the "Scripts" sub directory under the Python installation directory.
+
Add the path to the "Scripts" folder to the system's PATH environment variable.
+
You can follow instructions
https://www.pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/[here]
to set your PATH variable.
+
Verify that pip is recognized by typing the following in the cmd terminal.
You should see the help menu.
+
[source,bash]
----
pip3
----

==== Others

* We will run the Travel Web App in a Python
https://virtualenv.pypa.io/en/stable/[virtual environment].
First, check if `virtualenv` is installed on your system.
+
[source,bash]
----
$ virtualenv --version
----

* If `virtualenv` is not installed , you can use `apt-get` or `pip3` to install it.
+
[source,bash]
----
$ sudo pip3 install virtualenv
----

* Specify the folder for your virtual environment.
+
[source,bash]
----
$ virtualenv .
----

* Activate your environment. You should see a prompt as shown below.
+
[source,bash]
----
$ source bin/activate
(try-cb-python) $
----

=== Install dependencies & run app

The application uses several Python libraries that need to be installed, these are listed in *requirements.txt* and can be automatically loaded using the pip3 command.

[source,bash]
----
pip3 install -r requirements.txt
----

* Update *travel.py* to reflect the username and password that you have used when installing Couchbase Server.
This defaults to "Administrator" and "password".
+
[source,python]
----
DEFAULT_USER = "Administrator"
PASSWORD = 'password'
----

* Now launch the Travel Web App
+
[source,bash]
----
$ python travel.py
$ Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
----
+
You may see an alert similar to one below requesting access to run the app.
+
Make sure you select the "Allow access" option.
+

.Try it out
****
. Open http://127.0.0.1:8080/ in your web browser
. Verify that you see the login screen of the Travel Sample Web App similar to the screenshot shown below
****

[#fig-travsample]
.Travel Sample Login Screen