From cc6d6633cc8a5af901f119797bc21086bdbcab97 Mon Sep 17 00:00:00 2001 From: Skud Date: Wed, 8 May 2013 22:01:09 +1000 Subject: [PATCH] Rough attempt at showing photos from flickr. You can see a list of your recently uploaded Flickr photos at /photos/new, which is nice! However the tests are broken and there's a lot of mess that should be in the model instead of the controller. Committing as-is because I'm tired. --- Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/photos_controller.rb | 14 ++++++++++++++ app/views/photos/_form.html.haml | 22 ---------------------- app/views/photos/edit.html.haml | 7 +------ app/views/photos/new.html.haml | 22 +++++++++++++++++++++- 6 files changed, 39 insertions(+), 29 deletions(-) delete mode 100644 app/views/photos/_form.html.haml diff --git a/Gemfile b/Gemfile index 3f4318236..6eb4bbca7 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,7 @@ group :assets do end gem 'jquery-rails' +gem 'flickraw' # To use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 35ab7f28b..6c7782522 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,6 +85,7 @@ GEM factory_girl (~> 4.2.0) railties (>= 3.0.0) fastthread (1.0.7) + flickraw (0.9.6) friendly_id (4.0.9) fssm (0.2.10) geocoder (1.1.6) @@ -247,6 +248,7 @@ DEPENDENCIES devise diff-lcs factory_girl_rails (~> 4.0) + flickraw friendly_id geocoder gravatar-ultimate diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index d4fc62f5e..2454ab668 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -26,8 +26,22 @@ class PhotosController < ApplicationController # GET /photos/new.json def new @photo = Photo.new + + # NOTE: we should move a bunch of this into the Member model + @flickr_login = nil @flickr_auth = current_member.authentications.find_by_provider('flickr') + if @flickr_auth + FlickRaw.api_key = ENV['FLICKR_KEY'] + FlickRaw.shared_secret = ENV['FLICKR_SECRET'] + flickr = FlickRaw::Flickr.new + flickr.access_token = @flickr_auth.token + flickr.access_secret = @flickr_auth.secret + @flickr_login = flickr.test.login + + @photos = flickr.people.getPhotos(:user_id => 'me', :per_page => 30) + end + respond_to do |format| format.html # new.html.erb format.json { render json: @photo } diff --git a/app/views/photos/_form.html.haml b/app/views/photos/_form.html.haml deleted file mode 100644 index 8745c195b..000000000 --- a/app/views/photos/_form.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -= form_for @photo do |f| - - if @photo.errors.any? - #error_explanation - %h2= "#{pluralize(@photo.errors.count, "error")} prohibited this photo from being saved:" - %ul - - @photo.errors.full_messages.each do |msg| - %li= msg - - .field - = f.label :owner_id - = f.number_field :owner_id - .field - = f.label :flickr_photo_id - = f.number_field :flickr_photo_id - .field - = f.label :thumbnail_url - = f.text_field :thumbnail_url - .field - = f.label :fullsize_url - = f.text_field :fullsize_url - .actions - = f.submit 'Save' diff --git a/app/views/photos/edit.html.haml b/app/views/photos/edit.html.haml index 73440055c..5a43dd437 100644 --- a/app/views/photos/edit.html.haml +++ b/app/views/photos/edit.html.haml @@ -1,7 +1,2 @@ -%h1 Editing photo +- content_for :title, "Edit Photo" -= render 'form' - -= link_to 'Show', @photo -\| -= link_to 'Back', photos_path diff --git a/app/views/photos/new.html.haml b/app/views/photos/new.html.haml index c4de9cd39..f23caecdb 100644 --- a/app/views/photos/new.html.haml +++ b/app/views/photos/new.html.haml @@ -1,7 +1,27 @@ - content_for :title, "New Photo" - if @flickr_auth - = render 'form' + %p + Connected to Flickr as + = succeed "." do + = link_to @flickr_login.username, "http://flickr.com/photos/#{@flickr_login.id}" + + %p Select a photo from your recent uploads: + + - c = 0 + %ul.thumbnails + .row + - @photos.each do |p| + - c += 1 + %li.span2 + .thumbnail(style='height: 220px') + = image_tag(FlickRaw.url_q(p), :alt => '', :class => 'img-rounded') + %p + =p.title + - if (c % 6) == 0 + .row + + - else .alert You must