From c8c77072d9458b9d2631d99c2796214f94500546 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Mon, 16 May 2016 16:00:41 -0700 Subject: [PATCH 1/6] finished initial setup of including proper gems in the Gemfile and modified the layout view to include bootstrap --- Gemfile | 17 ++++-- Gemfile.lock | 72 ++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 12 ++++- 3 files changed, 96 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 288bb87..d693196 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '2.3.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.6' @@ -23,23 +23,34 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' - +gem 'httparty' # Use Unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'yelp', require: 'yelp' +gem 'rspotify', require: 'rspotify' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + + 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 'pry-rails' + gem 'erd' + gem 'bootstrap-sass', '~>3.2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end +group :production do + gem 'rails_12factor' +end diff --git a/Gemfile.lock b/Gemfile.lock index 6ff0f39..6b28ae1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,10 +37,18 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) 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) + bootstrap-sass (3.2.0.2) + sass (~> 3.2) 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) @@ -50,10 +58,21 @@ GEM coffee-script-source (1.10.0) concurrent-ruby (1.0.2) debug_inspector (0.0.2) + erd (0.4.0) + nokogiri + rails-erd (>= 0.4.5) 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) + 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 +82,42 @@ 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) minitest (5.8.4) 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.4.0) + 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) @@ -96,8 +138,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 +158,12 @@ 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) sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -116,6 +174,8 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + simple_oauth (0.3.1) + slop (3.6.0) spring (1.7.1) sprockets (3.6.0) concurrent-ruby (~> 1.0) @@ -136,22 +196,34 @@ GEM binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + 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 + bootstrap-sass (~> 3.2.0) byebug coffee-rails (~> 4.1.0) + erd + httparty jbuilder (~> 2.0) jquery-rails pg (~> 0.15) + pry-rails rails (= 4.2.6) + rails_12factor + rspotify sass-rails (~> 5.0) sdoc (~> 0.4.0) spring uglifier (>= 1.3.0) web-console (~> 2.0) + yelp BUNDLED WITH 1.12.3 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 509d1a2..7ba0ce9 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,8 +2,16 @@ TunesTakeout - <%= stylesheet_link_tag 'application', media: 'all' %> - <%= javascript_include_tag 'application' %> + + + + + + + + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> From 5a97e60445b41a5df8d2073ad41cde3033f101ab Mon Sep 17 00:00:00 2001 From: Yordanos Date: Thu, 19 May 2016 16:01:16 -0700 Subject: [PATCH 2/6] connected to Spotify to allow users to sign in --- .gitignore | 2 + Gemfile | 12 +- Gemfile.lock | 52 ++++-- app/assets/javascripts/application.js | 7 + app/assets/javascripts/home.coffee | 3 + app/assets/javascripts/sessions.coffee | 64 ++++++++ app/assets/javascripts/suggestions.coffee | 3 + app/assets/javascripts/user.coffee | 3 + app/assets/stylesheets/home.scss | 30 ++++ app/assets/stylesheets/sessions.scss | 117 +++++++++++++ app/assets/stylesheets/suggestions.scss | 143 ++++++++++++++++ app/assets/stylesheets/user.scss | 91 +++++++++++ app/controllers/application_controller.rb | 16 ++ app/controllers/home_controller.rb | 7 + app/controllers/sessions_controller.rb | 23 +++ app/controllers/suggestions_controller.rb | 17 ++ app/controllers/user_controller.rb | 11 ++ app/helpers/application_helper.rb | 3 + app/helpers/home_helper.rb | 2 + app/helpers/sessions_helper.rb | 2 + app/helpers/suggestions_helper.rb | 2 + app/helpers/user_helper.rb | 2 + app/models/food.rb | 14 ++ app/models/music.rb | 48 ++++++ app/models/user.rb | 24 +++ app/views/home/index.html.erb | 36 ++++ app/views/layouts/application.html.erb | 11 +- app/views/sessions/new.html.erb | 24 +++ app/views/sessions/new2.html.erb | 44 +++++ app/views/shared/_suggestion.html.erb | 154 ++++++++++++++++++ app/views/suggestions/favorites.html.erb | 0 app/views/suggestions/index.html.erb | 1 + app/views/user/index.html.erb | 46 ++++++ app/views/user/show.html.erb | 52 ++++++ config/application.rb | 7 +- config/initializers/omniauth.rb | 15 ++ config/initializers/yelp.rb | 6 + config/routes.rb | 21 +++ db/migrate/20160516235127_create_users.rb | 8 + .../20160518000445_add_column_uid_provider.rb | 7 + db/schema.rb | 26 +++ lib/Tunes_Takeout.rb | 52 ++++++ test/controllers/home_controller_test.rb | 7 + test/controllers/sessions_controller_test.rb | 7 + .../suggestions_controller_test.rb | 7 + test/controllers/user_controller_test.rb | 7 + test/fixtures/users.yml | 11 ++ test/models/user_test.rb | 7 + 48 files changed, 1232 insertions(+), 22 deletions(-) create mode 100644 app/assets/javascripts/home.coffee create mode 100644 app/assets/javascripts/sessions.coffee create mode 100644 app/assets/javascripts/suggestions.coffee create mode 100644 app/assets/javascripts/user.coffee create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/assets/stylesheets/sessions.scss create mode 100644 app/assets/stylesheets/suggestions.scss create mode 100644 app/assets/stylesheets/user.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/controllers/suggestions_controller.rb create mode 100644 app/controllers/user_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/helpers/suggestions_helper.rb create mode 100644 app/helpers/user_helper.rb create mode 100644 app/models/food.rb create mode 100644 app/models/music.rb create mode 100644 app/models/user.rb create mode 100644 app/views/home/index.html.erb create mode 100644 app/views/sessions/new.html.erb create mode 100644 app/views/sessions/new2.html.erb create mode 100644 app/views/shared/_suggestion.html.erb create mode 100644 app/views/suggestions/favorites.html.erb create mode 100644 app/views/suggestions/index.html.erb create mode 100644 app/views/user/index.html.erb create mode 100644 app/views/user/show.html.erb create mode 100644 config/initializers/omniauth.rb create mode 100644 config/initializers/yelp.rb create mode 100644 db/migrate/20160516235127_create_users.rb create mode 100644 db/migrate/20160518000445_add_column_uid_provider.rb create mode 100644 db/schema.rb create mode 100644 lib/Tunes_Takeout.rb create mode 100644 test/controllers/home_controller_test.rb create mode 100644 test/controllers/sessions_controller_test.rb create mode 100644 test/controllers/suggestions_controller_test.rb create mode 100644 test/controllers/user_controller_test.rb create mode 100644 test/fixtures/users.yml create mode 100644 test/models/user_test.rb 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 d693196..3a82c55 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.3.0' +ruby '2.3.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.6' @@ -33,10 +33,16 @@ gem 'httparty' gem 'yelp', require: 'yelp' gem 'rspotify', require: 'rspotify' +gem 'rest-client' +gem "omniauth" +gem 'omniauth-spotify' +gem 'omniauth-oauth2', '~> 1.3.1' + + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' - + gem 'dotenv-rails' end @@ -47,6 +53,8 @@ group :development do gem 'pry-rails' gem 'erd' gem 'bootstrap-sass', '~>3.2.0' + gem "binding_of_caller" + gem "rest-client" # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end diff --git a/Gemfile.lock b/Gemfile.lock index 6b28ae1..ad2bdf2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,7 +46,7 @@ GEM bootstrap-sass (3.2.0.2) sass (~> 3.2) builder (3.2.2) - byebug (8.2.5) + byebug (9.0.3) choice (0.2.0) coderay (1.1.1) coffee-rails (4.1.1) @@ -58,6 +58,12 @@ GEM coffee-script-source (1.10.0) concurrent-ruby (1.0.2) debug_inspector (0.0.2) + domain_name (0.5.20160310) + unf (>= 0.0.5, < 1.0.0) + dotenv (2.1.1) + dotenv-rails (2.1.1) + dotenv (= 2.1.1) + railties (>= 4.0, < 5.1) erd (0.4.0) nokogiri rails-erd (>= 0.4.5) @@ -70,6 +76,8 @@ GEM globalid (0.3.6) activesupport (>= 4.1.0) hashie (3.4.4) + http-cookie (1.0.2) + domain_name (~> 0.5) httparty (0.13.7) json (~> 1.8) multi_xml (>= 0.5.2) @@ -88,15 +96,13 @@ GEM 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) + mime-types (2.99.1) mini_portile2 (2.0.0) - minitest (5.8.4) - multi_json (1.12.0) + minitest (5.9.0) + multi_json (1.12.1) multi_xml (0.5.5) multipart-post (2.0.0) - netrc (0.7.9) + netrc (0.11.0) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) oauth2 (1.1.0) @@ -108,9 +114,11 @@ GEM omniauth (1.3.1) hashie (>= 1.2, < 4) rack (>= 1.0, < 3) - omniauth-oauth2 (1.4.0) + 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) @@ -158,11 +166,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) + rest-client (1.8.0) + http-cookie (>= 1.0.2, < 2.0) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) + rspotify (1.18.0) + omniauth-oauth2 (~> 1.3.1) + rest-client (~> 1.7) ruby-graphviz (1.2.2) sass (3.4.22) sass-rails (5.0.4) @@ -186,11 +196,14 @@ GEM sprockets (>= 3.0.0) thor (0.19.1) thread_safe (0.3.5) - tilt (2.0.2) + tilt (2.0.4) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (3.0.0) execjs (>= 0.3.0, < 3) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.2) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) @@ -206,17 +219,23 @@ PLATFORMS DEPENDENCIES better_errors + binding_of_caller bootstrap-sass (~> 3.2.0) byebug coffee-rails (~> 4.1.0) + dotenv-rails erd httparty jbuilder (~> 2.0) jquery-rails + omniauth + omniauth-oauth2 (~> 1.3.1) + omniauth-spotify pg (~> 0.15) pry-rails rails (= 4.2.6) rails_12factor + rest-client rspotify sass-rails (~> 5.0) sdoc (~> 0.4.0) @@ -225,5 +244,8 @@ DEPENDENCIES web-console (~> 2.0) yelp +RUBY VERSION + ruby 2.3.1p112 + BUNDLED WITH - 1.12.3 + 1.12.4 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 646c5ab..9e320d8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,3 +13,10 @@ //= require jquery //= require jquery_ujs //= require_tree . +$(document).ready(function() { +$(".btn-pref .btn").click(function () { + $(".btn-pref .btn").removeClass("btn-primary").addClass("btn-default"); + // $(".tab").addClass("active"); // instead of this do the below + $(this).removeClass("btn-default").addClass("btn-primary"); +}); +}); diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/home.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/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 0000000..380e2e7 --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,64 @@ +# 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/ + +(function() { + + function login(callback) { + var CLIENT_ID = '6b284830006843e7ae7b170725715aed'; + var REDIRECT_URI = 'http://jmperezperez.com/spotify-oauth-jsfiddle-proxy/'; + function getLoginURL(scopes) { + return 'https://accounts.spotify.com/authorize?client_id=' + CLIENT_ID + + '&redirect_uri=' + encodeURIComponent(REDIRECT_URI) + + '&scope=' + encodeURIComponent(scopes.join(' ')) + + '&response_type=token'; + } + + var url = getLoginURL([ + 'user-read-email' + ]); + + var width = 450, + height = 730, + left = (screen.width / 2) - (width / 2), + top = (screen.height / 2) - (height / 2); + + window.addEventListener("message", function(event) { + var hash = JSON.parse(event.data); + if (hash.type == 'access_token') { + callback(hash.access_token); + } + }, false); + + var w = window.open(url, + 'Spotify', + 'menubar=no,location=no,resizable=no,scrollbars=no,status=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ); + + } + + function getUserData(accessToken) { + return $.ajax({ + url: 'https://api.spotify.com/v1/me', + headers: { + 'Authorization': 'Bearer ' + accessToken + } + }); + } + + var templateSource = document.getElementById('result-template').innerHTML, + template = Handlebars.compile(templateSource), + resultsPlaceholder = document.getElementById('result'), + loginButton = document.getElementById('btn-login'); + + loginButton.addEventListener('click', function() { + login(function(accessToken) { + getUserData(accessToken) + .then(function(response) { + loginButton.style.display = 'none'; + resultsPlaceholder.innerHTML = template(response); + }); + }); + }); + +})(); 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/javascripts/user.coffee b/app/assets/javascripts/user.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/user.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/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 0000000..684577d --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,30 @@ +// Place all the styles related to the users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.album-picture { + float: none; + margin: 0 auto; + width: 20%; + height: 20%; + -webkit-border-radius: 10% !important; + -moz-border-radius: 10% !important; + border-radius: 10% !important; +} + +.ranking{ + text-align: left; + padding: 0; +} + +.title { + text-transform: uppercase; + color: cadetblue; +} + + + img { + vertical-align: middle; + width: 20%; + +} diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000..d8e2c26 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,117 @@ +// 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/ + +.spotify_logo img{ + width: 100%; +} + +body{ + position:absolute; + width:100%; + height:100%; + margin:0; + padding:0; + background-image:url(http://www.matthewlewicki.com/codefest/images/spotify-background.jpg);} +h1{ + margin:0 0 .5em 0; + padding:0; + color:#fff; + font-family:helvetica; + font-size:30px; + font-weight:100; + letter-spacing:1px; + text-align:center; + text-shadow: 0 1px 2px rgba(0,0,0,1);} +section{ + position:relative; + top:50%; + width:300px; + max-width:96%; + margin:0 auto; + padding-top:120px; + -webkit-transform:translateY(-50%); + -ms-transform:translateY(-50%); + transform:translateY(-50%); + background-image:url(http://www.matthewlewicki.com/codefest/images/spotify-logo-small.png); + background-position:top center; + background-repeat:no-repeat; + background-size:100px;} +form{ + padding:0; + border-radius: 4px; + background-color:rgba(255,255,255,.75); + box-shadow: 0 2px 5px 0px rgba(38,38,38,0.5);} +fieldset{ + display: block; + width:100%; + margin:0 auto; + padding:1em 0 1em 0; + border: none; + border-bottom: 1px solid #ccc;} +fieldset:first-child{ + margin-bottom:0;} +fieldset:last-child{ + border-bottom: none; + margin-top:0; + padding:0;} +input{ + display:block; + width: 90%; + height:20px; + margin:0 auto; + padding: 5px 0; + color: #81b71a; + border: 1px solid #ccc; + text-align:center; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + -o-border-radius: 4px; + border-radius: 4px;} +input[type="submit"]{ + display: block; + -webkit-appearance: none; + -moz-appearance: none; + width:100%; + max-width:100% !important; + height:3em; + margin: 0 auto; + padding: 7px 5px 5px 5px; + background-color:#262626; + font-family: helvetica, arial, sans-serif; + font-size: 1em; + text-transform: uppercase; + text-align:center; + color:#81b71a; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border:none; + border-radius: 0 0 4px 4px; + -webkit-transition: all 0.5s ease-out; + -moz-transition: all 0.5s ease-out; + -o-transition: all 0.5s ease-out; + transition: all 0.5s ease-out;} +input[type="submit"]:hover{ + background-color: #333; + text-shadow:none;} +input::-webkit-input-placeholder{ + -webkit-transition: all 0.5s ease; + -moz-transition: all 0.5s ease; + -o-transition: all 0.5s ease; + transition: all 0.5s ease;} +input:hover::-webkit-input-placeholder{ + color:#81b71a;} +input:focus::-webkit-input-placeholder{ + opacity:0;} +input[type="text"]:focus,input[type="text"]:active,[type="password"]:focus,input[type="password"]:active{ + outline:0; + -webkit-appearance: none; + -moz-appearance: none; + border-image:none; + -moz-box-shadow: 0 0 20px rgba(129,183,26,0.5); + box-shadow: 0 0 20px rgba(129,183,26,0.5); + -webkit-animation: shadow-pulse 3s infinite ease-in-out;} +@-webkit-keyframes shadow-pulse { + 0% {-webkit-box-shadow: 0 0 20px rgba(129,183,26,0);} + 50% {-webkit-box-shadow: 0 0 20px rgba(129,183,26,1);} + 100% {-webkit-box-shadow: 0 0 20px rgba(129,183,26,0);}} diff --git a/app/assets/stylesheets/suggestions.scss b/app/assets/stylesheets/suggestions.scss new file mode 100644 index 0000000..3583dec --- /dev/null +++ b/app/assets/stylesheets/suggestions.scss @@ -0,0 +1,143 @@ +// 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/ +/* -------------------------------------------------- + :: General + -------------------------------------------------- */ +body { + font-family: 'Open Sans', sans-serif; + color: #353535; +} +.content h1 { + text-align: center; +} +.content .content-footer p { + color: #6d6d6d; + font-size: 12px; + text-align: center; +} +.content .content-footer p a { + color: inherit; + font-weight: bold; +} + +/* -------------------------------------------------- + :: Table Filter + -------------------------------------------------- */ +.panel { + border: 1px solid #ddd; + background-color: #fcfcfc; +} +.panel .btn-group { + margin: 15px 0 30px; +} +.panel .btn-group .btn { + transition: background-color .3s ease; +} +.table-filter { + background-color: #fff; + border-bottom: 1px solid #eee; +} +.table-filter tbody tr:hover { + cursor: pointer; + background-color: #eee; +} +.table-filter tbody tr td { + padding: 10px; + vertical-align: middle; + border-top-color: #eee; +} +.table-filter tbody tr.selected td { + background-color: #eee; +} +.table-filter tr td:first-child { + width: 38px; +} +.table-filter tr td:nth-child(2) { + width: 35px; +} +.ckbox { + position: relative; +} +.ckbox input[type="checkbox"] { + opacity: 0; +} +.ckbox label { + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} +.ckbox label:before { + content: ''; + top: 1px; + left: 0; + width: 18px; + height: 18px; + display: block; + position: absolute; + border-radius: 2px; + border: 1px solid #bbb; + background-color: #fff; +} +.ckbox input[type="checkbox"]:checked + label:before { + border-color: #2BBCDE; + background-color: #2BBCDE; +} +.ckbox input[type="checkbox"]:checked + label:after { + top: 3px; + left: 3.5px; + content: '\e013'; + color: #fff; + font-size: 11px; + font-family: 'Glyphicons Halflings'; + position: absolute; +} +.table-filter .star { + color: #ccc; + text-align: center; + display: block; +} +.table-filter .star.star-checked { + color: #F0AD4E; +} +.table-filter .star:hover { + color: #ccc; +} +.table-filter .star.star-checked:hover { + color: #F0AD4E; +} +.table-filter .media-photo { + width: 35px; +} +.table-filter .media-body { + display: block; + /* Had to use this style to force the div to expand (wasn't necessary with my bootstrap version 3.3.6) */ +} +.table-filter .media-meta { + font-size: 11px; + color: #999; +} +.table-filter .media .title { + color: #2BBCDE; + font-size: 14px; + font-weight: bold; + line-height: normal; + margin: 0; +} +.table-filter .media .title span { + font-size: .8em; + margin-right: 20px; +} +.table-filter .media .title span.pagado { + color: #5cb85c; +} +.table-filter .media .title span.pendiente { + color: #f0ad4e; +} +.table-filter .media .title span.cancelado { + color: #d9534f; +} +.table-filter .media .summary { + font-size: 14px; +} diff --git a/app/assets/stylesheets/user.scss b/app/assets/stylesheets/user.scss new file mode 100644 index 0000000..016e365 --- /dev/null +++ b/app/assets/stylesheets/user.scss @@ -0,0 +1,91 @@ +// Place all the styles related to the user controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +/* USER PROFILE PAGE */ + + +.col-sm-6 { + width: 100%; +} + + .card { + margin-top: 20px; + padding: 30px; + background-color: rgba(214, 224, 226, 0.2); + -webkit-border-top-left-radius:5px; + -moz-border-top-left-radius:5px; + border-top-left-radius:5px; + -webkit-border-top-right-radius:5px; + -moz-border-top-right-radius:5px; + border-top-right-radius:5px; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.card.hovercard { + position: relative; + padding-top: 0; + overflow: hidden; + text-align: center; + background-color: #fff; + background-color: rgba(255, 255, 255, 1); +} +.card.hovercard .card-background { + height: 130px; +} +.card-background img { + -webkit-filter: blur(25px); + -moz-filter: blur(25px); + -o-filter: blur(25px); + -ms-filter: blur(25px); + filter: blur(25px); + margin-left: -100px; + margin-top: -200px; + min-width: 130%; +} +.card.hovercard .useravatar { + position: absolute; + top: 15px; + left: 0; + right: 0; +} +.card.hovercard .useravatar img { + width: 100px; + height: 100px; + max-width: 100px; + max-height: 100px; + -webkit-border-radius: 50%; + -moz-border-radius: 50%; + border-radius: 50%; + border: 5px solid rgba(255, 255, 255, 0.5); +} +.card.hovercard .card-info { + position: absolute; + bottom: 14px; + left: 0; + right: 0; +} +.card.hovercard .card-info .card-title { + padding:0 5px; + font-size: 20px; + line-height: 1; + color: #262626; + background-color: rgba(255, 255, 255, 0.1); + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; +} +.card.hovercard .card-info { + overflow: hidden; + font-size: 12px; + line-height: 20px; + color: #737373; + text-overflow: ellipsis; +} +.card.hovercard .bottom { + padding: 0 20px; + margin-bottom: 17px; +} +.btn-pref .btn { + -webkit-border-radius:0 !important; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e..a0ba5e3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,21 @@ 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 + + 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 login_path + end + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 0000000..cd15f8b --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,7 @@ +class HomeController < ApplicationController + skip_before_action :require_login, only: [:index] + + def index + @top_twenty = TunesTakeout.top_suggestions(20) + end +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..44ce452 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,23 @@ +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 "/user/#{user.id}" + else + redirect_to root_path, notice: "Failed to save the user" + 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..55a350e --- /dev/null +++ b/app/controllers/suggestions_controller.rb @@ -0,0 +1,17 @@ +class SuggestionsController < ApplicationController + def index + # shows top 20 suggestions, ranked by total number of favorites + end + + def favorites + # shows all suggestions favorited by the signed-in User + end + + def favorite + # adds a suggestion into the favorite list for the signed-in User. This requires interaction with the Tunes & Takeout API. + end + + def unfavorite + # removes a suggestion from the favorite list for the signed-in User. This requires interaction with theTunes & Takeout API. + end +end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb new file mode 100644 index 0000000..eb528a4 --- /dev/null +++ b/app/controllers/user_controller.rb @@ -0,0 +1,11 @@ +class UserController < ApplicationController + + def new + @user = User.new + end + + def show + end + + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..852623f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def music_by_type + pairing = TunesTakeout.top_limit(20) + end end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 0000000..23de56a --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +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/helpers/user_helper.rb b/app/helpers/user_helper.rb new file mode 100644 index 0000000..0147c3f --- /dev/null +++ b/app/helpers/user_helper.rb @@ -0,0 +1,2 @@ +module UserHelper +end diff --git a/app/models/food.rb b/app/models/food.rb new file mode 100644 index 0000000..cd7df2e --- /dev/null +++ b/app/models/food.rb @@ -0,0 +1,14 @@ +require 'httparty' +require 'yelp' + + + +class Food + + # def yelp_find(id) + # parameters = { term: params[:term], limit: 16 } + # render json: Yelp.client.search(id, parameters) + # end + + +end diff --git a/app/models/music.rb b/app/models/music.rb new file mode 100644 index 0000000..76c84a5 --- /dev/null +++ b/app/models/music.rb @@ -0,0 +1,48 @@ +require 'httparty' +require 'rspotify' + +class Music + BASE_URL = "https://api.spotify.com" + ALBUM_PICTURE = "http://marcoscolamedia.com/wp-content/uploads/2015/12/Music-Album-Blank-.jpg" + attr_reader :item_id, :type, :name, :url, :image_url + + # def initialize(data) + # @item_id = data["item_id"] + # @type = data["moves"] + # @name = data["name"] + # @url = data["url"] + # @image_url = data["image_url"] + # + # end + + # def self.find(id) + # data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=banana").parsed_response + # self.new(data) + # end + + def self.find(type, id) + result = "RSpotify::#{type}".constantize.find(id) + end + + # def self.find(type, id) + # data = HTTParty.get(BASE_URL + "/v1/#{type}/#{id}").parsed_response + # artists = RSpotify::Artist.search('Arctic Monkeys') + # result = "RSpotify/#{type}".camelize.search(id) + # + # album = RSpotify::Album.search(id) + # + # end + def self.picture?(image) + if image.nil? + return ALBUM_PICTURE + elsif image[0].nil? + return ALBUM_PICTURE + else + image[0]["url"] + end + end + + + private + +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..38e60bb --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,24 @@ +require 'httparty' + +class User < ActiveRecord::Base + + validates :uid, :provider, presence: true + + def self.find_or_create_from_omniauth(auth_hash) + # find or create a user + user = User.find_by(uid: auth_hash["uid"], provider: auth_hash["provider"]) + if user + return user + else + # no user found + user = User.new + user.uid = auth_hash["uid"] + user.provider = auth_hash["provider"] + if user.save + return user + else + return nil + end + end + end +end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 0000000..8e7d462 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,36 @@ +

HELLO

+<% count = 1 %> +
+

Top Twenty Suggestions

+ + + + + + + + + + <% @top_twenty.each do |suggestion| %> + <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + + + + <% count += 1 %> + + + <% end %> + +
Ranking MusicRelease Date
<%= count %> +
+ <% 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" %> + + <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> +
+ <%= music.name%> +
+
+
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 7ba0ce9..8394221 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,12 +10,15 @@ - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> - + <%= yield %> diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000..f82b32f --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,24 @@ + + + + + + Spotify Login + + + <% if flash.now[:danger] %> +
<%= flash.now[:danger] %>
+ <% end %> +
+

Welcome to Tunes and Food

+

Log in with your Spotify account

+ + <%= link_to '/auth/spotify' do%> + + Sign in + <% end %> + + +
+ + diff --git a/app/views/sessions/new2.html.erb b/app/views/sessions/new2.html.erb new file mode 100644 index 0000000..9cd9d05 --- /dev/null +++ b/app/views/sessions/new2.html.erb @@ -0,0 +1,44 @@ + + + + + + Spotify Login + + + <% if flash.now[:danger] %> +
<%= flash.now[:danger] %>
+ <% end %> +
+

Welcome to Tunes and Food

+

Log in with your Spotify account

+ + <%= form_for :session, url: sign_in_path, class: "form" do |f| %> + +
+ <% f.email_field :email, :placeholder => "Email" %> +
+
+ <% f.password_field :password, :placeholder => "Password" %> +
+
+ <%= f.submit "Log in" %> +
+ <% end %> +
+

Search for an Artist

+

Type an artist name and click on "Search". Then, click on any album from the results to play 30 seconds of its first track.

+
+ + +
+
+
+ +
+ + diff --git a/app/views/shared/_suggestion.html.erb b/app/views/shared/_suggestion.html.erb new file mode 100644 index 0000000..d1aabb1 --- /dev/null +++ b/app/views/shared/_suggestion.html.erb @@ -0,0 +1,154 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pagado) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pendiente) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Cancelado) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pagado) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pendiente) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + diff --git a/app/views/suggestions/favorites.html.erb b/app/views/suggestions/favorites.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb new file mode 100644 index 0000000..dbda070 --- /dev/null +++ b/app/views/suggestions/index.html.erb @@ -0,0 +1 @@ +<%= render '/shared/suggestion' %> diff --git a/app/views/user/index.html.erb b/app/views/user/index.html.erb new file mode 100644 index 0000000..5443330 --- /dev/null +++ b/app/views/user/index.html.erb @@ -0,0 +1,46 @@ + diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb new file mode 100644 index 0000000..68133e8 --- /dev/null +++ b/app/views/user/show.html.erb @@ -0,0 +1,52 @@ +
+
+
+ + +
+
+ +
+
HI + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+

+ <%= form_tag(user_favorites_path(@user.id), :method => "get", id: "search-form") do %> + <%= text_field_tag :search, params[:search], placeholder: "Search Posts" %> + <%= hidden_field_tag :user_id, value: @user.id %> + <%= submit_tag "Search" %> + <% end %> +

+
+
+

This is tab 2

+
+
+

This is tab 3

+
+
+
+ +
diff --git a/config/application.rb b/config/application.rb index 9b37a86..950edb6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -6,8 +6,13 @@ # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -module TunesTakeout +module TunesTakeoutWrapper + 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..b85b26f --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,15 @@ + # config/initializers/omniauth.rb +Rails.application.config.middleware.use OmniAuth::Builder do + provider :spotify, ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"] +end + +# Rails.application.config.middleware.use OmniAuth::Builder do +# provider :yelp,:consumer_key => ENV["YELP_CONSUMER_KEY"],:consumer_secret => ENV["YELP_SECRET_KEY"],:token => ENV["TOKEN_KEY"],:token_secret => ENV["TOKEN_SECRET"] +# end +# +# 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 diff --git a/config/initializers/yelp.rb b/config/initializers/yelp.rb new file mode 100644 index 0000000..8d2c71a --- /dev/null +++ b/config/initializers/yelp.rb @@ -0,0 +1,6 @@ +# 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 diff --git a/config/routes.rb b/config/routes.rb index 3f66539..f0afa78 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,27 @@ 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 'home#index' + get "/sign_in" => "sessions#new", as: "sign_in" + get "/sign_in" => "sessions#create" + get "/auth/:provider/callback" => "sessions#create" + get "/logout" => "sessions#destroy", as: "logout" + + + get '/v1/suggestions/search' => "suggestions#index", as:"search" + + resources :user, only: [:show, :index] do + resources :favorites, :controller => "suggestions", :only => [:index, :show] + end + + resources :favorites, :controller => "suggestions", :only => [:index, :show] + + # resources :user, only: [:show] + # + # resources :favorites, :controller => "sessions" + + + # You can have the root of your site routed with "root" # root 'welcome#index' diff --git a/db/migrate/20160516235127_create_users.rb b/db/migrate/20160516235127_create_users.rb new file mode 100644 index 0000000..e1b6e50 --- /dev/null +++ b/db/migrate/20160516235127_create_users.rb @@ -0,0 +1,8 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name # could be a nickname from provider + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160518000445_add_column_uid_provider.rb b/db/migrate/20160518000445_add_column_uid_provider.rb new file mode 100644 index 0000000..b88e56c --- /dev/null +++ b/db/migrate/20160518000445_add_column_uid_provider.rb @@ -0,0 +1,7 @@ +class AddColumnUidProvider < ActiveRecord::Migration + def change + add_column :users, :uid, :string, null:false + add_column :users, :provider, :string, null:false + + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..6b6f820 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,26 @@ +# 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: 20160518000445) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "users", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "uid", null: false + t.string "provider", null: false + end + +end diff --git a/lib/Tunes_Takeout.rb b/lib/Tunes_Takeout.rb new file mode 100644 index 0000000..b70ee75 --- /dev/null +++ b/lib/Tunes_Takeout.rb @@ -0,0 +1,52 @@ +require "httparty" + +module TunesTakeout + + BASE_URL = "https://tunes-takeout-api.herokuapp.com/" + + attr_reader :id, :food_id, :music_id, :music_type + + # def initialize(data) + # @id = data["id"] + # @food_id s= data["food_id"] + # @music_id = data["music_id"] + # @music_type = data["music_type"] + # end + + + def self.search_results(search_word) + + data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=#{search_word}").parsed_response + # self.new(data) + end + + def self.top_suggestions(max_number) + data = HTTParty.get(BASE_URL + "/v1/suggestions/top?limit=#{max_number}").parsed_response["suggestions"] + data.map!{|suggestions| TunesTakeout.search_suggestions_by(suggestions)} + end + + def self.search_suggestions_by(id) + data = HTTParty.get(BASE_URL + "/v1/suggestions/#{id}").parsed_response + data["suggestion"] + + end + + def self.favorites_by_user_id(user_id) + data = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response + + end + + def self.user_suggestion(suggestion) + uri = URI(BASE_URL + "/v1/users/#{suggestion}/favorites") + res = Net::HTTP.post_form(uri, "suggestion" => suggestion) + puts res.body + data = HTTParty.post(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response + end + + + + # def self.find(id) + # data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=banana").parsed_response + # self.new(data) + # end +end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000..730478d --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class HomeControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end 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/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb new file mode 100644 index 0000000..674468e --- /dev/null +++ b/test/controllers/user_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end 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/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..82f61e0 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From dcbf31d70636f143ba98689c530c83160e4c0232 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Thu, 19 May 2016 17:29:26 -0700 Subject: [PATCH 3/6] connected to Yelp API --- .gitignore | 2 ++ app/models/food.rb | 10 ++++++---- app/models/music.rb | 22 ---------------------- app/views/home/index.html.erb | 13 +++++++++++++ config/initializers/omniauth.rb | 11 ----------- config/initializers/yelp.rb | 17 +++++++++++------ lib/Tunes_Takeout.rb | 22 +--------------------- 7 files changed, 33 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 882d639..edd0586 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,5 @@ build-iPhoneSimulator/ .rvmrc /.env + +config/initializers/yelp.rb diff --git a/app/models/food.rb b/app/models/food.rb index cd7df2e..a562bd9 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -5,10 +5,12 @@ class Food - # def yelp_find(id) - # parameters = { term: params[:term], limit: 16 } - # render json: Yelp.client.search(id, parameters) - # end + + def self.yelp_find_by_business(id) + data = Yelp.client.business(id).business + end + + # Yelp.client.search(id, parameters) end diff --git a/app/models/music.rb b/app/models/music.rb index 76c84a5..8ada4ee 100644 --- a/app/models/music.rb +++ b/app/models/music.rb @@ -6,32 +6,10 @@ class Music ALBUM_PICTURE = "http://marcoscolamedia.com/wp-content/uploads/2015/12/Music-Album-Blank-.jpg" attr_reader :item_id, :type, :name, :url, :image_url - # def initialize(data) - # @item_id = data["item_id"] - # @type = data["moves"] - # @name = data["name"] - # @url = data["url"] - # @image_url = data["image_url"] - # - # end - - # def self.find(id) - # data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=banana").parsed_response - # self.new(data) - # end - def self.find(type, id) result = "RSpotify::#{type}".constantize.find(id) end - # def self.find(type, id) - # data = HTTParty.get(BASE_URL + "/v1/#{type}/#{id}").parsed_response - # artists = RSpotify::Artist.search('Arctic Monkeys') - # result = "RSpotify/#{type}".camelize.search(id) - # - # album = RSpotify::Album.search(id) - # - # end def self.picture?(image) if image.nil? return ALBUM_PICTURE diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 8e7d462..0ba49e1 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -27,6 +27,19 @@ + +
+ <% 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" %> + + <%= link_to( image_tag(Food.yelp_find_by_business(suggestion["food_id"]).image_url), image_path(Food.yelp_find_by_business(suggestion["food_id"]).url)) %> +
+ <%= music.name%> +
+
+ + "> <% count += 1 %> diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index b85b26f..50883b9 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -2,14 +2,3 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :spotify, ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"] end - -# Rails.application.config.middleware.use OmniAuth::Builder do -# provider :yelp,:consumer_key => ENV["YELP_CONSUMER_KEY"],:consumer_secret => ENV["YELP_SECRET_KEY"],:token => ENV["TOKEN_KEY"],:token_secret => ENV["TOKEN_SECRET"] -# end -# -# 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 diff --git a/config/initializers/yelp.rb b/config/initializers/yelp.rb index 8d2c71a..e556298 100644 --- a/config/initializers/yelp.rb +++ b/config/initializers/yelp.rb @@ -1,6 +1,11 @@ -# 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 +YELP_CONSUMER_KEY = "ac7g1t3S2ra7hSKSzUnBJA" +YELP_CONSUMER_SECRET_KEY = "G5SXOND_2_fUW34keN447g5TofA" +YELP_TOKEN_KEY = "0R49YaxmEebNFcNdEimzhyRLg463crzi" +YELP_TOKEN_SECRET = "t84iDFoWTJXcXmT2JQg2naj4x_Y" + +Yelp.client.configure do |config| + config.consumer_key = YELP_CONSUMER_KEY + config.consumer_secret = YELP_CONSUMER_SECRET_KEY + config.token = YELP_TOKEN_KEY + config.token_secret = YELP_TOKEN_SECRET +end diff --git a/lib/Tunes_Takeout.rb b/lib/Tunes_Takeout.rb index b70ee75..b672b2a 100644 --- a/lib/Tunes_Takeout.rb +++ b/lib/Tunes_Takeout.rb @@ -4,20 +4,9 @@ module TunesTakeout BASE_URL = "https://tunes-takeout-api.herokuapp.com/" - attr_reader :id, :food_id, :music_id, :music_type - - # def initialize(data) - # @id = data["id"] - # @food_id s= data["food_id"] - # @music_id = data["music_id"] - # @music_type = data["music_type"] - # end - def self.search_results(search_word) - data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=#{search_word}").parsed_response - # self.new(data) end def self.top_suggestions(max_number) @@ -26,14 +15,11 @@ def self.top_suggestions(max_number) end def self.search_suggestions_by(id) - data = HTTParty.get(BASE_URL + "/v1/suggestions/#{id}").parsed_response - data["suggestion"] - + data = HTTParty.get(BASE_URL + "/v1/suggestions/#{id}").parsed_response["suggestion"] end def self.favorites_by_user_id(user_id) data = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response - end def self.user_suggestion(suggestion) @@ -43,10 +29,4 @@ def self.user_suggestion(suggestion) data = HTTParty.post(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response end - - - # def self.find(id) - # data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=banana").parsed_response - # self.new(data) - # end end From 864f089f1358f520a5f00630ac72196cee81bf9b Mon Sep 17 00:00:00 2001 From: Yordanos Date: Fri, 20 May 2016 10:59:31 -0700 Subject: [PATCH 4/6] finished the favorite tab on the users view which displays the users favorite suggestions --- app/assets/stylesheets/application.css | 11 ++ app/assets/stylesheets/home.scss | 7 +- app/assets/stylesheets/user.scss | 6 +- app/controllers/suggestions_controller.rb | 9 +- app/models/food.rb | 3 +- app/views/home/index.html.erb | 16 +- app/views/shared/_suggestion.html.erb | 196 +++++----------------- app/views/shared/_suggestion2.html.erb | 154 +++++++++++++++++ app/views/suggestions/index.html.erb | 99 ++++++++++- app/views/user/show.html.erb | 131 +++++++++++++-- config/routes.rb | 6 +- lib/Tunes_Takeout.rb | 11 +- 12 files changed, 469 insertions(+), 180 deletions(-) create mode 100644 app/views/shared/_suggestion2.html.erb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f9cd5b3..e08be1c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -13,3 +13,14 @@ *= require_tree . *= require_self */ + .album-picture{ + width: 20%; + margin: 0; + + + } + + img{ + width: 20%; + padding: 0; + } diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss index 684577d..cb52089 100644 --- a/app/assets/stylesheets/home.scss +++ b/app/assets/stylesheets/home.scss @@ -2,7 +2,9 @@ // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ -.album-picture { + + +.album-picture img{ float: none; margin: 0 auto; width: 20%; @@ -28,3 +30,6 @@ width: 20%; } +.image{ + width: 20%; +} diff --git a/app/assets/stylesheets/user.scss b/app/assets/stylesheets/user.scss index 016e365..d528a1b 100644 --- a/app/assets/stylesheets/user.scss +++ b/app/assets/stylesheets/user.scss @@ -41,7 +41,7 @@ filter: blur(25px); margin-left: -100px; margin-top: -200px; - min-width: 130%; + // min-width: 130%; } .card.hovercard .useravatar { position: absolute; @@ -89,3 +89,7 @@ .btn-pref .btn { -webkit-border-radius:0 !important; } + +.user-header-image{ + width: 100%; +} diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb index 55a350e..db3c395 100644 --- a/app/controllers/suggestions_controller.rb +++ b/app/controllers/suggestions_controller.rb @@ -3,8 +3,15 @@ def index # shows top 20 suggestions, ranked by total number of favorites end + def search + # @result = TunesTakeout.search_results(params["search"]) + redirect_to user_path(id: params["id"], suggestions_search: params["search"]) + end + def favorites - # shows all suggestions favorited by the signed-in User + @result = TunesTakeout.favorites_by_user_id(params["user_id"]) + redirect_to user_favorites_path(params["user_id"]) + end def favorite diff --git a/app/models/food.rb b/app/models/food.rb index a562bd9..92cc15e 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -1,12 +1,13 @@ require 'httparty' require 'yelp' - +require "erb" class Food def self.yelp_find_by_business(id) + id = ERB::Util.url_encode(id) data = Yelp.client.business(id).business end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 0ba49e1..993e01f 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -13,9 +13,11 @@ <% @top_twenty.each do |suggestion| %> <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> + <%= count %> - +
<% album_picture = music.images if music.type == "album" %> <% album_picture = music.images if music.type == "artist" %> @@ -27,19 +29,17 @@
- +
- <% 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" %> - <%= link_to( image_tag(Food.yelp_find_by_business(suggestion["food_id"]).image_url), image_path(Food.yelp_find_by_business(suggestion["food_id"]).url)) %> + + <%= link_to( image_tag(food.image_url), image_path(food.url)) %>
- <%= music.name%> + <%= food.name%>
- "> + <% count += 1 %> diff --git a/app/views/shared/_suggestion.html.erb b/app/views/shared/_suggestion.html.erb index d1aabb1..22e7c8f 100644 --- a/app/views/shared/_suggestion.html.erb +++ b/app/views/shared/_suggestion.html.erb @@ -1,154 +1,48 @@ +<% count = 1 %> + +
+

+ + + + + + + + + + <% result.each do |suggestion| %> + <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> + + + + + + + <% count += 1 %> + + <% end %> + +
Ranking MusicRelease Date
<%= count %> +
+ <% 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" %> + + <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> +
+ <%= music.name%> +
+
+
+
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -
-
- - - - -
- - - -
- Febrero 13, 2016 -

- Lorem Impsum - (Pagado) -

-

Ut enim ad minim veniam, quis nostrud exercitation...

-
-
-
-
- - -
-
- - - - -
- - - -
- Febrero 13, 2016 -

- Lorem Impsum - (Pendiente) -

-

Ut enim ad minim veniam, quis nostrud exercitation...

-
-
-
-
- - -
-
- - - - -
- - - -
- Febrero 13, 2016 -

- Lorem Impsum - (Cancelado) -

-

Ut enim ad minim veniam, quis nostrud exercitation...

-
-
-
-
- - -
-
- - - - -
- - - -
- Febrero 13, 2016 -

- Lorem Impsum - (Pagado) -

-

Ut enim ad minim veniam, quis nostrud exercitation...

-
-
-
-
- - -
-
- - - - -
- - - -
- Febrero 13, 2016 -

- Lorem Impsum - (Pendiente) -

-

Ut enim ad minim veniam, quis nostrud exercitation...

-
-
-
-
- +
diff --git a/app/views/shared/_suggestion2.html.erb b/app/views/shared/_suggestion2.html.erb new file mode 100644 index 0000000..d1aabb1 --- /dev/null +++ b/app/views/shared/_suggestion2.html.erb @@ -0,0 +1,154 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pagado) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pendiente) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Cancelado) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pagado) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + +
+
+ + + + +
+ + + +
+ Febrero 13, 2016 +

+ Lorem Impsum + (Pendiente) +

+

Ut enim ad minim veniam, quis nostrud exercitation...

+
+
+
+
+ + diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb index dbda070..2ceca47 100644 --- a/app/views/suggestions/index.html.erb +++ b/app/views/suggestions/index.html.erb @@ -1 +1,98 @@ -<%= render '/shared/suggestion' %> +
+
+
+ + +
+
+ +
+
HI + +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+

+ <%= form_tag(user_favorites_path(@user.id), :method => "post", id: "search-form") do %> + <%= text_field_tag :search, params[:search], placeholder: "Search Posts" %> + <%= hidden_field_tag :user_id, value: @user.id %> + <%= submit_tag "Search" %> + <% end %> +

+
+

+ + + + + + + + + + <% @result.each do |suggestion| %> + <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> + + + + + + + <% count += 1 %> + + <% end %> + +
Ranking MusicRelease Date
<%= count %> +
+ <% 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" %> + + <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> +
+ <%= music.name%> +
+
+
+
+ + + <%= link_to( image_tag(food.image_url), image_path(food.url)) %> +
+ <%= food.name%> +
+
+
+
+ +
+
+

This is tab 2

+ +
+
+

This is tab 3

+
+
+
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index 68133e8..015f466 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -1,7 +1,7 @@ -
+
- +
@@ -13,17 +13,18 @@
-
+ <%= link_to "", user_path(current_user.id)%>
-
@@ -33,16 +34,126 @@

- <%= form_tag(user_favorites_path(@user.id), :method => "get", id: "search-form") do %> + <%= form_tag(suggestions_search_path(@user.id), :method => "post", id: "search-form") do %> <%= text_field_tag :search, params[:search], placeholder: "Search Posts" %> <%= hidden_field_tag :user_id, value: @user.id %> <%= submit_tag "Search" %> <% end %> -

-
+ + <% if !params["suggestions_search"].nil? %> + <% @result = TunesTakeout.search_results(params["suggestions_search"]) %> + + <% count = 1 %> + +
+

+ + + + + + + + + + <% @result.each do |suggestion| %> + <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> + <% 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" %> + + + + + + <% count += 1 %> + + <% end %> + +
Rank TunesTakeout
<%= count %> +
+ <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> +
+ <%= music.name%> +
+
+
+
+ <%= link_to( image_tag(food.image_url), image_path(food.url)) %> +
+ <%= food.name%> +
+
+
+
+ + <% end %> + + +
+ + +
-

This is tab 2

-
+

This is tab 2 + <% @favorites = TunesTakeout.favorites_by_user_id(current_user.id) %> + + <% count = 1 %> + +
+

+ + + + + + + + + + <% @favorites.each do |suggestion| %> + <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> + <% 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" %> + + + + + + + <% count += 1 %> + + <% end %> + +
Rank TunesTakeout
<%= count %> +
+ + <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> +
+ <%= music.name%> +
+
+
+
+ + + <%= link_to( image_tag(food.image_url), image_path(food.url)) %> +
+ <%= food.name%> +
+
+
+
+ +

+ + + + +

This is tab 3

diff --git a/config/routes.rb b/config/routes.rb index f0afa78..ced09d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,13 +7,17 @@ get "/auth/:provider/callback" => "sessions#create" get "/logout" => "sessions#destroy", as: "logout" + post "/user/:id/search" => "suggestions#search", as:"suggestions_search" - get '/v1/suggestions/search' => "suggestions#index", as:"search" + get "/user/:id/search" => "suggestions#search", as:"suggestions_result" + + # get '/v1/suggestions/search' => "suggestions#index", as:"search" resources :user, only: [:show, :index] do resources :favorites, :controller => "suggestions", :only => [:index, :show] end + resources :favorites, :controller => "suggestions", :only => [:index, :show] # resources :user, only: [:show] diff --git a/lib/Tunes_Takeout.rb b/lib/Tunes_Takeout.rb index b672b2a..c7a9d3a 100644 --- a/lib/Tunes_Takeout.rb +++ b/lib/Tunes_Takeout.rb @@ -2,16 +2,16 @@ module TunesTakeout - BASE_URL = "https://tunes-takeout-api.herokuapp.com/" + BASE_URL = "https://tunes-takeout-api.herokuapp.com" def self.search_results(search_word) - data = HTTParty.get(BASE_URL + "v1/suggestions/search?query=#{search_word}").parsed_response + data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{search_word}").parsed_response["suggestions"] end def self.top_suggestions(max_number) data = HTTParty.get(BASE_URL + "/v1/suggestions/top?limit=#{max_number}").parsed_response["suggestions"] - data.map!{|suggestions| TunesTakeout.search_suggestions_by(suggestions)} + data.map!{|suggestion| TunesTakeout.search_suggestions_by(suggestion)} end def self.search_suggestions_by(id) @@ -19,10 +19,11 @@ def self.search_suggestions_by(id) end def self.favorites_by_user_id(user_id) - data = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response + data = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response["suggestions"] + data.map!{|suggestion| TunesTakeout.search_suggestions_by(suggestion)} end - def self.user_suggestion(suggestion) + def self.user_suggestion(user_id, suggestion) uri = URI(BASE_URL + "/v1/users/#{suggestion}/favorites") res = Net::HTTP.post_form(uri, "suggestion" => suggestion) puts res.body From f85fc6faa72a3188678d44f0050a8aeac06a4249 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Sun, 22 May 2016 11:44:24 -0700 Subject: [PATCH 5/6] added play button for artist and albums --- Gemfile | 5 ++ Gemfile.lock | 33 ++++++++ app/assets/javascripts/application.js | 61 ++++++++++++++ app/assets/stylesheets/suggestions.scss | 5 ++ app/assets/stylesheets/user.scss | 5 +- app/controllers/suggestions_controller.rb | 2 +- app/models/food.rb | 4 +- app/views/suggestions/index.html.erb | 49 ++++++++++++ app/views/user/show.html.erb | 97 +++++++++++++++++++++-- lib/Tunes_Takeout.rb | 17 ++-- test/models/user_test.rb | 15 +++- test/test_helper.rb | 16 ++++ 12 files changed, 288 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 3a82c55..9b7f1e7 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,11 @@ group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' gem 'dotenv-rails' + gem 'pry-rails' + gem 'minitest-vcr' + gem 'minitest-reporters' + gem 'webmock' + gem 'simplecov' end diff --git a/Gemfile.lock b/Gemfile.lock index ad2bdf2..f5ffd9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,8 @@ 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) @@ -57,7 +59,10 @@ 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) domain_name (0.5.20160310) unf (>= 0.0.5, < 1.0.0) dotenv (2.1.1) @@ -75,6 +80,7 @@ GEM faraday (>= 0.7.4, < 0.10) globalid (0.3.6) activesupport (>= 4.1.0) + hashdiff (0.3.0) hashie (3.4.4) http-cookie (1.0.2) domain_name (~> 0.5) @@ -98,7 +104,18 @@ GEM method_source (0.8.2) mime-types (2.99.1) mini_portile2 (2.0.0) + minispec-metadata (2.0.0) + minitest minitest (5.9.0) + 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.1) multi_xml (0.5.5) multipart-post (2.0.0) @@ -174,6 +191,8 @@ GEM omniauth-oauth2 (~> 1.3.1) rest-client (~> 1.7) 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) @@ -185,6 +204,11 @@ GEM 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) @@ -204,11 +228,16 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.2) + vcr (3.0.3) 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) @@ -228,6 +257,8 @@ DEPENDENCIES httparty jbuilder (~> 2.0) jquery-rails + minitest-reporters + minitest-vcr omniauth omniauth-oauth2 (~> 1.3.1) omniauth-spotify @@ -239,9 +270,11 @@ DEPENDENCIES rspotify sass-rails (~> 5.0) sdoc (~> 0.4.0) + simplecov spring uglifier (>= 1.3.0) web-console (~> 2.0) + webmock yelp RUBY VERSION diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9e320d8..4f6c679 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -20,3 +20,64 @@ $(".btn-pref .btn").click(function () { $(this).removeClass("btn-default").addClass("btn-primary"); }); }); + +(function() { + + function login(callback) { + var CLIENT_ID = '6b284830006843e7ae7b170725715aed'; + var REDIRECT_URI = 'http://jmperezperez.com/spotify-oauth-jsfiddle-proxy/'; + function getLoginURL(scopes) { + return 'https://accounts.spotify.com/authorize?client_id=' + CLIENT_ID + + '&redirect_uri=' + encodeURIComponent(REDIRECT_URI) + + '&scope=' + encodeURIComponent(scopes.join(' ')) + + '&response_type=token'; + } + + var url = getLoginURL([ + 'user-read-email' + ]); + + var width = 450, + height = 730, + left = (screen.width / 2) - (width / 2), + top = (screen.height / 2) - (height / 2); + + window.addEventListener("message", function(event) { + var hash = JSON.parse(event.data); + if (hash.type == 'access_token') { + callback(hash.access_token); + } + }, false); + + var w = window.open(url, + 'Spotify', + 'menubar=no,location=no,resizable=no,scrollbars=no,status=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ); + + } + + function getUserData(accessToken) { + return $.ajax({ + url: 'https://api.spotify.com/v1/me', + headers: { + 'Authorization': 'Bearer ' + accessToken + } + }); + } + + var templateSource = document.getElementById('result-template').innerHTML, + template = Handlebars.compile(templateSource), + resultsPlaceholder = document.getElementById('result'), + loginButton = document.getElementById('btn-login'); + + loginButton.addEventListener('click', function() { + login(function(accessToken) { + getUserData(accessToken) + .then(function(response) { + loginButton.style.display = 'none'; + resultsPlaceholder.innerHTML = template(response); + }); + }); + }); + +})(); diff --git a/app/assets/stylesheets/suggestions.scss b/app/assets/stylesheets/suggestions.scss index 3583dec..efbd90d 100644 --- a/app/assets/stylesheets/suggestions.scss +++ b/app/assets/stylesheets/suggestions.scss @@ -141,3 +141,8 @@ body { .table-filter .media .summary { font-size: 14px; } + +img{ + width: 20%; + +} diff --git a/app/assets/stylesheets/user.scss b/app/assets/stylesheets/user.scss index d528a1b..98b954e 100644 --- a/app/assets/stylesheets/user.scss +++ b/app/assets/stylesheets/user.scss @@ -91,5 +91,8 @@ } .user-header-image{ - width: 100%; + width: 20%; +} +.image_style{ + width: 20%; } diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb index db3c395..77c5f0e 100644 --- a/app/controllers/suggestions_controller.rb +++ b/app/controllers/suggestions_controller.rb @@ -4,7 +4,7 @@ def index end def search - # @result = TunesTakeout.search_results(params["search"]) + @result = TunesTakeout.search_results(params["search"]) redirect_to user_path(id: params["id"], suggestions_search: params["search"]) end diff --git a/app/models/food.rb b/app/models/food.rb index 92cc15e..eeccf93 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -4,14 +4,12 @@ class Food - + def self.yelp_find_by_business(id) id = ERB::Util.url_encode(id) data = Yelp.client.business(id).business end - # Yelp.client.search(id, parameters) - end diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb index 2ceca47..fa7479f 100644 --- a/app/views/suggestions/index.html.erb +++ b/app/views/suggestions/index.html.erb @@ -90,6 +90,55 @@

This is tab 2

+ +
+

+ + + + + + + + + + <% @result.each do |suggestion| %> + <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> + <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> + + + + + + + <% count += 1 %> + + <% end %> + +
Ranking MusicRelease Date
<%= count %> +
+ <% 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" %> + + <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> +
+ <%= music.name%> +
+
+
+
+ + + <%= link_to( image_tag(food.image_url), image_path(food.url)) %> +
+ <%= food.name%> +
+
+
+
+ +

This is tab 3

diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index 015f466..3fb5f56 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -1,4 +1,5 @@
+
@@ -6,6 +7,25 @@
+
HI @@ -56,34 +76,94 @@ + <% track = [] %> + <% @result.each do |suggestion| %> <% music = Music.find(suggestion["music_type"].capitalize, suggestion["music_id"]) %> <% food = Food.yelp_find_by_business(suggestion["food_id"]) %> <% 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" %> + <% @id_value = suggestion["music_id"]%> + <%= count %> + " onclick="changeImage('<%=@id_value%>')" src="http://thumb7.shutterstock.com/display_pic_with_logo/1280533/200698931/stock-vector-most-listened-favorite-icon-200698931.jpg" value = "" width="60%" > -
- <%= link_to( image_tag(Music.picture?(album_picture)), image_path( music.external_urls["spotify"] )) %> -
- <%= music.name%> -
+
+ "> +
+ <%= music.name%>
- +
+
- <%= link_to( image_tag(food.image_url), image_path(food.url)) %> +
<%= food.name%>
+ + <% count += 1 %> + + <% if music.type == "album" %> + + <% end %> + <% if music.type == "track" %> + <% track << music.id %> + <% end %> + <% if music.type == "artist" %> + + <% end %> + <% end %> + +
@@ -156,6 +236,9 @@

This is tab 3

+ <% track = track.join(",") %> + +
diff --git a/lib/Tunes_Takeout.rb b/lib/Tunes_Takeout.rb index c7a9d3a..bf4cfb2 100644 --- a/lib/Tunes_Takeout.rb +++ b/lib/Tunes_Takeout.rb @@ -1,4 +1,6 @@ require "httparty" +require "net/http" +# require "uri" module TunesTakeout @@ -23,11 +25,16 @@ def self.favorites_by_user_id(user_id) data.map!{|suggestion| TunesTakeout.search_suggestions_by(suggestion)} end - def self.user_suggestion(user_id, suggestion) - uri = URI(BASE_URL + "/v1/users/#{suggestion}/favorites") - res = Net::HTTP.post_form(uri, "suggestion" => suggestion) - puts res.body - data = HTTParty.post(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response + def self.user_suggestion(user_id, suggestion_id) + uri = URI(BASE_URL + "/v1/users/#{user_id}/favorites") + response = HTTParty.post(uri, :body => {"suggestion":"#{suggestion_id}"}.to_json, + :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'} ) + + if response.response.code == "201" + "favorite" + else + "not saved" + end end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 82f61e0..843a1b6 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,7 +1,14 @@ require 'test_helper' -class UserTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end +# class UserTest < ActiveSupport::TestCase +# # test "the truth" do +# # assert true +# # end +# end + + +describe User do + it "user has 'Spotify' as an API provider" do + assert_equal "Spotify", User.find(1).provider + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 92e39b2..4fff413 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,22 @@ 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" +require 'simplecov' + +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 From 09c8be8953be05370d120eba861c83a440955ec1 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Sun, 22 May 2016 21:26:04 -0700 Subject: [PATCH 6/6] finished some tests --- app/assets/stylesheets/user.scss | 6 + app/controllers/sessions_controller.rb | 1 + app/models/music.rb | 4 + app/views/user/show.html.erb | 45 +- ...valid_RSpotify_music_id_and_music_type.yml | 2352 +++++++++++++++ .../returns_a_valid_Yelp_food_id.yml | 2510 +++++++++++++++++ .../returns_top_twenty_suggestions.yml | 780 +++++ test/models/user_test.rb | 35 +- test/test_helper.rb | 4 +- 9 files changed, 5703 insertions(+), 34 deletions(-) create mode 100644 test/cassettes/TunesTakeout/returns_a_valid_RSpotify_music_id_and_music_type.yml create mode 100644 test/cassettes/TunesTakeout/returns_a_valid_Yelp_food_id.yml create mode 100644 test/cassettes/TunesTakeout/returns_top_twenty_suggestions.yml diff --git a/app/assets/stylesheets/user.scss b/app/assets/stylesheets/user.scss index 98b954e..9d9d94b 100644 --- a/app/assets/stylesheets/user.scss +++ b/app/assets/stylesheets/user.scss @@ -96,3 +96,9 @@ .image_style{ width: 20%; } + +.db{ + height: 80px; + position: relative; + border: 1px solid #282828; +} diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 44ce452..266fa1e 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -6,6 +6,7 @@ def new def create auth_hash = request.env['omniauth.auth'] + raise user = User.find_or_create_from_omniauth(auth_hash) if user session[:user_id] = user.id diff --git a/app/models/music.rb b/app/models/music.rb index 8ada4ee..9c5e935 100644 --- a/app/models/music.rb +++ b/app/models/music.rb @@ -10,6 +10,10 @@ def self.find(type, id) result = "RSpotify::#{type}".constantize.find(id) end + def self.user_info + data = HTTParty.get("https://api.spotify.com/v1/me").parsed_response + end + def self.picture?(image) if image.nil? return ALBUM_PICTURE diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index 3fb5f56..ed1af6d 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -89,39 +89,28 @@ <%= count %> " onclick="changeImage('<%=@id_value%>')" src="http://thumb7.shutterstock.com/display_pic_with_logo/1280533/200698931/stock-vector-most-listened-favorite-icon-200698931.jpg" value = "" width="60%" > - -
- "> -
- <%= music.name%> -
-
- - -
- -
- <%= food.name%> -
-
+ <% count += 1 %> + <% if music.type == "album" %> + <% elsif music.type == "track" %> + <% track << music.id %> + <% else %> + <% end %> + + <% raise %> + - - <% count += 1 %> +
+
+ - <% if music.type == "album" %> - <% end %> - <% if music.type == "track" %> - <% track << music.id %> - <% end %> - <% if music.type == "artist" %> - - <% end %> - <% end %> +