Class: MoxiworksPlatform::Event

Inherits:
Resource
  • Object
show all
Defined in:
lib/moxiworks_platform/event.rb

Overview

Moxi Works Platform Event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

accept_header, attr_accessor, attributes, #attributes, auth_header, check_for_error_in_response, content_type_header, #float_attrs, headers, #initialize, #method_missing, #numeric_attrs, #numeric_value_for, #to_hash

Constructor Details

This class inherits a constructor from MoxiworksPlatform::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MoxiworksPlatform::Resource

Instance Attribute Details

#all_dayBoolean

whether the event is an all day event

Returns:

  • (Boolean)


65
66
67
# File 'lib/moxiworks_platform/event.rb', line 65

def all_day
  @all_day
end

#event_endInteger

a unix timestamp representing the end time of the event

Returns:

  • (Integer)


59
# File 'lib/moxiworks_platform/event.rb', line 59

attr_writer :event_end

#event_locationString

a short description of the location of the event

Returns:

  • (String)


29
30
31
# File 'lib/moxiworks_platform/event.rb', line 29

def event_location
  @event_location
end

#event_startInteger

a unix timestamp representing the start time of the event

Returns:

  • (Integer)


53
# File 'lib/moxiworks_platform/event.rb', line 53

attr_writer :event_start

#event_subjectString

a short description of the event

Returns:

  • (String)


23
24
25
# File 'lib/moxiworks_platform/event.rb', line 23

def event_subject
  @event_subject
end

#is_meetingBoolean

whether this event is a meeting

Returns:

  • (Boolean)


47
48
49
# File 'lib/moxiworks_platform/event.rb', line 47

def is_meeting
  @is_meeting
end

#locationString

a short description of the location of the event

Returns:

  • (String)


29
# File 'lib/moxiworks_platform/event.rb', line 29

attr_accessor :event_location

#moxi_works_agent_idString

moxi_works_agent_id is the Moxi Works Platform ID of the agent which a event is or is to be associated with.

this must be set for any Moxi Works Platform transaction

Returns:

  • (String)

    the Moxi Works Platform ID of the agent



11
12
13
# File 'lib/moxiworks_platform/event.rb', line 11

def moxi_works_agent_id
  @moxi_works_agent_id
end

#noteString

a more detailed description of the event

Returns:

  • (String)


35
36
37
# File 'lib/moxiworks_platform/event.rb', line 35

def note
  @note
end

#optional_attendeesString

a comma separated list of attendee IDs

Returns:

  • (String)


77
78
79
# File 'lib/moxiworks_platform/event.rb', line 77

def optional_attendees
  @optional_attendees
end

#partner_event_idString

your system’s event ID for the event

Returns:

  • (String)

    representing the ID of the event in your system



17
18
19
# File 'lib/moxiworks_platform/event.rb', line 17

def partner_event_id
  @partner_event_id
end

#remind_minutes_beforeInteger

how many minutes before the event a reminder should be sent

Returns:

  • (Integer)


41
# File 'lib/moxiworks_platform/event.rb', line 41

attr_writer :remind_minutes_before

#required_attendeesString

a comma separated list of attendee IDs

Returns:

  • (String)


71
72
73
# File 'lib/moxiworks_platform/event.rb', line 71

def required_attendees
  @required_attendees
end

Class Method Details

.create(opts = {}) ⇒ MoxiworksPlatform::Event

Creates a new Event in Moxi Works Platform

Examples:

MoxiworksPlatform::Event.create(
      partner_event_id: 'mySystemsUniqueEventID',
      event_subject: 'foo deeaz',
      event_location: '1234 there ave',
      note: 'yo, whatup?',
      remind_minutes_before: 10,
      is_meeting: true,
      event_start: Time.now.to_i,
      event_end: Time.now.to_i + 86400,
      all_day: false
  )

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this event is to be associated

  • :partner_event_id (String)

    REQUIRED Your system’s unique ID for this event.

    optional Event parameters

  • :event_subject (String)

    a brief human-readable description of the event

  • :event_location (String)

    human-readable description of the event’s location

  • :note (String)

    human-readable details regarding the event

  • :remind_minutes_before (Integer)

    how many minutes before the event the reminder should be sent

  • :is_meeting (Boolean)

    whether the event is a meeting

  • :event_start (Integer)

    Unix timestamp representing the start time of the event

  • :event_end (Integer)

    Unix timestamp representing the end time of the event

  • :all_day (Boolean)

    whether the event is an all day event

  • :required_attendees (String)

    comma separated list of attendee IDs using Contact IDs from your system (partner_contact_id) that have already been added to The Moxi Works Platform as a Contact

  • :optional_attendees (String)

    comma separated list of attendee IDs using Contact IDs from your system (partner_contact_id) that have already been added to The Moxi Works Platform as a Contact

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



115
116
117
# File 'lib/moxiworks_platform/event.rb', line 115

def self.create(opts={})
  self.send_request(:post, opts)
end

.delete(opts = {}) ⇒ Boolean

Delete an Event your system has previously created in Moxi Works Platform

Examples:

success = MoxiWorksPlatform::Event.delete(moxi_works_agent_id: '123abcd', partner_event_id: 'myUniqueEventId' )

Parameters:

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

    named parameter Hash

    required parameters

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this event is associated

  • :partner_event_id (String)

    REQUIRED Your system’s unique ID for this event.

Returns:

  • (Boolean)

    – success of the delete action

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/moxiworks_platform/event.rb', line 241

def self.delete(opts={})
  url = "#{MoxiworksPlatform::Config.url}/api/events/#{opts[:partner_event_id]}"
  required_opts = [:moxi_works_agent_id, :partner_event_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  RestClient::Request.execute(method: :delete,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    json = JSON.parse(response)
    raise ::MoxiworksPlatform::Exception::RemoteRequestFailure,
          'unable to delete' if json['status'] == 'error'
    json['status'] == 'success'
  end
end

.find(opts = {}) ⇒ MoxiworksPlatform::Event

Find an Event your system has previously created in Moxi Works Platform

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this event is associated

  • :partner_event_id (String)

    REQUIRED Your system’s unique ID for this event.

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



129
130
131
132
# File 'lib/moxiworks_platform/event.rb', line 129

def self.find(opts={})
  url = "#{MoxiworksPlatform::Config.url}/api/events/#{opts[:partner_event_id]}"
  self.send_request(:get, opts, url)
end

.search(opts = {}) ⇒ Array

Search an Agent’s Events in Moxi Works Platform

Examples:

results = MoxiworksPlatform::Contact.search(
moxi_works_agent_id: '123abc',
date_start: Time.now - 60 * 60 * 24 * 7, # 1 week
date_end: Time.now
  )

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this event is associated

  • :date_start (Integer)

    REQUIRED The Unix timestamp representing the date after which to search

  • :date_end (Integer)

    REQUIRED The Unix timestamp representing the date before which to search

Returns:

  • (Array)

    containing Hash objects formatted as follows: { “date” => “MM/DD/YY”,

    "events" => [ MoxiworkPlatform::Event, MoxiworkPlatform::Event ]
    

    }

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/moxiworks_platform/event.rb', line 156

def self.search(opts={})
  url ||= "#{MoxiworksPlatform::Config.url}/api/events"
  required_opts = [:moxi_works_agent_id, :date_start, :date_end]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  results = []
  RestClient::Request.execute(method: :get,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    self.check_for_error_in_response(response)
    json = JSON.parse(response)
    json.each do |events_for_date|
      events = []
      events_for_date.each do |date, event_array|
        event_array.each do |r|
          events << MoxiworksPlatform::Event.new(r) unless r.nil? or r.empty?
        end
        results << {date: date, events: events}
      end
    end
  end
  results
end

.send_request(method, opts = {}, url = nil) ⇒ MoxiworksPlatform::Event

Send our remote request to the Moxi Works Platform

Parameters:

  • method (String)

    The HTTP method to be used when connecting; ex: :put, :post, :get

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

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this event is associated

  • :partner_event_id (String)

    REQUIRED Your system’s unique ID for this event.

    optional Event parameters

  • :event_subject (String)

    a brief human-readable description of the event

  • :event_location (String)

    human-readable description of the event’s location

  • :note (String)

    human-readable details regarding the event

  • :remind_minutes_before (Integer)

    how many minutes before the event the reminder should be sent

  • :is_meeting (Boolean)

    whether the event is a meeting

  • :event_start (Integer)

    Unix timestamp representing the start time of the event

  • :event_end (Integer)

    Unix timestamp representing the end time of the event

  • :recurring (Boolean)

    whether the event is a recurring event

  • :all_day (Boolean)

    whether the event is an all day event

  • :required_attendees (String)

    comma separated list of attendee IDs using Contact IDs from your system (partner_contact_id) that have already been added to The Moxi Works Platform as a Contact

  • :optional_attendees (String)

    comma separated list of attendee IDs using Contact IDs from your system (partner_contact_id) that have already been added to The Moxi Works Platform as a Contact

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



285
286
287
288
289
290
291
292
293
294
# File 'lib/moxiworks_platform/event.rb', line 285

def self.send_request(method, opts={}, url=nil)
  url ||= "#{MoxiworksPlatform::Config.url}/api/events"
  required_opts = [:moxi_works_agent_id, :partner_event_id]
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  opts[:event_id] = opts[:partner_event_id]
  super(method, opts, url)
end

.update(opts = {}) ⇒ MoxiworksPlatform::Event

Updates a new Event in Moxi Works Platform

Examples:

MoxiworksPlatform::Event.update(
      partner_event_id: 'mySystemsUniqueEventID',
      event_subject: 'foo deeaz',
      event_location: '1234 there ave',
      note: 'yo, whatup?',
      remind_minutes_before: 10,
      is_meeting: true,
      event_start: Time.now.to_i,
      event_end: Time.now.to_i + 86400,
      all_day: false
  )

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_agent_id (String)

    REQUIRED The Moxi Works Agent ID for the agent to which this event is to be associated

  • :partner_event_id (String)

    REQUIRED Your system’s unique ID for this event.

    optional Event parameters

  • :event_subject (String)

    a brief human-readable description of the event

  • :event_location (String)

    human-readable description of the event’s location

  • :note (String)

    human-readable details regarding the event

  • :remind_minutes_before (Integer)

    how many minutes before the event the reminder should be sent

  • :is_meeting (Boolean)

    whether the event is a meeting

  • :event_start (Integer)

    Unix timestamp representing the start time of the event

  • :event_end (Integer)

    Unix timestamp representing the end time of the event

  • :all_day (Boolean)

    whether the event is an all day event

  • :required_attendees (String)

    comma separated list of attendee IDs using Contact IDs from your system (partner_contact_id) that have already been added to The Moxi Works Platform as a Contact

  • :optional_attendees (String)

    comma separated list of attendee IDs using Contact IDs from your system (partner_contact_id) that have already been added to The Moxi Works Platform as a Contact

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



219
220
221
222
223
# File 'lib/moxiworks_platform/event.rb', line 219

def self.update(opts={})
  opts[:event_id] = opts[:partner_event_id]
  url = "#{MoxiworksPlatform::Config.url}/api/events/#{opts[:partner_event_id]}"
  self.send_request(:put, opts, url)
end

Instance Method Details

#deleteBoolean

Delete an instance of MoxiWorksPlatform::Event from Moxi Works Platform that your system has previously created

Examples:

event = MoxiWorksPlatform::Event.find(moxi_works_agent_id: '123abcd', partner_event_id: 'myUniqueEventtId' )
success = event.delete

Returns:

  • (Boolean)

    – success of the delete action



318
319
320
# File 'lib/moxiworks_platform/event.rb', line 318

def delete
  MoxiworksPlatform::Event.delete(self.to_hash)
end

#saveMoxiWorksPlatform:Event

Save an instance of MoxiWorksPlatform::Event to Moxi Works Platform

Examples:

event = MoxiWorksPlatform::Event.new()
event.moxi_works_agent_id = '123abcd'
event.partner_event_id = 'myUniqueEventdentifier'
event.event_start =  Time.now.to_i
event.save

Returns:

  • (MoxiWorksPlatform:Event)


306
307
308
# File 'lib/moxiworks_platform/event.rb', line 306

def save
  MoxiworksPlatform::Event.update(self.to_hash)
end