Module: Users

Includes:
BaseClient
Included in:
Spartacus
Defined in:
lib/client/users.rb

Instance Method Summary collapse

Methods included from BaseClient

#auth_header, #convert_keys, #convert_response, #handle_timeouts, #success?, #whitelist_params

Instance Method Details

#get_accomplishments(id) ⇒ HTTParty::Response

Get user accomplishments

Examples:

Get user accomplishments

Spartacus#get_accomplishments

Parameters:

  • id (Integer)

    A user id.

Returns:

  • (HTTParty::Response)

    User accomplishments.



93
94
95
96
97
98
# File 'lib/client/users.rb', line 93

def get_accomplishments(id)
  url = "#{@api_base_path}/users/#{id}/accomplishments"
  handle_timeouts do
    self.class.get(url, headers: auth_header)
  end
end

#get_availability(id) ⇒ HTTParty::Response

Get user availability

Examples:

Get user availability

Spartacus#get_availability

Parameters:

  • id (Integer)

    A user id.

Returns:

  • (HTTParty::Response)

    User availability.



66
67
68
69
70
71
72
# File 'lib/client/users.rb', line 66

def get_availability(id)
  url = "#{@api_base_path}/users/#{id}/availability"
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "availability")
  end
end

#get_available_mentorsUser

Get available mentors for a user

Examples:

Get avaiable mentors

Spartacus#get_available_mentors

Parameters:

  • id (Integer)

    A user id.

Returns:

  • (User)

    Available mentors.



52
53
54
55
56
57
58
# File 'lib/client/users.rb', line 52

def get_available_mentors
  url = "#{@api_base_path}/users/available_mentors"
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "user")
  end
end

#get_enrollments(id) ⇒ HTTParty::Response

Get user enrollments

Examples:

Get user enrollments

Spartacus#get_enrollments

Parameters:

  • id (Integer)

    A user id.

Returns:

  • (HTTParty::Response)

    User enrollments.



80
81
82
83
84
85
# File 'lib/client/users.rb', line 80

def get_enrollments(id)
  url = "#{@api_base_path}/users/#{id}/enrollments"
  handle_timeouts do
    self.class.get(url, headers: auth_header)
  end
end

#get_meUser

Get your own user

Examples:

Get yourself

Spartacus#get_me

Returns:

  • (User)

    You.



24
25
26
27
28
29
30
# File 'lib/client/users.rb', line 24

def get_me
  url = "#{@api_base_path}/users/me"
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "user")
  end
end

#get_user(id) ⇒ User

Get all user

Examples:

Get a user

Spartacus#get_user

Parameters:

  • id (Integer)

    A user id.

Returns:

  • (User)

    A user.



38
39
40
41
42
43
44
# File 'lib/client/users.rb', line 38

def get_user(id)
  url = "#{@api_base_path}/users/#{id}"
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "user")
  end
end

#get_usersHTTParty::Response

Get all users

Examples:

Get all users

Spartacus#get_users

Returns:

  • (HTTParty::Response)

    All users.



11
12
13
14
15
16
17
# File 'lib/client/users.rb', line 11

def get_users
  url = "#{@api_base_path}/users"
  handle_timeouts do
    response = self.class.get(url, headers: auth_header)
    convert_response(response, "user")
  end
end

#onboard(id) ⇒ HTTParty::Response

Mark user’s current enrollment as onboarded

Examples:

Onboard user

Spartacus#onboard

Parameters:

  • id (Integer)

    A user id.

Returns:

  • (HTTParty::Response)

    Succes or failure message.



106
107
108
109
110
111
# File 'lib/client/users.rb', line 106

def onboard(id)
  url = "#{@api_base_path}/users/#{id}/onboard"
  handle_timeouts do
    self.class.post(url, headers: auth_header)
  end
end

#update_password(id, password) ⇒ User

Update the user’s password

Examples:

Update user password

Spartacus#update_password

Parameters:

  • id (Integer)

    A user id.

  • password (String)

    User password.

Returns:

  • (User)

    Updated user.



120
121
122
123
124
125
126
127
128
129
# File 'lib/client/users.rb', line 120

def update_password(id, password)
  url = "#{@api_base_path}/users/#{id}/update_password"
  handle_timeouts do
    response = self.class.put(url, headers: auth_header,
                              body: { user: { password: password,
                                               confirmation: password } })
    convert_response(response, "user")

  end
end

#update_user(id, options = {}) ⇒ User

Update a user

Examples:

Update a user’s data

Spartacus#update_user_data(129, {how_heard: 'On the Googles'})

Parameters:

  • id (Integer)

    A user id.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :email (String)

    User email.

  • :first_name (String)

    User first_name.

  • :last_name (String)

    User last name.

  • :twitter_handle (String)

    User Twitter handle.

  • :dribbble_handle (String)

    User Dribbble handle.

  • :github_handle (String)

    User GitHub handle.

  • :codecademy_handle (String)

    User Codecademy handle.

  • :linkedin (String)

    User LinkIn profile.

  • :time_zone (String)

    User time zone

  • :bio (String)

    User biography.

  • :name (String)

    User fullname.

  • :photo (String)

    User photo.

  • :os (String)

    User operating system.

  • :dismissed_holiday_freeze (Boolean)

    User dismissed holiday freeze.

  • :title (String)

    User title.

  • :lead_mentor_account (String)

    User lead mentor account.

  • :password (String)

    User password.

  • :password_confirmation (String)

    User password confirmation.

  • :remember_me (Boolean)

    Remeber user.

  • :facebook_id (String)

    User Facebook ID.

  • :stripe_customer_id (String)

    User Stripe customer ID.

  • :stripe_token (String)

    User Stripe token.

  • :skype_handle (String)

    User Skype handle.

  • :referral_token (String)

    User referral token.

  • :send_new_message_emails (Boolean)

    Send user new emails.

  • :referred_by_id (String)

    User referred by ID.

  • :google_plus_id (String)

    User GooglePlus ID.

  • :private_profile (Boolean)

    Set user profile to private.

  • :quota (Integer)

    User student quota.

  • :quota_limit (Integer)

    User student quota limit.

  • :first_visit_id (Integer)

    User first visit ID.

  • :crm_lead_id (Integer)

    User CRM lead ID.

  • :phone_num (String)

    User phone number.

  • :role (String)

    User role.

  • :student_profile (Integer)

    User student profile.

  • :tos (String)

Returns:

  • (User)

    The updated user.



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/client/users.rb', line 175

def update_user(id, options={})
  whitelist = ['email','first_name','last_name','twitter_handle',
               'dribbble_handle','github_handle','codecademy_handle',
               'linkedin','time_zone','bio','name','photo','os',
               'dismissed_holiday_freeze','title','lead_mentor_account',
               'password','password_confirmation','remember_me','facebook_id',
               'stripe_customer_id','stripe_token','skype_handle',
               'referral_token','send_new_message_emails','referred_by_id',
               'google_plus_id','private_profile','quota','quota_limit',
               'first_visit_id','crm_lead_id','phone_num','role',
               'student_profile','tos']

  options = convert_keys(options)
  user_params = whitelist_params(options, whitelist)
  url = "#{@api_base_path}/users/#{id}"

  handle_timeouts do
    response = self.class.put(url, headers: auth_header,
                              body: { user: user_params })
    convert_response(response, "User")
  end
end