class Economic::Proxies::Actions::FindByName

Attributes

name[R]

Public Class Methods

new(caller, name) click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 9
def initialize(caller, name)
  @caller = caller
  @name = name
  @session = caller.session
end

Public Instance Methods

call() click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 15
def call
  contacts = build_partial_contact_entities(handles_from_endpoint)
  scope_to_owner(contacts)
end

Private Instance Methods

build(*options) click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 22
def build(*options)
  @caller.build(options)
end
build_partial_contact_entities(handles) click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 26
def build_partial_contact_entities(handles)
  handles.collect do |handle|
    contact = build
    contact.partial = true
    contact.persisted = true
    contact.handle = handle
    contact.id = handle[:id]
    contact.number = handle[:number]
    contact
  end
end
handle_key() click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 42
def handle_key
  (Support::String.underscore(@caller.class.entity_class_name) + "_handle").to_sym
end
handles_from_endpoint() click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 38
def handles_from_endpoint
  [response[handle_key]].flatten.reject(&:blank?)
end
owner() click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 46
def owner
  @caller.owner
end
request(action, data) click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 50
def request(action, data)
  @session.request(
    Endpoint.new.soap_action_name(@caller.entity_class, action),
    data
  )
end
response() click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 57
def response
  request("FindByName", "name" => name)
end
scope_to_owner(contacts) click to toggle source
# File lib/economic/proxies/actions/find_by_name.rb, line 61
def scope_to_owner(contacts)
  if owner.is_a?(Session)
    contacts
  else
    owner_type = Support::String.underscore(
      Support::String.demodulize(owner.class.name)
    )
    contacts.select do |contact|
      contact.get_data
      contact.send(owner_type) == owner
    end
  end
end