module UserEngage::Operation::Find
Public Instance Methods
find(params = {})
click to toggle source
# File lib/user_engage/operation/find.rb, line 8 def find(params = {}) check_for_unsupported_params!(params) attributes = get_resource(params) new(attributes) end
find_by_id(id)
click to toggle source
# File lib/user_engage/operation/find.rb, line 14 def find_by_id(id) attributes = get_resource_by_id(id) new(attributes) end
Private Instance Methods
check_for_existing_resource!(response, params)
click to toggle source
# File lib/user_engage/operation/find.rb, line 51 def check_for_existing_resource!(response, params) return if response.status == 200 raise( UserEngage::ResourceNotFoundException, "No resource with {#{params.inspect}} found!" ) end
check_for_unsupported_params!(params)
click to toggle source
# File lib/user_engage/operation/find.rb, line 60 def check_for_unsupported_params!(params) if params.is_a?(Hash) unsupported_params = params.keys - supported_find_params return if unsupported_params.size.zero? raise( UserEngage::InvalidFindAttributeException, "Unsupported parameter/s used: #{unsupported_params.join(', ')}" ) else true end end
get_by_hash(params)
click to toggle source
# File lib/user_engage/operation/find.rb, line 41 def get_by_hash(params) path = "/#{resource_name}/search/" UserEngage.client.get(path, params) end
get_by_id(id)
click to toggle source
# File lib/user_engage/operation/find.rb, line 46 def get_by_id(id) path = "/#{resource_name}/#{id}/" UserEngage.client.get(path) end
get_resource(params)
click to toggle source
Private methods ##
# File lib/user_engage/operation/find.rb, line 24 def get_resource(params) response = if params.is_a?(Hash) get_by_hash(params) else get_by_id(params) end check_for_existing_resource!(response, params) JSON.parse(response.body, symbolize_names: true) end
get_resource_by_id(id)
click to toggle source
# File lib/user_engage/operation/find.rb, line 35 def get_resource_by_id(id) path = "/#{resource_name}-by-id/#{id}/" response = UserEngage.client.get(path) JSON.parse(response.body, symbolize_names: true) end