Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/odata/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def set_property_lazy_load(name, xml_value )

def self.process_properties(entity, xml_doc)
entity.instance_eval do
xml_doc.xpath('./content/properties/*').each do |property_xml|
xml_doc.xpath('./content/properties/*', './properties/*').each do |property_xml|
property_name = property_xml.name
if property_xml.attributes['null'] &&
property_xml.attributes['null'].value == 'true'
Expand Down Expand Up @@ -234,4 +234,4 @@ def self.process_links(entity, xml_doc)
end
end
end
end
end
19 changes: 18 additions & 1 deletion lib/odata/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def limit(value)
self
end

# Add search term criteria to query.
# @param value
# @return [self]
def search_term(value)
criteria_set[:search_term] = value
self
end

# Add inline count criteria to query.
# Not Supported in CRM2011
# @return [self]
Expand Down Expand Up @@ -146,13 +154,15 @@ def setup_empty_criteria_set
orderby: [],
skip: 0,
top: 0,
inline_count: false
inline_count: false,
search_term: nil
}
end

def assemble_criteria
criteria = [
filter_criteria,
search_term_criteria(:search_term),
list_criteria(:orderby),
list_criteria(:expand),
list_criteria(:select),
Expand All @@ -179,6 +189,13 @@ def inline_count_criteria
criteria_set[:inline_count] ? '$inlinecount=allpages' : nil
end

def search_term_criteria(name)
search = criteria_set[name].present? == 0 ? nil : "searchTerm='#{criteria_set[name]}'"
if search.present?
search += '&includePrerelease=false'
end
end

def paging_criteria(name)
criteria_set[name] == 0 ? nil : "$#{name}=#{criteria_set[name]}"
end
Expand Down
25 changes: 22 additions & 3 deletions lib/odata/query/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ def initialize(query, result)
# Provided for Enumerable functionality
# @param block [block] a block to evaluate
# @return [OData::Entity] each entity in turn for the query result
MAX_EXECUTIONS = 100
def each(&block)
last_processed_url = next_page_url
process_results(&block)
until next_page.nil?
result = service.execute(next_page_url)

finished_processing = last_processed_url == next_page_url
execution_count = 0
until finished_processing
last_processed_url = next_page_url
result = service.execute(last_processed_url, {}, true)
process_results(&block)
execution_count += 1
finished_processing = next_page.nil? || last_processed_url == next_page_url
raise 'Possible infinite loop detected' if execution_count > MAX_EXECUTIONS
end
end

Expand Down Expand Up @@ -52,7 +61,17 @@ def next_page
end

def next_page_url
next_page.attributes['href'].value.gsub(service.service_url, '')
next_page_value = next_page
return unless next_page_value && next_page_value.attributes['href']

# We used to get the url in http format, then it changed
# to https. Let's remove both
http_verison = service.service_url.sub('https://', 'http://')
https_version = service.service_url.sub('http://', 'https://')
next_page_value.attributes['href']
.value
.gsub(http_verison, '')
.gsub(https_version, '')
end
end
end
Expand Down
18 changes: 16 additions & 2 deletions lib/odata/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,23 @@ def [](entity_set_name)
# @param url_chunk [to_s] string to append to service url
# @param additional_options [Hash] options to pass to Typhoeus
# @return [Typhoeus::Response]
def execute(url_chunk, additional_options = {})
def execute(url_chunk, additional_options = {}, escaped = false)
# There must be a better way to do it,
# but we only use it for Chocolatey, so it won't break anything else
# This just forces us to use Search endpoint for searching through
# Chocolatey instead of Packages.
if url_chunk && url_chunk.starts_with?('Packages?')
url_chunk = url_chunk.gsub('Packages?', 'Search()?')
end

url = if escaped
"#{URI.escape(service_url)}/#{url_chunk}"
else
URI.escape("#{service_url}/#{url_chunk}")
end

request = ::Typhoeus::Request.new(
URI.escape("#{service_url}/#{url_chunk}"),
url,
options[:typhoeus].merge({ method: :get
})
.merge(additional_options)
Expand Down
4 changes: 2 additions & 2 deletions odata.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'vcr', '~> 2.9.2'
spec.add_development_dependency 'timecop', '~> 0.7.1'

spec.add_dependency 'nokogiri', '~> 1.6.2'
spec.add_dependency 'typhoeus', '~> 0.6.8'
spec.add_dependency 'nokogiri', '>= 1.6.2'
spec.add_dependency 'typhoeus', '>= 0.6.8'
spec.add_dependency 'andand', '~> 1.3.3'
end