Skip to content

Commit

Permalink
URL encodes queries and URL encodes spaces from paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
shelleydoljack committed Nov 7, 2023
1 parent eefdcb9 commit 6056b48
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/folio_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def get_json(path)
end

def get_cql(path, query)
path += "?query=#{query}"
path += "?query=#{CGI.escape(query)}"
parse(authenticated_request(path))
end

def get_cql_json(path, query)
path += "?query=#{query}"
path += "?query=#{CGI.escape(query)}"
puts JSON.pretty_generate(JSON.parse(authenticated_request(path)))
end

Expand Down Expand Up @@ -86,6 +86,7 @@ def base_url
end

def make_path(path)
path = path.gsub(/\s/, '%20')
path.start_with?('/') ? path.strip : "/#{path.strip}"
end

Expand Down
4 changes: 2 additions & 2 deletions tasks/helpers/orders/po_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ def lookup_holdings(obj)

def holding_no_callnum(instance_id, location_id)
query = "instanceId==#{instance_id} and permanentLocationId==#{location_id}"
results = @@folio_request.get_cql('/holdings-storage/holdings', CGI.escape(query).to_s)
results = @@folio_request.get_cql('/holdings-storage/holdings', query.to_s)
results['holdingsRecords'][0]['id'] if results['totalRecords'] != 0
end

def holding_with_callnum(instance_id, location_id, call_num)
query = "instanceId==#{instance_id} and permanentLocationId==#{location_id} and callNumber==\"#{call_num}\""
results = @@folio_request.get_cql('/holdings-storage/holdings', CGI.escape(query).to_s)
results = @@folio_request.get_cql('/holdings-storage/holdings', query.to_s)
results['holdingsRecords'][0]['id'] if results['totalRecords'] == 1
end

Expand Down
2 changes: 1 addition & 1 deletion tasks/helpers/organizations/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def determine_org_uuid(legacy_identifier, okapi_url)

def organizations_id(code)
response = FolioRequest.new.get_cql('/organizations/organizations',
"code==#{CGI.escape(code).dump}")['organizations']
"code==#{code.dump}")['organizations']
begin
response[0]['id']
rescue NoMethodError
Expand Down

0 comments on commit 6056b48

Please sign in to comment.