Class: MoxiworksPlatform::Event

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

Overview

Moxi Works Platform Event

Instance Attribute Summary collapse

Attributes inherited from Resource

#headers

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, #init_attrs_from_hash, #initialize, #method_missing, #numeric_attrs, #numeric_value_for, #to_hash, underscore, underscore_array, underscore_attribute_names, underscore_hash, user_agent_header

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)


9
10
11
# File 'lib/moxiworks_platform/event.rb', line 9

def all_day
  @all_day
end

#attendeesString

a comma separated list of attendee IDs

Returns:

  • (String)


15
16
17
# File 'lib/moxiworks_platform/event.rb', line 15

def attendees
  @attendees
end

#event_endInteger

a unix timestamp representing the end time of the event

Returns:

  • (Integer)


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

attr_writer :event_end

#event_locationString

a short description of the location of the event

Returns:

  • (String)


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

def event_location
  @event_location
end

#event_startInteger

a unix timestamp representing the start time of the event

Returns:

  • (Integer)


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

attr_writer :event_start

#event_subjectString

a short description of the event

Returns:

  • (String)


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

def event_subject
  @event_subject
end

#is_meetingBoolean

whether this event is a meeting

Returns:

  • (Boolean)


45
46
47
# File 'lib/moxiworks_platform/event.rb', line 45

def is_meeting
  @is_meeting
end

#locationString

a short description of the location of the event

Returns:

  • (String)


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

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



54
55
56
# File 'lib/moxiworks_platform/event.rb', line 54

def moxi_works_agent_id
  @moxi_works_agent_id
end

#noteString

a more detailed description of the event

Returns:

  • (String)


60
61
62
# File 'lib/moxiworks_platform/event.rb', line 60

def note
  @note
end

#partner_event_idString

your system’s event ID for the event

Returns:

  • (String)

    representing the ID of the event in your system



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

def partner_event_id
  @partner_event_id
end

#remind_minutes_beforeInteger

how many minutes before the event a reminder should be sent

Returns:

  • (Integer)


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

attr_writer :remind_minutes_before

#send_reminderBoolean

whether to send a reminder to attendees

Returns:

  • (Boolean)


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

def send_reminder
  @send_reminder
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

  • :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



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/moxiworks_platform/event.rb', line 247

def self.delete(opts={})
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  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
182
183
184
185
186
187
188
# File 'lib/moxiworks_platform/event.rb', line 156

def self.search(opts={})
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  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 = MoxiResponseArray.new()
  RestClient::Request.execute(method: :get,
                              url: url,
                              payload: opts, headers: self.headers) do |response|
    puts response if MoxiworksPlatform::Config.debug
    results.headers = response.headers
    self.check_for_error_in_response(response)
    json = JSON.parse(response)

    results.page_number = 1
    results.total_pages = 1

    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

  • :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



292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/moxiworks_platform/event.rb', line 292

def self.send_request(method, opts={}, url=nil)
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  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

  • :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



225
226
227
228
229
# File 'lib/moxiworks_platform/event.rb', line 225

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



327
328
329
# File 'lib/moxiworks_platform/event.rb', line 327

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)


315
316
317
# File 'lib/moxiworks_platform/event.rb', line 315

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