Class: ProcessOut::Project

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes the Project object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/processout/project.rb', line 112

def initialize(client, data = {})
  @client = client

  self.id = data.fetch(:id, nil)
  self.supervisor_project = data.fetch(:supervisor_project, nil)
  self.supervisor_project_id = data.fetch(:supervisor_project_id, nil)
  self.api_version = data.fetch(:api_version, nil)
  self.name = data.fetch(:name, nil)
  self.logo_url = data.fetch(:logo_url, nil)
  self.email = data.fetch(:email, nil)
  self.default_currency = data.fetch(:default_currency, nil)
  self.private_key = data.fetch(:private_key, nil)
  self.dunning_configuration = data.fetch(:dunning_configuration, nil)
  self.created_at = data.fetch(:created_at, nil)
  
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



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

def api_version
  @api_version
end

#created_atObject

Returns the value of attribute created_at.



20
21
22
# File 'lib/processout/project.rb', line 20

def created_at
  @created_at
end

#default_currencyObject

Returns the value of attribute default_currency.



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

def default_currency
  @default_currency
end

#dunning_configurationObject

Returns the value of attribute dunning_configuration.



19
20
21
# File 'lib/processout/project.rb', line 19

def dunning_configuration
  @dunning_configuration
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/processout/project.rb', line 10

def id
  @id
end

#logo_urlObject

Returns the value of attribute logo_url.



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

def logo_url
  @logo_url
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#private_keyObject

Returns the value of attribute private_key.



18
19
20
# File 'lib/processout/project.rb', line 18

def private_key
  @private_key
end

#supervisor_projectObject

Returns the value of attribute supervisor_project.



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

def supervisor_project
  @supervisor_project
end

#supervisor_project_idObject

Returns the value of attribute supervisor_project_id.



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

def supervisor_project_id
  @supervisor_project_id
end

Instance Method Details

#create_supervised(options = {}) ⇒ Object

Create a new supervised project. Params:

options

Hash of options



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/processout/project.rb', line 333

def create_supervised(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/supervised-projects"
  data    = {
    "id" => @id, 
    "name" => @name, 
    "default_currency" => @default_currency, 
    "dunning_configuration" => @dunning_configuration, 
    "applepay_settings" => options.fetch(:applepay_settings, nil)
  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["project"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end

#delete(options = {}) ⇒ Object

Delete the project. Be careful! Executing this request will prevent any further interaction with the API that uses this project. Params:

options

Hash of options



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/processout/project.rb', line 282

def delete(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/projects/{project_id}"
  data    = {

  }

  response = Response.new(request.delete(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  return_values[0]
end

#fetch(options = {}) ⇒ Object

Fetch the current project information. Params:

options

Hash of options



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/processout/project.rb', line 230

def fetch(options = {})
  self.prefill(options)

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

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["project"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end

#fetch_supervised(options = {}) ⇒ Object

Get all the supervised projects. Params:

options

Hash of options



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/processout/project.rb', line 303

def fetch_supervised(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/supervised-projects"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['projects']
    tmp = Project.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



137
138
139
140
141
142
143
144
145
146
147
148
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
175
176
# File 'lib/processout/project.rb', line 137

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "id"
    self.id = data["id"]
  end
  if data.include? "supervisor_project"
    self.supervisor_project = data["supervisor_project"]
  end
  if data.include? "supervisor_project_id"
    self.supervisor_project_id = data["supervisor_project_id"]
  end
  if data.include? "api_version"
    self.api_version = data["api_version"]
  end
  if data.include? "name"
    self.name = data["name"]
  end
  if data.include? "logo_url"
    self.logo_url = data["logo_url"]
  end
  if data.include? "email"
    self.email = data["email"]
  end
  if data.include? "default_currency"
    self.default_currency = data["default_currency"]
  end
  if data.include? "private_key"
    self.private_key = data["private_key"]
  end
  if data.include? "dunning_configuration"
    self.dunning_configuration = data["dunning_configuration"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  
  self
end

#new(data = {}) ⇒ Object

Create a new Project using the current client



130
131
132
# File 'lib/processout/project.rb', line 130

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

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/processout/project.rb', line 181

def prefill(data)
  if data.nil?
    return self
  end
  self.id = data.fetch(:id, self.id)
  self.supervisor_project = data.fetch(:supervisor_project, self.supervisor_project)
  self.supervisor_project_id = data.fetch(:supervisor_project_id, self.supervisor_project_id)
  self.api_version = data.fetch(:api_version, self.api_version)
  self.name = data.fetch(:name, self.name)
  self.logo_url = data.fetch(:logo_url, self.logo_url)
  self.email = data.fetch(:email, self.email)
  self.default_currency = data.fetch(:default_currency, self.default_currency)
  self.private_key = data.fetch(:private_key, self.private_key)
  self.dunning_configuration = data.fetch(:dunning_configuration, self.dunning_configuration)
  self.created_at = data.fetch(:created_at, self.created_at)
  
  self
end

#regenerate_private_key(options = {}) ⇒ Object

Regenerate the project private key. Make sure to store the new private key and use it in any future request. Params:

options

Hash of options



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/processout/project.rb', line 203

def regenerate_private_key(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/private-keys"
  data    = {

  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["project"]
  
  
  obj = Project.new(@client)
  return_values.push(obj.fill_with_data(body))
  

  
  return_values[0]
end

#save(options = {}) ⇒ Object

Save the updated project’s attributes. Params:

options

Hash of options



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/processout/project.rb', line 256

def save(options = {})
  self.prefill(options)

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

  }

  response = Response.new(request.put(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["project"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end