Skip to content

Commit

Permalink
Merge pull request #9 from CDRH/rows_nums_and_update
Browse files Browse the repository at this point in the history
fixes error where num and rows were not being used correctly
  • Loading branch information
techgique authored May 2, 2019
2 parents ec482f9 + afed0c9 commit 2a149d7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.4.1
ruby-2.6.3
5 changes: 3 additions & 2 deletions lib/api_bridge/helpers.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def self.escape_values options
return options
end

def self.get_start page, rows
return (page - 1) * rows
def self.get_start page, num
return (page - 1) * num
end

def self.clone_and_stringify_options aOpts
Expand Down Expand Up @@ -72,6 +72,7 @@ def self.set_page page
private

def self.encode_query_params(query_string)
# puts "QUERY_STRING: #{query_string}"
query_string.split(/[&]/).map { |param|
name, value = param.split("=")

Expand Down
18 changes: 14 additions & 4 deletions lib/api_bridge/query.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize url, facets=[], options={}
# TODO how to incorporate facets here and facets from request
# into query? See also: f[] field
@facet_fields = facets
options = _remove_rows(options)
@options = override_options options
@options["facet"] = facets
else
Expand Down Expand Up @@ -96,10 +97,10 @@ def _calc_start options
page = ApiBridge.set_page(options["page"])
# remove page from options
options.delete("page")
if !options.has_key?("start")
# use the page and rows to set a start
rows = options.has_key?("rows") ? options["rows"].to_i : @options["rows"].to_i
options["start"] = ApiBridge.get_start(page, rows)
if !options.key?("start")
# use the page and rows to set a start, use default is no num specified
num = options.key?("num") ? options["num"].to_i : @options["num"].to_i
options["start"] = ApiBridge.get_start(page, num)
end
return options
end
Expand All @@ -111,6 +112,7 @@ def _prepare_options options
opts.delete("action")
opts.delete("utf8")
opts.delete("commit")
opts = _remove_rows(opts)
# remove page and replace with start
opts = _calc_start opts
# remove .year from the middle of date filters for api's sake
Expand All @@ -131,5 +133,13 @@ def _query options={}
return ApiBridge::Response.new(res, url, req_params)
end

def _remove_rows opts={}
if opts.key?("rows")
opts["num"] = opts["rows"] if !opts.key?("num")
opts.delete("rows")
end
opts
end

end # end of Query class
end # end of ApiBridge module
2 changes: 1 addition & 1 deletion lib/api_bridge/response.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def first
end

def pages
ApiBridge.calculate_page self.count, @req_opts["rows"]
ApiBridge.calculate_page self.count, @req_opts["num"]
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/api_bridge/version.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ApiBridge
VERSION = "0.0.3"
VERSION = "0.0.4"

def self.version
VERSION
Expand Down

0 comments on commit 2a149d7

Please sign in to comment.