Rename fields in the JSON response for more coherencetags/v0.4.0
@@ -39,6 +39,7 @@ class Dumper(ABC): | |||||
class JsonDumper(Dumper): | class JsonDumper(Dumper): | ||||
def to_string(self): | def to_string(self): | ||||
self.ephemeris['events'] = self.events | self.ephemeris['events'] = self.events | ||||
self.ephemeris['ephemerides'] = self.ephemeris.pop('details') | |||||
return json.dumps(self.ephemeris, | return json.dumps(self.ephemeris, | ||||
default=self._json_default, | default=self._json_default, | ||||
indent=4) | indent=4) | ||||
@@ -54,6 +55,8 @@ class JsonDumper(Dumper): | |||||
if isinstance(obj, Object): | if isinstance(obj, Object): | ||||
obj = obj.__dict__ | obj = obj.__dict__ | ||||
obj.pop('skyfield_name') | obj.pop('skyfield_name') | ||||
obj['object'] = obj.pop('name') | |||||
obj['details'] = obj.pop('ephemerides') | |||||
return obj | return obj | ||||
if isinstance(obj, AsterEphemerides): | if isinstance(obj, AsterEphemerides): | ||||
return obj.__dict__ | return obj.__dict__ | ||||
@@ -18,16 +18,6 @@ class DumperTestCase(unittest.TestCase): | |||||
' "phase": "FULL_MOON",\n' | ' "phase": "FULL_MOON",\n' | ||||
' "date": "2019-10-14T00:00:00Z"\n' | ' "date": "2019-10-14T00:00:00Z"\n' | ||||
' },\n' | ' },\n' | ||||
' "details": [\n' | |||||
' {\n' | |||||
' "name": "Mars",\n' | |||||
' "ephemerides": {\n' | |||||
' "rise_time": null,\n' | |||||
' "culmination_time": null,\n' | |||||
' "set_time": null\n' | |||||
' }\n' | |||||
' }\n' | |||||
' ],\n' | |||||
' "events": [\n' | ' "events": [\n' | ||||
' {\n' | ' {\n' | ||||
' "event_type": "OPPOSITION",\n' | ' "event_type": "OPPOSITION",\n' | ||||
@@ -35,6 +25,16 @@ class DumperTestCase(unittest.TestCase): | |||||
' "start_time": "2018-07-27T05:12:00Z",\n' | ' "start_time": "2018-07-27T05:12:00Z",\n' | ||||
' "end_time": null\n' | ' "end_time": null\n' | ||||
' }\n' | ' }\n' | ||||
' ],\n' | |||||
' "ephemerides": [\n' | |||||
' {\n' | |||||
' "object": "Mars",\n' | |||||
' "details": {\n' | |||||
' "rise_time": null,\n' | |||||
' "culmination_time": null,\n' | |||||
' "set_time": null\n' | |||||
' }\n' | |||||
' }\n' | |||||
' ]\n' | ' ]\n' | ||||
'}', JsonDumper(data, | '}', JsonDumper(data, | ||||
[Event('OPPOSITION', Planet('Mars', 'MARS'), | [Event('OPPOSITION', Planet('Mars', 'MARS'), | ||||