API implementation guide

If you want to add your network in Hey!Spread, you need to provide us an API. So, here is an implementation guide to help you in this task.

You just need to provide us at least two actions (login and upload), this should be easy.

Note that this implementation is just a draft, you can do your own if you want.

HTTP Methods

Login

Fields: login, password

This is to check if the credentials are correct. It's better to know if the user exists before uploading the video.

If correct return HTTP code 200, if not 401.

Upload

Fields: title, tags, category, description, video, login, password

If correct return HTTP code 200 and the final video link in the body, if not return 400 and the reason in the body.

Recommendations

This is highly recommended to let us delete an uploaded video and to get the total views for a given video. You can see the example with RubyOnRails bellow.

Example with RubyOnRails

class HeyspreadController < ApplicationController
  before_filter :login_required, :only => [:upload, :delete]
  
  def login
    render :nothing => true
  end

  def upload
    @video = @user.videos.new(
      :title => params[:title],
      :description => params[:description],
      :tags => params[:tags],
      :category => params[:category],
      :video => params[:video]
    )  

    if @video.save
      render :text => @video.url
    else
      render :text => @video.errors.first, :status => 400
    end
  end
  
  def delete
    if @user.videos.find(params[:id]).destroy
      render :nothing => true, :status => 204
    else
      render :nothing => true, :status => 400
    end
  end
  
  def views
    @video = Video.find(params[:id])
    render :text => @video.views
  end
  
  private
  
  def login_required
    unless @user = User.authenticate(params[:login], params[:password])
      render :nothing => true, :status => 401
    end
  end
end