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..5607d5f 100644 --- a/Gemfile +++ b/Gemfile @@ -16,11 +16,21 @@ gem 'coffee-rails', '~> 4.1.0' # Use jquery as the JavaScript library gem 'jquery-rails' +gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc +gem 'httparty', '0.13.7' +# gem 'yelp', require: 'yelp' +gem 'yelp', '~> 2.1', '>= 2.1.2' +gem 'rspotify', '1.10.0' + +gem 'omniauth' +#gem 'omniauth-github' +gem 'omniauth-oauth2', '~> 1.3.1' +gem 'addressable' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -32,14 +42,26 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug' + gem 'byebug', '8.2.5' + gem "pry-rails", '0.3.4' + gem 'simplecov', '0.11.2' + gem 'minitest-vcr' + # gem 'vcr' + gem 'minitest-reporters' + gem 'webmock', '2.0.2' + gem 'dotenv-rails' + 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" # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' + # gem 'spring' end +group :production do + gem 'rails_12factor' +end diff --git a/Gemfile.lock b/Gemfile.lock index 6ff0f39..086d704 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,11 +36,18 @@ 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) + coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -49,11 +56,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 +86,53 @@ 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) 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) @@ -98,6 +155,11 @@ GEM rails-deprecated_sanitizer (>= 1.0.1) 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 +168,13 @@ 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-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,7 +185,13 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - spring (1.7.1) + 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) sprockets (3.6.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -127,31 +202,59 @@ GEM 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.2) + 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 - byebug + addressable + better_errors + byebug (= 8.2.5) coffee-rails (~> 4.1.0) + dotenv-rails + httparty (= 0.13.7) jbuilder (~> 2.0) jquery-rails + minitest-reporters + minitest-vcr + omniauth + omniauth-oauth2 (~> 1.3.1) pg (~> 0.15) + pry-rails (= 0.3.4) rails (= 4.2.6) + rails_12factor + rspotify (= 1.10.0) sass-rails (~> 5.0) sdoc (~> 0.4.0) - spring + simplecov (= 0.11.2) + turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) + webmock (= 2.0.2) + yelp (~> 2.1, >= 2.1.2) + +RUBY VERSION + ruby 2.2.3p173 BUNDLED WITH - 1.12.3 + 1.12.4 diff --git a/app/assets/images/animated_favicon1.gif b/app/assets/images/animated_favicon1.gif new file mode 100755 index 0000000..e5a00a2 Binary files /dev/null and b/app/assets/images/animated_favicon1.gif differ diff --git a/app/assets/images/favicon.ico b/app/assets/images/favicon.ico new file mode 100755 index 0000000..9addc77 Binary files /dev/null and b/app/assets/images/favicon.ico 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/application.css b/app/assets/stylesheets/application.css index f9cd5b3..c401b7f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,15 +1,86 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any styles - * defined in the other CSS/SCSS files in this directory. It is generally better to create a new - * file per style scope. - * - *= require_tree . - *= require_self - */ +body { + background-image: url(https://cdn.elegantthemes.com/blog/wp-content/uploads/2013/09/bg-11-full.jpg); + background-image: url(http://static1.squarespace.com/static/54e5fa76e4b0453ef23d0e1c/t/55256769e4b007c5fd384a2e/1428514738661/website-background-image3_BRIGHTER.jpg?format=1200w); + height: 100%; + background-repeat: no-repeat; + background-attachment: fixed; +} + +.picprofile { + border-radius: 50%; + height: 50px; + width: 50px; +} + +.totheleft { + float: right; +} + +.table>tbody>tr>.food { + width: 42%; + padding: 4% 2%; + padding-right: 7%; +} + +.table>tbody>tr>.music { + width: 42%; + padding: 4% 7%; + padding-right: 2%; +} + +tr { + margin-bottom: 40px; + background-color: rgba(250, 250, 250, 0.7); +} + +.fava { + width: 16%; + text-align: center; +} + +.spotifypic { + height: 100px; + width: 100px; +} + +.spotifyheaderti { + margin-top: 0; + float: right; + text-align: right; + width: 60%; +} + +.spotifyheaderti h3 { + padding-top: 0; + margin-top: 0; +} + +.yelp_pic { + float: right; +} + +.yelpheader { + overflow: auto; +} + +.yelpheaderti{ + margin-top: 0; +} + +.ratingpic { + float: right; +} + +.yelprates { + overflow: auto; +} + +table a { + color: rgb(130, 16, 30); +} + +.iframe-frame { + margin-top: 60px; + height: 100px; + overflow: hidden; +} 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..5b6ec7b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,20 @@ 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 + #protect_from_forgery with: :null_session + helper_method :current_user + + #before_action :require_login + + 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 this section" + 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..4719430 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,24 @@ +class SessionsController < ApplicationController + skip_before_action :require_login, only: [:new, :create] + + def new + end + + def create + 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 + flash[:notice] = "did not login in" + 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..2d81ff9 --- /dev/null +++ b/app/controllers/suggestions_controller.rb @@ -0,0 +1,62 @@ +require "#{Rails.root}/lib/charles/TunesTakeoutWrapper.rb" + +class SuggestionsController < ApplicationController +before_action :require_login, only: [:favorites, :favorite, :unfavorites, :search_result] + def index + @top = Charles::TunesTakeoutWrapper.all_favorites + + if @top.nil? + flash.now[:notice] = "Something went wrong, please try again" + else + @zip = @top.suggestions.map do |sugg_hash| + [ + Music.create(sugg_hash["suggestion"]["music_type"], sugg_hash["suggestion"]["music_id"]), + Food.find_in_api(sugg_hash["suggestion"]["food_id"]), + sugg_hash["suggestion"]["id"] + ] + end + end + end + + def favorites + @my_favorites = Charles::TunesTakeoutWrapper.get_my_favorite(current_user.uid) + + if @my_favorites.suggestions.nil? + flash.now[:notice] = "Something went wrong, please try again" + else + @zip = @my_favorites.suggestions.map do |sugg_hash| + [ + Music.create(sugg_hash['suggestion']["music_type"], sugg_hash['suggestion']["music_id"]), + Food.find_in_api(sugg_hash['suggestion']["food_id"]), + sugg_hash['suggestion']["id"] + ] + end + end + end + + def favorite + @result = Charles::TunesTakeoutWrapper.add_favorite(params[:current_user_id], params[:suggestion_id]) + redirect_to my_favorites_path + end + + def unfavorite + @result = Charles::TunesTakeoutWrapper.delete_favorite(params[:current_user_id], params[:suggestion_id]) + redirect_to my_favorites_path + end + + def search_result + @all_suggestions = Charles::TunesTakeoutWrapper.find(params[:user_input]) + + if @all_suggestions.suggestions.nil? + flash.now[:notice] = "Something went wrong, please try again" + else + @zip = @all_suggestions.suggestions.map do |sugg_hash| + [ + Music.create(sugg_hash["music_type"], sugg_hash["music_id"]), + Food.find_in_api(sugg_hash["food_id"]), + sugg_hash["id"] + ] + end + end + 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..f1e2c43 --- /dev/null +++ b/app/models/food.rb @@ -0,0 +1,21 @@ + +class Food + attr_reader :the_image_url, :rating, :name, :review_count, :rating_img_url_large, :categories, :location, :display_phone, :open_yelp_url + def initialize(data) + @the_image_url = data.business.image_url + @name = data.business.name + @rating = data.business.rating + @review_count = data.business.review_count + @rating_img_url_large = data.business.rating_img_url_large + @categories = data.business.categories + @location = data.business.location.display_address + @display_phone = data.business.display_phone + @open_yelp_url = data.business.url + end + + def self.find_in_api(id) + uri = Addressable::URI.parse(id) + data = Yelp.client.business(uri.normalize.to_s) + return self.new(data) + end +end diff --git a/app/models/music.rb b/app/models/music.rb new file mode 100644 index 0000000..977a313 --- /dev/null +++ b/app/models/music.rb @@ -0,0 +1,31 @@ +# require 'rspotify ' + +class Music + attr_reader :item_id, :type, :name, :open_spotify_url, :image, :uri + def initialize(data) + @item_id = data.id + @type = data.type + @name = data.name + @open_spotify_url = data.external_urls["spotify"] + if data.type == "track" + @image = data.album.images[1]["url"] + elsif data.type == "artist" + @image = data.albums[0].images[1]["url"] + else + @image = data.images[1]["url"] + end + @uri = data.uri + end + + def self.create(type, id) + if type == "artist" + music_result = RSpotify::Artist.find(id) + elsif type == "album" + music_result = RSpotify::Album.find(id) + else + music_result = RSpotify::Track.find(id) + end + return self.new(music_result) + end + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..5fa54ea --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,31 @@ +class User < ActiveRecord::Base + validates :uid, :provider, presence: true + #:name + + def self.find_or_create_from_omniauth(auth_hash) + # Find or create a user + + user = self.find_by(uid: auth_hash["info"]["id"], provider: auth_hash["provider"]) + if !user.nil? + return user + else + user = User.new + if auth_hash["info"]["images"] == [] + user.uid = auth_hash["info"]["id"] + user.images = "http://i1.wp.com/www.techrepublic.com/bundles/techrepubliccore/images/icons/standard/icon-user-default.png" + else + user.uid = auth_hash["uid"] + user.name = auth_hash["info"]["display_name"] + user.images = auth_hash["info"]["images"][0]["url"] + end + user.open_spotify_url = auth_hash["info"]["external_urls"]["spotify"] + user.provider = auth_hash["provider"] + + 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..8567205 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,10 +5,73 @@ <%= stylesheet_link_tag 'application', media: 'all' %> <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> + + + + + + + + +<%= favicon_link_tag 'favicon.ico' %> +
-<%= yield %> + + + + <% if flash[:notice] -%> +<%=h flash[:notice] %>
+