Changed record keys to use lists instead of atoms.
Using atoms will not scale in the large. Also, using atoms as keys forced the API to convert arbitrary end-user input to atoms, adding another potential drain of the finite atom-space available. - ts_api: url paths are now treated and matched as lists, not atoms. Usernames and API calls all use lists now. - ts_json: key items (username, timeline ids) are now expected to be lists, not atoms.
This commit is contained in:
@ -7,10 +7,11 @@ encode_record(Record) -> lists:flatten(json:encode(record_to_ejson(Record))).
|
||||
|
||||
record_to_ejson(Record=#ts_user{}) ->
|
||||
{struct, [
|
||||
{id, atom_to_list(Record#ts_user.username)},
|
||||
{id, Record#ts_user.username},
|
||||
{name, Record#ts_user.name},
|
||||
{email, Record#ts_user.email},
|
||||
{join_date, encode_datetime(Record#ts_user.join_date)}]};
|
||||
{join_date, encode_datetime(Record#ts_user.join_date)},
|
||||
{ext_data, Record#ts_user.ext_data}]};
|
||||
|
||||
record_to_ejson(Record=#ts_timeline{}) ->
|
||||
% pull out the username and timeline id
|
||||
@ -18,8 +19,8 @@ record_to_ejson(Record=#ts_timeline{}) ->
|
||||
|
||||
% create the EJSON struct
|
||||
{struct, [
|
||||
{user_id, atom_to_list(Username)},
|
||||
{id, atom_to_list(TimelineId)},
|
||||
{user_id, Username},
|
||||
{id, TimelineId},
|
||||
{created, encode_datetime(Record#ts_timeline.created)},
|
||||
{description, Record#ts_timeline.desc}]};
|
||||
|
||||
@ -32,15 +33,15 @@ record_to_ejson(Record=#ts_entry{}) ->
|
||||
|
||||
% create the EJSON struct
|
||||
{struct, [
|
||||
{user_id, atom_to_list(Username)},
|
||||
{timeline_id, atom_to_list(TimelineId)},
|
||||
{user_id, Username},
|
||||
{timeline_id, TimelineId},
|
||||
{id, EntryId},
|
||||
{timestamp, encode_datetime(DateTime)},
|
||||
{mark, Record#ts_entry.mark},
|
||||
{notes, Record#ts_entry.notes}]}.
|
||||
|
||||
encode_datetime({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
||||
lists:flatten(io_lib:format("~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0B~3.10.0BZ",
|
||||
lists:flatten(io_lib:format("~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0B.~3.10.0BZ",
|
||||
[Year, Month, Day, Hour, Minute, Second, 000])).
|
||||
|
||||
ejson_to_record(_Empty=#ts_timeline{}, EJSON) ->
|
||||
|
Reference in New Issue
Block a user