demarches-normaliennes/app/lib/api_adresse/adapter.rb

34 lines
604 B
Ruby
Raw Normal View History

2018-10-15 23:21:22 +02:00
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