Sha256: 0f3dda2748e1ac9f2fb05a104fa3e98f209f18afe6d4ab234cda03a3d95170e0

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# Provides a method for grabbing sublists
module NSConnector::SubList
	# Grab sublist_id from NetSuite
	# Returns:: An array of SubListItems
	def self.fetch parent, sublist_id, fields
		NSConnector::Restlet.execute!(
			:action => 'fetch_sublist',
			:type_id => parent.type_id,
			:parent_id => parent.id,
			:fields => fields,
			:sublist_id => sublist_id
		).map do |upstream_store|
			NSConnector::SubListItem.new(
				sublist_id,
				fields,
				parent,
				upstream_store
			)
		end
	end

	# Save our array of SubListItems in the order in which they appear.
	# Arguments:: An array of SubListItem, the parent object and the fields
	# Returns:: An array of SubListItem that have been saved
	def self.save! sublist_items, parent, sublist_id, fields
		data = sublist_items.uniq.map do |item|
			item.store
		end

		NSConnector::Restlet.execute!(
			:action => 'update_sublist',
			:type_id => parent.type_id,
			:parent_id => parent.id,
			:fields => fields,
			:sublist_id => sublist_id,
			:data => data
		)

		# We have to do this in a second request as NetSuite needs a
		# short time to think about any added records.
		return NSConnector::SubList.fetch(parent, sublist_id, fields)
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ns_connector-0.1.0 lib/ns_connector/sublist.rb
ns_connector-0.0.17 lib/ns_connector/sublist.rb
ns_connector-0.0.16 lib/ns_connector/sublist.rb
ns_connector-0.0.15 lib/ns_connector/sublist.rb