Class: ProcessOut::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/activity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ Activity

Initializes the Activity object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



65
66
67
68
69
70
71
72
73
74
75
76
# 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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



15
16
17
# File 'lib/processout/activity.rb', line 15

def content
  @content
end

#created_atObject

Returns the value of attribute created_at.



17
18
19
# File 'lib/processout/activity.rb', line 17

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/processout/activity.rb', line 11

def id
  @id
end

#levelObject

Returns the value of attribute level.



16
17
18
# File 'lib/processout/activity.rb', line 16

def level
  @level
end

#projectObject

Returns the value of attribute project.



12
13
14
# File 'lib/processout/activity.rb', line 12

def project
  @project
end

#project_idObject

Returns the value of attribute project_id.



13
14
15
# File 'lib/processout/activity.rb', line 13

def project_id
  @project_id
end

#titleObject

Returns the value of attribute title.



14
15
16
# File 'lib/processout/activity.rb', line 14

def title
  @title
end

Instance Method Details

#all(options = {}) ⇒ Object

Get all the project activities. Params:

options

Hash of options



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# 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

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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 = {}) ⇒ Object

Find a specific activity and fetch its data. Params:

activity_id

ID of the activity

options

Hash of options



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# 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

#new(data = {}) ⇒ Object

Create a new Activity using the current client



79
80
81
# File 'lib/processout/activity.rb', line 79

def new(data = {})
  Activity.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



84
85
86
87
88
89
90
91
92
93
94
# 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