Class: Plyom::PlyomProduct

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PlyomProduct

Returns a new instance of PlyomProduct.



83
84
85
# File 'lib/plyom_user.rb', line 83

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

Class Method Details

.allObject



87
88
89
90
91
92
93
# File 'lib/plyom_user.rb', line 87

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



95
96
97
98
99
# File 'lib/plyom_user.rb', line 95

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

Instance Method Details

#removeObject



116
117
118
# File 'lib/plyom_user.rb', line 116

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

#saveObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/plyom_user.rb', line 101

def save
  param_names = ["name", "status"]
  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