Class: Plyom::PlyomUser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PlyomUser

Returns a new instance of PlyomUser.



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

def initialize(params={})
  params.each { |var, val| public_send("#{var}=", val) }
end

Class Method Details

.allObject



13
14
15
16
17
18
19
# File 'lib/plyom_user.rb', line 13

def self.all
  list = []
  response = action_by("read")
  objs = JSON.parse(response.body)
  objs.each { |obj| list << self.new(obj) }
  list
end

.find(id) ⇒ Object



21
22
23
24
25
# File 'lib/plyom_user.rb', line 21

def self.find(id)
  response = action_by("read", id: id)
  obj = JSON.parse(response.body)
  self.new(obj)
end

Instance Method Details

#removeObject



42
43
44
# File 'lib/plyom_user.rb', line 42

def remove
  PlyomUser.action_by("del", id: @id)
end

#saveObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/plyom_user.rb', line 27

def save
  param_names = ["name", "email", "username", "password", "password_confirmation", "status", "product_ids"]
  data = filter_params(param_names)
  if data.length > 0
    paramters = { user: data }
    paramters.update({ id: @id }) if @id.to_i > 0
    action = @id.to_i > 0 ? "update" : "add"
    response = PlyomUser.action_by(action, paramters)
    @id = response['id'] if action == "add"
    response
  else
    nil
  end
end