From 8dfa6b641ab881187183889c8062602e5fb4ce29 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Mon, 16 May 2016 16:00:45 -0700
Subject: [PATCH 01/20] made models and updated gemfiles with necessary gems
---
Gemfile | 5 ++++-
Gemfile.lock | 42 +++++++++++++++++++++++++++++++++++++++++-
app/models/food.rb | 1 +
app/models/music.rb | 1 +
app/models/user.rb | 1 +
5 files changed, 48 insertions(+), 2 deletions(-)
create mode 100644 app/models/food.rb
create mode 100644 app/models/music.rb
create mode 100644 app/models/user.rb
diff --git a/Gemfile b/Gemfile
index 288bb87..bfe38e2 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,6 +21,10 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
+gem 'httparty'
+gem 'rspotify'
+gem 'yelp', require: 'yelp'
+
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
@@ -42,4 +46,3 @@ group :development do
# 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 6ff0f39..6d371df 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -52,8 +52,16 @@ GEM
debug_inspector (0.0.2)
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,6 +71,7 @@ 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)
@@ -73,8 +82,23 @@ GEM
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)
rack (1.6.4)
rack-test (0.6.3)
@@ -106,6 +130,11 @@ 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)
sass (3.4.22)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
@@ -116,6 +145,7 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
+ simple_oauth (0.3.1)
spring (1.7.1)
sprockets (3.6.0)
concurrent-ruby (~> 1.0)
@@ -136,6 +166,10 @@ 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
@@ -143,15 +177,21 @@ PLATFORMS
DEPENDENCIES
byebug
coffee-rails (~> 4.1.0)
+ httparty
jbuilder (~> 2.0)
jquery-rails
pg (~> 0.15)
rails (= 4.2.6)
+ rspotify
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
uglifier (>= 1.3.0)
web-console (~> 2.0)
+ yelp
+
+RUBY VERSION
+ ruby 2.3.1p112
BUNDLED WITH
- 1.12.3
+ 1.12.4
diff --git a/app/models/food.rb b/app/models/food.rb
new file mode 100644
index 0000000..fcfd9f7
--- /dev/null
+++ b/app/models/food.rb
@@ -0,0 +1 @@
+require 'httparty'
diff --git a/app/models/music.rb b/app/models/music.rb
new file mode 100644
index 0000000..fcfd9f7
--- /dev/null
+++ b/app/models/music.rb
@@ -0,0 +1 @@
+require 'httparty'
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 0000000..fcfd9f7
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1 @@
+require 'httparty'
From a382c1431f6155a16977362e1cd75efb872572c7 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Mon, 16 May 2016 17:05:15 -0700
Subject: [PATCH 02/20] created controllers and started methods
---
app/assets/javascripts/sessions.coffee | 3 +++
app/assets/javascripts/suggestions.coffee | 3 +++
app/assets/stylesheets/sessions.scss | 3 +++
app/assets/stylesheets/suggestions.scss | 3 +++
app/controllers/sessions_controller.rb | 16 +++++++++++++
app/controllers/suggestions_controller.rb | 18 +++++++++++++++
app/helpers/sessions_helper.rb | 2 ++
app/helpers/suggestions_helper.rb | 2 ++
app/models/food.rb | 23 +++++++++++++++++++
app/models/music.rb | 15 ++++++++++++
app/models/user.rb | 4 ++++
test/controllers/sessions_controller_test.rb | 7 ++++++
.../suggestions_controller_test.rb | 7 ++++++
13 files changed, 106 insertions(+)
create mode 100644 app/assets/javascripts/sessions.coffee
create mode 100644 app/assets/javascripts/suggestions.coffee
create mode 100644 app/assets/stylesheets/sessions.scss
create mode 100644 app/assets/stylesheets/suggestions.scss
create mode 100644 app/controllers/sessions_controller.rb
create mode 100644 app/controllers/suggestions_controller.rb
create mode 100644 app/helpers/sessions_helper.rb
create mode 100644 app/helpers/suggestions_helper.rb
create mode 100644 test/controllers/sessions_controller_test.rb
create mode 100644 test/controllers/suggestions_controller_test.rb
diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/sessions.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/suggestions.coffee b/app/assets/javascripts/suggestions.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/suggestions.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss
new file mode 100644
index 0000000..7bef9cf
--- /dev/null
+++ b/app/assets/stylesheets/sessions.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the sessions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/suggestions.scss b/app/assets/stylesheets/suggestions.scss
new file mode 100644
index 0000000..c0d3b8d
--- /dev/null
+++ b/app/assets/stylesheets/suggestions.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the suggestions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
new file mode 100644
index 0000000..bc6e40b
--- /dev/null
+++ b/app/controllers/sessions_controller.rb
@@ -0,0 +1,16 @@
+class SessionsController < ApplicationController
+
+ def new
+ #shows a view with OAuth sign-in link
+ end
+
+ def create
+ #accepts OAuth information from Spotify, finds or creates a User account, and sets user_id in session
+ end
+
+ def destroy
+ #deletes user_id from session
+ # 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..69e0e66
--- /dev/null
+++ b/app/controllers/suggestions_controller.rb
@@ -0,0 +1,18 @@
+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 the Tunes & Takeout API.
+ 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
index fcfd9f7..e20a79b 100644
--- a/app/models/food.rb
+++ b/app/models/food.rb
@@ -1 +1,24 @@
require 'httparty'
+
+class Restaurant
+BASE_URL = "https://api.yelp.com/v2/"
+attr_reader :business_id, :name, :url, :image_url, :phone, :rating
+
+
+def initialize(data)
+ @business_id = data["business_id"]
+ @name = data["name"]
+ @url = data["url"]
+ @image_url = data["image_url"]
+ @phone = ["phone"]
+ @rating = ["rating"]
+end
+
+def self.find(id)
+ data = HTTParty.get(BASE_URL + "business/#{id}").parsed_response
+
+ self.new(data)
+end
+
+
+end
diff --git a/app/models/music.rb b/app/models/music.rb
index fcfd9f7..3de053d 100644
--- a/app/models/music.rb
+++ b/app/models/music.rb
@@ -1 +1,16 @@
require 'httparty'
+
+class Music
+#BASE_URL
+attr_reader :item_id, :name, :type, :image_url, :url
+
+
+def initialize(data)
+ @item_id = data["item_id"]
+ @name = data["name"]
+ @type = ["type"]
+ @image_url = data["image_url"]
+ @url = data["url"]
+end
+
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index fcfd9f7..c751cb3 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1 +1,5 @@
require 'httparty'
+
+# validates :name, presence: true #string?
+# validates :provider, presence: true #string and equal spotify?
+# validates :uid, presence: true
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
From a82966196a4d51eccc941b1ee5f9e29280c03e3b Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Tue, 17 May 2016 23:54:29 -0700
Subject: [PATCH 03/20] made queries for pairing suggestions
---
.env | 4 ++
Gemfile | 8 +++-
Gemfile.lock | 48 +++++++++++++++++++-
app/controllers/suggestions_controller.rb | 22 +++++++++
app/models/food.rb | 27 +++++++----
app/models/music.rb | 33 ++++++++++----
app/models/user.rb | 3 ++
app/views/suggestions/index.html.erb | 12 +++++
config/routes.rb | 55 ++---------------------
db/schema.rb | 19 ++++++++
lib/TunesTakeoutWrapper.rb | 21 +++++++++
11 files changed, 182 insertions(+), 70 deletions(-)
create mode 100644 .env
create mode 100644 app/views/suggestions/index.html.erb
create mode 100644 db/schema.rb
create mode 100644 lib/TunesTakeoutWrapper.rb
diff --git a/.env b/.env
new file mode 100644
index 0000000..48ee554
--- /dev/null
+++ b/.env
@@ -0,0 +1,4 @@
+YELP_CONSUMER_KEY: RC-dbM2zuKUQmpuXSeYp5A
+YELP_CONSUMER_SECRET: O_YOLmwe2o1IwVsl4-hUVvQn0dM
+YELP_TOKEN: fa72RCZMt4-Y6j7B6xNJj3OvH6Gz8L_0
+YELP_TOKEN_SECRET: 23zr83d8CCHLGiyBaVxDPdSh1O0
diff --git a/Gemfile b/Gemfile
index bfe38e2..73cf571 100644
--- a/Gemfile
+++ b/Gemfile
@@ -36,12 +36,18 @@ gem 'yelp', require: 'yelp'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
- gem 'byebug'
+ gem 'pry-rails'
+ gem 'minitest-vcr'
+ gem 'minitest-reporters'
+ gem 'webmock' #mocking library (around HTTP transactions, webmock is pretending to be HTTP)
+ 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'
diff --git a/Gemfile.lock b/Gemfile.lock
index 6d371df..b75a3b0 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -36,11 +36,17 @@ 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,7 +55,13 @@ 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)
+ 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)
@@ -58,6 +70,7 @@ GEM
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)
@@ -76,11 +89,23 @@ GEM
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)
@@ -100,6 +125,12 @@ GEM
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)
@@ -135,6 +166,8 @@ GEM
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)
@@ -146,6 +179,7 @@ GEM
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)
@@ -161,11 +195,16 @@ GEM
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)
@@ -175,12 +214,16 @@ PLATFORMS
ruby
DEPENDENCIES
- byebug
+ better_errors
coffee-rails (~> 4.1.0)
+ dotenv-rails
httparty
jbuilder (~> 2.0)
jquery-rails
+ minitest-reporters
+ minitest-vcr
pg (~> 0.15)
+ pry-rails
rails (= 4.2.6)
rspotify
sass-rails (~> 5.0)
@@ -188,6 +231,7 @@ DEPENDENCIES
spring
uglifier (>= 1.3.0)
web-console (~> 2.0)
+ webmock
yelp
RUBY VERSION
diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb
index 69e0e66..e6ac4cc 100644
--- a/app/controllers/suggestions_controller.rb
+++ b/app/controllers/suggestions_controller.rb
@@ -1,9 +1,31 @@
+require 'TunesTakeoutWrapper'
+require 'Food'
+require 'Music'
+
+
class SuggestionsController < ApplicationController
def index
+ #shows form to search by keyword
#shows top 20 suggestions, ranked by total number of favorites
end
+ def create
+ #raise make sure the form is working first
+ pairing_query = params["food_pairing_query"]
+
+ pairing = TunesTakeoutWrapper.find(pairing_query)
+
+ food_item = Restaurant.find(pairing.food_id)
+
+ song = Music.find(pairing.music_id)
+
+ redirect_to suggestions_path
+
+ #take the keyword and go to Charles' API i guess??
+ end
+
+
def favorites
#shows all suggestions favorited by the signed-in User
end
diff --git a/app/models/food.rb b/app/models/food.rb
index e20a79b..f85e502 100644
--- a/app/models/food.rb
+++ b/app/models/food.rb
@@ -1,21 +1,32 @@
-require 'httparty'
+require 'yelp'
+
+
+#A plain Ruby object that receives and models data retrieved from the Yelp Search API. Wraps interactions with the Yelp Search API by leveraging the Yelp-Ruby gem.
class Restaurant
+
+ CLIENT = Yelp::Client.new({ consumer_key: ENV["YELP_CONSUMER_KEY"],
+ consumer_secret: ENV["YELP_CONSUMER_SECRET"],
+ token: ENV["YELP_TOKEN"],
+ token_secret: ENV["YELP_TOKEN_SECRET"]
+ })
+
+
BASE_URL = "https://api.yelp.com/v2/"
attr_reader :business_id, :name, :url, :image_url, :phone, :rating
def initialize(data)
- @business_id = data["business_id"]
- @name = data["name"]
- @url = data["url"]
- @image_url = data["image_url"]
- @phone = ["phone"]
- @rating = ["rating"]
+ @business_id = data.business.id
+ @name = data.business.name
+ @url = data.business.url
+ @image_url = data.business.image_url
+ @phone = data.business.phone
+ @rating = data.business.rating
end
def self.find(id)
- data = HTTParty.get(BASE_URL + "business/#{id}").parsed_response
+ data = CLIENT.business(id)
self.new(data)
end
diff --git a/app/models/music.rb b/app/models/music.rb
index 3de053d..dd5d9ce 100644
--- a/app/models/music.rb
+++ b/app/models/music.rb
@@ -1,16 +1,33 @@
require 'httparty'
+require 'rspotify'
+
+# A plain Ruby object that receives and models data retrieved from the Spotify API. Wraps interactions with the Spotify API by leveraging the RSpotify gem. NOTE: Data retrieved from Spotify may describe an artist, album, track, or playlist.
class Music
-#BASE_URL
attr_reader :item_id, :name, :type, :image_url, :url
-def initialize(data)
- @item_id = data["item_id"]
- @name = data["name"]
- @type = ["type"]
- @image_url = data["image_url"]
- @url = data["url"]
-end
+ def initialize(data) #data.length on data array is 20, for the keyword "banana"...i just chose [0] from the data array ...should it be an each loop here instead? Is that what they meant by the 20 favorite? :/
+ @item_id = data[0].id
+ @name = data[0].name #this is weird...do a raise and look at it
+ @type = data[0].type
+ @image_url = data[0].images[0]["url"] #there are multiple url's in the image hash
+ @external_url = data[0].external_urls
+
+ end
+
+ def self.find(id)
+ data = RSpotify::Artist.search("id")
+
+ self.new(data)
+ end
+
+
+ #data = RSpotify::Artist.find('1WGWUsR3u4DpQEaE8zWwcr') #this is a specific one** make it generic based on what you get back from charles' stuff(tunestakeoutwrapper)/somehow talk to eachother
+ #data = HTTParty.get("https://api.spotify.com/v1/artists/1WGWUsR3u4DpQEaE8zWwcr").parsed_response
end
+
+
+#rspotify docs tell you all thing things you can call with rspotify
+#RSpotify::Artist.find('1WGWUsr3U4Dp'
diff --git a/app/models/user.rb b/app/models/user.rb
index c751cb3..fe17940 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,5 +1,8 @@
require 'httparty'
+#A signed-in user account, created via OmniAuth and connected to a Spotify account.
+
+
# validates :name, presence: true #string?
# validates :provider, presence: true #string and equal spotify?
# validates :uid, presence: true
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
new file mode 100644
index 0000000..1e45b24
--- /dev/null
+++ b/app/views/suggestions/index.html.erb
@@ -0,0 +1,12 @@
+Search suggestions by keyword:
+<%= form_tag suggestions_path do %>
+ <%= label_tag :food_pairing_query %>
+ <%= text_field_tag :food_pairing_query %>
+ <%=submit_tag %>
+<% end %>
+
+<%= params %>
+
+<% if pairing_query %>
+ you're pairing is: <%= #{food_item} %> and <%= #{song} %>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 3f66539..4a4d8d2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,56 +1,9 @@
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".
+#on the main page we ask them where they are?
- # You can have the root of your site routed with "root"
- # root 'welcome#index'
+ #search Charles' API site?? is this a patch/update?
+ # get '/monster/:id' =>
- # Example of regular route:
- # get 'products/:id' => 'catalog#view'
+ resources :suggestions, only: [:index, :create]
- # Example of named route that can be invoked with purchase_url(id: product.id)
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
-
- # Example resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Example resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Example resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Example resource route with more complex sub-resources:
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', on: :collection
- # end
- # end
-
- # Example resource route with concerns:
- # concern :toggleable do
- # post 'toggle'
- # end
- # resources :posts, concerns: :toggleable
- # resources :photos, concerns: :toggleable
-
- # Example resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000..ea89ed5
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,19 @@
+# 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: 0) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+end
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
new file mode 100644
index 0000000..0c1bb43
--- /dev/null
+++ b/lib/TunesTakeoutWrapper.rb
@@ -0,0 +1,21 @@
+#this is like the pokemon thing he made yesterday.... but he made it in his models
+
+require 'httparty'
+
+class TunesTakeoutWrapper
+ BASE_URL = "https://tunes-takeout-api.herokuapp.com/"
+ attr_reader :id, :food_id, :music_id, :music_type
+
+ def initialize(data)
+ @id = data["suggestions"][0]["id"]
+ @food_id = data["suggestions"][0]["food_id"]
+ @music_id = data["suggestions"][0]["music_id"]
+ @music_type = data["suggestions"][0]["music_type"]
+ end
+
+ def self.find(item)
+ data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{item}&limit=1").parsed_response
+ self.new(data)
+ end
+
+end
From 8f51241a0585e60cbf3160ae4e12c17217a1baea Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Wed, 18 May 2016 17:28:56 -0700
Subject: [PATCH 04/20] got the api requests workng and printing out the
results on the index page
---
app/controllers/suggestions_controller.rb | 18 ++++++++++++------
app/models/music.rb | 22 ++++++++++++++--------
app/views/suggestions/index.html.erb | 8 +++++---
lib/TunesTakeoutWrapper.rb | 4 +++-
4 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb
index e6ac4cc..79ec13b 100644
--- a/app/controllers/suggestions_controller.rb
+++ b/app/controllers/suggestions_controller.rb
@@ -6,23 +6,29 @@
class SuggestionsController < ApplicationController
def index
+ # @pairing = params["pairing"]
+ # @food_item = params["food_item"]
+ # @song = params["song"]
#shows form to search by keyword
#shows top 20 suggestions, ranked by total number of favorites
+ #instances of the items found
end
def create
#raise make sure the form is working first
- pairing_query = params["food_pairing_query"]
+ #if params["pairing_query"].present?
+ params["pairing_query"] = params["food_pairing_query"]
- pairing = TunesTakeoutWrapper.find(pairing_query)
+ params["pairing"] = TunesTakeoutWrapper.find(params["pairing_query"])
- food_item = Restaurant.find(pairing.food_id)
+ params["food_item"] = Restaurant.find(params["pairing"].food_id)
- song = Music.find(pairing.music_id)
+ params["song"] = Music.find(params["pairing"].music_type,params["pairing"].music_id) #music_type
+
+
+ render :index
- redirect_to suggestions_path
- #take the keyword and go to Charles' API i guess??
end
diff --git a/app/models/music.rb b/app/models/music.rb
index dd5d9ce..578a7cb 100644
--- a/app/models/music.rb
+++ b/app/models/music.rb
@@ -5,19 +5,25 @@
class Music
attr_reader :item_id, :name, :type, :image_url, :url
-
+#where do i put in my tokens?
def initialize(data) #data.length on data array is 20, for the keyword "banana"...i just chose [0] from the data array ...should it be an each loop here instead? Is that what they meant by the 20 favorite? :/
- @item_id = data[0].id
- @name = data[0].name #this is weird...do a raise and look at it
- @type = data[0].type
- @image_url = data[0].images[0]["url"] #there are multiple url's in the image hash
- @external_url = data[0].external_urls
+ @item_id = data.id
+ @name = data.name #this is weird...do a raise and look at it
+ @type = data.type
+ #@image_url = data.images[0]["url"] #there are multiple url's in the image hash
+ @external_url = data.external_urls
end
- def self.find(id)
- data = RSpotify::Artist.search("id")
+ def self.find(music_type,music_id)
+ if music_type == "track"
+ data = RSpotify::Track.find(music_id) #sometimes quotes work here, sometimes they dont....
+ elsif music_type == "album"
+ data = RSpotify::Album.find(music_id)
+ elsif music_type == "artist"
+ data = RSpotify::Artist.find(music_id)
+ end
self.new(data)
end
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 1e45b24..376025c 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -1,5 +1,5 @@
Search suggestions by keyword:
-<%= form_tag suggestions_path do %>
+<%= form_tag do %>
<%= label_tag :food_pairing_query %>
<%= text_field_tag :food_pairing_query %>
<%=submit_tag %>
@@ -7,6 +7,8 @@
<%= params %>
-<% if pairing_query %>
- you're pairing is: <%= #{food_item} %> and <%= #{song} %>
+<% if params["pairing"].present? %>
+ Your pairing suggestions for <%= params["pairing_query"] %> are:
+ artist: <%= params["song"].name %>
+ food: <%= params["food_item"].name %>
<% end %>
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index 0c1bb43..4b5131c 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -11,10 +11,12 @@ def initialize(data)
@food_id = data["suggestions"][0]["food_id"]
@music_id = data["suggestions"][0]["music_id"]
@music_type = data["suggestions"][0]["music_type"]
+
end
+
def self.find(item)
- data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{item}&limit=1").parsed_response
+ data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{item}").parsed_response
self.new(data)
end
From 8c7e2e5a153e6c38ceaa6f7e0491f91e96f3f288 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Thu, 19 May 2016 15:05:42 -0700
Subject: [PATCH 05/20] have sessions and api requests working.
---
.env | 10 +++++--
.gitignore | 2 +-
Gemfile | 3 ++
Gemfile.lock | 12 ++++++--
app/assets/javascripts/favorites.coffee | 3 ++
app/assets/stylesheets/favorites.scss | 3 ++
app/controllers/application_controller.rb | 5 ++++
app/controllers/favorites_controller.rb | 15 ++++++++++
app/controllers/sessions_controller.rb | 29 +++++++++++++++----
app/controllers/suggestions_controller.rb | 9 ++++--
app/helpers/favorites_helper.rb | 2 ++
app/models/user.rb | 22 ++++++++++++++
app/views/favorites/success_huh.html.erb | 4 +++
app/views/layouts/application.html.erb | 8 +++++
app/views/suggestions/index.html.erb | 14 +++++++++
config/initializers/omniauth.rb | 4 +++
config/routes.rb | 7 +++++
db/migrate/20160519211717_create_users.rb | 9 ++++++
db/schema.rb | 8 ++++-
lib/TunesTakeoutWrapper.rb | 8 ++++-
test/controllers/favorites_controller_test.rb | 7 +++++
21 files changed, 169 insertions(+), 15 deletions(-)
create mode 100644 app/assets/javascripts/favorites.coffee
create mode 100644 app/assets/stylesheets/favorites.scss
create mode 100644 app/controllers/favorites_controller.rb
create mode 100644 app/helpers/favorites_helper.rb
create mode 100644 app/views/favorites/success_huh.html.erb
create mode 100644 config/initializers/omniauth.rb
create mode 100644 db/migrate/20160519211717_create_users.rb
create mode 100644 test/controllers/favorites_controller_test.rb
diff --git a/.env b/.env
index 48ee554..c865e35 100644
--- a/.env
+++ b/.env
@@ -1,4 +1,10 @@
YELP_CONSUMER_KEY: RC-dbM2zuKUQmpuXSeYp5A
YELP_CONSUMER_SECRET: O_YOLmwe2o1IwVsl4-hUVvQn0dM
-YELP_TOKEN: fa72RCZMt4-Y6j7B6xNJj3OvH6Gz8L_0
-YELP_TOKEN_SECRET: 23zr83d8CCHLGiyBaVxDPdSh1O0
+YELP_TOKEN: KERJPZzNUilFm-RRMdk9V-90kxzYO213
+YELP_TOKEN_SECRET: uLfJRgRSyUporozYTKebsZ81Asc
+
+
+
+CLIENT_ID: 84d3407e199f4c9bbbfe6e6e51b9fe0a
+
+CLIENT_SECRET: 84c0798ce9b94370a384d263efccc892
diff --git a/.gitignore b/.gitignore
index 03f3ce7..dcd300f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,7 +26,7 @@
/tmp/
# Used by dotenv library to load environment variables.
-# .env
+ /.env
## Specific to RubyMotion:
.dat*
diff --git a/Gemfile b/Gemfile
index 73cf571..afd9e5b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,9 +21,12 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
+gem 'simplecov'
+
gem 'httparty'
gem 'rspotify'
gem 'yelp', require: 'yelp'
+gem 'omniauth-oauth2', '1.3.1'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
diff --git a/Gemfile.lock b/Gemfile.lock
index b75a3b0..171bd64 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -58,6 +58,7 @@ GEM
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)
@@ -106,7 +107,7 @@ GEM
minispec-metadata (~> 2.0)
minitest (>= 4.7.5)
vcr (>= 2.9)
- multi_json (1.12.0)
+ multi_json (1.12.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
netrc (0.7.9)
@@ -121,7 +122,7 @@ 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)
pg (0.18.4)
@@ -179,6 +180,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)
@@ -222,12 +228,14 @@ DEPENDENCIES
jquery-rails
minitest-reporters
minitest-vcr
+ omniauth-oauth2 (= 1.3.1)
pg (~> 0.15)
pry-rails
rails (= 4.2.6)
rspotify
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
+ simplecov
spring
uglifier (>= 1.3.0)
web-console (~> 2.0)
diff --git a/app/assets/javascripts/favorites.coffee b/app/assets/javascripts/favorites.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/favorites.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/favorites.scss b/app/assets/stylesheets/favorites.scss
new file mode 100644
index 0000000..819decf
--- /dev/null
+++ b/app/assets/stylesheets/favorites.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the favorites 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..25db5ec 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,4 +2,9 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
+ helper_method :current_user
+
+ def current_user
+ @user ||= User.find_by(id: session[:user_id])
+ end
end
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
new file mode 100644
index 0000000..c2bfed8
--- /dev/null
+++ b/app/controllers/favorites_controller.rb
@@ -0,0 +1,15 @@
+class FavoritesController < ApplicationController
+
+ def create
+ status_code = TunesTakeoutWrapper.add_favorite(1, params["suggestion_id"]) #session["user_id"]
+
+ if status_code == 201
+ @message = "Favorite sucessfully added!"
+ else
+ @message = "Sorry, we were unable to save your favorite at this time."
+ end
+
+ render :success_huh
+ end
+
+end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index bc6e40b..e1e2b94 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,16 +1,35 @@
class SessionsController < ApplicationController
+ #skip_before_action :require_login, only: [:new, :create]
def new
- #shows a view with OAuth sign-in link
end
def create
- #accepts OAuth information from Spotify, finds or creates a User account, and sets user_id in session
+ auth_hash = request.env['omniauth.auth'] #omniauth puts data it gets from github into this hash (request variables from github)
+ if auth_hash[:info][:id]
+ @user = User.find_or_create_from_omniauth(auth_hash)
+ if @user
+ session[:user_id] = @user.id
+ redirect_to suggestions_path
+ else
+ redirect_to suggestions_path, notice: "Failed to save the user"
+ end
+
+ else
+ redirect_to suggestions_path, notice: "Failed to authenticate"
+ end
+
+ #user = User.log_in(params[:email], params[:password])
+ # if user
+ # session[:user_id] = user.id
+ # redirect_to root_path
+ # else
+ # render :new
+ # end
end
def destroy
- #deletes user_id from session
- # session.delete :user_id
- # redirect_to root_path
+ session.delete :user_id
+ redirect_to root_path
end
end
diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb
index 79ec13b..f08bc1e 100644
--- a/app/controllers/suggestions_controller.rb
+++ b/app/controllers/suggestions_controller.rb
@@ -6,9 +6,10 @@
class SuggestionsController < ApplicationController
def index
- # @pairing = params["pairing"]
- # @food_item = params["food_item"]
- # @song = params["song"]
+ @pairing = params["pairing"]
+ @food_item = params["food_item"]
+ @song = params["song"]
+
#shows form to search by keyword
#shows top 20 suggestions, ranked by total number of favorites
#instances of the items found
@@ -17,6 +18,8 @@ def index
def create
#raise make sure the form is working first
#if params["pairing_query"].present?
+ #@pairing...better practice, shouldn't store stuffs in the params.
+
params["pairing_query"] = params["food_pairing_query"]
params["pairing"] = TunesTakeoutWrapper.find(params["pairing_query"])
diff --git a/app/helpers/favorites_helper.rb b/app/helpers/favorites_helper.rb
new file mode 100644
index 0000000..4e9a950
--- /dev/null
+++ b/app/helpers/favorites_helper.rb
@@ -0,0 +1,2 @@
+module FavoritesHelper
+end
diff --git a/app/models/user.rb b/app/models/user.rb
index fe17940..c9725c4 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,3 +6,25 @@
# validates :name, presence: true #string?
# validates :provider, presence: true #string and equal spotify?
# validates :uid, presence: true
+
+class User < ActiveRecord::Base
+ validates :uid, :provider, :name, presence: true
+
+ def self.find_or_create_from_omniauth(auth_hash)
+ #Find or create a user:
+ @user = User.find_by(uid: auth_hash[:info][:id], provider: auth_hash[:provider])
+ #will give a user if it matches those two parameters
+ if !@user.nil?
+ return @user
+ else
+ # no user found, do something here
+ @user = User.new(name: auth_hash[:info][:display_name], uid: auth_hash[:info][:id], provider: auth_hash[:provider])
+
+ if @user.save
+ return @user
+ else
+ return nil
+ end
+ end
+ end
+end
diff --git a/app/views/favorites/success_huh.html.erb b/app/views/favorites/success_huh.html.erb
new file mode 100644
index 0000000..426b78d
--- /dev/null
+++ b/app/views/favorites/success_huh.html.erb
@@ -0,0 +1,4 @@
+<%= @message %>
+
+
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 509d1a2..d0548a2 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -6,6 +6,14 @@
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
+
+
+<% if current_user.nil? %>
+<%= link_to "Sign In With Spotify", "/auth/spotify" %>
+<% else %>
+<%= link_to "Sign Out", logout_path, method: :delete %>
+<% end %>
+
<%= yield %>
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 376025c..2b998a4 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -1,3 +1,13 @@
+
+<% if current_user.nil? %>
+ Welcome, guest!
+ You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
+<% else %>
+ Welcome, <%= current_user.name %>!
+
+<% end %>
+
+
Search suggestions by keyword:
<%= form_tag do %>
<%= label_tag :food_pairing_query %>
@@ -11,4 +21,8 @@
Your pairing suggestions for <%= params["pairing_query"] %> are:
artist: <%= params["song"].name %>
food: <%= params["food_item"].name %>
+
+
+ <%# button_to "Favorite", action: favorites_path(params["pairing"].id), :controller => "favorite" %>
+ <%= link_to "Favorite", favorites_path(params["pairing"].id), method: :post %>
<% end %>
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
new file mode 100644
index 0000000..f37b672
--- /dev/null
+++ b/config/initializers/omniauth.rb
@@ -0,0 +1,4 @@
+# config/initializers/omniauth.rb
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :spotify, ENV["CLIENT_ID"], ENV["CLIENT_SECRET"]
+end
diff --git a/config/routes.rb b/config/routes.rb
index 4a4d8d2..73c8357 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -6,4 +6,11 @@
resources :suggestions, only: [:index, :create]
+ post '/favorites/:suggestion_id' => 'favorites#create', as: 'favorites'
+
+ resources :sessions, :only => [:create]
+ get "/auth/:provider/callback" => "sessions#create"
+ delete "/logout" => "sessions#destroy", as: 'logout'
+
+
end
diff --git a/db/migrate/20160519211717_create_users.rb b/db/migrate/20160519211717_create_users.rb
new file mode 100644
index 0000000..bee9e2c
--- /dev/null
+++ b/db/migrate/20160519211717_create_users.rb
@@ -0,0 +1,9 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :name, null: false
+ t.string :uid, null: false
+ t.string :provider, null: false #must equal spotify?????
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ea89ed5..3fde1ad 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,9 +11,15 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 0) do
+ActiveRecord::Schema.define(version: 20160519211717) 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.string "name", null: false
+ t.string "uid", null: false
+ t.string "provider", null: false
+ end
+
end
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index 4b5131c..6ec0c69 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -11,7 +11,7 @@ def initialize(data)
@food_id = data["suggestions"][0]["food_id"]
@music_id = data["suggestions"][0]["music_id"]
@music_type = data["suggestions"][0]["music_type"]
-
+
end
@@ -20,4 +20,10 @@ def self.find(item)
self.new(data)
end
+ def self.add_favorite(user_id, suggestion_id)
+ body_data = {"suggestion": suggestion_id}
+ response = HTTParty.post(BASE_URL + "/v1/users/#{user_id}/favorites", body: body_data)
+ return response.code
+ end
+
end
diff --git a/test/controllers/favorites_controller_test.rb b/test/controllers/favorites_controller_test.rb
new file mode 100644
index 0000000..8736e37
--- /dev/null
+++ b/test/controllers/favorites_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FavoritesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
From 735db88429e6c77498af680866498bfc8cba54f3 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Fri, 20 May 2016 12:42:46 -0700
Subject: [PATCH 06/20] finally got the home page to top 20 favorited results
---
app/assets/images/spotify.jpeg | Bin 0 -> 6041 bytes
app/controllers/favorites_controller.rb | 7 +++-
app/controllers/sessions_controller.rb | 9 ++---
app/controllers/suggestions_controller.rb | 23 ++++++++-----
app/models/music.rb | 11 +++++-
app/models/user.rb | 6 +++-
app/views/favorites/success_huh.html.erb | 3 +-
app/views/layouts/application.html.erb | 2 ++
app/views/suggestions/_suggestion.html.erb | 16 +++++++++
app/views/suggestions/index.html.erb | 15 +++++---
.../20160519224408_add_image_to_user.rb | 5 +++
db/schema.rb | 3 +-
lib/TunesTakeoutWrapper.rb | 32 ++++++++++++++----
13 files changed, 103 insertions(+), 29 deletions(-)
create mode 100644 app/assets/images/spotify.jpeg
create mode 100644 app/views/suggestions/_suggestion.html.erb
create mode 100644 db/migrate/20160519224408_add_image_to_user.rb
diff --git a/app/assets/images/spotify.jpeg b/app/assets/images/spotify.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..2afb1404cf65139aed55572a95469ad4da30f550
GIT binary patch
literal 6041
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
+<%= @status_code %>
-
+<%= link_to "back", suggestions_path)%>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index d0548a2..31b68c7 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -10,8 +10,10 @@
<% if current_user.nil? %>
<%= link_to "Sign In With Spotify", "/auth/spotify" %>
+<%= image_tag "spotify.jpeg" %>
<% else %>
<%= link_to "Sign Out", logout_path, method: :delete %>
+<%= image_tag current_user.image %>
<% end %>
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
new file mode 100644
index 0000000..23e3450
--- /dev/null
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -0,0 +1,16 @@
+
+
+food:
+ <%= link_to food_suggestion.name, food_suggestion.url %>
+
+
+ <%= image_tag food_suggestion.image_url %>
+
+
+
+ this <%= music_suggestion.type %>:
+ <%= link_to music_suggestion.name, music_suggestion.url %>
+
+ <%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
+
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 2b998a4..6530613 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -17,12 +17,17 @@
<%= params %>
-<% if params["pairing"].present? %>
- Your pairing suggestions for <%= params["pairing_query"] %> are:
- artist: <%= params["song"].name %>
- food: <%= params["food_item"].name %>
+<% if @pairing.present? %>
+ Your pairing suggestions for <%= @pairing_query %> are:
+ artist: <%= @song.name %>
+ food: <%= @food_item.name %>
<%# button_to "Favorite", action: favorites_path(params["pairing"].id), :controller => "favorite" %>
- <%= link_to "Favorite", favorites_path(params["pairing"].id), method: :post %>
+ <%= link_to "Favorite", favorites_path(@pairing.id), method: :post %>
+<% end %>
+
+ Top 20 Favorites
+<% @top20.each do |suggestion| %>
+ <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type, suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id) %>
<% end %>
diff --git a/db/migrate/20160519224408_add_image_to_user.rb b/db/migrate/20160519224408_add_image_to_user.rb
new file mode 100644
index 0000000..ca32b2b
--- /dev/null
+++ b/db/migrate/20160519224408_add_image_to_user.rb
@@ -0,0 +1,5 @@
+class AddImageToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :image, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3fde1ad..d383147 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160519211717) do
+ActiveRecord::Schema.define(version: 20160519224408) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -20,6 +20,7 @@
t.string "name", null: false
t.string "uid", null: false
t.string "provider", null: false
+ t.string "image"
end
end
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index 6ec0c69..fa19faf 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -7,23 +7,43 @@ class TunesTakeoutWrapper
attr_reader :id, :food_id, :music_id, :music_type
def initialize(data)
- @id = data["suggestions"][0]["id"]
- @food_id = data["suggestions"][0]["food_id"]
- @music_id = data["suggestions"][0]["music_id"]
- @music_type = data["suggestions"][0]["music_type"]
+ @id = data["suggestion"]["id"]
+ @food_id = data["suggestion"]["food_id"]
+ @music_id = data["suggestion"]["music_id"]
+ @music_type = data["suggestion"]["music_type"]
end
def self.find(item)
- data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{item}").parsed_response
+ data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{item}&limit=1/").parsed_response
+ data["suggestion"] = data.delete("suggestions")
+ data["suggestion"] = data["suggestion"][0]
self.new(data)
end
def self.add_favorite(user_id, suggestion_id)
- body_data = {"suggestion": suggestion_id}
+ body_data = {"suggestion": suggestion_id}.to_json
response = HTTParty.post(BASE_URL + "/v1/users/#{user_id}/favorites", body: body_data)
return response.code
end
+ def self.top
+ data = HTTParty.get(BASE_URL + "/v1/suggestions/top").parsed_response
+
+ suggestion_pairings = []
+ data["suggestions"].each do |suggestion|
+ suggestion_pairings << HTTParty.get(BASE_URL + "/v1/suggestions/#{suggestion}").parsed_response
+ end
+
+ suggestion_instances = []
+ suggestion_pairings.each do |pairing|
+ suggestion_instances << self.new(pairing)
+ end
+
+ return suggestion_instances
+
+ end
+
+
end
From 14c74e1f27f04bc76deea413f302d4f9dd23ff66 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Fri, 20 May 2016 15:20:56 -0700
Subject: [PATCH 07/20] fixed the links to spotify for the top 20 results
---
app/controllers/favorites_controller.rb | 4 ++--
app/controllers/suggestions_controller.rb | 3 ++-
app/models/music.rb | 3 ++-
app/views/favorites/success_huh.html.erb | 3 +--
app/views/suggestions/_suggestion.html.erb | 1 +
app/views/suggestions/index.html.erb | 1 +
lib/TunesTakeoutWrapper.rb | 2 +-
7 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 5b0833e..647de19 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -4,7 +4,7 @@
class FavoritesController < ApplicationController
def create
- status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], params["suggestion_id"]) #session["user_id"]
+ status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], params["suggestion_id"])
if status_code == 201
@message = "Favorite sucessfully added!"
@@ -13,7 +13,7 @@ def create
end
@status_code = status_code
-
+
render :success_huh
end
diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb
index 9c31674..8e57220 100644
--- a/app/controllers/suggestions_controller.rb
+++ b/app/controllers/suggestions_controller.rb
@@ -33,7 +33,8 @@ def create
@song = Music.find(@pairing.music_type,@pairing.music_id)
#params["song"] = Music.find(params["pairing"].music_type,params["pairing"].music_id) #music_type
-
+ @top20 = TunesTakeoutWrapper.top
+
render :index
diff --git a/app/models/music.rb b/app/models/music.rb
index f7ddc06..53f3b90 100644
--- a/app/models/music.rb
+++ b/app/models/music.rb
@@ -18,7 +18,7 @@ def initialize(data) #data.length on data array is 20, for the keyword "banana"
data.album.images[0]["url"]
else
#PLACEHOLDER_IMG_URL
- @external_url = data.external_urls
+ @url = data.external_urls.values[0]
end
end
@@ -33,6 +33,7 @@ def self.find(music_type,music_id)
end
self.new(data)
+
end
diff --git a/app/views/favorites/success_huh.html.erb b/app/views/favorites/success_huh.html.erb
index 4ee20b7..2e349d0 100644
--- a/app/views/favorites/success_huh.html.erb
+++ b/app/views/favorites/success_huh.html.erb
@@ -1,5 +1,4 @@
<%= @message %>
<%= @status_code %>
-
-<%= link_to "back", suggestions_path)%>
+<%= link_to "back", suggestions_path(params["suggestion_id"])%>
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index 23e3450..a201f55 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -12,5 +12,6 @@ food:
<%= link_to music_suggestion.name, music_suggestion.url %>
<%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
+
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 6530613..370825b 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -30,4 +30,5 @@
Top 20 Favorites
<% @top20.each do |suggestion| %>
<%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type, suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id) %>
+
<% end %>
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index fa19faf..0579066 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -42,7 +42,7 @@ def self.top
end
return suggestion_instances
-
+
end
From ce84ff571b70bf69f3dc5f3a5310367920694743 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sat, 21 May 2016 16:57:56 -0700
Subject: [PATCH 08/20] got unfavorites working, started listing the users
favorites...
---
app/controllers/favorites_controller.rb | 30 +++++++++++++++++--
app/controllers/suggestions_controller.rb | 3 +-
app/models/music.rb | 6 ++--
...html.erb => favorite_success_huh.html.erb} | 0
.../favorites/unfavorite_success_huh.html.erb | 4 +++
app/views/favorites/your_favorites.html.erb | 0
app/views/suggestions/_suggestion.html.erb | 3 +-
app/views/suggestions/index.html.erb | 11 ++++---
config/routes.rb | 2 ++
lib/TunesTakeoutWrapper.rb | 13 +++++++-
10 files changed, 60 insertions(+), 12 deletions(-)
rename app/views/favorites/{success_huh.html.erb => favorite_success_huh.html.erb} (100%)
create mode 100644 app/views/favorites/unfavorite_success_huh.html.erb
create mode 100644 app/views/favorites/your_favorites.html.erb
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 647de19..a16cb10 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -8,13 +8,39 @@ def create
if status_code == 201
@message = "Favorite sucessfully added!"
+ elsif status_code == 409
+ @message = "You've already favorited this pairing."
else
@message = "Sorry, we were unable to save your favorite at this time."
end
@status_code = status_code
-
- render :success_huh
+
+ render :favorite_success_huh
+ end
+
+
+ def destroy
+ status_code = TunesTakeoutWrapper.unfavorite(session[:user_id], params["suggestion_id"])
+
+ if status_code == 204
+ @message = "You've unfavorited this pairing."
+ elsif status_code == 404
+ @message = "This pairing wasn't one of your favorites."
+ elsif status_code == 400
+ @message = "Sorry, we could not unfavorite this pairing at this time."
+ end
+
+ @status_code = status_code
+
+ render :unfavorite_success_huh
+
end
+ def your_favorites
+ @favorites = TunesTakeoutWrapper.favorites
+
+
+
+ end
end
diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb
index 8e57220..e3f3b2c 100644
--- a/app/controllers/suggestions_controller.rb
+++ b/app/controllers/suggestions_controller.rb
@@ -14,6 +14,7 @@ def index
#shows form to search by keyword
#shows top 20 suggestions, ranked by total number of favorites
#instances of the items found
+
end
def create
@@ -34,7 +35,7 @@ def create
#params["song"] = Music.find(params["pairing"].music_type,params["pairing"].music_id) #music_type
@top20 = TunesTakeoutWrapper.top
-
+
render :index
diff --git a/app/models/music.rb b/app/models/music.rb
index 53f3b90..dd5d521 100644
--- a/app/models/music.rb
+++ b/app/models/music.rb
@@ -4,7 +4,7 @@
# A plain Ruby object that receives and models data retrieved from the Spotify API. Wraps interactions with the Spotify API by leveraging the RSpotify gem. NOTE: Data retrieved from Spotify may describe an artist, album, track, or playlist.
class Music
-attr_reader :item_id, :name, :type, :image_url, :url
+attr_reader :item_id, :name, :type, :image_url, :url, :uri
#where do i put in my tokens?
#PLACEHOLDER_IMG_URL = " webs"
@@ -20,6 +20,7 @@ def initialize(data) #data.length on data array is 20, for the keyword "banana"
#PLACEHOLDER_IMG_URL
@url = data.external_urls.values[0]
end
+ @uri = data.uri
end
@@ -31,9 +32,8 @@ def self.find(music_type,music_id)
elsif music_type == "artist"
data = RSpotify::Artist.find(music_id)
end
-
self.new(data)
-
+
end
diff --git a/app/views/favorites/success_huh.html.erb b/app/views/favorites/favorite_success_huh.html.erb
similarity index 100%
rename from app/views/favorites/success_huh.html.erb
rename to app/views/favorites/favorite_success_huh.html.erb
diff --git a/app/views/favorites/unfavorite_success_huh.html.erb b/app/views/favorites/unfavorite_success_huh.html.erb
new file mode 100644
index 0000000..2e349d0
--- /dev/null
+++ b/app/views/favorites/unfavorite_success_huh.html.erb
@@ -0,0 +1,4 @@
+<%= @message %>
+
+<%= @status_code %>
+<%= link_to "back", suggestions_path(params["suggestion_id"])%>
diff --git a/app/views/favorites/your_favorites.html.erb b/app/views/favorites/your_favorites.html.erb
new file mode 100644
index 0000000..e69de29
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index a201f55..435d1b5 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -12,6 +12,7 @@ food:
<%= link_to music_suggestion.name, music_suggestion.url %>
<%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
-
+
+
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 370825b..5d54beb 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -7,6 +7,7 @@
<% end %>
+<%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
Search suggestions by keyword:
<%= form_tag do %>
@@ -19,16 +20,18 @@
<% if @pairing.present? %>
Your pairing suggestions for <%= @pairing_query %> are:
- artist: <%= @song.name %>
- food: <%= @food_item.name %>
+ Music: <%= @song.name %>
+ Restaurant: <%= @food_item.name %>
<%# button_to "Favorite", action: favorites_path(params["pairing"].id), :controller => "favorite" %>
<%= link_to "Favorite", favorites_path(@pairing.id), method: :post %>
+
+ <%= link_to "Unfavorite", unfavorites_path(@pairing.id), method: :destroy %>
+
<% end %>
Top 20 Favorites
<% @top20.each do |suggestion| %>
- <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type, suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id) %>
-
+ <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type, suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :uri_sugggestion => Music.find(suggestion.music_type, suggestion.music_id) %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 73c8357..14e9c52 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -7,6 +7,8 @@
resources :suggestions, only: [:index, :create]
post '/favorites/:suggestion_id' => 'favorites#create', as: 'favorites'
+ delete '/favorites/:suggestion_id' => 'favorites#destroy', as: 'unfavorites'
+ get 'favorites/:user_id' => 'favorites#your_favorites', as: 'your_favorites'
resources :sessions, :only => [:create]
get "/auth/:provider/callback" => "sessions#create"
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index 0579066..7df6058 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -28,6 +28,17 @@ def self.add_favorite(user_id, suggestion_id)
return response.code
end
+ def self.unfavorite(user_id, suggestion_id)
+ body_data = {"suggestion": suggestion_id}.to_json
+ response = HTTParty.delete(BASE_URL + "/v1/users/#{user_id}/favorites", body: body_data)
+ return response.code
+ end
+
+ def self.your_favorites(user_id)
+ favorites = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response
+ raise
+ end
+
def self.top
data = HTTParty.get(BASE_URL + "/v1/suggestions/top").parsed_response
@@ -42,7 +53,7 @@ def self.top
end
return suggestion_instances
-
+
end
From 681e355eda0553bac682a5efd861f684b3d5e587 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 15:18:32 -0700
Subject: [PATCH 09/20] I got it showing favorites for a user, but broke the
ability to favorite and unfavorite....I've been staring at it for 4 hours and
I have no clue why @pairing isnt being passed from the link_to through the
routes into the controller.....I'm getting 400 status code everytime and it
seems not to know @pairing nor params[suggestion_id] once i make the post
request to favorite and get routed into the controller method.....not really
sure why
---
app/controllers/favorites_controller.rb | 8 ++---
app/controllers/suggestions_controller.rb | 38 +++++++++++++++++++--
app/views/favorites/your_favorites.html.erb | 8 +++++
app/views/suggestions/_suggestion.html.erb | 5 +--
app/views/suggestions/favorite.html.erb | 4 +++
app/views/suggestions/favorites.html.erb | 8 +++++
app/views/suggestions/index.html.erb | 8 ++---
app/views/suggestions/unfavorite.html.erb | 4 +++
config/routes.rb | 6 ++--
lib/TunesTakeoutWrapper.rb | 28 +++++++++++++--
10 files changed, 98 insertions(+), 19 deletions(-)
create mode 100644 app/views/suggestions/favorite.html.erb
create mode 100644 app/views/suggestions/favorites.html.erb
create mode 100644 app/views/suggestions/unfavorite.html.erb
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index a16cb10..72117d3 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -4,7 +4,7 @@
class FavoritesController < ApplicationController
def create
- status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], params["suggestion_id"])
+ status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], @pairing.id)
if status_code == 201
@message = "Favorite sucessfully added!"
@@ -21,8 +21,7 @@ def create
def destroy
- status_code = TunesTakeoutWrapper.unfavorite(session[:user_id], params["suggestion_id"])
-
+ status_code = TunesTakeoutWrapper.unfavorite(session[:user_id], @pairing.id)
if status_code == 204
@message = "You've unfavorited this pairing."
elsif status_code == 404
@@ -38,7 +37,8 @@ def destroy
end
def your_favorites
- @favorites = TunesTakeoutWrapper.favorites
+ @favorites = TunesTakeoutWrapper.your_favorites(session[:user_id])
+
diff --git a/app/controllers/suggestions_controller.rb b/app/controllers/suggestions_controller.rb
index e3f3b2c..462d85e 100644
--- a/app/controllers/suggestions_controller.rb
+++ b/app/controllers/suggestions_controller.rb
@@ -43,14 +43,46 @@ def create
def favorites
- #shows all suggestions favorited by the signed-in User
+ @favorites = TunesTakeoutWrapper.your_favorites(session[:user_id])
end
+
def favorite
- #adds a suggestion into the favorite list for the signed-in User. This requires interaction with the Tunes & Takeout API.
+ user = User.find(session[:user_id])
+ user_id = user.uid
+ status_code = TunesTakeoutWrapper.add_favorite(user_id, params["suggestion_id"])
+ # status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], params["suggestion_id"])
+
+ if status_code == 201
+ @message = "Favorite sucessfully added!"
+ elsif status_code == 409
+ @message = "You've already favorited this pairing."
+ else
+ @message = "Sorry, we were unable to save your favorite at this time."
+ end
+
+ @status_code = status_code
+
end
+
def unfavorite
- #removes a suggestion from the favorite list for the signed-in User. This requires interaction with the Tunes & Takeout API.
+ user = User.find(session[:user_id])
+ user_id = user.uid
+ suggestion_id = params["suggestion_id"]
+ status_code = TunesTakeoutWrapper.unfavorite(user_id,suggestion_id)
+
+ # status_code = TunesTakeoutWrapper.unfavorite(session[:user_id], params["suggestion_id"])
+
+ if status_code == 204
+ @message = "You've unfavorited this pairing."
+ elsif status_code == 404
+ @message = "This pairing wasn't one of your favorites."
+ elsif status_code == 400
+ @message = "Sorry, we could not unfavorite this pairing at this time."
+ end
+
+ @status_code = status_code
+
end
end
diff --git a/app/views/favorites/your_favorites.html.erb b/app/views/favorites/your_favorites.html.erb
index e69de29..f9dc5c6 100644
--- a/app/views/favorites/your_favorites.html.erb
+++ b/app/views/favorites/your_favorites.html.erb
@@ -0,0 +1,8 @@
+
+<% @favorites.each do |suggestion| %>
+ <%= render "suggestion", :music_suggestion => SpotifyItem.find(suggestion.music_type,suggestion.music_id), :food_suggestion => FoodItem.find(suggestion.food_id), :suggestion_id => suggestion.id %>
+<% end %>
+
+<% if @favorites.empty? %>
+ No favorites yet, why not add some?
+<% end %>
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index 435d1b5..7fb6889 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -14,5 +14,6 @@ food:
<%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
-
+
+
+
diff --git a/app/views/suggestions/favorite.html.erb b/app/views/suggestions/favorite.html.erb
new file mode 100644
index 0000000..2e349d0
--- /dev/null
+++ b/app/views/suggestions/favorite.html.erb
@@ -0,0 +1,4 @@
+<%= @message %>
+
+<%= @status_code %>
+<%= link_to "back", suggestions_path(params["suggestion_id"])%>
diff --git a/app/views/suggestions/favorites.html.erb b/app/views/suggestions/favorites.html.erb
new file mode 100644
index 0000000..38f4684
--- /dev/null
+++ b/app/views/suggestions/favorites.html.erb
@@ -0,0 +1,8 @@
+
+<% @favorites.each do |suggestion| %>
+ <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type,suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :suggestion_id => suggestion.id %>
+<% end %>
+
+<% if @favorites.empty? %>
+ No favorites yet, why not add some?
+<% end %>
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 5d54beb..eb80485 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -23,15 +23,13 @@
Music: <%= @song.name %>
Restaurant: <%= @food_item.name %>
+ <%= link_to "Favorite", favorite_path(@pairing.id), method: :post %>
+ <%= link_to "Unfavorite", unfavorite_path(@pairing.id), method: :delete %>
- <%# button_to "Favorite", action: favorites_path(params["pairing"].id), :controller => "favorite" %>
- <%= link_to "Favorite", favorites_path(@pairing.id), method: :post %>
-
- <%= link_to "Unfavorite", unfavorites_path(@pairing.id), method: :destroy %>
<% end %>
Top 20 Favorites
<% @top20.each do |suggestion| %>
- <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type, suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :uri_sugggestion => Music.find(suggestion.music_type, suggestion.music_id) %>
+ <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type, suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :uri_sugggestion => Music.find(suggestion.music_type, suggestion.music_id), :suggestion_id => suggestion.id %>
<% end %>
diff --git a/app/views/suggestions/unfavorite.html.erb b/app/views/suggestions/unfavorite.html.erb
new file mode 100644
index 0000000..2e349d0
--- /dev/null
+++ b/app/views/suggestions/unfavorite.html.erb
@@ -0,0 +1,4 @@
+<%= @message %>
+
+<%= @status_code %>
+<%= link_to "back", suggestions_path(params["suggestion_id"])%>
diff --git a/config/routes.rb b/config/routes.rb
index 14e9c52..b98da55 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -6,9 +6,9 @@
resources :suggestions, only: [:index, :create]
- post '/favorites/:suggestion_id' => 'favorites#create', as: 'favorites'
- delete '/favorites/:suggestion_id' => 'favorites#destroy', as: 'unfavorites'
- get 'favorites/:user_id' => 'favorites#your_favorites', as: 'your_favorites'
+ post 'favorite' => 'favorites#create', as: 'favorite'
+ delete 'unfavorite' => 'favorites#destroy', as: 'unfavorite'
+ get 'favorites' => 'suggestions#favorites', as: 'your_favorites'
resources :sessions, :only => [:create]
get "/auth/:provider/callback" => "sessions#create"
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index 7df6058..207ea16 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -19,26 +19,50 @@ def self.find(item)
data = HTTParty.get(BASE_URL + "/v1/suggestions/search?query=#{item}&limit=1/").parsed_response
data["suggestion"] = data.delete("suggestions")
data["suggestion"] = data["suggestion"][0]
+
+ if data["suggestion"].nil?
+ return @message = "Sorry, we couldn't find a good suggestion."
+ end
+
self.new(data)
end
+
+
def self.add_favorite(user_id, suggestion_id)
body_data = {"suggestion": suggestion_id}.to_json
response = HTTParty.post(BASE_URL + "/v1/users/#{user_id}/favorites", body: body_data)
return response.code
end
+
+
def self.unfavorite(user_id, suggestion_id)
body_data = {"suggestion": suggestion_id}.to_json
response = HTTParty.delete(BASE_URL + "/v1/users/#{user_id}/favorites", body: body_data)
return response.code
end
+
+
def self.your_favorites(user_id)
- favorites = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response
- raise
+ data = HTTParty.get(BASE_URL + "/v1/users/#{user_id}/favorites").parsed_response
+
+ pairings = []
+ data["suggestions"].each do |suggestion|
+ pairings << HTTParty.get(BASE_URL + "/v1/suggestions/#{suggestion}").parsed_response
+ end
+
+ instances = []
+ pairings.each do |pairing|
+ instances << self.new(pairing)
+ end
+
+ return instances
end
+
+
def self.top
data = HTTParty.get(BASE_URL + "/v1/suggestions/top").parsed_response
From 18cafcafc7da8cc50c54764f5b23a8dc908b57c6 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 15:28:46 -0700
Subject: [PATCH 10/20] yay! it finally works! You can favorite or unfavorite
a pairing again Whoop
---
app/controllers/favorites_controller.rb | 4 ++--
app/views/suggestions/index.html.erb | 5 +++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 72117d3..1406d4e 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -4,7 +4,7 @@
class FavoritesController < ApplicationController
def create
- status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], @pairing.id)
+ status_code = TunesTakeoutWrapper.add_favorite(session[:user_id], params[:suggestion_id])
if status_code == 201
@message = "Favorite sucessfully added!"
@@ -21,7 +21,7 @@ def create
def destroy
- status_code = TunesTakeoutWrapper.unfavorite(session[:user_id], @pairing.id)
+ status_code = TunesTakeoutWrapper.unfavorite(session[:user_id], params[:suggestion_id])
if status_code == 204
@message = "You've unfavorited this pairing."
elsif status_code == 404
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index eb80485..fd3f0b9 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -23,8 +23,9 @@
Music: <%= @song.name %>
Restaurant: <%= @food_item.name %>
- <%= link_to "Favorite", favorite_path(@pairing.id), method: :post %>
- <%= link_to "Unfavorite", unfavorite_path(@pairing.id), method: :delete %>
+
+ <%= link_to "Favorite", favorite_path(:suggestion_id => @pairing.id), method: :post %>
+ <%= link_to "Unfavorite", unfavorite_path(:suggestion_id => @pairing.id), method: :delete %>
<% end %>
From bf7cd2212f5522a13a410626a9ec0cb7b39d0dc6 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 16:09:24 -0700
Subject: [PATCH 11/20] added ability to click on name to route to spotify
page, but I'm having problems with doing the same for the image
---
app/views/layouts/application.html.erb | 15 +++++++++++----
app/views/suggestions/index.html.erb | 7 -------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 31b68c7..6f99df4 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -8,12 +8,19 @@
+
<% if current_user.nil? %>
-<%= link_to "Sign In With Spotify", "/auth/spotify" %>
-<%= image_tag "spotify.jpeg" %>
+ Welcome, guest!
+ <%= link_to "Sign In With Spotify", "/auth/spotify" %>
+ <%= image_tag "spotify.jpeg" %>
+ You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
<% else %>
-<%= link_to "Sign Out", logout_path, method: :delete %>
-<%= image_tag current_user.image %>
+
+ Hello, <%= link_to "#{User.find(session["user_id"]).name}", "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>!
+
+ <%= image_tag current_user.image %>
+
+ <%= link_to "Sign Out", logout_path, method: :delete %>
<% end %>
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index fd3f0b9..92c5b64 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -1,11 +1,4 @@
-<% if current_user.nil? %>
- Welcome, guest!
- You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
-<% else %>
- Welcome, <%= current_user.name %>!
-
-<% end %>
<%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
From dab0976d627f2996ae3f84ef7d9d29c135a04eed Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 16:38:40 -0700
Subject: [PATCH 12/20] finally figured out how to use spotify photo as link to
spotify page.
---
app/views/layouts/application.html.erb | 3 ++-
app/views/suggestions/_suggestion.html.erb | 4 +++-
app/views/suggestions/favorites.html.erb | 1 +
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 6f99df4..135cd6b 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -18,7 +18,8 @@
Hello, <%= link_to "#{User.find(session["user_id"]).name}", "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>!
- <%= image_tag current_user.image %>
+
+ <%= link_to image_tag(User.find(session["user_id"]).image, height: '100', width: '100'), "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>
<%= link_to "Sign Out", logout_path, method: :delete %>
<% end %>
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index 7fb6889..c34ebbf 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -14,6 +14,8 @@ food:
<%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
-
+
+
+
diff --git a/app/views/suggestions/favorites.html.erb b/app/views/suggestions/favorites.html.erb
index 38f4684..12b3453 100644
--- a/app/views/suggestions/favorites.html.erb
+++ b/app/views/suggestions/favorites.html.erb
@@ -1,6 +1,7 @@
<% @favorites.each do |suggestion| %>
<%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type,suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :suggestion_id => suggestion.id %>
+
<% end %>
<% if @favorites.empty? %>
From b86287d1d88d9414a8b6ee88ff36b61f51c69722 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 16:57:10 -0700
Subject: [PATCH 13/20] guest cannot search nor access favorites
---
app/views/layouts/application.html.erb | 2 +-
app/views/suggestions/index.html.erb | 11 +++++++----
lib/TunesTakeoutWrapper.rb | 2 +-
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 135cd6b..0366975 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -12,7 +12,7 @@
<% if current_user.nil? %>
Welcome, guest!
<%= link_to "Sign In With Spotify", "/auth/spotify" %>
- <%= image_tag "spotify.jpeg" %>
+ <%= image_tag "spotify.jpeg", height: '100', width: '100' %>
You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
<% else %>
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 92c5b64..eab95ca 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -1,15 +1,18 @@
+<% if current_user %>
+ <%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
+<% end %>
-<%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
-Search suggestions by keyword:
-<%= form_tag do %>
+<% if current_user %>
+ Search suggestions by keyword:
+ <%= form_tag do %>
<%= label_tag :food_pairing_query %>
<%= text_field_tag :food_pairing_query %>
<%=submit_tag %>
+ <% end %>
<% end %>
-<%= params %>
<% if @pairing.present? %>
Your pairing suggestions for <%= @pairing_query %> are:
diff --git a/lib/TunesTakeoutWrapper.rb b/lib/TunesTakeoutWrapper.rb
index 207ea16..0e7a7ee 100644
--- a/lib/TunesTakeoutWrapper.rb
+++ b/lib/TunesTakeoutWrapper.rb
@@ -21,7 +21,7 @@ def self.find(item)
data["suggestion"] = data["suggestion"][0]
if data["suggestion"].nil?
- return @message = "Sorry, we couldn't find a good suggestion."
+ return @message = "Sorry, no pairing suggestion. Try again."
end
self.new(data)
From 7a3f33e91bfa54befb48f21f3e88499c09f29c38 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 18:34:09 -0700
Subject: [PATCH 14/20] updated my gemfile, but feeling overwhelmingly lost on
testing with vcr and yml...have spent the past 2 1/2 hours researching and
yeah...no clue yet...gonna keep going
---
app/assets/images/url.jpg | 2 +
app/assets/stylesheets/application.css | 43 +++++++++++++++++++++
app/views/favorites/your_favorites.html.erb | 4 +-
app/views/suggestions/_suggestion.html.erb | 34 +++++++++-------
app/views/suggestions/favorite.html.erb | 2 +-
app/views/suggestions/favorites.html.erb | 4 +-
app/views/suggestions/unfavorite.html.erb | 2 +-
7 files changed, 70 insertions(+), 21 deletions(-)
create mode 100644 app/assets/images/url.jpg
diff --git a/app/assets/images/url.jpg b/app/assets/images/url.jpg
new file mode 100644
index 0000000..d5fe514
--- /dev/null
+++ b/app/assets/images/url.jpg
@@ -0,0 +1,2 @@
+
\ No newline at end of file
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index f9cd5b3..192efb3 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -1,3 +1,46 @@
+
+
+
+
+
+
+#suggestion-wrapper {
+ border: .25rem solid white;
+ background-color: #000045;
+ width: 50%;
+ overflow: hidden;
+ margin-bottom: 1.5rem;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+
+#food-suggestion {
+ text-align: center;
+ width: 49%;
+ float: left;
+}
+
+#music-suggestion {
+ text-align: center;
+ width: 49%;
+ float: left;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
diff --git a/app/views/favorites/your_favorites.html.erb b/app/views/favorites/your_favorites.html.erb
index f9dc5c6..8c58bb8 100644
--- a/app/views/favorites/your_favorites.html.erb
+++ b/app/views/favorites/your_favorites.html.erb
@@ -1,8 +1,8 @@
<% @favorites.each do |suggestion| %>
- <%= render "suggestion", :music_suggestion => SpotifyItem.find(suggestion.music_type,suggestion.music_id), :food_suggestion => FoodItem.find(suggestion.food_id), :suggestion_id => suggestion.id %>
+ <%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type,suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :suggestion_id => suggestion.id %>
<% end %>
<% if @favorites.empty? %>
- No favorites yet, why not add some?
+ No favorites yet.
<% end %>
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index c34ebbf..c40256f 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -1,21 +1,25 @@
-
-
-food:
- <%= link_to food_suggestion.name, food_suggestion.url %>
+>
+
+ food:
+ <%= link_to food_suggestion.name, food_suggestion.url %>
+
+ <%= image_tag food_suggestion.image_url %>
+
-
- <%= image_tag food_suggestion.image_url %>
-
+
+ this <%= music_suggestion.type %>:
+ <%= link_to music_suggestion.name, music_suggestion.url %>
-
- this <%= music_suggestion.type %>:
- <%= link_to music_suggestion.name, music_suggestion.url %>
+ <% if music_suggestion.image_url != nil %>
+ <%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
+ <% else %>
+ <%= image_tag("url.jpg", height: '100', width: '100') %>
+ <% end %>
+
- <%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
+
-
+
-
-
-
+
diff --git a/app/views/suggestions/favorite.html.erb b/app/views/suggestions/favorite.html.erb
index 2e349d0..b843235 100644
--- a/app/views/suggestions/favorite.html.erb
+++ b/app/views/suggestions/favorite.html.erb
@@ -1,4 +1,4 @@
<%= @message %>
<%= @status_code %>
-<%= link_to "back", suggestions_path(params["suggestion_id"])%>
+<%= link_to "search again", suggestions_path(params["suggestion_id"])%>
diff --git a/app/views/suggestions/favorites.html.erb b/app/views/suggestions/favorites.html.erb
index 12b3453..a17f513 100644
--- a/app/views/suggestions/favorites.html.erb
+++ b/app/views/suggestions/favorites.html.erb
@@ -1,9 +1,9 @@
<% @favorites.each do |suggestion| %>
<%= render "suggestion", :music_suggestion => Music.find(suggestion.music_type,suggestion.music_id), :food_suggestion => Restaurant.find(suggestion.food_id), :suggestion_id => suggestion.id %>
-
+
<% end %>
<% if @favorites.empty? %>
- No favorites yet, why not add some?
+ No favorites yet.
<% end %>
diff --git a/app/views/suggestions/unfavorite.html.erb b/app/views/suggestions/unfavorite.html.erb
index 2e349d0..b843235 100644
--- a/app/views/suggestions/unfavorite.html.erb
+++ b/app/views/suggestions/unfavorite.html.erb
@@ -1,4 +1,4 @@
<%= @message %>
<%= @status_code %>
-<%= link_to "back", suggestions_path(params["suggestion_id"])%>
+<%= link_to "search again", suggestions_path(params["suggestion_id"])%>
From 2e2dfc9c5a5b569db186ee5b8e5f6457cecb779f Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 19:47:55 -0700
Subject: [PATCH 15/20] cant figure out testing...moved onto styling and
feeling like i really dont remember anything about css and wish i had more
time to learn about it and work with it because its something that I feel i
could be really good at, but yeah, it looks like complete crap now...
---
app/assets/stylesheets/application.css | 12 +++++++++---
app/views/layouts/application.html.erb | 4 +---
app/views/suggestions/_suggestion.html.erb | 10 +++++-----
app/views/suggestions/index.html.erb | 12 ++++++++----
4 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 192efb3..a1148dd 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -1,13 +1,15 @@
-
+body{
+ background-color: rgba(22, 136, 182, 0.85);
+}
#suggestion-wrapper {
border: .25rem solid white;
- background-color: #000045;
- width: 50%;
+ background-color: rgba(255, 255, 255, 0.5);
+ width: 80%;
overflow: hidden;
margin-bottom: 1.5rem;
margin-left: auto;
@@ -27,6 +29,10 @@
float: left;
}
+iframe {
+ float: right;
+}
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 0366975..60e016b 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -7,11 +7,9 @@
<%= csrf_meta_tags %>
-
<% if current_user.nil? %>
Welcome, guest!
- <%= link_to "Sign In With Spotify", "/auth/spotify" %>
<%= image_tag "spotify.jpeg", height: '100', width: '100' %>
You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
<% else %>
@@ -21,7 +19,7 @@
<%= link_to image_tag(User.find(session["user_id"]).image, height: '100', width: '100'), "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>
- <%= link_to "Sign Out", logout_path, method: :delete %>
+
<% end %>
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index c40256f..75bcb79 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -1,8 +1,8 @@
->
+
food:
<%= link_to food_suggestion.name, food_suggestion.url %>
-
+
<%= image_tag food_suggestion.image_url %>
@@ -12,14 +12,14 @@
<% if music_suggestion.image_url != nil %>
<%= image_tag music_suggestion.image_url, height: '100', width: '100' %>
- <% else %>
+ <% else %>
<%= image_tag("url.jpg", height: '100', width: '100') %>
- <% end %>
+ <% end %>
+
-
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index eab95ca..c2f6dce 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -1,8 +1,12 @@
+
+ <% if current_user %>
+ <%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
-<% if current_user %>
- <%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
-<% end %>
-
+ <%= link_to "Sign Out", logout_path, method: :delete %>
+ <% else %>
+ <%= link_to "Sign In With Spotify", "/auth/spotify" %>
+ <% end %>
+
<% if current_user %>
Search suggestions by keyword:
From 1aa37b64ff2f55588b4435f15a016fb21a68cd1c Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 20:29:10 -0700
Subject: [PATCH 16/20] ok this is where I am with this...
---
app/assets/stylesheets/application.css | 28 ++++++++++++++++++++++++++
app/views/layouts/application.html.erb | 28 +++++++++++++-------------
app/views/suggestions/index.html.erb | 21 ++++++++++---------
3 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index a1148dd..6c56517 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -3,8 +3,36 @@ body{
background-color: rgba(22, 136, 182, 0.85);
}
+.user-stuff{
+ display: inline;
+}
+
+.user-stuff image_tag{
+ border-radius: 50%;
+}
+
+header {
+ height: 130px;
+ width: 100%;
+ padding: 1% 2% 0 2%;
+}
+h1{
+ font-size: 18px;
+}
+.nav{
+ background-color: rgba(255, 255, 255, 0.5);
+}
+
+ul.nav li{
+ display: inline;
+ padding-right: 5px;
+ list-style: none;
+ font-size: 18px;
+ font-weight: bold;
+ padding: 40px;
+}
#suggestion-wrapper {
border: .25rem solid white;
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 60e016b..38820b1 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -7,20 +7,20 @@
<%= csrf_meta_tags %>
-
-<% if current_user.nil? %>
- Welcome, guest!
- <%= image_tag "spotify.jpeg", height: '100', width: '100' %>
- You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
-<% else %>
-
- Hello, <%= link_to "#{User.find(session["user_id"]).name}", "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>!
-
-
- <%= link_to image_tag(User.find(session["user_id"]).image, height: '100', width: '100'), "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>
-
-
-<% end %>
+
+ <% if current_user.nil? %>
+ <%= image_tag "spotify.jpeg", height: '100', width: '100' %>
+
Welcome, guest!
+
You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
+ <% else %>
+
+ <%= link_to image_tag(User.find(session["user_id"]).image, height: '100', width: '100'), "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>
+
+ Hello, <%= link_to "#{User.find(session["user_id"]).name}", "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>!
+
+
+ <% end %>
+
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index c2f6dce..ceeef63 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -1,12 +1,15 @@
-
- <% if current_user %>
- <%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
-
- <%= link_to "Sign Out", logout_path, method: :delete %>
- <% else %>
- <%= link_to "Sign In With Spotify", "/auth/spotify" %>
- <% end %>
-
+
+
+
+ <% if current_user %>
+ <%= link_to "Your Favorites", your_favorites_path(session[:user_id]), method: :get %>
+
+ <%= link_to "Sign Out", logout_path, method: :delete %>
+ <% else %>
+ <%= link_to "Sign In With Spotify", "/auth/spotify" %>
+ <% end %>
+
+
<% if current_user %>
Search suggestions by keyword:
From c8156cd1548db05b7e502d23d4cfc8a06050808e Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 23:02:21 -0700
Subject: [PATCH 17/20] forgot to create links for search results...got that
working now, gonna style it
---
app/views/layouts/application.html.erb | 4 ++--
app/views/suggestions/index.html.erb | 15 +++++++++++----
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 38820b1..5e6dec7 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -11,14 +11,14 @@
<% if current_user.nil? %>
<%= image_tag "spotify.jpeg", height: '100', width: '100' %>
Welcome, guest!
- You'll need to log into Spotify to use this application. Click "Sign In With Spotify" above!
+ You'll need to log into Spotify to use this application. Click "Sign In With Spotify"!
<% else %>
<%= link_to image_tag(User.find(session["user_id"]).image, height: '100', width: '100'), "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>
Hello, <%= link_to "#{User.find(session["user_id"]).name}", "https://open.spotify.com/user/#{User.find(session["user_id"]).uid}" %>!
-
+
<% end %>
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index ceeef63..7149559 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -22,10 +22,17 @@
<% if @pairing.present? %>
- Your pairing suggestions for <%= @pairing_query %> are:
- Music: <%= @song.name %>
- Restaurant: <%= @food_item.name %>
-
+ Music: <%= @song.name %>
+
Your pairing suggestions for <%= @pairing_query %> are:
+ <%= image_tag @song.image_url, height: '100', width: '100' %>
+ <%= link_to @song.name, @song.url %>
+
+
+ Restaurant: <%= @food_item.name %>
+ <%= link_to @food_item.name, @food_item.url %>
+
+ <%= image_tag @food_item.image_url %>
+
<%= link_to "Favorite", favorite_path(:suggestion_id => @pairing.id), method: :post %>
<%= link_to "Unfavorite", unfavorite_path(:suggestion_id => @pairing.id), method: :delete %>
From 7a369456da2d91796fbbd6d8c50973dd7771e902 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 23:39:27 -0700
Subject: [PATCH 18/20] styling is getting kind of better for the pairing qery
results
---
app/assets/stylesheets/application.css | 17 +++++++++
app/views/suggestions/_suggestion.html.erb | 6 ++--
app/views/suggestions/index.html.erb | 42 +++++++++++++---------
3 files changed, 45 insertions(+), 20 deletions(-)
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 6c56517..dc5255f 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -44,6 +44,17 @@ ul.nav li{
margin-right: auto;
}
+#pairing-wrapper {
+ border: .25rem solid white;
+ background-color: rgba(255, 255, 255, 0.5);
+ width: 100%;
+ height: 40%;
+ overflow: hidden;
+ margin-bottom: 1.5rem;
+ margin-left: auto;
+ margin-right: auto;
+}
+
#food-suggestion {
text-align: center;
@@ -57,6 +68,12 @@ ul.nav li{
float: left;
}
+span{
+ text-align: center;
+ width: 49%;
+ float: right;
+}
+
iframe {
float: right;
}
diff --git a/app/views/suggestions/_suggestion.html.erb b/app/views/suggestions/_suggestion.html.erb
index 75bcb79..eae70b7 100644
--- a/app/views/suggestions/_suggestion.html.erb
+++ b/app/views/suggestions/_suggestion.html.erb
@@ -1,12 +1,12 @@
-
-
+
+
food:
<%= link_to food_suggestion.name, food_suggestion.url %>
<%= image_tag food_suggestion.image_url %>
-
+
this <%= music_suggestion.type %>:
<%= link_to music_suggestion.name, music_suggestion.url %>
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 7149559..9bdf125 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -20,25 +20,33 @@
<% end %>
<% end %>
+
+ <% if @pairing.present? %>
+
+
Your pairing suggestions for <%= @pairing_query %> are:
+
+ <%= link_to "Favorite", favorite_path(:suggestion_id => @pairing.id), method: :post %>
+ <%= link_to "Unfavorite", unfavorite_path(:suggestion_id => @pairing.id), method: :delete %>
+
+ Music: <%= @song.name %>
+ <%= image_tag @song.image_url, height: '100', width: '100' %>
+ <%= link_to @song.name, @song.url %>
+
+
+
+
+
+
Restaurant: <%= @food_item.name %>
+ <%= image_tag @food_item.image_url %>
+
+ <%= link_to @food_item.name, @food_item.url %>
+
+
+
-<% if @pairing.present? %>
-
Music: <%= @song.name %>
-
Your pairing suggestions for <%= @pairing_query %> are:
- <%= image_tag @song.image_url, height: '100', width: '100' %>
- <%= link_to @song.name, @song.url %>
-
-
-
Restaurant: <%= @food_item.name %>
- <%= link_to @food_item.name, @food_item.url %>
-
- <%= image_tag @food_item.image_url %>
-
-
- <%= link_to "Favorite", favorite_path(:suggestion_id => @pairing.id), method: :post %>
- <%= link_to "Unfavorite", unfavorite_path(:suggestion_id => @pairing.id), method: :delete %>
-
+ <% end %>
+
-<% end %>
Top 20 Favorites
<% @top20.each do |suggestion| %>
From faa440abbac27cbb80954d2d2aeae2015c6b45b6 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sun, 22 May 2016 23:46:01 -0700
Subject: [PATCH 19/20] styling
---
app/views/suggestions/index.html.erb | 2 ++
1 file changed, 2 insertions(+)
diff --git a/app/views/suggestions/index.html.erb b/app/views/suggestions/index.html.erb
index 9bdf125..e90048b 100644
--- a/app/views/suggestions/index.html.erb
+++ b/app/views/suggestions/index.html.erb
@@ -19,6 +19,8 @@
<%=submit_tag %>
<% end %>
<% end %>
+
+
<% if @pairing.present? %>
From 5e3c98567627464d1888de9740c8abcc38d1b2d5 Mon Sep 17 00:00:00 2001
From: Mindy Carson
Date: Sat, 18 Jun 2016 01:00:30 -0700
Subject: [PATCH 20/20] updated
---
.env | 10 -------
.gitignore | 2 +-
app/controllers/sessions_controller.rb | 41 +++++++++++---------------
3 files changed, 18 insertions(+), 35 deletions(-)
delete mode 100644 .env
diff --git a/.env b/.env
deleted file mode 100644
index c865e35..0000000
--- a/.env
+++ /dev/null
@@ -1,10 +0,0 @@
-YELP_CONSUMER_KEY: RC-dbM2zuKUQmpuXSeYp5A
-YELP_CONSUMER_SECRET: O_YOLmwe2o1IwVsl4-hUVvQn0dM
-YELP_TOKEN: KERJPZzNUilFm-RRMdk9V-90kxzYO213
-YELP_TOKEN_SECRET: uLfJRgRSyUporozYTKebsZ81Asc
-
-
-
-CLIENT_ID: 84d3407e199f4c9bbbfe6e6e51b9fe0a
-
-CLIENT_SECRET: 84c0798ce9b94370a384d263efccc892
diff --git a/.gitignore b/.gitignore
index dcd300f..18b1fa8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,7 +26,7 @@
/tmp/
# Used by dotenv library to load environment variables.
- /.env
+.env
## Specific to RubyMotion:
.dat*
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 9ea9730..9f8eb3e 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -1,36 +1,29 @@
class SessionsController < ApplicationController
- #skip_before_action :require_login, only: [:new, :create]
+ skip_before_action :require_login, only: [:new, :create]
+
+ # #create signs in a user by finding the id in User model and assigning session[:user_id]
+ # use keep_cart_items
+
+ # #destroy signs out a user by destroying the sessions[:user_id]
def new
- # shows a view with OAuth sign-in link
end
- def create #accepts OAuth information from Spotify, finds or creates a User account, and sets user_id in session
- auth_hash = request.env['omniauth.auth']
- if auth_hash[:info][:id]
- @user = User.find_or_create_from_omniauth(auth_hash)
- if @user
- session[:user_id] = @user.id
- redirect_to suggestions_path
- else
- redirect_to suggestions_path, notice: "Failed to save the user"
- end
-
+ def create
+ @user = User.log_in(params[:session][:email], params[:session][:password])
+ @cart_items = CartItem.where(session_id: session[:session_id])
+ keep_cart_items(@cart_items)
+ if @user
+ session[:user_id] = @user.id
+ redirect_to root_path
else
- redirect_to suggestions_path, notice: "Failed to authenticate"
+ flash.now[:danger] = 'Invalid email/password combination'
+ render 'new'
end
-
- #user = User.log_in(params[:email], params[:password])
- # if user
- # session[:user_id] = user.id
- # redirect_to root_path
- # else
- # render :new
- # end
end
- def destroy #deletes user_id from session
+ def destroy
session.delete :user_id
- redirect_to suggestions_path
+ redirect_to root_path
end
end