class CueCloudApi

Constants

API_VERSION
DEFAULT_BASE_URL

Attributes

request[RW]

Public Class Methods

new(api_key, api_pass, base_url=nil) click to toggle source
# File lib/cuecloud/cuecloud_api.rb, line 8
def initialize(api_key, api_pass, base_url=nil)
  unless base_url
    base_url = CueCloudApi::DEFAULT_BASE_URL + CueCloudApi::API_VERSION
  end
  @request = CueCloudRequest.new(api_key, api_pass, base_url)
end

Public Instance Methods

approve_cue_completion(cue_completion_id) click to toggle source

This will approve a CueCompletion that has been submitted to the user’s Cue.

# File lib/cuecloud/cuecloud_api.rb, line 92
def approve_cue_completion(cue_completion_id)
  data = {'CueCompletionID' => cue_completion_id}
  build_request('completions/approve/', 'POST', data)
end
assign_cue(cue_id) click to toggle source

This will try and check-in or check-out a Cue depending on whether the Cue is already checked out by that user.

# File lib/cuecloud/cuecloud_api.rb, line 178
def assign_cue(cue_id)
  data = {'CueID' => cue_id}
  build_request('cues/assign/', "POST", data)
end
cancel_cue(cue_id) click to toggle source

This will cancel a Cue that you have posted, refunding your balance.

# File lib/cuecloud/cuecloud_api.rb, line 104
def cancel_cue(cue_id)
  data = {'CueID' => cue_id}
  build_request('cues/cancel/', 'POST', data)
end
create_cue(title, amount, num_opportunities: 1, description: nil, is_anonymous: nil, push_notification_on_cue_completion: nil, disallow_anonymous: nil, iframe_url: nil, url_notification_on_cue_completion: nil, email_notification_on_cue_completion: nil, lifetime_in_minutes: nil, time_limit_to_complete_cue_in_minutes: nil, auto_approve_cue_completion_in_minutes: nil, note_to_self: nil, keywords: nil) click to toggle source

The only required items are ‘title`, `amount`, and `num_opportunities` (which defaults to 1 An `iframe_url` can be specified if you want a user to fill out a custom form on your site.

# File lib/cuecloud/cuecloud_api.rb, line 131
def create_cue(title, amount, num_opportunities: 1,
               description: nil, is_anonymous: nil, push_notification_on_cue_completion: nil,
               disallow_anonymous: nil, iframe_url: nil, url_notification_on_cue_completion: nil,
               email_notification_on_cue_completion: nil, lifetime_in_minutes: nil,
               time_limit_to_complete_cue_in_minutes: nil, auto_approve_cue_completion_in_minutes: nil,
               note_to_self: nil, keywords: nil)

  data = {
      'Title' => title,
      'Amount' => amount,
      'NumOpportunities' => num_opportunities,
      'Description' => description,
      'IsAnonymous' => is_anonymous,
      'PushNotificationOnCueCompletion' => push_notification_on_cue_completion,
      'DisallowAnonymousCueCompletions' => disallow_anonymous,
      'iFrameURL' => iframe_url,
      'URLNotificationOnCueCompletion' => url_notification_on_cue_completion,
      'EmailNotificationOnCueCompletion' => email_notification_on_cue_completion,
      'LifetimeInMinutes' => lifetime_in_minutes,
      'TimeLimitToCompleteCueInMinutes' => time_limit_to_complete_cue_in_minutes,
      'AutoApproveCueCompletionAfterThisManyMinutes' => auto_approve_cue_completion_in_minutes,
      'NoteToSelf' => note_to_self,
      'Keywords' => keywords,
  }
  build_request("cues/create", "POST", data)

end
decline_cue_completion(cue_completion_id) click to toggle source

This will decline a CueCompletion that has been submitted to the user’s Cue.

# File lib/cuecloud/cuecloud_api.rb, line 98
def decline_cue_completion(cue_completion_id)
  data = {'CueCompletionID' => cue_completion_id}
  build_request('completions/decline/', 'POST', data)
end
get_balance() click to toggle source

This will return the user’s current balance, in USD.

# File lib/cuecloud/cuecloud_api.rb, line 28
def get_balance
  build_request('balance/', 'GET')
end
get_cue_completions(cue_id, cue_completion_id=nil, status=nil, page=nil) click to toggle source

This will return CueCompletions for a particular Cue. Status options for CueCompletions are ‘Pending`, `Accepted`, and `Declined`.

# File lib/cuecloud/cuecloud_api.rb, line 111
def get_cue_completions(cue_id, cue_completion_id=nil, status=nil, page=nil)

  data = {
      'CueID' => cue_id,
      'CueCompletionID' => cue_completion_id,
      'Status' => status,
      'Page' => page
  }

  url = encode_data_in_url('completions/', data)
  unless data.empty?
    build_request(url, 'GET', data)
  else
    build_request(url, 'GET')
  end

end
get_cues(cue_id: nil, group_id: nil, note_to_self: nil, has_pending_cue_completions: nil, status: nil, page: nil) click to toggle source

This will get all Cues the user has created. ‘has_pending_cue_completions` is a boolean.

status` can be one of 'Active', 'Complete', 'Canceled', or 'Expired'
# File lib/cuecloud/cuecloud_api.rb, line 162
def get_cues(cue_id: nil, group_id: nil, note_to_self: nil, has_pending_cue_completions: nil, status: nil, page: nil)
  data = {
      'CueID' => cue_id,
      'GroupID' => group_id,
      'NoteToSelf' => note_to_self,
      'HasPendingCueCompletions' => has_pending_cue_completions,
      'Status' => status,
      'Page' => page
  }

  url = encode_data_in_url('cues/', data)
  build_request(url, "GET")
end
get_keywords() click to toggle source

This will return common keywords for Cues. Useful for CueCreation.

# File lib/cuecloud/cuecloud_api.rb, line 23
def get_keywords
  build_request('cues/keywords/', 'GET')
end
get_payments(payment_type=nil, payment_id=nil, note_to_self=nil, page=nil) click to toggle source

Payment type may be one of ‘Deposits`, `Withdrawals`, or `Bonuses`. 50 results will show per page.

# File lib/cuecloud/cuecloud_api.rb, line 73
def get_payments(payment_type=nil, payment_id=nil, note_to_self=nil, page=nil)

  data = {
      'PaymentType' => payment_type,
      'PaymentID' => payment_id,
      'NoteToSelf' => note_to_self,
      'Page' => page
  }

  url = encode_data_in_url('payments/', data)
  unless data.empty?
    build_request(url, 'GET', data)
  else
    build_request(url, 'GET')
  end

end
grant_bonus(cue_completion_id, amount, reason='Thanks for your hard work!', note_to_self=nil) click to toggle source

This will grant a bonus to the user who has completed a particular Cue for us.

A reason for the bonus must be specified, though here we default to “Thanks for your hard work!” if none is provided.

Note to self can be proviuded, which is a string that can only be viewed
by the person who granted the bonus. An example might be:

“Bonus paid here on 2014-01-01 to see if it motivates better work from this person.”

# File lib/cuecloud/cuecloud_api.rb, line 61
def grant_bonus(cue_completion_id, amount, reason='Thanks for your hard work!', note_to_self=nil)
  data = {
      'CueCompletionID' => cue_completion_id,
      'Amount' => amount,
      'Reason' => reason,
      'NoteToSelf' => note_to_self
  }
  build_request('payments/bonus/', 'POST', data)
end
make_deposit(amount_in_usd, cc_last_four) click to toggle source

Given a valid CC on file in the app, This will deposit that amount into the user’s balance. Note, a credit card may only be added within the app. Not the API.

# File lib/cuecloud/cuecloud_api.rb, line 35
def make_deposit(amount_in_usd, cc_last_four)
  data = {
      'AmountInUSD' => amount_in_usd.to_f,
      'CreditCardLastFourDigits' => cc_last_four
  }
  build_request('payments/deposit/', 'POST', data)
end
submit_cue_completion(assignment_id, answer_text: nil, video_url: nil, video_thumbnail_url: nil, image_url: nil, is_anonymous: nil) click to toggle source

This will submit the CueCompletion data, though In production the method will block any requests without an HTTP_REFERER.

# File lib/cuecloud/cuecloud_api.rb, line 185
def submit_cue_completion(assignment_id, answer_text: nil, video_url: nil, video_thumbnail_url: nil, image_url: nil, is_anonymous: nil)

  data = {
      'AssignmentID' => assignment_id,
      'AnswerText' => answer_text,
      'VideoURL' => video_url,
      'VideoThumbnailURL' => video_thumbnail_url,
      'ImageURL' => image_url,
      'IsAnonymous' => is_anonymous
  }
  build_request('cues/complete/', "POST", data)
end
validate_user() click to toggle source

This is a test method to make sure that the user has valid API credentials.

# File lib/cuecloud/cuecloud_api.rb, line 17
def validate_user
  build_request('validate/', 'GET')
end
withdraw_funds(amount_in_usd=nil) click to toggle source

Given a PayPal email, this will deposit the funds immediately into that user’s PayPal account. If no amount is specified, it will try and deduct the entire user’s balance.

# File lib/cuecloud/cuecloud_api.rb, line 47
def withdraw_funds(amount_in_usd=nil)
  data = {'AmountInUSD' => amount_in_usd.to_f}
  build_request('payments/withdraw/', 'POST', data)
end

Private Instance Methods

build_request(url, method, data=nil) click to toggle source
# File lib/cuecloud/cuecloud_api.rb, line 209
def build_request(url, method, data=nil)
  request.build_request(url, method, data)
end
encode_data_in_url(resource, data) click to toggle source
# File lib/cuecloud/cuecloud_api.rb, line 200
def encode_data_in_url(resource, data)
  data.select! { |_key, value| !value.nil? }
  unless data.empty?
    resource + '?' + URI::encode(data.map { |x| x.to_a.join("=") }.join("&"))
  else
    resource
  end
end