From 50b0b0f6ff7da76ad21af9b4b5cd8932d5defb83 Mon Sep 17 00:00:00 2001 From: Sybil <sybil.deboin@gmail.com> Date: Tue, 16 Dec 2014 20:38:21 +0100 Subject: [PATCH] End of code purification. --- Gemfile | 4 +- Gemfile.lock | 8 ---- README.rdoc | 8 ++-- app/controllers/channels_controller.rb | 23 ++++------- app/controllers/musics_controller.rb | 11 ++--- app/controllers/tags_controller.rb | 35 ++-------------- config/application.rb | 8 ++-- config/routes.rb | 56 -------------------------- 8 files changed, 25 insertions(+), 128 deletions(-) diff --git a/Gemfile b/Gemfile index c3f018f..5320d81 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.5' # Use sqlite3 as the database for Active Record -gem 'sqlite3' +#gem 'sqlite3' # Use SCSS for stylesheets #gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets @@ -12,7 +12,7 @@ gem 'sqlite3' # Use CoffeeScript for .js.coffee assets and views #gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes -gem 'therubyracer', platforms: :ruby +#gem 'therubyracer', platforms: :ruby #Gem to produce a lightweight json API gem 'rails-api' diff --git a/Gemfile.lock b/Gemfile.lock index f2eb9d1..a727228 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,7 +47,6 @@ GEM activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) json (1.8.1) - libv8 (3.16.14.3) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -85,7 +84,6 @@ GEM rake (10.3.2) rdoc (4.1.1) json (~> 1.4) - ref (1.0.5) sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) @@ -100,10 +98,6 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) - sqlite3 (1.3.9) - therubyracer (0.12.1) - libv8 (~> 3.16.14.0) - ref thin (1.6.2) daemons (>= 1.0.9) eventmachine (>= 1.0.0) @@ -130,7 +124,5 @@ DEPENDENCIES rails-api sdoc (~> 0.4.0) spring - sqlite3 - therubyracer thin turbolinks diff --git a/README.rdoc b/README.rdoc index 80b8204..5af39bb 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,8 +1,10 @@ -WebPlayBot +== PlayBotAPI -Abstract +* Abstract -WebPlayBot delivers a web interface to listen/watch video or musics gathered by PlayBot. +PlayBotAPI delivers a json API to communicate with PlayBot's database which contain music tracks and some metadata. + +* PLayBot PlayBot (https://github.com/erdnaxeli/PlayBot) is an awesome irc bot which enable people to easily manipulate music/video links through irc channels. Each of these links are stored in an unique database which allows to handle favourites, reminders, exchange, tags ... diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index a08f31a..997639b 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -1,31 +1,22 @@ class ChannelsController < ApplicationController def index_users get_users() - - respond_to do |format| - format.json {render json: users, status: 200} - end + render json: @users, status: 200 end def index get_channels() - - respond_to do |format| - format.json {render json: channels, status: 200} - end + render json: @channels, status: 200 end def show_user - @musics = Music.joins(:channel).where(playbot_chan: {sender_irc: params[:user]}).page params[:page] - respond_to do |format| - format.json {render json: user, status: 200} - end + @musics = Music.joins(:channel).where(playbot_chan: {sender_irc: params[:user]}) + render json: @user, status: 200 end def show_channel - @musics = Music.joins(:channel).where(playbot_chan: {chan: "#"+params[:channel]}).page params[:page] - respond_to do |format| - format.json {render json: channel, status:200} - end + @musics = Music.joins(:channel).where(playbot_chan: {chan: "#"+params[:channel]}) + render json: @channel, status:200 end + end diff --git a/app/controllers/musics_controller.rb b/app/controllers/musics_controller.rb index 6218c67..8ec3981 100644 --- a/app/controllers/musics_controller.rb +++ b/app/controllers/musics_controller.rb @@ -8,19 +8,16 @@ class MusicsController < ApplicationController end def index - @musics = Music.page params[:page] + @musics = Music.all filters :tag, :channel, :user - respond_to do |format| - format.json {render json: musics, status: 200} - end + render json: @musics, status: 200 end def show @music = Music.find(params[:id]) - respond_to do |format| - format.json {render json: music, status: 200} - end + + render json: @music, status: 200 end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index a193a1d..61e6cc4 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,40 +1,11 @@ class TagsController < ApplicationController def index - #tags = Tag.all - - #list_tags = Array.new - #tags.each do |tag| - # list_tags.push(tag.tag) - #end - - #@tags = Hash.new - #list_tags.each do |tag| - # if @tags.key?(tag) - # @tags[tag] += 1.0 - # else - # @tags[tag] = 1.0 - # end - #end - - #max_weight = @tags.values.max - #@tags.each do |tag, occ| - # if occ == 1 - # @tags.delete(tag) - # else - # @tags[tag] = occ / max_weight - # end - #end - - respond_to do |format| - format.json {render json: tags, status: 200} - end + render json: @tags, status: 200 end def show - @musics = Music.joins(:tags).where(playbot_tags: {tag: params[:tag]}).page params[:page] - respond_to do |format| - format.json {render json: tag, status: 200} - end + @musics = Music.joins(:tags).where(playbot_tags: {tag: params[:tag]}) + render json: @tag, status: 200 end end diff --git a/config/application.rb b/config/application.rb index d3b5e47..c8591de 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,11 +1,11 @@ require File.expand_path('../boot', __FILE__) -#require 'rails/all' +require 'rails/all' # require "active_record/railtie" -require "action_controller/railtie" -require "action_mailer/railtie" +# require "action_controller/railtie" +# require "action_mailer/railtie" # require "sprockets/railtie" -require "rails/test_unit/railtie" +# require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/routes.rb b/config/routes.rb index 69f6aa2..0b1640f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,59 +1,4 @@ Rails.application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end - # constraints subdomain: 'api' do get '/users', to: "channels#index_users" @@ -68,5 +13,4 @@ Rails.application.routes.draw do root to: 'musics#index' end - #get '/users/:user_id/musics', to: "musics#index" end -- GitLab