Class: Ketchup::Profile
- Inherits:
-
Object
- Object
- Ketchup::Profile
- Defined in:
- lib/ketchup/profile.rb
Overview
A user profile, which provides an interface to the user’s meetings and projects. You can either create it yourself, using an email and password, or through the Ketchup module’s authenticate method - they’re exactly the same.
This is the central object for all of your operations through the Ketchup API. You don’t need to create or manually request any other objects, but instead, access them all through the collections on this class.
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#email ⇒ Object
Returns the value of attribute email.
-
#name ⇒ Object
Returns the value of attribute name.
-
#single_access_token ⇒ Object
readonly
Returns the value of attribute single_access_token.
-
#timezone ⇒ Object
Returns the value of attribute timezone.
Class Method Summary collapse
-
.create(email, password, options = {}) ⇒ Object
Create a completely new user account.
-
.load(email, password) ⇒ Ketchup::Profile
Set up a connection to an existing profile.
Instance Method Summary collapse
-
#change_password(password) ⇒ Object
Change the password for this profile account.
-
#initialize(api) ⇒ Profile
constructor
Set up a new profile object with an active API connection.
-
#meetings ⇒ Ketchup::MeetingArray
Get an array of meetings attached to this profile.
-
#projects ⇒ Array
Get an array of projects attached to this profile.
-
#reload! ⇒ Object
Reset the meeting and project objects of this profile, allowing them to be reloaded from the server when next requested.
-
#save ⇒ Object
Saves any profile changes to the name, timezone and/or email.
Constructor Details
#initialize(api) ⇒ Profile
Set up a new profile object with an active API connection.
62 63 64 65 66 |
# File 'lib/ketchup/profile.rb', line 62 def initialize(api) @api = api overwrite @api.get('/profile.json') end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
16 17 18 |
# File 'lib/ketchup/profile.rb', line 16 def api @api end |
#email ⇒ Object
Returns the value of attribute email.
17 18 19 |
# File 'lib/ketchup/profile.rb', line 17 def email @email end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/ketchup/profile.rb', line 17 def name @name end |
#single_access_token ⇒ Object (readonly)
Returns the value of attribute single_access_token.
16 17 18 |
# File 'lib/ketchup/profile.rb', line 16 def single_access_token @single_access_token end |
#timezone ⇒ Object
Returns the value of attribute timezone.
17 18 19 |
# File 'lib/ketchup/profile.rb', line 17 def timezone @timezone end |
Class Method Details
.create(email, password, options = {}) ⇒ Object
Create a completely new user account. You (currently) don’t need to have any existing authentication to the server to call this method - just specify the new user’s email address and password.
Other extra parameters are the name and timezone of the user account, but these are optional.
Please note: This method doesn’t return a new profile, just sets the account up.
51 52 53 54 55 56 |
# File 'lib/ketchup/profile.rb', line 51 def self.create(email, password, = {}) Ketchup::API.post '/users.json', :body => .merge( 'email' => email, 'password' => password ) end |
Instance Method Details
#change_password(password) ⇒ Object
Change the password for this profile account.
113 114 115 |
# File 'lib/ketchup/profile.rb', line 113 def change_password(password) @api.put '/profile.json', 'password' => password end |
#meetings ⇒ Ketchup::MeetingArray
Get an array of meetings attached to this profile. Note that the returned object is actually an instance of Ketchup::MeetingArray, which has helper methods for creating and re-ordering meetings.
82 83 84 |
# File 'lib/ketchup/profile.rb', line 82 def meetings @meetings ||= Ketchup::MeetingArray.new api end |
#projects ⇒ Array
Get an array of projects attached to this profile. This is not a special project array, as you can only edit projects, not create them. They are created explicitly from meetings.
92 93 94 95 96 |
# File 'lib/ketchup/profile.rb', line 92 def projects @projects ||= api.get('/projects.json').collect { |hash| Ketchup::Project.new(api, hash) } end |
#reload! ⇒ Object
Reset the meeting and project objects of this profile, allowing them to be reloaded from the server when next requested.
71 72 73 74 |
# File 'lib/ketchup/profile.rb', line 71 def reload! @meetings = nil @projects = nil end |
#save ⇒ Object
Saves any profile changes to the name, timezone and/or email. This does not save any changes made to underlying meetings and projects.
101 102 103 104 105 106 107 |
# File 'lib/ketchup/profile.rb', line 101 def save overwrite @api.put('/profile.json', 'name' => name, 'timezone' => timezone, 'email' => email ) end |