class ProcessOut::Event

Attributes

data[R]
fired_at[R]
id[R]
name[R]
project[R]
project_id[R]
sandbox[R]

Public Class Methods

new(client, data = {}) click to toggle source

Initializes the Event object Params:

client

ProcessOut client instance

data

data that can be used to fill the object

# File lib/processout/event.rb, line 66
def initialize(client, data = {})
  @client = client

  self.id = data.fetch(:id, nil)
  self.project = data.fetch(:project, nil)
  self.project_id = data.fetch(:project_id, nil)
  self.name = data.fetch(:name, nil)
  self.data = data.fetch(:data, nil)
  self.sandbox = data.fetch(:sandbox, nil)
  self.fired_at = data.fetch(:fired_at, nil)
  
end

Public Instance Methods

all(options = {}) click to toggle source

Get all the events. Params:

options

Hash of options

# File lib/processout/event.rb, line 180
def all(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/events"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['events']
    tmp = Event.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end
data=(val) click to toggle source
# File lib/processout/event.rb, line 48
def data=(val)
  @data = val
  
end
fetch_webhooks(options = {}) click to toggle source

Get all the webhooks of the event. Params:

options

Hash of options

# File lib/processout/event.rb, line 150
def fetch_webhooks(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/events/" + CGI.escape(@id) + "/webhooks"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['webhooks']
    tmp = Webhook.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end
fill_with_data(data) click to toggle source

Fills the object with data coming from the API Params:

data

Hash of data coming from the API

# File lib/processout/event.rb, line 100
def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "id"
    self.id = data["id"]
  end
  if data.include? "project"
    self.project = data["project"]
  end
  if data.include? "project_id"
    self.project_id = data["project_id"]
  end
  if data.include? "name"
    self.name = data["name"]
  end
  if data.include? "data"
    self.data = data["data"]
  end
  if data.include? "sandbox"
    self.sandbox = data["sandbox"]
  end
  if data.include? "fired_at"
    self.fired_at = data["fired_at"]
  end
  
  self
end
find(event_id, options = {}) click to toggle source

Find an event by its ID. Params:

event_id

ID of the event

options

Hash of options

# File lib/processout/event.rb, line 211
def find(event_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/events/" + CGI.escape(event_id) + ""
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["event"]
  
  
  obj = Event.new(@client)
  return_values.push(obj.fill_with_data(body))
  

  
  return_values[0]
end
fired_at=(val) click to toggle source
# File lib/processout/event.rb, line 57
def fired_at=(val)
  @fired_at = val
end
id=(val) click to toggle source
# File lib/processout/event.rb, line 20
def id=(val)
  @id = val
end
name=(val) click to toggle source
# File lib/processout/event.rb, line 44
def name=(val)
  @name = val
end
new(data = {}) click to toggle source

Create a new Event using the current client

# File lib/processout/event.rb, line 80
def new(data = {})
  Event.new(@client, data)
end
prefill(data) click to toggle source

Prefills the object with the data passed as parameters Params:

data

Hash of data

# File lib/processout/event.rb, line 132
def prefill(data)
  if data.nil?
    return self
  end
  self.id = data.fetch(:id, self.id)
  self.project = data.fetch(:project, self.project)
  self.project_id = data.fetch(:project_id, self.project_id)
  self.name = data.fetch(:name, self.name)
  self.data = data.fetch(:data, self.data)
  self.sandbox = data.fetch(:sandbox, self.sandbox)
  self.fired_at = data.fetch(:fired_at, self.fired_at)
  
  self
end
project=(val) click to toggle source
# File lib/processout/event.rb, line 24
def project=(val)
  if val.nil?
    @project = val
    return
  end

  if val.instance_of? Project
    @project = val
  else
    obj = Project.new(@client)
    obj.fill_with_data(val)
    @project = obj
  end
  
end
project_id=(val) click to toggle source
# File lib/processout/event.rb, line 40
def project_id=(val)
  @project_id = val
end
sandbox=(val) click to toggle source
# File lib/processout/event.rb, line 53
def sandbox=(val)
  @sandbox = val
end
to_json(options) click to toggle source

Overrides the JSON marshaller to only send the fields we want

# File lib/processout/event.rb, line 85
def to_json(options)
  {
      "id": self.id,
      "project": self.project,
      "project_id": self.project_id,
      "name": self.name,
      "data": self.data,
      "sandbox": self.sandbox,
      "fired_at": self.fired_at,
  }.to_json
end