Class: CueCloudApi
- Inherits:
-
Object
- Object
- CueCloudApi
- Defined in:
- lib/cuecloud/cuecloud_api.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
'https://cuecloud.com/'- API_VERSION =
'api/v1.0'
Instance Attribute Summary collapse
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
-
#approve_cue_completion(cue_completion_id) ⇒ Object
This will approve a CueCompletion that has been submitted to the user’s Cue.
-
#assign_cue(cue_id) ⇒ Object
This will try and check-in or check-out a Cue depending on whether the Cue is already checked out by that user.
-
#cancel_cue(cue_id) ⇒ Object
This will cancel a Cue that you have posted, refunding your balance.
-
#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) ⇒ Object
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..
-
#decline_cue_completion(cue_completion_id) ⇒ Object
This will decline a CueCompletion that has been submitted to the user’s Cue.
-
#get_balance ⇒ Object
This will return the user’s current balance, in USD.
-
#get_cue_completions(cue_id, cue_completion_id = nil, status = nil, page = nil) ⇒ Object
This will return CueCompletions for a particular Cue.
-
#get_cues(cue_id: nil, group_id: nil, note_to_self: nil, has_pending_cue_completions: nil, status: nil, page: nil) ⇒ Object
This will get all Cues the user has created.
-
#get_keywords ⇒ Object
This will return common keywords for Cues.
-
#get_payments(payment_type = nil, payment_id = nil, note_to_self = nil, page = nil) ⇒ Object
Payment type may be one of ‘Deposits`, `Withdrawals`, or `Bonuses`.
-
#grant_bonus(cue_completion_id, amount, reason = 'Thanks for your hard work!', note_to_self = nil) ⇒ Object
This will grant a bonus to the user who has completed a particular Cue for us.
-
#initialize(api_key, api_pass, base_url = nil) ⇒ CueCloudApi
constructor
A new instance of CueCloudApi.
-
#make_deposit(amount_in_usd, cc_last_four) ⇒ Object
Given a valid CC on file in the app, This will deposit that amount into the user’s balance.
-
#submit_cue_completion(assignment_id, answer_text: nil, video_url: nil, video_thumbnail_url: nil, image_url: nil, is_anonymous: nil) ⇒ Object
This will submit the CueCompletion data, though In production the method will block any requests without an HTTP_REFERER.
-
#validate_user ⇒ Object
This is a test method to make sure that the user has valid API credentials.
-
#withdraw_funds(amount_in_usd = nil) ⇒ Object
Given a PayPal email, this will deposit the funds immediately into that user’s PayPal account.
Constructor Details
#initialize(api_key, api_pass, base_url = nil) ⇒ CueCloudApi
Returns a new instance of CueCloudApi.
8 9 10 11 12 13 |
# 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 |
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'lib/cuecloud/cuecloud_api.rb', line 6 def request @request end |
Instance Method Details
#approve_cue_completion(cue_completion_id) ⇒ Object
This will approve a CueCompletion that has been submitted to the user’s Cue.
92 93 94 95 |
# 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) ⇒ Object
This will try and check-in or check-out a Cue depending on whether the Cue is already checked out by that user.
178 179 180 181 |
# 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) ⇒ Object
This will cancel a Cue that you have posted, refunding your balance.
104 105 106 107 |
# 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) ⇒ Object
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.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# 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) ⇒ Object
This will decline a CueCompletion that has been submitted to the user’s Cue.
98 99 100 101 |
# 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 ⇒ Object
This will return the user’s current balance, in USD.
28 29 30 |
# 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) ⇒ Object
This will return CueCompletions for a particular Cue. Status options for CueCompletions are ‘Pending`, `Accepted`, and `Declined`.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# 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) ⇒ Object
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'
162 163 164 165 166 167 168 169 170 171 172 173 174 |
# 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 ⇒ Object
This will return common keywords for Cues. Useful for CueCreation.
23 24 25 |
# 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) ⇒ Object
Payment type may be one of ‘Deposits`, `Withdrawals`, or `Bonuses`. 50 results will show per page.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# 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) ⇒ Object
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.”
61 62 63 64 65 66 67 68 69 |
# 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) ⇒ Object
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.
35 36 37 38 39 40 41 |
# 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) ⇒ Object
This will submit the CueCompletion data, though In production the method will block any requests without an HTTP_REFERER.
185 186 187 188 189 190 191 192 193 194 195 196 |
# 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 ⇒ Object
This is a test method to make sure that the user has valid API credentials.
17 18 19 |
# File 'lib/cuecloud/cuecloud_api.rb', line 17 def validate_user build_request('validate/', 'GET') end |
#withdraw_funds(amount_in_usd = nil) ⇒ Object
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.
47 48 49 50 |
# 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 |