class SalsaLabs::ObjectsFetcher
Service object that fetches a collection of objects from API and returns them as instances of a specified class
Attributes
client[R]
filters[R]
item_class[R]
type[R]
Public Class Methods
fetch(opts = {})
click to toggle source
# File lib/salsa_labs/objects_fetcher.rb, line 7 def self.fetch(opts = {}) filters = opts[:filters] || {} credentials = opts[:credentials] || {} client = SalsaLabs::ApiClient.new(credentials) type = opts.fetch(:type) item_class = opts[:item_class] || SalsaLabs::SalsaObject new(filters: filters, client: client, type: type, item_class: item_class).fetch end
new(opts = {})
click to toggle source
# File lib/salsa_labs/objects_fetcher.rb, line 16 def initialize(opts = {}) @filters = opts[:filters] @client = opts[:client] @type = opts[:type] @item_class = opts[:item_class] end
Public Instance Methods
fetch()
click to toggle source
# File lib/salsa_labs/objects_fetcher.rb, line 23 def fetch item_nodes.map do |node| item_class.new(SalsaLabsApiObjectNode.new(node).attributes) end end
Private Instance Methods
api_call()
click to toggle source
# File lib/salsa_labs/objects_fetcher.rb, line 33 def api_call client.fetch('/api/getObjects.sjs', api_parameters) end
api_parameters()
click to toggle source
# File lib/salsa_labs/objects_fetcher.rb, line 37 def api_parameters filters.merge(object: type) end
item_nodes()
click to toggle source
# File lib/salsa_labs/objects_fetcher.rb, line 41 def item_nodes Nokogiri::XML(api_call).css('item') end