Class: Upcoming::Group

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/upcoming/group.rb

Class Method Summary collapse

Methods included from Defaults

included

Class Method Details

.add(info, token) ⇒ Object

Add a new group to the database. This method requires authentication.

token (Required) An authentication token.

name (Required) The name of the group.

description (Optional) The group’s description. May contain some HTML.

event_moderation (Numeric, either 1 or 0) Whether to enable moderation of event suggestions. Default is 0.

member_moderation (Numeric, either 1 or 0) Whether to enable moderation of new members. Default is 0.

is_private (Number, 1 or 0) Indicates whether it should be a private, invite-only group(1), or available for public view and searching (0).



108
109
110
111
112
113
114
115
116
# File 'lib/upcoming/group.rb', line 108

def self.add(info, token)
  token = Upcoming::Auth.token_code(token)
  format :xml
  body = {:method => 'group.add', :token => token}
  body.merge!(info)
  body.merge!(Upcoming.default_options)
  body.merge!({:format => 'xml'})
  Mash.new(self.post('/', :body => body)).rsp.group
end

.add_event(group_id, event_id, token) ⇒ Object

Try to add an event to a group. If the group is moderated, the request may be queued for administrator review instead of processed immediately.This method requires authentication.

token (Required) An authentication token.

group_id (Required) The id of the group.

event_id (Required) The id of the event to send.



194
195
196
197
198
199
200
201
# File 'lib/upcoming/group.rb', line 194

def self.add_event(group_id, event_id, token)
  token = Upcoming::Auth.token_code(token)
  format :xml
  body = {:method => 'group.addEventTo', :group_id => group_id,  :event_id => event_id, :token => token}
  body.merge!(Upcoming.default_options)
  body.merge!({:format => 'xml'})
  Mash.new(self.post('/', :body => body)).rsp.group
end

.edit(group, token) ⇒ Object

Edit a group. Only an admin of a group may edit it.This method requires authentication.

token (Required) An authentication token.

group_id (Numeric, Required) The id of the group to edit.

name (Required) The name of the group.

description (Optional) The group’s description. May contain some HTML.

event_moderation (Numeric, either 1 or 0) Whether to enable moderation of event suggestions. Default is 0.

member_moderation (Numeric, either 1 or 0) Whether to enable moderation of new members. Default is 0.

is_private (Number, 1 or 0) Indicates whether it should be a private, invite-only group(1), or available for public view and searching (0).



141
142
143
144
145
146
147
148
149
# File 'lib/upcoming/group.rb', line 141

def self.edit(group, token)
  token = Upcoming::Auth.token_code(token)
  format :xml
  body = {:method => 'group.edit', :token => token}
  body.merge!(info)
  body.merge!(Upcoming.default_options)
  body.merge!({:format => 'xml'})
  Mash.new(self.post('/', :body => body)).rsp.group
end

.events(group_id, token, options = {}) ⇒ Object

Retrieve group event information and metadata for any public group or private group that the authenticated user is a member of.

token (Optional) An authentication token.

group_id (Numeric, Required) The group id requested.

events_per_page (Numeric, Optional) To restrict the number of members per page of results.

page (Numeric, Optional) Page # to return. Starts with 1.

order (Either ‘event_time’ or ‘time_added’, default: ‘event_time’) Event_time orders by event start date, time_added orders by the time the event was added to the group.

dir (Either ‘asc’ or ‘desc’, default: asc) Sort direction.

show_past (Either 1 or 0, default: 0) Whether to exclusively show past results (instead of upcoming) in the event results.



72
73
74
75
76
77
78
79
# File 'lib/upcoming/group.rb', line 72

def self.events(group_id, token, options={})
  opts = {:eventsPerPage => 100, :page => 1, :order => 'event_time', :dir => 'asc', :show_past => 0}
  opts.merge! options
  opts[:eventsPerPage] = opts.delete(:events_per_page) if opts[:events_per_page]
  token = token['token'] if token and token['token']
  query = {:method => 'group.getEvents', :group_id => group_id, :token => token}
  Mash.new(self.get('/', :query => query.merge(opts).merge(Upcoming.default_options))).rsp.event
end

.info(group_id, token = nil) ⇒ Object

Retrieve group information and metadata for public and private groups.

group_id (Required) The id number of the group. You can also pass multiple group_id’s separated by commas to getInfo on multiple groups.

token (Optional) An authentication token. Pass to see even private groups.



13
14
15
16
17
18
19
# File 'lib/upcoming/group.rb', line 13

def self.info(group_id, token=nil)
  group_id = group_id.join(',') if group_id.is_a?(Array)
  token = token['token'] if token and token['token']
  query = {:method => 'group.getInfo', :group_id => group_id}
  query.merge!(:token => token) if token
  Mash.new(self.get('/', :query => query.merge(Upcoming.default_options))).rsp.group
end

.join(group_id, token) ⇒ Object

Try to join a group. If the group is moderated, the request may be queued for administrator review instead of processed immediately. This method requires authentication.

token (Required) An authentication token.

group_id (Required) The id of the group to join.



158
159
160
161
162
163
164
165
# File 'lib/upcoming/group.rb', line 158

def self.join(group_id, token)
  token = Upcoming::Auth.token_code(token)
  format :xml
  body = {:method => 'group.join', :group_id => group_id,  :token => token}
  body.merge!(Upcoming.default_options)
  body.merge!({:format => 'xml'})
  Mash.new(self.post('/', :body => body)).rsp.group
end

.leave(group_id, token) ⇒ Object

Try to leave a group. If the user leaving was the last member of the group, the group is permanently deleted, and may not be rejoined. If the user who left was the last admin in the group, the user remaining with the earliest join timestamp becomes an admin. This method requires authentication.

token (Required) An authentication token.

group_id (Required) The id of the group to leave.



174
175
176
177
178
179
180
181
# File 'lib/upcoming/group.rb', line 174

def self.leave(group_id, token)
  token = Upcoming::Auth.token_code(token)
  format :xml
  body = {:method => 'group.leave', :group_id => group_id,  :token => token}
  body.merge!(Upcoming.default_options)
  body.merge!({:format => 'xml'})
  Mash.new(self.post('/', :body => body)).rsp.stat == 'ok'
end

.members(group_id, token, options = {}) ⇒ Object

Retrieve group member user information and metadata for any public group or private group that the authenticated user is a member of.

token (Required) An authentication token.

group_id (Numeric, Required) The group id requested.

members_per_page (Numeric, Optional) To restrict the number of members per page of results. Default is 100.

page (Numeric, Optional) Page # to return. Starts with 1.

order (Either ‘member_timestamp’ or ‘username’, default: ‘username’) Member_timestamp orders by date joined.

dir (Either ‘asc’ or ‘desc’, default: asc) Sort direction.



41
42
43
44
45
46
47
48
# File 'lib/upcoming/group.rb', line 41

def self.members(group_id, token, options={})
  opts = {:membersPerPage => 100, :page => 1, :order => 'username', :dir => 'asc'}
  opts.merge! options
  opts[:membersPerPage] = opts.delete(:members_per_page) if opts[:members_per_page]
  token = token['token'] if token and token['token']
  query = {:method => 'group.getMembers', :group_id => group_id, :token => token}
  Mash.new(self.get('/', :query => query.merge(opts).merge(Upcoming.default_options))).rsp.user
end

.my_groups(token) ⇒ Object

Retrieve group information and metadata for all groups that the authenticated user is a member of. This method requires authentication.

token (Required) An authentication token.



85
86
87
# File 'lib/upcoming/group.rb', line 85

def self.my_groups(token)
  Mash.new(self.get('/', :query => {:method => 'getMyGroups', :token => token}.merge(Upcoming.default_options))).rsp.event
end

.remove_event(group_id, event_id, token) ⇒ Object

Try to remove an event to a group. This method can only be called by an authenticated group admin, or by the user who added the event to the group. This method requires authentication.

token (Required) An authentication token.

group_id (Required) The id of the group.

event_id (Required) The id of the event to remove.



214
215
216
217
218
219
220
221
# File 'lib/upcoming/group.rb', line 214

def self.remove_event(group_id, event_id, token)
  token = Upcoming::Auth.token_code(token)
  format :xml
  body = {:method => 'group.removeEvent', :group_id => group_id, :event_id => event, :token => token}
  body.merge!(Upcoming.default_options)
  body.merge!({:format => 'xml'})
  Mash.new(self.post('/', :body => body)).rsp.stat == 'ok'
end