module Totter::Client::Choices

Client methods for working with choices.

Public Instance Methods

choice(user_id, decision_id, choice_id) click to toggle source

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)
# File lib/totter/client/choices.rb, line 13
def choice(user_id, decision_id, choice_id)
  get("users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}").body
end
choice_votes(user_id, decision_id, choice_id) click to toggle source

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)
# File lib/totter/client/choices.rb, line 25
def choice_votes(user_id, decision_id, choice_id)
  get("users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}/votes").body
end
create_choice_for_image(user_id, decision_id, options = {}) click to toggle source

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')
# File lib/totter/client/choices.rb, line 42
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_choice_upload(user_id, decision_id) click to toggle source

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)
# File lib/totter/client/choices.rb, line 68
def create_choice_upload(user_id, decision_id)
  post("users/#{user_id}/decisions/#{decision_id}/choices").body
end
crop_choice(user_id, decision_id, choice_id, x, y, width, height) click to toggle source

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)
# File lib/totter/client/choices.rb, line 96
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
destroy_choice(user_id, decision_id, choice_id) click to toggle source

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)
# File lib/totter/client/choices.rb, line 80
def destroy_choice(user_id, decision_id, choice_id)
  boolean_from_response(:delete, "users/#{user_id}/decisions/#{decision_id}/choices/#{choice_id}")
end