lib/open311/client/service.rb in open311-0.2.3 vs lib/open311/client/service.rb in open311-0.3.0
- old
+ new
@@ -8,12 +8,12 @@
# @param options [Hash] A customizable set of options.
# @return [Array]
# @see http://wiki.open311.org/GeoReport_v2#GET_Service_List
# @example Provide a list of acceptable 311 service request types and their associated service codes
# Open311.service_list
- def service_list(options={})
- options.merge!(:jurisdiction_id => jurisdiction)
+ def service_list(options = {})
+ merge_options!(options)
response = get('services', options)
unpack_if_xml(response) do
response['services']['service']
end
end
@@ -24,12 +24,12 @@
# @param options [Hash] A customizable set of options.
# @return Hash
# @see http://wiki.open311.org/GeoReport_v2#GET_Service_Definition
# @example define attributes associated with a service code, i.e. 033
# Open311.service_definition
- def service_definition(id, options={})
- options.merge!(:jurisdiction_id => jurisdiction)
+ def service_definition(id, options = {})
+ merge_options!(options)
response = get("services/#{id}", options)
unpack_if_xml(response) do
response['service_definition']
end
end
@@ -38,15 +38,17 @@
# @key false
# @param options [Hash] A customizable set of options.
# @return [Array]
# @see http://wiki.open311.org/GeoReport_v2#GET_Service_Requests
# Open311.service_requests
- def service_requests(options={})
- options.merge!(:jurisdiction_id => jurisdiction)
- response = get("requests", options)
+ def service_requests(options = {})
+ merge_options!(options)
+ response = get('requests', options)
unpack_if_xml(response) do
- response.service_requests.request.map do |request|
+ return [] unless response.service_requests.respond_to? :request
+
+ response.service_requests.request.map do |_request|
response['service_requests']['request']
end
end
end
@@ -54,13 +56,13 @@
# @key true
# @param options [Hash] A customizable set of options.
# @return Hash
# @see http://wiki.open311.org/GeoReport_v2#POST_Service_Request
# Open311.post_service_request
- def post_service_request(options={})
- options.merge!(:jurisdiction_id => jurisdiction, :api_key => api_key)
- response = post("requests", options)
+ def post_service_request(options = {})
+ merge_options!(options, api_key: api_key)
+ response = post('requests', options)
unpack_if_xml(response) do
response['service_requests']['request']
end
end
@@ -69,12 +71,12 @@
# @param id String of the service request id
# @param options [Hash] A customizable set of options.
# @return Hash
# @see http://wiki.open311.org/GeoReport_v2#GET_Service_Requests
# Open311.get_service_request
- def get_service_request(id, options={})
- options.merge!(:jurisdiction_id => jurisdiction)
+ def get_service_request(id, options = {})
+ merge_options!(options)
response = get("requests/#{id}", options)
unpack_if_xml(response) do
response['service_requests']['request']
end
end
@@ -85,17 +87,22 @@
# @param options [Hash] A customizable set of options.
# @return Array
# @see http://wiki.open311.org/GeoReport_v2#GET_request_id_from_a_token
# Open311.request_id
def request_id_from_token(token_id, options = {})
- options.merge!(:jurisdiction_id => jurisdiction)
+ merge_options!(options)
response = get("tokens/#{token_id}", options)
unpack_if_xml(response) do
response['service_requests']['request']
end
end
- private
+ private
+
+ def merge_options!(options, additional_options = {})
+ options.merge!(jurisdiction_id: jurisdiction) if jurisdiction
+ options.merge!(additional_options)
+ end
def unpack_if_xml(response)
if format.to_s.downcase == 'xml'
yield
else