demarches-normaliennes/app/lib/api_adresse/adapter.rb
2018-10-16 09:33:16 +02:00

33 lines
604 B
Ruby

class ApiAdresse::Adapter
private
def initialize(address, limit, blank_return)
@address = address
@limit = limit
@blank_return = blank_return
end
def features
@features ||= get_features
end
def get_features
response = ApiAdresse::API.call(@address, @limit)
result = JSON.parse(response)
result['features']
rescue RestClient::Exception, JSON::ParserError, TypeError
@blank_return
end
def handle_result
if features.present?
process_features
else
@blank_return
end
end
def process_features
raise NoMethodError
end
end