Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
Omit optional parameters when none are passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
allolex committed Dec 29, 2014
1 parent 8863853 commit f170094
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
12 changes: 8 additions & 4 deletions lib/nacre/concerns/getable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ module Nacre::Getable

def get(range)
if range?(range)
request_url = build_request_url(url, range, request_options)
else
request_url = build_request_url(url, range)
else
request_url = build_request_url(url, range, request_options)
end
response = link.get(request_url)
from_json(response.body)
if response.success?
from_json(response.body)
else
raise ArgumentError, "Request error: #{request_url}\n#{response.body}"
end
end

private
Expand All @@ -29,6 +33,6 @@ def build_request_url(url, query, options = nil)
end

def range?(arg)
/\d-\d/ === arg && /\d,\d/ === arg
/\d[,-]\d?/ === arg
end
end
6 changes: 5 additions & 1 deletion lib/nacre/request_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def pagination_params
end

def options
["includeOptional=#{@options.join(',')}"]
if @options
["includeOptional=#{@options.join(',')}"]
else
[]
end
end

def arguments
Expand Down
7 changes: 1 addition & 6 deletions spec/lib/nacre/order_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
let(:get_options) do
{
search_url: order_service_url,
ids: range,
options: [
'customFields',
'nullCustomFields'
]
ids: range
}
end

Expand All @@ -63,7 +59,6 @@
@collection = described_class.get(range)
end


it 'should query the API server' do
expect(a_request(:get, @url.to_s)).to have_been_made
end
Expand Down
6 changes: 1 addition & 5 deletions spec/lib/nacre/product_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@
let(:get_options) do
{
search_url: product_service_url,
ids: range,
options: [
'customFields',
'nullCustomFields'
]
ids: range
}
end

Expand Down

0 comments on commit f170094

Please sign in to comment.