as2.ml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (*
  2. * _ _ ____ _
  3. * _| || |_/ ___| ___ _ __ _ __ ___ | |
  4. * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
  5. * |_ _|___) | __/ |_) | |_) | (_) |_|
  6. * |_||_| |____/ \___| .__/| .__/ \___/(_)
  7. * |_| |_|
  8. *
  9. * Personal Social Web.
  10. *
  11. * Copyright (C) The #Seppo contributors. All rights reserved.
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *)
  26. (*
  27. * https://www.w3.org/TR/activitystreams-core/
  28. * https://www.w3.org/TR/activitystreams-core/#media-type
  29. *)
  30. module No_p_yes = struct
  31. type t = No | Pending | Yes
  32. let to_string = function
  33. | No -> "no"
  34. | Pending -> "pending"
  35. | Yes -> "yes"
  36. let of_string = function
  37. | "no" -> Some No
  38. | "pending" -> Some Pending
  39. | "yes"
  40. | "on" -> Some Yes (* convenience for html form submit feedback *)
  41. | _ -> None
  42. end
  43. let examine_response j =
  44. let ok = function
  45. | `O ["error", `String e] -> Error e
  46. | _ ->
  47. Logr.warn (fun m -> m "unknown response: %s" j);
  48. Error ("unknown response: " ^ j) in
  49. let error = function
  50. | `Error _ as e ->
  51. let e = e |> Ezjsonm.read_error_description in
  52. Logr.warn (fun m -> m "json parsing error: '%s' in '%s'" e j);
  53. Error ("json parsing error '" ^ e ^ "' in '" ^ j ^ "'")
  54. | `Unexpected _ ->
  55. Logr.warn (fun m -> m "unexpected json: '%s'" j);
  56. Error ("unexpected json '" ^ j ^ "'")
  57. | `End_of_input -> Error "end of input"
  58. in
  59. j
  60. |> Ezjsonm.value_from_string_result
  61. |> Result.fold ~ok ~error
  62. (*
  63. let ns_as = As2_vocab.Constants.ActivityStreams.ns_as
  64. let ns_sec = As2_vocab.Constants.ActivityStreams.ns_sec
  65. let public = As2_vocab.Constants.ActivityStreams.public
  66. *)