class ProcessOut::Activity

Attributes

content[R]
created_at[R]
id[R]
level[R]
project[R]
project_id[R]
title[R]

Public Class Methods

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

Initializes the Activity object Params:

client

ProcessOut client instance

data

data that can be used to fill the object

# File lib/processout/activity.rb, line 65
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.title = data.fetch(:title, nil)
  self.content = data.fetch(:content, nil)
  self.level = data.fetch(:level, nil)
  self.created_at = data.fetch(:created_at, nil)
  
end

Public Instance Methods

all(options = {}) click to toggle source

Get all the project activities. Params:

options

Hash of options

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

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

  }

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

  return_values.push(a)
  

  
  return_values[0]
end
content=(val) click to toggle source
# File lib/processout/activity.rb, line 48
def content=(val)
  @content = val
end
created_at=(val) click to toggle source
# File lib/processout/activity.rb, line 56
def created_at=(val)
  @created_at = val
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/activity.rb, line 99
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? "title"
    self.title = data["title"]
  end
  if data.include? "content"
    self.content = data["content"]
  end
  if data.include? "level"
    self.level = data["level"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  
  self
end
find(activity_id, options = {}) click to toggle source

Find a specific activity and fetch its data. Params:

activity_id

ID of the activity

options

Hash of options

# File lib/processout/activity.rb, line 180
def find(activity_id, options = {})
  self.prefill(options)

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

  }

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

  
  return_values[0]
end
id=(val) click to toggle source
# File lib/processout/activity.rb, line 20
def id=(val)
  @id = val
end
level=(val) click to toggle source
# File lib/processout/activity.rb, line 52
def level=(val)
  @level = val
end
new(data = {}) click to toggle source

Create a new Activity using the current client

# File lib/processout/activity.rb, line 79
def new(data = {})
  Activity.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/activity.rb, line 131
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.title = data.fetch(:title, self.title)
  self.content = data.fetch(:content, self.content)
  self.level = data.fetch(:level, self.level)
  self.created_at = data.fetch(:created_at, self.created_at)
  
  self
end
project=(val) click to toggle source
# File lib/processout/activity.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/activity.rb, line 40
def project_id=(val)
  @project_id = val
end
title=(val) click to toggle source
# File lib/processout/activity.rb, line 44
def title=(val)
  @title = val
end
to_json(options) click to toggle source

Overrides the JSON marshaller to only send the fields we want

# File lib/processout/activity.rb, line 84
def to_json(options)
  {
      "id": self.id,
      "project": self.project,
      "project_id": self.project_id,
      "title": self.title,
      "content": self.content,
      "level": self.level,
      "created_at": self.created_at,
  }.to_json
end