Class: Ketchup::Profile

Inherits:
Object
  • Object
show all
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.

Examples:

profile = Ketchup::Profile.load '[email protected]', 'secret'
profile.meetings.each do |meeting|
  puts meeting.title
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Profile

Set up a new profile object with an active API connection.

Parameters:



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

#apiObject (readonly)

Returns the value of attribute api.



16
17
18
# File 'lib/ketchup/profile.rb', line 16

def api
  @api
end

#emailObject

Returns the value of attribute email.



17
18
19
# File 'lib/ketchup/profile.rb', line 17

def email
  @email
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/ketchup/profile.rb', line 17

def name
  @name
end

#single_access_tokenObject (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

#timezoneObject

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.

Examples:

Ketchup::Profile.create '[email protected]', 'swordfish', 'name' => 'Bruce'

Parameters:

  • email (String)

    The email address of the new user.

  • password (String)

    The chosen password of the new user.

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

    Other optional user details, such as the name and timezone.



51
52
53
54
55
56
# File 'lib/ketchup/profile.rb', line 51

def self.create(email, password, options = {})
  Ketchup::API.post '/users.json', :body => options.merge(
    'email'     => email,
    'password'  => password
  )
end

.load(email, password) ⇒ Ketchup::Profile

Set up a connection to an existing profile.

Examples:

profile = Ketchup::Profile.load '[email protected]', 'secret'

Parameters:

  • email (String)

    The user’s email address

  • password (String)

    The user’s passwords

Returns:

Raises:



29
30
31
# File 'lib/ketchup/profile.rb', line 29

def self.load(email, password)
  Ketchup::Profile.new Ketchup::API.new(email, password)
end

Instance Method Details

#change_password(password) ⇒ Object

Change the password for this profile account.

Parameters:

  • password (String)

    The new password for the account.



113
114
115
# File 'lib/ketchup/profile.rb', line 113

def change_password(password)
  @api.put '/profile.json', 'password' => password
end

#meetingsKetchup::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.

Returns:



82
83
84
# File 'lib/ketchup/profile.rb', line 82

def meetings
  @meetings ||= Ketchup::MeetingArray.new api
end

#projectsArray

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.

Returns:

  • (Array)

    The collection of projects.



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

#saveObject

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