Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HomeController < ApplicationController
- def index
- @photo = Photo.new
- if current_user
- @album_hash = get_album_hash(current_user)
- end
- end
- # '/share'
- def share
- if params[:id]
- @photo = Photo.find(params[:id])
- if current_user
- @fb_user = FbGraph::User.me(current_user.fb_token)
- @friends = @fb_user.fetch.friends.collection.to_json
- end
- end
- render :layout => true
- end
- # '/share/postcard'
- def postcard
- @postcard = Postcard.new
- @postcard.build_address
- end
- # POST '/share/postcard'
- def postcard_create
- @photo = Photo.find(params[:postcard][:photo_id])
- params[:postcard].delete(:photo_id)
- @postcard = Postcard.new(params[:postcard])
- if @postcard.save
- @photo.postcard_id = @postcard.id
- @photo.save
- render :text => "OK!"
- end
- end
- def stripe
- # remember to change secret key to live key
- Stripe.api_key = "M3t0pd80EUGG0ocyWtpoFqKBZsVyNsmE"
- puts "HELLO@!!"
- puts params
- puts current_user
- puts session
- puts "HELLO!!!"
- if params[:stripeToken]
- # get the credit card details submitted by the form
- token = params[:stripeToken]
- # create a customer
- customer = Stripe::Customer.create(
- :card => token,
- :description => current_user.id
- )
- # save the stripe_id to the user model
- current_user.stripe_id = customer.id
- current_user.save
- end
- # create the charge on Stripe's servers - this will charge the user's card
- charge = Stripe::Charge.create(
- :amount => 100, #amount in cents, again
- :currency => "usd",
- :customer => current_user.stripe_id
- )
- render :text => "OK!"
- end
- private
- def get_album_hash(current_user)
- fb_user = FbGraph::User.me(current_user.fb_token)
- @albums = fb_user.albums
- @album_hash = Hash.new
- @albums.each do |album|
- @album_hash.merge!(album.raw_attributes["id"] => album.raw_attributes["name"])
- end
- return @album_hash
- end
- def get_photos_from_album(album_id)
- @album = FbGraph::Album.new(album_id, :access_token => current_user.fb_token)
- @photos = @album.photos
- @photos.each do |photo|
- photo.picture
- end
- end
- end
Add Comment
Please, Sign In to add comment