diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..878259d Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 03f3ce7..882d639 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,5 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc + +/.env diff --git a/Gemfile b/Gemfile index 288bb87..f6414d6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,9 @@ source 'https://rubygems.org' ruby '2.3.1' +gem 'httparty' + +gem 'sqlite3' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.6' # Use postgresql as the database for Active Record @@ -21,6 +24,18 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc +gem 'turbolinks' + +gem 'rspotify' + +gem('yelp', {require: 'yelp'}) + +gem 'omniauth' + +gem 'omniauth-spotify' + +gem 'omniauth-oauth2', '~> 1.3.1' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -30,16 +45,29 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +group :production do + gem 'rails_12factor' +end + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'dotenv-rails' + gem 'minitest-vcr' + gem 'minitest-reporters' + gem 'pry-rails' + gem 'webmock' + gem 'simplecov', '~> 0.11.2' + gem 'vcr' end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' - + gem 'better_errors' + gem 'binding_of_caller' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' + gem 'rails-erd' end diff --git a/Gemfile.lock b/Gemfile.lock index 6ff0f39..fcef4c3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,11 +36,19 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.4.0) + ansi (1.5.0) arel (6.0.3) + better_errors (2.1.1) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) byebug (8.2.5) + choice (0.2.0) + coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -49,11 +57,27 @@ GEM execjs coffee-script-source (1.10.0) concurrent-ruby (1.0.2) + crack (0.4.3) + safe_yaml (~> 1.0.0) debug_inspector (0.0.2) + docile (1.1.5) + dotenv (2.1.1) + dotenv-rails (2.1.1) + dotenv (= 2.1.1) + railties (>= 4.0, < 5.1) erubis (2.7.0) execjs (2.6.0) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + faraday_middleware (0.10.0) + faraday (>= 0.7.4, < 0.10) globalid (0.3.6) activesupport (>= 4.1.0) + hashdiff (0.3.0) + hashie (3.4.4) + httparty (0.13.7) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.7.0) jbuilder (2.4.1) activesupport (>= 3.0.0, < 5.1) @@ -63,19 +87,55 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) + jwt (1.5.1) loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.4) mime-types (>= 1.16, < 4) + method_source (0.8.2) mime-types (3.0) mime-types-data (~> 3.2015) mime-types-data (3.2016.0221) mini_portile2 (2.0.0) + minispec-metadata (2.0.0) + minitest minitest (5.8.4) + minitest-reporters (1.1.9) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + minitest-vcr (1.4.0) + minispec-metadata (~> 2.0) + minitest (>= 4.7.5) + vcr (>= 2.9) multi_json (1.12.0) + multi_xml (0.5.5) + multipart-post (2.0.0) + netrc (0.7.9) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) + oauth2 (1.1.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0, < 1.5.2) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.3.1) + hashie (>= 1.2, < 4) + rack (>= 1.0, < 3) + omniauth-oauth2 (1.3.1) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-spotify (0.0.9) + omniauth-oauth2 (~> 1.1) pg (0.18.4) + pry (0.10.3) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-rails (0.3.4) + pry (>= 0.9.10) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -96,8 +156,18 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-erd (1.4.7) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) railties (4.2.6) actionpack (= 4.2.6) activesupport (= 4.2.6) @@ -106,6 +176,14 @@ GEM rake (11.1.2) rdoc (4.2.2) json (~> 1.4) + rest_client (1.8.3) + netrc (~> 0.7.7) + rspotify (1.10.0) + omniauth-oauth2 (~> 1.1) + rest_client (~> 1.8) + ruby-graphviz (1.2.2) + ruby-progressbar (1.8.1) + safe_yaml (1.0.4) sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -116,6 +194,13 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simple_oauth (0.3.1) + simplecov (0.11.2) + docile (~> 1.1.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + slop (3.6.0) spring (1.7.1) sprockets (3.6.0) concurrent-ruby (~> 1.0) @@ -124,34 +209,68 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + sqlite3 (1.3.11) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.2) + turbolinks (2.5.3) + coffee-rails tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (3.0.0) execjs (>= 0.3.0, < 3) + vcr (3.0.1) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + webmock (2.0.3) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff + yelp (2.1.2) + faraday (~> 0.8, >= 0.8.0) + faraday_middleware (~> 0.8, >= 0.8.0) + simple_oauth (~> 0.3.1) PLATFORMS ruby DEPENDENCIES + better_errors + binding_of_caller byebug coffee-rails (~> 4.1.0) + dotenv-rails + httparty jbuilder (~> 2.0) jquery-rails + minitest-reporters + minitest-vcr + omniauth + omniauth-oauth2 (~> 1.3.1) + omniauth-spotify pg (~> 0.15) + pry-rails rails (= 4.2.6) + rails-erd + rails_12factor + rspotify sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov (~> 0.11.2) spring + sqlite3 + turbolinks uglifier (>= 1.3.0) + vcr web-console (~> 2.0) + webmock + yelp + +RUBY VERSION + ruby 2.3.1p112 BUNDLED WITH - 1.12.3 + 1.12.4 diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..99ec127 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/.DS_Store b/app/assets/.DS_Store new file mode 100644 index 0000000..b444bdd Binary files /dev/null and b/app/assets/.DS_Store differ diff --git a/app/assets/images/.DS_Store b/app/assets/images/.DS_Store new file mode 100644 index 0000000..e20531b Binary files /dev/null and b/app/assets/images/.DS_Store differ diff --git a/app/assets/images/spotify.jpeg b/app/assets/images/spotify.jpeg new file mode 100644 index 0000000..2afb140 Binary files /dev/null and b/app/assets/images/spotify.jpeg differ diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/suggestions.coffee b/app/assets/javascripts/suggestions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/suggestions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000..7bef9cf --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/suggestions.scss b/app/assets/stylesheets/suggestions.scss new file mode 100644 index 0000000..c0d3b8d --- /dev/null +++ b/app/assets/stylesheets/suggestions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the suggestions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..479459f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,16 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + helper_method :current_user + + def current_user + @user ||= User.find_by(id: session[:user_id]) + end + + def require_login + if current_user.nil? + flash[:error] = "You must be logged in to view" + redirect to root_path + end + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..9d0e85b --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,25 @@ +class SessionsController < ApplicationController + skip_before_action :require_login, only: [:new, :create] + + def new + end + + # logged in users + def create + # this is for creating a new session after login + auth_hash = request.env['omniauth.auth'] + user = User.find_or_create_from_omniauth(auth_hash) + + if user + session[:user_id] = user.id + redirect_to root_path + else + redirect_to root_path + end + end + + def destroy + session.delete :user_id + redirect_to root_path + end +end diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb new file mode 100644 index 0000000..db0bdc9 --- /dev/null +++ b/app/controllers/suggestions_controller.rb @@ -0,0 +1,55 @@ +require_relative "../../lib/TunesTakeoutWrapper" + +class SuggestionsController < ApplicationController + skip_before_action :require_login, only: :index + + def index + if current_user + @user = User.find(session[:user_id]) + end + + if params[:query] != nil + #for search results + @query = params[:query] + @suggestions = TunesTakeoutWrapper.search(@query)["suggestions"] + @food = Food.get_food(@suggestions) + @music = Music.get_music(@suggestions) + render :index + + else + #for top suggestions + @suggestion_ids = TunesTakeoutWrapper.top_suggestions + @suggestions = @suggestion_ids.map {|id| TunesTakeoutWrapper.retrieve(id)["suggestion"]} + @food = Food.get_food(@suggestions) + @music = Music.get_music(@suggestions) + end + end + + def myfavorites + @my_favorites = TunesTakeoutWrapper.favorites(current_user.uid)["suggestions"] + @suggestions = @my_favorites.map {|id| TunesTakeoutWrapper.retrieve(id)["suggestion"]} + @food = Food.get_food(@suggestions) + @music = Music.get_music(@suggestions) + end + + def favorite + response = TunesTakeoutWrapper.favorite(current_user.uid, params[:suggestion_id]) + + if response.code == 201 + @message = "Successfully Added" + elsif response.code == 409 + @message = "Already Favorited" + else + @message = "Not valid" + end + + redirect_to "/myfavorites" + end + + def unfavorite + response = TunesTakeoutWrapper.unfavorite(current_user.uid, params[:suggestion_id]) + + redirect_to "/myfavorites" + end + +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000..309f8b2 --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/suggestions_helper.rb b/app/helpers/suggestions_helper.rb new file mode 100644 index 0000000..0e358dd --- /dev/null +++ b/app/helpers/suggestions_helper.rb @@ -0,0 +1,2 @@ +module SuggestionsHelper +end diff --git a/app/models/food.rb b/app/models/food.rb new file mode 100644 index 0000000..e35fede --- /dev/null +++ b/app/models/food.rb @@ -0,0 +1,13 @@ +require 'yelp' + +class Food < ActiveRecord::Base + BASE_URL = "https://api.yelp.com/" + + #data should be an array of suggestion info + def self.get_food(data) + business = data.map do |datum| + Yelp.client.business(datum["food_id"]).business + end + return business + end +end diff --git a/app/models/music.rb b/app/models/music.rb new file mode 100644 index 0000000..cf5a040 --- /dev/null +++ b/app/models/music.rb @@ -0,0 +1,30 @@ +require 'rspotify' + +class Music < ActiveRecord::Base + DEFAULT_PIC = "spotify.jpeg" + #data should be array + def self.get_music(sug_array) + data = sug_array.map do |sug| + if sug["music_type"] == "artist" + RSpotify::Artist.find(sug["music_id"]) + elsif sug["music_type"] == "album" + RSpotify::Album.find(sug["music_id"]) + elsif sug["music_type"] == "track" + RSpotify::Track.find(sug["music_id"]) + #go to albums images then url + end + end + return data + end + + def self.find_image(image) + + if image.nil? + return DEFAULT_PIC + elsif image[0].nil? + return DEFAULT_PIC + else + image[0]["url"] + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..5de6d87 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,24 @@ +class User < ActiveRecord::Base + validates :uid, :provider, presence: true + + + def self.find_or_create_from_omniauth(auth_hash) + user = self.find_by(uid: auth_hash["uid"], provider: auth_hash["provider"]) + if !user.nil? + return user + else + # no user found, do something here + user = User.new + user.uid = auth_hash["uid"] + user.provider = auth_hash["provider"] + user.name = auth_hash["info"]["name"] + user.image = auth_hash["info"]["image"] + + if user.save + return user + else + return nil + end + end + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 509d1a2..3b17b4a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,13 +2,36 @@ TunesTakeout + + + + + + + + + + <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> + -<%= yield %> + <%= yield %> + + diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000..a6d5f03 --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,7 @@ + +<%= image_tag("spotify.jpeg", height: '150', width: '150') unless current_user %> +

Spotify

+ +
+ +<%= link_to "Log In or Sign Up with Spotify", "/auth/spotify" unless current_user %> \ No newline at end of file diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb new file mode 100644 index 0000000..300d6a1 --- /dev/null +++ b/app/views/suggestions/_suggestion.html.erb @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + +
Suggestion #<%= number %>
+ + the business #{f.name} + +

<%= food.name %>

+

<%= food.phone.nil? ? " " : food.phone %>

+
+

and

+
+ + "> + + <% album_picture = music.images if music.type == "album" %> + <% album_picture = music.images if music.type == "artist" %> + <% album_picture = music.album.images if music.type == "track" %> + + + +

<%= music.name %>

+

Type: <%= music.type.capitalize %>

+ +
+ <% if current_user && !current_page?(controller: "suggestions", action: "myfavorites") %> + <%= link_to "","/favorite/#{suggestion["id"]}", method: :post, class:" glyphicon glyphicon-thumbs-up" %> + <% elsif current_page?(controller: "suggestions", action: "myfavorites") %> + <%= link_to "","/unfavorite/#{suggestion["id"]}", method: :delete, class:" glyphicon glyphicon-thumbs-down" %> + <%end%> +
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb new file mode 100644 index 0000000..1ced9e6 --- /dev/null +++ b/app/views/suggestions/index.html.erb @@ -0,0 +1,17 @@ +<% if current_user %> +

What do you want to find?

+ + <%= form_tag "/" do %> + <%= label_tag("Insert word") %> + <%= text_field_tag(:query) %> + <%= submit_tag("Search") %> + <% end %> +<% else %> +

Please login to start pairing!

+<%end%> + +<%= params[:query] == nil ? "Top Suggestions" : "Here's what we found" %> + +<% @food.each_with_index do |f, i| %> + <%= render partial: "suggestion", locals: { food: f, music: @music[i], number: (i+1), suggestion: @suggestions[i]} %> +<% end %> diff --git a/app/views/suggestions/myfavorites.html.erb b/app/views/suggestions/myfavorites.html.erb new file mode 100644 index 0000000..0e9c06a --- /dev/null +++ b/app/views/suggestions/myfavorites.html.erb @@ -0,0 +1,9 @@ + +<% if @food[0] != nil %> + <% @food.each_with_index do |f, i| %> + <%= render partial: "suggestion", locals: { food: f, music: @music[i], number: (i+1), suggestion: @suggestions[i]} %> + <%end%> + +<% else %> +

No favorites found. You should browse a little!

+<%end%> \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 9b37a86..027776c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -8,6 +8,9 @@ module TunesTakeout class Application < Rails::Application + + config.autoload_paths += %W(#{config.root}/lib) + config.autoload_paths += %W(#{config.root}/extras) # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 0000000..8f1aab5 --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :spotify, ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"] +end \ No newline at end of file diff --git a/config/initializers/spotify.rb b/config/initializers/spotify.rb new file mode 100644 index 0000000..1ebaa89 --- /dev/null +++ b/config/initializers/spotify.rb @@ -0,0 +1,3 @@ +require 'rspotify' + +RSpotify::authenticate(ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"]) \ No newline at end of file diff --git a/config/initializers/yelp.rb b/config/initializers/yelp.rb new file mode 100644 index 0000000..c9b2e18 --- /dev/null +++ b/config/initializers/yelp.rb @@ -0,0 +1,8 @@ +require 'yelp' + +Yelp.client.configure do |config| + config.consumer_key = ENV["YELP_CONSUMER_KEY"] + config.consumer_secret = ENV["YELP_CONSUMER_SECRET"] + config.token = ENV["YELP_TOKEN"] + config.token_secret = ENV["YELP_TOKEN_SECRET"] +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3f66539..f575314 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,56 +1,16 @@ 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". + root 'suggestions#index' - # You can have the root of your site routed with "root" - # root 'welcome#index' + resources :users, :only => [:new, :create] - # Example of regular route: - # get 'products/:id' => 'catalog#view' + delete "/logout" => "sessions#destroy", as: 'logout' + get "/auth/:provider/callback" => "sessions#create" + get "/signin", to: "sessions#new", as: :signin + post "/" => "suggestions#index" + get "/myfavorites" => "suggestions#myfavorites" - # 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 -end + post "/favorite/:suggestion_id" => "suggestions#favorite" + delete "/unfavorite/:suggestion_id" => "suggestions#unfavorite" + # delete "/logout" => "sessions#destroy" + # get "/login" => "sessions#new" +end \ No newline at end of file diff --git a/db/migrate/20160518213803_create_users.rb b/db/migrate/20160518213803_create_users.rb new file mode 100644 index 0000000..aeff593 --- /dev/null +++ b/db/migrate/20160518213803_create_users.rb @@ -0,0 +1,12 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :provider, null: false + t.string :uid, null: false + t.string :name + t.string :email + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160518214846_create_foods.rb b/db/migrate/20160518214846_create_foods.rb new file mode 100644 index 0000000..5d62fcd --- /dev/null +++ b/db/migrate/20160518214846_create_foods.rb @@ -0,0 +1,8 @@ +class CreateFoods < ActiveRecord::Migration + def change + create_table :foods do |t| + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160518214850_create_musics.rb b/db/migrate/20160518214850_create_musics.rb new file mode 100644 index 0000000..2cc03f3 --- /dev/null +++ b/db/migrate/20160518214850_create_musics.rb @@ -0,0 +1,8 @@ +class CreateMusics < ActiveRecord::Migration + def change + create_table :musics do |t| + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160519055803_deleting_null_restrictions.rb b/db/migrate/20160519055803_deleting_null_restrictions.rb new file mode 100644 index 0000000..78d8420 --- /dev/null +++ b/db/migrate/20160519055803_deleting_null_restrictions.rb @@ -0,0 +1,6 @@ +class DeletingNullRestrictions < ActiveRecord::Migration + def change + change_column :users, :uid, :string, null: true + change_column :users, :provider, :string, null: true + end +end diff --git a/db/migrate/20160519060114_deleteemailcolumn.rb b/db/migrate/20160519060114_deleteemailcolumn.rb new file mode 100644 index 0000000..324091c --- /dev/null +++ b/db/migrate/20160519060114_deleteemailcolumn.rb @@ -0,0 +1,5 @@ +class Deleteemailcolumn < ActiveRecord::Migration + def change + remove_column :users, :email + end +end diff --git a/db/migrate/20160519194329_add_image_to_user.rb b/db/migrate/20160519194329_add_image_to_user.rb new file mode 100644 index 0000000..1216e99 --- /dev/null +++ b/db/migrate/20160519194329_add_image_to_user.rb @@ -0,0 +1,6 @@ +class AddImageToUser < ActiveRecord::Migration + def change + add_column :users, :image, :string, default: "spotify.jpeg" + change_column :users, :provider, :string, default: "spotify" + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..0fb65d3 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,38 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20160519194329) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "foods", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "musics", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.string "provider", default: "spotify" + t.string "uid" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "image", default: "spotify.jpeg" + end + +end diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb new file mode 100644 index 0000000..43a3835 --- /dev/null +++ b/lib/TunesTakeoutWrapper.rb @@ -0,0 +1,34 @@ +require 'HTTParty' + +class TunesTakeoutWrapper + BASE_URL = "https://tunes-takeout-api.herokuapp.com" + + #find a defined list of suggestion based on query + def self.search(query, limit=10, seed=query) + data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{query}&limit=#{limit}&seed=#{query}").parsed_response + end + + #find a defined size of top suggestions, brings back an array + def self.top_suggestions(limit=20) + data = HTTParty.get(BASE_URL + "/v1/suggestions/top?limit=#{limit}").parsed_response["suggestions"] + end + + #find suggestion attributes based on suggestion ID + def self.retrieve(suggestion_id) + HTTParty.get(BASE_URL + "/v1/suggestions/#{suggestion_id}").parsed_response + end + + def self.favorites(uid) + data = HTTParty.get(BASE_URL + "/v1/users/#{uid}/favorites").parsed_response + end + + def self.favorite(uid, suggestion_id) + response = HTTParty.post(BASE_URL+"/v1/users/#{uid}/favorites", {:body => { "suggestion": "#{suggestion_id}"}.to_json}) + return response + end + + def self.unfavorite(uid,suggestion_id) + response = HTTParty.delete(BASE_URL+"/v1/users/#{uid}/favorites", {:body => { "suggestion": "#{suggestion_id}"}.to_json}) + return response + end +end \ No newline at end of file diff --git a/list b/list new file mode 100644 index 0000000..e3624dd --- /dev/null +++ b/list @@ -0,0 +1,12 @@ +#Favorite individual food+music pairing suggestions + +- be able to log in (spotify) + - need to identify the logged in user +- get suggestions from Charles' API + - need suggestion ID +- gotta be able to send favorite data back to Charles' API +- gotta be able to display suggestions +- indicate satus of post-favorite action +- need interaction in UI to initiate favoriting +- gotta able to unfavorite +- what data's needed when user favorites \ No newline at end of file diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb new file mode 100644 index 0000000..d30ebc3 --- /dev/null +++ b/test/controllers/sessions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SessionsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/suggestions_controller_test.rb b/test/controllers/suggestions_controller_test.rb new file mode 100644 index 0000000..f4587a5 --- /dev/null +++ b/test/controllers/suggestions_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SuggestionsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/foods.yml b/test/fixtures/foods.yml new file mode 100644 index 0000000..937a0c0 --- /dev/null +++ b/test/fixtures/foods.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/musics.yml b/test/fixtures/musics.yml new file mode 100644 index 0000000..937a0c0 --- /dev/null +++ b/test/fixtures/musics.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..937a0c0 --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the '{}' from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/models/food_test.rb b/test/models/food_test.rb new file mode 100644 index 0000000..8ad7dff --- /dev/null +++ b/test/models/food_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class FoodTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/music_test.rb b/test/models/music_test.rb new file mode 100644 index 0000000..82aca4e --- /dev/null +++ b/test/models/music_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + + +describe Music do + +class MusicTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end + + +end + + +#sample data +#{"id"=>"Vz0KQY-RRwADboE-", "food_id"=>"a-la-mode-pies-seattle", + #{}"music_id"=>"1OYLLmDS0pJVFRbUo19vrG", "music_type"=>"album"} diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..d0e95f6 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end + #insert tests here! +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 92e39b2..3ce8471 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,25 @@ +require 'simplecov' +SimpleCov.start + ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' +require 'minitest/spec' +require "minispec-metadata" +require 'vcr' +require 'minitest-vcr' +require 'webmock/minitest' +require "minitest/reporters" + +VCR.configure do |c| + c.cassette_library_dir = 'test/cassettes' + c.hook_into :webmock +end + +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new +MinitestVcr::Spec.configure! + class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all