4913e15 by Anon Ray at 2014-02-19 1
swtstore (Sweet Store)
2
======================
3
4
----
5
6
7
Introduction
8
------------
9
10
This is the sweet store application.
11
The store for the decentralized, semantic, social web tweets a.k.a SWeeTs!
12
f867edb by Anon Ray at 2014-04-10 13
This README is about installing, configuring and running/deploying this
14
application. If you want to know more about SWeeTs, please go to
15
[wiki.janastu.org/Sweet_Web](http://janastu.org/technoscience/index.php/Sweet_Web) and
16
[trac.pantoto.org/sweet-web](http://trac.pantoto.org/sweet-web).
17
4913e15 by Anon Ray at 2014-02-19 18
This application acts as the repository store for all the SWeeTs that are
f867edb by Anon Ray at 2014-04-10 19
generated from the clients registered with the sweet store. It provides
4913e15 by Anon Ray at 2014-02-19 20
query APIs to query the SWeeTs.
21
f867edb by Anon Ray at 2014-04-10 22
It also provides user management to manage the users of the swtstore.
23
24
All the APIs of the swtstore are accessed by using an access token which is
25
generated by the swtstore when an user authorizes a third-party application
26
through OAuth.
27
4913e15 by Anon Ray at 2014-02-19 28
Sweet store provides the following APIs:
29
30
    - [GET] /api/sweets/<id>: Get a specific SWeeT by its id.
31
f867edb by Anon Ray at 2014-04-10 32
    - [GET] /api/sweets/q?who=<username>&what=<contextname>&where=<URL> :
33
      This API is for querying sweet based on the who, what and where
34
      parameters.
42f8d28 by Arvind Khadri at 2014-05-30 35
      This API does not support querying based on parameters mentioned in how,
f867edb by Anon Ray at 2014-04-10 36
      but will be supported in future. Right now, the client can get sweets
37
      based on the above mentioned three parameters, and as the 'how' part is
38
      a JSON, it is trivial to do further filtering based on parameters of
39
      'how' by the client.
40
4913e15 by Anon Ray at 2014-02-19 41
    - [POST] /api/sweets : Post a SWeeT to this swtstore with the data in the
f867edb by Anon Ray at 2014-04-10 42
    body of the request. The data or payload is a list of sweets. Even if you
43
    are sending one sweet, make sure that the sweet is in a list.
4913e15 by Anon Ray at 2014-02-19 44
f867edb by Anon Ray at 2014-04-10 45
    - [GET] /api/users/me : Get a JSON details of the current user logged in.
4913e15 by Anon Ray at 2014-02-19 46
47
f867edb by Anon Ray at 2014-04-10 48
Any third-party client side application can communicate with the swtstore
49
using these APIs, provided they have a valid access token.
4913e15 by Anon Ray at 2014-02-19 50
51
be3a20c by Anon Ray at 2014-05-29 52
Pre-requisites
53
--------------
4913e15 by Anon Ray at 2014-02-19 54
55
The swtstore application is written in Python and uses a relational database.
56
bba7e81 by Anon Ray at 2014-05-30 57
Hence, the dependencies of this application are:
4913e15 by Anon Ray at 2014-02-19 58
bba7e81 by Anon Ray at 2014-05-30 59
  * Python 2.7. See [here](https://www.python.org/about/gettingstarted/)
60
    for more details on installing Python.
4913e15 by Anon Ray at 2014-02-19 61
bba7e81 by Anon Ray at 2014-05-30 62
  * any relational database supported by SQLAlchemy. Most common RDBMS
63
    supported by SQLAlchemy are MySQL, Postgresql.
4913e15 by Anon Ray at 2014-02-19 64
bba7e81 by Anon Ray at 2014-05-30 65
    For more information on supported databases see
66
    [here](http://docs.sqlalchemy.org/en/rel_0_9/dialects/index.html).
67
68
    _Installing and setting up a database like MySQL or Postgresql is out of scope
69
    of this document. Please search the Internet to get help about installing and
70
    setting up a RDBMS._
71
72
  * Also, make sure you have [pip](https://pip.pypa.io/en/latest/) installed, as
73
    swtstore depends of few external python packages.
74
    See [here](https://pip.pypa.io/en/latest/) to get more details.
be3a20c by Anon Ray at 2014-05-29 75
76
**NOTE: Make sure you have the pre-requisites installed before following the
77
installation steps.**
78
79
80
Installing
81
----------
4913e15 by Anon Ray at 2014-02-19 82
bba7e81 by Anon Ray at 2014-05-30 83
* Clone the repository from <https://git.pantoto.org/sweet-web/sweet-web-engine>
4913e15 by Anon Ray at 2014-02-19 84
cffc26d by Anon Ray at 2014-06-10 85
  > `` $ git clone https://git.pantoto.org/sweet-web/sweet-web-engine.git ``
be3a20c by Anon Ray at 2014-05-29 86
87
* It is recommended to do the installation inside a python virtual
88
  environment.
89
  For deploying on a server, it depends on how you have setup your server
90
  environment.
f867edb by Anon Ray at 2014-04-10 91
  If you think, you know what you are doing and don't need the virtual
be3a20c by Anon Ray at 2014-05-29 92
  environment, you can skip to the next step.
93
f867edb by Anon Ray at 2014-04-10 94
  Initialize a python virtual environment using `virtualenv` in the same directory
95
  where you cloned the repository in the above step. Now, activate the
96
  environment
97
98
  > ``$ source <path/to/your/current-virtual-env>/bin/activate ``
4913e15 by Anon Ray at 2014-02-19 99
f867edb by Anon Ray at 2014-04-10 100
  See [http://www.virtualenv.org/en/latest/virtualenv.html](http://www.virtualenv.org/en/latest/virtualenv.html) for more details about `virtualenv`.
4913e15 by Anon Ray at 2014-02-19 101
102
* Run the setup.py script to install  `` python setup.py install ``
103
be3a20c by Anon Ray at 2014-05-29 104
105
You're done with the installation step.
106
107
Now you need to configure swtstore to run it correctly.
4913e15 by Anon Ray at 2014-02-19 108
109
110
Configure swtstore
111
------------------
112
be3a20c by Anon Ray at 2014-05-29 113
* Make sure you have configured the user management module with correct values.
114
4913e15 by Anon Ray at 2014-02-19 115
* Copy the contents of ``sample_config.py`` inside the ``swtstore`` directory
116
  into ``config.py`` inside ``swtstore`` directory itself.
117
be3a20c by Anon Ray at 2014-05-29 118
  Assuming you are using a \*-nix based system, and you are in the root directory
4913e15 by Anon Ray at 2014-02-19 119
  of the codebase,
120
bba7e81 by Anon Ray at 2014-05-30 121
  > `` $ cp swtstore/sample_config.py swtstore/config.py``
4913e15 by Anon Ray at 2014-02-19 122
0e0c240 by Arvind Khadri at 2014-05-31 123
* Install the required driver for using database mentioned in the
3a8424a by Arvind Khadri at 2014-06-02 124
  SQLALCHEMY_DATABASE_URI. Install psycopg2 if you have chosen postgresql as
0e0c240 by Arvind Khadri at 2014-05-31 125
  the database to use.
126
127
  > `` $ pip install psycopg2 ``
128
129
  Install oursql if you have chosen mysql as the database to use.
130
131
  > `` $ pip install oursql``
132
133
  You would also have to install dependecies, for using mysql:
134
  - python-dev
135
  - libmysqlclient-dev
136
  Install these dependencies from the package manager of your distribution.
137
4913e15 by Anon Ray at 2014-02-19 138
* Edit the config.py file, and change the values accordingly.
139
f867edb by Anon Ray at 2014-04-10 140
* Now, you have to setup the database for the swtstore application. But
141
  fortunately, the creation of database and tables have also been scripted, so
142
  all you need to do is run the ``dbsetup.py`` script.
bba7e81 by Anon Ray at 2014-05-30 143
144
  > `` $ python dbsetup.py ``
f867edb by Anon Ray at 2014-04-10 145
146
**NOTE:** Please remember that all these configuration step is necessary and is
42f8d28 by Arvind Khadri at 2014-05-30 147
required whether you are running the application locally or deploying it on a
f867edb by Anon Ray at 2014-04-10 148
server.
149
4913e15 by Anon Ray at 2014-02-19 150
151
152
Running the server locally
153
--------------------------
154
155
Run the runserver.py script to run the server locally,
156
f867edb by Anon Ray at 2014-04-10 157
> `` $ python runserver.py ``
4913e15 by Anon Ray at 2014-02-19 158
f867edb by Anon Ray at 2014-04-10 159
This runs the application locally, on port 5001. So you can direct your browser
160
to http://localhost:5001
4913e15 by Anon Ray at 2014-02-19 161
162
163
164
Deploying the application
165
-------------------------
166
f867edb by Anon Ray at 2014-04-10 167
SwtStore is deployed as a WSGI application server.
168
169
The wsgi script to deploy the application is provided (its called
170
`swtstore.wsgi`).
171
Point your webserver like Apache, or Nginx to point to the `swtstore.wsgi`
4913e15 by Anon Ray at 2014-02-19 172
script.
173
174
See Apache WSGI configuration here:
f867edb by Anon Ray at 2014-04-10 175
[http://modwsgi.readthedocs.org/en/latest/configuration-directives/WSGIScriptAlias.html](http://modwsgi.readthedocs.org/en/latest/configuration-directives/WSGIScriptAlias.html)
176
42f8d28 by Arvind Khadri at 2014-05-30 177
See Nginx WSGI configuration here:
178
[http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html](http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html)
4913e15 by Anon Ray at 2014-02-19 179
180
181
Help / Feedback
182
---------------
183
184
If you need any help, or have any questions, comments or feedback, you can contact at
f867edb by Anon Ray at 2014-04-10 185
rayanon or arvind or bhanu at servelots.com
4913e15 by Anon Ray at 2014-02-19 186
187
You can also join channel #servelots on freenode network, using your favourite
188
IRC client. We usually hang out at #servelots.
189
190
191
License
192
-------
193
194
BSD Licensed.
195
196
See LICENSE for more details.
f867edb by Anon Ray at 2014-04-10 197
42f8d28 by Arvind Khadri at 2014-05-30 198
199
Known Issues
200
------------
201
202
* Infinite loop in Persona sign-in flow. When the backend API /users/login fail
203
  to connect to the Mozilla Persona APIs (connection timed out etc.) - the
204
  /users/login returns a 500, and then the Persona Javascript SDK calls the
205
  logout API /users/logout and then it calls the login API again; as a result
206
  the entire sign-in flow falls in a infinite loop.
207
208
* Automatic log out from Persona. Persona forces a user to login, again, when he
209
  opens SWeeT store while being logged into Persona, through a different
210
  site. Persona requires the user, every time, to explicilty say that he is
211
  agreeing to share the email adress with a site that is using Persona API.