Class: Acumatica::StockItem
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Acumatica::StockItem
- Defined in:
- lib/acumatica/stock_item.rb
Class Method Summary collapse
- .create(params = {}) ⇒ Object
- .find_all(select: nil, filter: nil, expand: nil, offset: nil, limit: nil) ⇒ Object
- .url ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ StockItem
constructor
A new instance of StockItem.
Constructor Details
#initialize(params = {}) ⇒ StockItem
Returns a new instance of StockItem.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/acumatica/stock_item.rb', line 36 def initialize(params = {}) new_params = {} params.each do |k,v| v = v.values.first if v.is_a?(Hash) && v.keys == ["value"] new_params[methodify(k)] = v end super(new_params) self.attributes ||= [] attributes.each { |a| self[methodify(a['AttributeID']['value'])] = a['Value']['value'] } end |
Class Method Details
.create(params = {}) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/acumatica/stock_item.rb', line 3 def self.create(params = {}) response = Acumatica::Client.instance.connection.put do |req| req.url url req.body = params end self.new(response.body) end |
.find_all(select: nil, filter: nil, expand: nil, offset: nil, limit: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/acumatica/stock_item.rb', line 12 def self.find_all(select: nil, filter: nil, expand: nil, offset: nil, limit: nil) params = {} params['$select'] = select if select params['$filter'] = filter if filter params['$expand'] = if params['$skip'] = offset if offset params['$top'] = limit if limit response = Acumatica::Client.instance.connection.get do |req| req.url url req.params = params end response.body.map { |attrs| self.new(attrs) } end |
.url ⇒ Object
29 30 31 32 33 34 |
# File 'lib/acumatica/stock_item.rb', line 29 def self.url URI.join( Acumatica::Client.instance.url, "/entity/Default/#{Acumatica::Client::API_VERSION}/StockItem" ) end |