Created
February 17, 2020 06:26
-
-
Save techpotatoes/b2a1a49a68e5109b91a8fc38e34d8474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'package:apod_daydream_flutter/model/apod.dart'; | |
import 'package:apod_daydream_flutter/repo/apod_cache_manager.dart'; | |
abstract class ApodRepository { | |
Future<Apod> getApod(); | |
} | |
class RestfulApodRepository implements ApodRepository { | |
static const String API_KEY = "BtSbq8W1IPztOxALpIuYzh8IcCqbkAiXMpAeUGMZ"; | |
static const String API = "https://api.nasa.gov/planetary/apod?api_key=$API_KEY"; | |
@override | |
Future<Apod> getApod() async { | |
var file = await ApodCacheManager().getSingleFile(API); | |
if (file != null && await file.exists()) { | |
var res = await file.readAsString(); | |
return Apod.fromJson(json.decode(res)); | |
} | |
throw Exception('Failed to load APOD'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment