No description or website provided.
Ruby JavaScript Shell CoffeeScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
app
config
db
doc
git_hooks
lib
log
public
script
spec
vendor
.gitignore
.rspec
.rvmrc
Gemfile
Gemfile.lock
Guardfile
README.rdoc
Rakefile
config.ru

README.rdoc

RubyFloyd

About the project

RubyFloyd is a project for RailsRumble contest

Contributors

Installation

git clone git@github.com:railsrumble/r12-team-455.git
cp config/database.yml.sample config/database.yml # Add your postgres configuration
bundle install
rake db:migrate

API guide

Before start

Notice that you need to add the authentication token to every request appended at the end of the url, like: `wave_music.colimacolectivo.com/api/songs?auth_token=JbeRuU5pYPTbQ2FZWdE5` which is returned as json when you open a new session.

API authentication

Also you need to register your application on [developers page](wave_music.colimacolectivo.com/developers), and you'll receive your access token and is necessary to include it on each request like, `wave_music.colimacolectivo.com/api/songs?auth_token=JbeRuU5pYPTbQ2FZWdE5&access_token=5Ome50rt0ft0k3n`

Songs interface

There are many ways to interact with the songs API interface, the most important thing is that the interface provides you the data as JSON format, which is the most common and easy way to create JavaScript objects from API response.

The following route provides you the entire list of songs stored into the application library

GET /api/songs

And this is the sample response:

{
  "songs": [
      {
          "id": 1,
          "name": "Fade to black",
          "artist": "Metallica",
          "album": "Ride the Lightning",
          "album_art_url": "/system/songs/album_arts/000/000/001/large/77094516.png?1352223754",
          "filename": "04_Fade_To_Black.mp3",
          "duration": "415000",
          "url": "/uploads/song/file/1/04_Fade_To_Black.mp3"
      },
      {
          "id": 2,
          "name": "Creeping death",
          "artist": "Metallica",
          "album": "Ride the Lightning",
          "album_art_url": "/system/songs/album_arts/000/000/002/large/77094516.png?1352224213",
          "filename": "07_Creeping_Death.mp3",
          "duration": "396000",
          "url": "/uploads/song/file/2/07_Creeping_Death.mp3"
      },
      {
          "id": 3,
          "name": "Monkey Punch",
          "artist": "Avesta",
          "album": "Unknown Album",
          "album_art_url": "/system/songs/album_arts/000/000/003/large/default_album_300_g4.png?1352351384",
          "filename": "Avesta_-_Monkey_Punch__Original_Mix_.mp3",
          "duration": null,
          "url": "/uploads/song/file/3/Avesta_-_Monkey_Punch__Original_Mix_.mp3"
      },
      {
          "id": 4,
          "name": "I just had sex",
          "artist": "The Lonley Island",
          "album": "Unknown Album",
          "album_art_url": "/system/songs/album_arts/000/000/004/large/default_album_300_g4.png?1352351793",
          "filename": "03._I_Just_Had_Sex__Ft._Akon__iM1.mp3",
          "duration": null,
          "url": "/uploads/song/file/4/03._I_Just_Had_Sex__Ft._Akon__iM1.mp3"
      }
  ]
}

You can test this response by typing in your browser adding the following url after you are logged in the application.

http://wave_music.colimacolectivo.com/api/songs

Then using the previous ids you can get a specific song attributes

GET    /api/songs/:id

And this is the response

http://wave_music.colimacolectivo.com/api/songs/1
{
  "song": {
      "id": 1,
      "name": "Fade to black",
      "artist": "Metallica",
      "album": "Ride the Lightning",
      "album_art_url": "/system/songs/album_arts/000/000/001/large/77094516.png?1352223754",
      "filename": "04_Fade_To_Black.mp3",
      "duration": "415000",
      "url": "/uploads/song/file/1/04_Fade_To_Black.mp3"
  }
}

This is the search function and it's called by `GET` http method:

GET    /api/songs/search?name=something

And this is the response, returns the songs as array list

http://wave_music.colimacolectivo.com/api/songs/search?name=fade

{
  "songs": [
      {
          "id": 1,
          "name": "Fade to black",
          "artist": "Metallica",
          "album": "Ride the Lightning",
          "album_art_url": "/system/songs/album_arts/000/000/001/large/77094516.png?1352223754",
          "filename": "04_Fade_To_Black.mp3",
          "duration": "415000",
          "url": "/uploads/song/file/1/04_Fade_To_Black.mp3"
      }
  ]
}

Playlists interface

Technincally it has the same behavior as songs interface but instead of doing requests with `/api/songs` you should do it with `/api/playlists`

The generic response is:

{
  "playlists": [
      {
          "id": 1,
          "name": 'Favorite songs',
          "user_id": 1,
          "songs": [1,2,3,4,5] // notice this is an array of ids, you can fetch that songs info by id with "GET /api/songs/:id" for each one of those
      }
  ]
}

This is the feature set of playlists:

You can create a new playlist with the following url and method

POST   /api/playlists/

And send the `data` as JSON like the following one:

{ name: 'My favorite songs' }

With the following response:

{ status: 200, message: 'Successfully created playlist...', playlist: 1 }

This one songs to the playlist defined by id:

POST   /api/playlists/:id/add_songs

And send the data as JSON like:

{id: playlist_id, songs: [1,2,3,4,5]} // as array of ids

Uploading songs

You can upload songs with a POST request as JSON, but it takes time to complete so you can create a event handler in order to manage timeouts and javascript connections to wait until the upload is done, or a callback

POST   /api/uploads

And this is the required data

{name: 'my song', artist: 'my artsit', file: some sort of file attached }

Logging users

Exists this url for logging in users and have access to all the features described below

POST /api/sessions

With data defined as following

{user_login: { email: 'user@example.com', password: 'supersecret' }}

And destroying sessions:

DELETE /api/sessions/:id

With data:

{id: user_id}

And that's it, if you have suggestions please feel free to add issues and email me cavjzz@gmail.com in order to let me know if something is behaving wrong or documentation is incomplete

Copyright (C) 2012 RubyFloyd

This program 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 3 of the License, or (at your option) any later version.

This program 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 this program. If not, see <www.gnu.org/licenses/>.