module Totter class Client # Client methods for working with choices. module Choices # Get a single choice # # @param user_id [Numeric] The choice's decision's user id # @param decision_id [Numeric] The choice's decision's id # @param choice_id [Numeric] The choice's id # @return [Hashie::Mash] # @example # Totter.choice(1, 1, 1) def choice(user_id, decision_id, choice_id) get("users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}").body end # Gets votes on a single choice bucketed into authed and invited votes # # @param user_id [Numeric] The choice's decision's user id # @param decision_id [Numeric] The choice's decision's id # @param choice_id [Numeric] The choice's id # @return [Hashie::Mash] # @example # Totter.choice_votes(1, 1, 1) def choice_votes(user_id, decision_id, choice_id) get("users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}/votes").body end # Create a new choice using a supplied image url # # @param user_id [Numeric] The choice's decision's user id # @param decision_id [Numeric] The choice's decision's id # @param options [Hash] # @option options [String] :image_url The image url (required) # @option options [String] :subject The image label # @option options [String] :link_url A link to this image's page # @option options [String] :link_title The title of a link to this image's page # @return [Hashie::Mash] # @example # Totter.create_choice_for_image(1, 1, image_url: 'http://recess.s3.amazonaws.com/default_avatars/v1/photo_1.png', \ # subject: 'Sample Avatar', link_url: 'https://seesaw.co', link_title: 'Seesaw') def create_choice_for_image(user_id, decision_id, options = {}) raise ArgumentError.new('image_url option is required') unless options[:image_url] data = { :choice => { :type => 'image', :image_url => options[:image_url], :subject => options[:subject], :meta => { :link_url => options[:link_url], :link_title => options[:link_title] } } } post("users/#{user_id}/decisions/#{decision_id}/choices", data).body end # Create a new choice upload. Resulting hash contains an #upload parameter # providing keys necessary to perform a signed S3 upload. # # @param user_id [Numeric] The choice's decision's user id # @param decision_id [Numeric] The choice's decision's id # @return [Hashie::Mash] # @example # Totter.create_choice_upload(1, 1) def create_choice_upload(user_id, decision_id) post("users/#{user_id}/decisions/#{decision_id}/choices").body end # Destroy a choice # # @param user_id [Numeric] The choice's decision's user id # @param decision_id [Numeric] The choice's decision's id # @param choice_id [Numeric] The choice's id # @return [Boolean] True if follow was successful, false otherwise. # @example # Totter.destroy_choice(1, 1, 1) def destroy_choice(user_id, decision_id, choice_id) boolean_from_response(:delete, "users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}") end # Crop a choice # # @param user_id [Numeric] The choice's decision's user id # @param decision_id [Numeric] The choice's decision's id # @param choice_id [Numeric] The choice's id # @param x [Numeric] The x position of the start point # @param y [Numeric] the y position of the start point # @param width [Numeric] The crop width # @param height [Numeric] The crop height # @return [Boolean] True if follow was successful, false otherwise. # @example # Totter.crop_choice(1, 1, 1, 0, 0, 300, 300) def crop_choice(user_id, decision_id, choice_id, x, y, width, height) data = { x: x, y: y, height: height, width: width } boolean_from_response(:post, "users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}/crop", data) end end end end