Giter Site home page Giter Site logo

w3's Introduction

What Where When

http://w3.surla.mobi

REST APIs

Posting messages

To post new messages to the system, use this endpoint:

POST /api/v1/messages?apiKey={apiKey}

The endpoint requires authentication and authorization in one of two forms:

  • the browser user had been authenticated using one of the authentication methods (e.g. Twitter) and the cookie based session attests that. In addition, currently the system enforces that the authenticated user is in the whitelist specified as a comma separated list of screen names in the W3_BETA_USERS environment variable.
  • the call explicitly specifies the apiKey query parameter. Currently the system allows for a single apiKey to specified as W3_API_KEY environment variable.

Request body

The content type of the HTTP request must contain the message to be posted as text/plain content type. The maximum length of the request is 140 bytes. The reqeust:

  • must specify at least one location using the $(long,lat[:| <description>]) notation
  • must specify at least one moment in time using the ^(<ISO time>) notation
  • may specify any number of tags using the #<tagName> notation
  • may specify any number of people references using the @<person> notation

For example, this is a valid request body:

Test message $(24,-120: My favorite fishing spot) $(21,20: My second best) ^(2013-06-19) ^(2013-06-20) 
#fishing /cc @theworld @tjanczuk

Request processing

The service validates and normalizes the request by generating a a the cross-product of all locations and times specified in the message. Each entry in that cross-product is specific to a single location and single moment in time. The resulting array of entries is inserted into the Mongo databse. In case of the sample request above, four entries would be generated.

Response

The endpoint returns HTTP 400 status code when the submitted data is invalid. The body of the response contains details of the error.

The endpoint returns HTTP 500 status code when inserting to the database fails. The body of the response contains details of the error.

The endpoint returns HTTP 201 status code when the message was successfuly persisted in the database. The body of the HTTP response contains application/json representation of the normalized array of entries inserted into the database. For example, given the following request:

Test message $(24,-120: My favorite fishing spot) ^(2013-06-19) ^(2013-06-20) 
#fishing /cc @theworld @tjanczuk

the response should look as follows:

[
  {
    "created": 1371701758573,
    "text": "Test message $(-120,24: My favorite fishing spot) ^(2013-06-19) ^(2013-06-20) #fishing /cc @theworld @tjanczuk",
    "tags": [
      "fishing"
    ],
    "people": [
      "theworld",
      "tjanczuk"
    ],
    "location": {
      "type": "Point",
      "coordinates": [
        -120,
        24
      ]
    },
    "location_name": "My favorite fishing spot",
    "time": {
      "type": "Moment",
      "time": [
        1371600000000
      ]
    },
    "version": "0.0.1",
    "id": "51c28200e345dc7f22000012"
  },
  {
    "created": 1371701758573,
    "text": "Test message $(-120,24: My favorite fishing spot) ^(2013-06-19) ^(2013-06-20) #fishing /cc @theworld @tjanczuk",
    "tags": [
      "fishing"
    ],
    "people": [
      "theworld",
      "tjanczuk"
    ],
    "location": {
      "type": "Point",
      "coordinates": [
        -120,
        24
      ]
    },
    "location_name": "My favorite fishing spot",
    "time": {
      "type": "Moment",
      "time": [
        1371686400000
      ]
    },
    "version": "0.0.1",
    "id": "51c28200e345dc7f22000013"
  }
]      

Querying messages

To query messages, use this endpoint:

POST /api/v1/query?apiKey={apiKey}

Currently the endpoint requires authentication using the same mechanism as the POST /api/v1/message endpoint. Long term the endpoint will be unauthenticated.

Request body

Request body must be application\json and specify the query in the following format:

{
    geometry: {
        type: 'Polygon',
        coordinates: [[[-122,49], [-120,49], [-120,47], [-122,47], [-122,49]]]
    },
    time: {
        type: 'Period',
        time: [ 1371611873300, 1371611900000 ]
    }
}

The geometry property must be a geoJSON object of type Polygon. The coordinates must be closed, i.e. the last point must be the same as the first.

The time property is a JSON object with two properties: type and time. The type at present must be equal to Period. This is to allow future extensibility of specifying time using other concepts (e.g. recurrence). The time property must currently be an array of two integers: time from and time to, specified as number of milliseconds since 1 January 1970 UTC (i.e. Date.now() in JavaScript). The second integer may be Infinite to indicate unbounded upper limit.

Processing

The service will match all messages which location falls within the defined polygon and time range.

Response

The endpoint returns HTTP 400 status code when the submitted query is invalid. The body of the response contains details of the error. This includes a case when the number of matching messages exceeds the limit set on the server using the W3_MAX_QUERY_LIMIT environment variable (set based on WAWS app settings), or 200 by default. In the case of exceeded limit the response body will be Number of query results exceeded the limit..

The endpoint returns HTTP 500 status code when querying the database fails. The body of the response contains details of the error.

The endpoint returns HTTP 200 status code when the query was successful. The body of the HTTP response in that case contains application/json representation of the array representing query results. For example, given the following request:

{
    "geometry": {
        "type": "Polygon",
        "coordinates": [[[-122,49], [-118,49], [-118,51], [-122,51], [-122,49]]]
    },
    "time": {
        "type": "Period",
        "time": [ 1371500000000, 1403222500000 ]
    }
}

The result (depending on the content of the databse) may look like this:

[
  {
    "created": 1371702899272,
    "text": "Test message $(-120,50: My favorite fishing spot) $(20,20: My second best) ^(2013-06-19) ^(2014-06-20) #fishing /cc @theworld @tjanczuk",
    "tags": [
      "fishing"
    ],
    "people": [
      "theworld",
      "tjanczuk"
    ],
    "location": {
      "type": "Point",
      "coordinates": [
        -120,
        50
      ]
    },
    "location_name": "My favorite fishing spot",
    "time": {
      "type": "Moment",
      "time": [
        1371600000000
      ]
    },
    "version": "0.0.1",
    "id": "51c28674de8c929441000003"
  },
  {
    "created": 1371702899272,
    "text": "Test message $(-120,50: My favorite fishing spot) $(20,20: My second best) ^(2013-06-19) ^(2014-06-20) #fishing /cc @theworld @tjanczuk",
    "tags": [
      "fishing"
    ],
    "people": [
      "theworld",
      "tjanczuk"
    ],
    "location": {
      "type": "Point",
      "coordinates": [
        -120,
        50
      ]
    },
    "location_name": "My favorite fishing spot",
    "time": {
      "type": "Moment",
      "time": [
        1403222400000
      ]
    },
    "version": "0.0.1",
    "id": "51c28674de8c929441000004"
  }
]

Tips and tricks

Run the server at localhost:3000 during development (MacOS):

sudo W3_MONGO_URL=mongodb://w3:[email protected]:10033/w3 ./rundev

Connect to the Mongo DB from command line (requires MongoDB client):

mongo dharma.mongohq.com:10033/w3 -u w3 -p cdd66d02385c4ed19177d1d4247735b8

Post a message from the message1.txt file to the system listening on http://localhost:3000 from command line:

curl http://localhost:3000/api/v1/messages?apiKey=gow3go --data-binary @message1.txt

The same to the production system:

curl http://w3.surla.mobi/api/v1/messages?apiKey=gow3go --data-binary @message1.txt

To issue a query in query1.json file to the system listening on http://localhost:3000 from command line:

curl http://localhost:3000/api/v1/query?apiKey=gow3go --header "Content-Type: application/json" --data-binary @query1.json

The same query issued to production system:

curl http://w3.surla.mobi/api/v1/query?apiKey=gow3go --header "Content-Type: application/json" --data-binary @query1.json

To execute the database setup script which sets up appropriate indexes (from root of project):

mongo dharma.mongohq.com:10033/w3 -u w3 -p cdd66d02385c4ed19177d1d4247735b8 ./tools/setup_db.js 

w3's People

Contributors

tjanczuk avatar

Watchers

James Cloos avatar Claudio Caldato avatar  avatar

w3's Issues

idea: social features

Some ideas:

  • voting events up or down
  • commenting on events
  • "re-twitting" the events
  • sharing via twitter or facebook

Keep query count for messages

Every message should have a counter that is increased every time the messages is returned as part of a user query.

First cut

  • authentication with Twitter
  • clustering of markers
  • better info box
  • pre-load data
  • opacity of markers - time representation
  • 5 star ranking

latitude/longitude are in the wrong order in the REST response

Maybe it is the Google's map convention but usually coordinates are in Latitude-Longitude order
In the README, the REST call samples seems to be in the opposite order: longitude-latitude.

"location": {
"type": "Point",
"coordinates": [
-122.043556008789,
47.6222513047473
]
}

Not a big deal, just make sure we are consistent.

Feedback widget

For Alpha/Beta should we have a UI widget to allow users to submit quick feedback about the app?

idea: link shortener

Links in messages should be shortened using our own redirection service. This will give us more data to mine as we will understand what people click on.

idea: layers

Layers can be a first class concept, or a lightweight concept where layers are created "on the fly" using tags in messages across the viewport.

cluster map markers

In event-dense areas we should have a way to aggregate icons on the map, a la redfin.

upper left corner: Google Street view mode

There is a small bar in the upper left corner that allow users to switch to street view.
If the user clicks on that there is no way to go back to the W3 app, clicking on the browser's back button take the user back to the twitter login page.

Maybe we should disable Street view for now

beta people

T Tomek's brother, @andrzejjanczuk, [email protected]
T Glenn, @gblock, [email protected]
T Omri, @Omrig, [email protected]
C VJ
T Alex Dej, @alexdej, [email protected]
C JC
C Andrew Clinick
T Jan Alexander, @janalexcz, [email protected]
T Elad Bin-Israel, @emeshbi, [email protected]
C Ari Bixhorn
T Shawn Burke, @funcshawnal, [email protected]
C Peter Galli
C Tom Hughes-Croucher
T Miika, @mantyvaara, [email protected]
C Eugenio Pace @Eugenio_pace [email protected]
T Andrew Miadowicz
C Tal Saraf @tsaraf, [email protected]
T Erich Pleny, @erichpleny, [email protected]
C Trent Swanson
T Oliver Sharp, @ojsharp, [email protected]
T Mikolaj Sibila, [email protected], no twitter account yet
T Adam Tepper
T Michal Zawirski, @mzawirski, [email protected]

how do we go viral

I had that nagging feeling we were missing something important in w3: what are the mechanisms that would support its going viral?

I think we need to consider the Twitter-like concepts of retweeting and following and how they apply to w3.

Unlike on Twitter where you can only follow people, we have additional options of following locations. For example: "I want to follow everything related to 50 miles around Seattle.". How would a timeline look like to visualize this? Is it a map or a list?

I can't think of a scenario for following based on the time attribute.
@Gissues:{"order":33.33333333333332,"status":"backlog"}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.