triannon-client 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.env_example +16 -2
  3. data/.rspec +1 -0
  4. data/README.md +49 -18
  5. data/Rakefile +15 -2
  6. data/lib/triannon-client.rb +12 -6
  7. data/lib/triannon-client/configuration.rb +26 -14
  8. data/lib/triannon-client/triannon_client.rb +139 -44
  9. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_application/x-turtle_.yml → CRUD/create_annotation.yml} +192 -132
  10. data/spec/fixtures/vcr_cassettes/TriannonClientAUTH/with_authentication/behaves_like_authenticate/-_authenticate_returns_true.yml +343 -0
  11. data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/POST_401_response_retries_and_logs_RestClient_Exception_message.yml +170 -0
  12. data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/POST_403_response_does_not_retry_and_logs_RestClient_Exception_message.yml +170 -0
  13. data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/POST_500_response_does_not_retry_and_logs_RestClient_Exception_message.yml +170 -0
  14. data/spec/fixtures/vcr_cassettes/{TriannonClient/_get_annotations/returns_an_annotation_list_with_an_annotation_created_by_a_prior_POST.yml → TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/does_not_raise_an_error_when_submitting_a_valid_open_annotation.yml} +203 -319
  15. data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/logs_RuntimeError_message.yml +170 -0
  16. data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/_post_annotation/with_authentication/behaves_like_create_annotations/returns_a_RestClient_Response_object.yml +170 -0
  17. data/spec/fixtures/vcr_cassettes/{TriannonClient/_post_annotation → TriannonClientCREATE/_post_annotation/without_authentication/behaves_like_create_annotations}/does_not_raise_an_error_when_submitting_a_valid_open_annotation.yml +29 -27
  18. data/spec/fixtures/vcr_cassettes/TriannonClientCREATE/clear_annotations.yml +590 -0
  19. data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/with_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_does_NOT_exist.yml +349 -0
  20. data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/with_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_exists.yml +332 -0
  21. data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/with_authentication/behaves_like_delete_annotations/validates_the_annotation_ID.yml +288 -0
  22. data/spec/fixtures/vcr_cassettes/{TriannonClient/_delete_annotation/returns_TRUE_when_deleting_an_open_annotation_that_does_NOT_exist.yml → TriannonClientDELETE/_delete_annotation/without_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_does_NOT_exist.yml} +13 -9
  23. data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/_delete_annotation/without_authentication/behaves_like_delete_annotations/returns_TRUE_when_deleting_an_annotation_that_exists.yml +127 -0
  24. data/spec/fixtures/vcr_cassettes/{TriannonClient/_delete_annotation → TriannonClientDELETE/_delete_annotation/without_authentication/behaves_like_delete_annotations}/validates_the_annotation_ID.yml +7 -5
  25. data/spec/fixtures/vcr_cassettes/TriannonClientDELETE/clear_annotations.yml +594 -0
  26. data/spec/fixtures/vcr_cassettes/{TriannonClient → TriannonClientREAD/GET}/_get_annotations/returns_an_RDF_Graph.yml +30 -23
  27. data/spec/fixtures/vcr_cassettes/{TriannonClient → TriannonClientREAD/GET}/_get_annotations/returns_an_RDF_Graph_that_contains_an_AnnotationList.yml +30 -23
  28. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/_get_annotations/returns_an_annotation_list_with_an_annotation_created_by_a_prior_POST.yml +302 -0
  29. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/n-quads_.yml → TriannonClientREAD/GET/_get_iiif_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml} +25 -78
  30. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/n-triples_.yml → TriannonClientREAD/GET/_get_oa_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml} +25 -78
  31. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/_response2graph/accepts_a_RestClient_Response_instance.yml +2399 -0
  32. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/csvm_json_.yml +1231 -0
  33. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-quads_.yml +1231 -0
  34. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-triples_.yml +1231 -0
  35. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_json_.yml +1231 -0
  36. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_n3_.yml +1231 -0
  37. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trig_.yml +1231 -0
  38. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trix_.yml +1231 -0
  39. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/turtle_.yml +1231 -0
  40. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-ld_json_.yml +1231 -0
  41. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-trig_.yml +1231 -0
  42. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/csv_.yml +1231 -0
  43. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/n3_.yml +1231 -0
  44. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/plain_.yml +1231 -0
  45. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_n3_.yml +1231 -0
  46. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_turtle_.yml +1231 -0
  47. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/tab-separated-values_.yml +1231 -0
  48. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/x-nquads_.yml +1231 -0
  49. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application → TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_application}/ld_json_.yml +25 -78
  50. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_application/rdf_xml_.yml +68 -0
  51. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_application/x-turtle_.yml +69 -0
  52. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_custom_content_type/gets_an_open_annotation_by_ID_with_content_type_text/turtle_.yml +69 -0
  53. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type → TriannonClientREAD/GET/annotation_by_ID/using_default_content_type}/checks_the_annotation_ID.yml +25 -78
  54. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/GET/annotation_by_ID/using_default_content_type/returns_an_EMPTY_RDF_graph_with_a_valid_ID_for_NO_annotation_on_the_server.yml +186 -0
  55. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/rdf_json_.yml → TriannonClientREAD/GET/annotation_by_ID/using_default_content_type/returns_an_RDF_graph_with_a_valid_ID_for_an_annotation_on_the_server.yml} +25 -78
  56. data/spec/fixtures/vcr_cassettes/TriannonClientREAD/clear_annotations.yml +648 -0
  57. data/spec/fixtures/vcr_cassettes/{TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_application/rdf_xml_.yml → TriannonClientREAD/create_annotation.yml} +192 -131
  58. data/spec/lib/triannon-client/configuration_spec.rb +83 -27
  59. data/spec/lib/triannon-client/triannon_client_auth_spec.rb +61 -0
  60. data/spec/lib/triannon-client/triannon_client_class_spec.rb +104 -0
  61. data/spec/lib/triannon-client/triannon_client_create_spec.rb +119 -0
  62. data/spec/lib/triannon-client/triannon_client_delete_spec.rb +117 -0
  63. data/spec/lib/triannon-client/triannon_client_read_spec.rb +342 -0
  64. data/spec/spec_helper.rb +140 -4
  65. data/triannon-client.gemspec +1 -1
  66. metadata +112 -153
  67. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-quads_.yml +0 -3995
  68. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/n-triples_.yml +0 -3995
  69. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_json_.yml +0 -3995
  70. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/rdf_n3_.yml +0 -3995
  71. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trig_.yml +0 -3995
  72. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/trix_.yml +0 -3995
  73. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/turtle_.yml +0 -3995
  74. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-ld_json_.yml +0 -3995
  75. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_application/x-trig_.yml +0 -3995
  76. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/n3_.yml +0 -3995
  77. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_n3_.yml +0 -3995
  78. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/rdf_turtle_.yml +0 -3995
  79. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/cannot_get_an_open_annotation_by_ID_with_content_type_text/x-nquads_.yml +0 -3995
  80. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_application/ld_json_.yml +0 -4946
  81. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/gets_an_open_annotation_by_ID_with_content_type_text/turtle_.yml +0 -2566
  82. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/rdf_n3_.yml +0 -2502
  83. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/rdf_xml_.yml +0 -2502
  84. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/trig_.yml +0 -2502
  85. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/trix_.yml +0 -2502
  86. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/turtle_.yml +0 -2502
  87. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/x-ld_json_.yml +0 -2502
  88. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/x-trig_.yml +0 -2502
  89. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_application/x-turtle_.yml +0 -2502
  90. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/n3_.yml +0 -2502
  91. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/rdf_n3_.yml +0 -2502
  92. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/rdf_turtle_.yml +0 -2502
  93. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/turtle_.yml +0 -2502
  94. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/with_content_type/requests_an_open_annotation_by_ID_with_content_type_text/x-nquads_.yml +0 -2502
  95. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/logs_exceptions.yml +0 -2502
  96. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/raises_an_argument_error_with_a_nil_ID.yml +0 -2502
  97. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/raises_an_argument_error_with_an_empty_string_ID.yml +0 -2502
  98. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/raises_an_argument_error_with_an_integer_ID.yml +0 -2502
  99. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/requests_an_open_annotation_by_ID_accepting_a_default_JSON-LD_content.yml +0 -2502
  100. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/returns_an_EMPTY_RDF_graph_for_a_500_server_response.yml +0 -2502
  101. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/returns_an_EMPTY_RDF_graph_with_a_valid_ID_for_NO_annotation_on_the_server.yml +0 -2561
  102. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_annotation/without_content_type/returns_an_RDF_graph_with_a_valid_ID_for_an_annotation_on_the_server.yml +0 -4946
  103. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_iiif_annotation/requests_an_open_annotation_by_ID_using_a_IIIF_profile.yml +0 -2502
  104. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_iiif_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml +0 -2746
  105. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_oa_annotation/requests_an_open_annotation_by_ID_using_an_OA_profile.yml +0 -2502
  106. data/spec/fixtures/vcr_cassettes/TriannonClient/GET_annotation_by_ID_/_get_oa_annotation/returns_an_RDF_Graph_of_an_open_annotation.yml +0 -4946
  107. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/does_not_log_exceptions_for_missing_annotations_404_responses_.yml +0 -64
  108. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/does_not_log_exceptions_for_missing_annotations_410_responses_.yml +0 -64
  109. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/logs_exceptions.yml +0 -64
  110. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_FALSE_for_a_500_response_to_a_DELETE_request.yml +0 -64
  111. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_200_response_to_a_DELETE_request.yml +0 -64
  112. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_202_response_to_a_DELETE_request.yml +0 -64
  113. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_204_response_to_a_DELETE_request.yml +0 -64
  114. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_404_response_to_a_DELETE_request.yml +0 -64
  115. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_for_a_410_response_to_a_DELETE_request.yml +0 -64
  116. data/spec/fixtures/vcr_cassettes/TriannonClient/_delete_annotation/returns_TRUE_when_deleting_an_open_annotation_that_exists.yml +0 -2549
  117. data/spec/fixtures/vcr_cassettes/TriannonClient/_post_annotation/logs_exceptions.yml +0 -5355
  118. data/spec/fixtures/vcr_cassettes/TriannonClient/_post_annotation/logs_exceptions_for_RestClient_Exception.yml +0 -5355
  119. data/spec/fixtures/vcr_cassettes/TriannonClient/_post_annotation/returns_a_RestClient_Response_object.yml +0 -2502
  120. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_id/returns_a_String_ID_from_the_RDF_URI_of_an_annotation.yml +0 -2502
  121. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_id/returns_a_String_ID_that_is_not_empty.yml +0 -2502
  122. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_uris/returns_an_RDF_URI_that_is_a_valid_URI.yml +0 -2551
  123. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_annotation_uris/returns_an_array_of_RDF_URI_from_an_RDF_Graph_of_an_annotation.yml +0 -2502
  124. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/accepts_a_RestClient_Response_instance.yml +0 -4898
  125. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/raises_ArgumentError_when_given_an_empty_String.yml +0 -2502
  126. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/raises_ArgumentError_when_given_nil.yml +0 -2502
  127. data/spec/fixtures/vcr_cassettes/TriannonClient/response_processing_utilities/_response2graph/returns_an_RDF_Graph.yml +0 -2502
  128. data/spec/lib/triannon-client/triannon_client_spec.rb +0 -546
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 441323f7e1dd09f5f178e4cf69616de6b83b3412
4
- data.tar.gz: a7ad7fb1d115be0de670a307e0c590adfebd7350
3
+ metadata.gz: fa133f38dd35b61695e30ed8efec553ea53711dd
4
+ data.tar.gz: 751821968feed148b466c6e88686ec2aa2f8b6a5
5
5
  SHA512:
6
- metadata.gz: fbf5b789df0b9efc5e034d145cfe6e2ef89951f5c6e0851db138e2e37ac0ea9e14b244f0311ab6cdca41909b116c8f2b3d9c8f6ac9c4b3214a617d081f16418d
7
- data.tar.gz: 600389b5a8483bfeda17b81c7536663a70bdfc3b5f2f4bb8f1769392e8a7cdc3dbf4c8a2e2dd16f885fd2667f3084fb44993b84dd32a9987e2ab29425aaa0633
6
+ metadata.gz: 1d13a81a4e7f7931ab25acd7b722ed22631d8f07b2ca4f31010ef4b925a7c219540f55f0e4a477baa8861fc6da0eeff3ac13da0f6977c7bc2d8c705eea69aedf
7
+ data.tar.gz: 93179351efed9e2f834f69c81fcf872e658960263ba2a38f87d828d8f4c7053832a4efaf12bbf634c3989c8ff14c5c10bae4c7faace3a04f42870c478ebc6e4f
@@ -12,7 +12,21 @@ export TRIANNON_LOG_FILE='log/triannon_client.log'
12
12
 
13
13
  # Configure the triannon service
14
14
  export TRIANNON_HOST='http://localhost:3000'
15
- export TRIANNON_USER=''
16
- export TRIANNON_PASS=''
15
+
16
+ # Parameters for triannon client authentication
17
+ export TRIANNON_CLIENT_ID=''
18
+ export TRIANNON_CLIENT_PASS=''
19
+
20
+ # Parameters for triannon container
17
21
  export TRIANNON_CONTAINER='/annotations/foo'
22
+ export TRIANNON_CONTAINER_USER=''
23
+ export TRIANNON_CONTAINER_WORKGROUPS=''
24
+
18
25
 
26
+ # The following configuration settings in comments may work with the triannon
27
+ # server setup on localhost and running the 'development' config.
28
+ #export TRIANNON_CLIENT_ID='clientA'
29
+ #export TRIANNON_CLIENT_PASS='secretA'
30
+ #export TRIANNON_CONTAINER='/annotations/bar'
31
+ #export TRIANNON_CONTAINER_USER='test'
32
+ #export TRIANNON_CONTAINER_WORKGROUPS='org:wg-A'
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -21,7 +21,7 @@ gem 'triannon-client'
21
21
 
22
22
  Then execute:
23
23
 
24
- ```console
24
+ ```sh
25
25
  bundle
26
26
  ```
27
27
 
@@ -31,21 +31,28 @@ bundle
31
31
  ### Configuration
32
32
 
33
33
  Edit a `.env` file to configure the triannon server address etc.
34
- (see .env_example); or use a configure block, e.g.
34
+ (see .env_example); or use a configure block. The configuration
35
+ for authentication depends on prior triannon server configuration.
36
+ This example configuration may work with a triannon server running on localhost in the development environment (see below for details).
35
37
 
36
38
  ```ruby
37
39
  require 'triannon-client'
40
+ ::TriannonClient.reset
38
41
  ::TriannonClient.configure do |config|
39
- config.debug = true
40
- config.host = 'http://triannon.example.org:8080'
41
- config.user = 'authUser'
42
- config.pass = 'secret'
43
- container = '/annotations/'
42
+ config.debug = false
43
+ config.host = 'http://localhost:3000'
44
+ config.client_id = 'clientA'
45
+ config.client_pass = 'secretA'
46
+ config.container = '/annotations/bar'
47
+ config.container_user = ''
48
+ config.container_workgroups = 'org:wg-A, org:wg-B'
44
49
  end
45
50
  ```
46
51
 
47
52
  ### Get a client instance
48
53
 
54
+ A new instance is initialized using the configuration parameters (see above).
55
+
49
56
  ```ruby
50
57
  tc = TriannonClient::TriannonClient.new
51
58
  ```
@@ -56,7 +63,7 @@ tc = TriannonClient::TriannonClient.new
56
63
  # return an RDF::Graph
57
64
  graph = tc.get_annotations
58
65
  anno_uris = tc.annotation_uris(graph)
59
- anno_ids = anno_uris.collect {|uri| tc.annotation_id(uri) }
66
+ anno_ids = anno_uris.map {|uri| tc.annotation_id(uri) }
60
67
  ```
61
68
 
62
69
  ### Get a particular annotation
@@ -91,24 +98,48 @@ id = tc.annotation_id(uri) #=> "45%2F4a%2Fc0%2F93%2F454ac093-b37d-4580-bebd-449f
91
98
  tc.delete_annotation(id)
92
99
  ```
93
100
 
94
- Note: the annotation URI contains a pair-tree path (created by a Fedora 4 repository for
95
- triannon annotations). The annotation ID is the entire pair-tree path, after a URI escape.
96
- The URI escape makes it easier to work with the ID for tc.get_annotation(id) and
97
- tc.delete_annotation(id). For more information on object storage using pair-trees, see
101
+ Note: the annotation URI contains a pair-tree path (created by a Fedora 4 repository for triannon annotations). The annotation ID is the entire pair-tree path, after a URI escape. The URI escape makes it easier to work with the ID for `tc.get_annotation(id)` and `tc.delete_annotation(id)`. For more information on object storage using pair-trees, see
98
102
  - http://www.slideshare.net/jakkbl/dcc-pair-posterppt
99
103
  - https://wiki.ucop.edu/display/Curation/PairTree
100
104
 
101
105
  ## Development
102
106
 
103
- Clone and install:
107
+ #### Clone and install:
104
108
 
105
- ```console
106
- ./bin/setup.sh
109
+ ```sh
110
+ git clone https://github.com/sul-dlss/triannon-client.git
111
+ cd triannon-client
112
+ ./bin/setup.sh # runs bundle install
107
113
  ```
108
114
 
109
- Run tests:
115
+ #### Run tests:
110
116
 
111
- ```console
112
- ./bin/test.sh
117
+ ```sh
118
+ rake
113
119
  ```
114
120
 
121
+ The server request/response cycle has been recorded in `spec/fixtures/vcr_cassettes` (see http://www.relishapp.com/vcr).
122
+
123
+ #### Tests with live server interactions
124
+
125
+ - Startup a triannon server running on localhost in the development environment (the `spec/spec_helper.rb` is configured to interact with this server). For details on running triannon in development, see
126
+ - https://gist.github.com/darrenleeweber/bcfc9698ce5f5af8f465
127
+ - https://github.com/sul-dlss/triannon#running-this-code-in-development
128
+
129
+ ```sh
130
+ git clone https://github.com/sul-dlss/triannon.git
131
+ git clone https://gist.github.com/bcfc9698ce5f5af8f465.git triannon_reset
132
+ cp ./triannon_reset/triannon_server_reset.sh triannon/bin/
133
+ cd triannon
134
+ ./bin/triannon_server_reset.sh
135
+ # GO GET A TASTY BEVERAGE ;-)
136
+ ```
137
+
138
+ - Run the triannon client specs against the localhost server.
139
+ ```sh
140
+ git clone https://github.com/sul-dlss/triannon-client.git
141
+ cd triannon-client
142
+ ./bin/setup.sh # bundle update and package
143
+ rm -rf spec/fixtures/vcr_cassettes
144
+ rake
145
+ ```
data/Rakefile CHANGED
@@ -1,7 +1,20 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
1
7
  require 'bundler/gem_tasks'
2
8
  require 'rspec/core/rake_task'
3
9
  RSpec::Core::RakeTask.new(:spec)
4
10
 
5
11
  desc 'Default: run specs.'
6
- task :default => :spec
7
- task :specs => :spec
12
+ task :default => :ci
13
+
14
+ desc 'Run specs (without .env file)'
15
+ task :ci do
16
+ # Manage .env file around specs.
17
+ FileUtils.mv '.env', '.env_bak', force: true
18
+ Rake::Task['spec'].invoke
19
+ FileUtils.mv '.env_bak', '.env', force: true
20
+ end
@@ -1,15 +1,20 @@
1
1
  require 'dotenv'
2
2
  Dotenv.load
3
- # The pry dependency must be available when the client is configured to
4
- # run in debug mode, where it will fall into a pry console for rescue blocks.
5
- require 'pry'
6
- require 'pry-doc'
3
+
4
+ # pry must be available when the client is configured to run in debug mode,
5
+ # where it will fall into a pry console for rescue blocks.
6
+ if ENV['DEBUG']
7
+ require 'pry'
8
+ require 'pry-doc'
9
+ end
10
+
7
11
  # require rest client prior to linkeddata, so the latter can use it.
8
12
  require 'rest-client'
9
13
  # If a proxy is present, RestClient needs explicit configuration to use it.
10
14
  # (The ruby stdlib http client will use a proxy automatically.)
11
15
  RestClient.proxy = ENV['http_proxy'] unless ENV['http_proxy'].nil?
12
16
  RestClient.proxy = ENV['HTTP_PROXY'] unless ENV['HTTP_PROXY'].nil?
17
+
13
18
  require 'linkeddata'
14
19
  require_relative 'triannon-client/configuration'
15
20
  require_relative 'triannon-client/triannon_client'
@@ -18,9 +23,9 @@ require_relative 'triannon-client/triannon_client'
18
23
  # working with open annotations in a Triannon server, see
19
24
  # https://github.com/sul-dlss/triannon
20
25
  module TriannonClient
21
- # configuration at the module level, see
22
- # http://brandonhilkert.com/blog/ruby-gem-configuration-patterns/
23
26
 
27
+ # Configuration at the module level, see
28
+ # http://brandonhilkert.com/blog/ruby-gem-configuration-patterns/
24
29
  class << self
25
30
  attr_writer :configuration
26
31
  end
@@ -36,4 +41,5 @@ module TriannonClient
36
41
  def self.configure
37
42
  yield(configuration)
38
43
  end
44
+
39
45
  end
@@ -5,40 +5,52 @@ module TriannonClient
5
5
 
6
6
  attr_accessor :debug
7
7
  attr_accessor :logger
8
+ attr_reader :log_file
8
9
 
10
+ # Parameters for triannon server
9
11
  attr_accessor :host
10
- attr_accessor :user
11
- attr_accessor :pass
12
+ # attr_accessor :user # triannon doesn't support basic auth
13
+ # attr_accessor :pass # triannon doesn't support basic auth
14
+
15
+ # Parameters for triannon container
12
16
  attr_accessor :container
17
+ attr_accessor :container_user
18
+ attr_accessor :container_workgroups
19
+
20
+ # Parameters for triannon client authentication
21
+ attr_accessor :client_id
22
+ attr_accessor :client_pass
13
23
 
14
24
  def initialize
15
25
  @debug = env_boolean('DEBUG')
16
26
 
17
27
  @host = ENV['TRIANNON_HOST'] || 'http://localhost:3000'
18
- @user = ENV['TRIANNON_USER'] || ''
19
- @pass = ENV['TRIANNON_PASS'] || ''
28
+ # @user = ENV['TRIANNON_USER'] || '' # triannon doesn't support basic auth
29
+ # @pass = ENV['TRIANNON_PASS'] || '' # triannon doesn't support basic auth
30
+
31
+ # Parameters for triannon client authentication
32
+ @client_id = ENV['TRIANNON_CLIENT_ID'] || ''
33
+ @client_pass = ENV['TRIANNON_CLIENT_PASS'] || ''
34
+
35
+ # Parameters for triannon container
20
36
  @container = ENV['TRIANNON_CONTAINER'] || ''
21
37
  @container += '/' unless(@container.empty? || @container.end_with?('/'))
38
+ @container_user = ENV['TRIANNON_CONTAINER_USER'] || ''
39
+ @container_workgroups = ENV['TRIANNON_CONTAINER_WORKGROUPS'] || ''
22
40
 
23
41
  # logger
24
- log_file = ENV['TRIANNON_LOG_FILE'] || 'triannon_client.log'
25
- log_file = File.absolute_path log_file
26
- @log_file = log_file
27
- log_path = File.dirname log_file
28
- unless File.directory? log_path
29
- # try to create the log directory
30
- Dir.mkdir log_path rescue nil
31
- end
32
42
  begin
43
+ log_file = ENV['TRIANNON_LOG_FILE'] || 'log/triannon_client.log'
44
+ @log_file = File.absolute_path log_file
45
+ FileUtils.mkdir_p File.dirname(@log_file) rescue nil
33
46
  log_dev = File.new(@log_file, 'w+')
34
47
  rescue
35
48
  log_dev = $stderr
36
49
  @log_file = 'STDERR'
37
50
  end
38
51
  log_dev.sync = true if @debug # skip IO buffering in debug mode
39
- @logger = Logger.new(log_dev, 'monthly')
52
+ @logger = Logger.new(log_dev, 'weekly')
40
53
  @logger.level = @debug ? Logger::DEBUG : Logger::INFO
41
-
42
54
  end
43
55
 
44
56
  def env_boolean(var)
@@ -13,66 +13,117 @@ module TriannonClient
13
13
  CONTENT_TYPE_OA = "#{JSONLD_TYPE}; profile=\"#{PROFILE_OA}\""
14
14
 
15
15
  attr_reader :config
16
+ attr_accessor :auth
16
17
  attr_accessor :site
17
18
  attr_accessor :container
18
19
 
19
20
  # Initialize a new triannon client
20
- # All params are optional, the defaults are set in
21
- # the ::TriannonClient.configuration
22
- # @param host [String] HTTP URI for triannon server
23
- # @param user [String] Authorized username for access to triannon server
24
- # @param pass [String] Authorized password for access to triannon server
25
- # @param container [String] The container path on the triannon server
26
- def initialize(host=nil, user=nil, pass=nil, container=nil)
21
+ # All params are set using ::TriannonClient.configuration
22
+ def initialize
27
23
  # Configure triannon-app service
28
24
  @config = ::TriannonClient.configuration
29
- host ||= @config.host
25
+ host = @config.host
30
26
  host.chomp!('/') if host.end_with?('/')
31
- user ||= @config.user
32
- pass ||= @config.pass
33
27
  @site = RestClient::Resource.new(
34
28
  host,
35
- user: user,
36
- password: pass,
29
+ cookies: {},
30
+ headers: jsonld_payloads,
37
31
  open_timeout: 5,
38
32
  read_timeout: 30
39
33
  )
40
- container ||= @config.container
34
+ @auth = @site['/auth']
35
+ container = @config.container
41
36
  container = "/#{container}" unless container.start_with?('/')
42
37
  container = "#{container}/" unless container.end_with?('/')
43
38
  @container = @site[container]
44
39
  end
45
40
 
41
+ # Reset authentication
42
+ def authenticate!
43
+ @access_expiry = nil
44
+ authenticate
45
+ end
46
+
47
+ def authenticate
48
+ if @access_expiry.to_i < Time.now.to_i
49
+ @access_code = nil
50
+ @site.headers.delete :Authorization
51
+ @site.options[:cookies] = {}
52
+ end
53
+ @access_code || begin
54
+ # 1. Obtain a client authorization code (short-lived token)
55
+ return false if @config.client_id.empty? && @config.client_pass.empty?
56
+ client = {
57
+ clientId: @config.client_id,
58
+ clientSecret: @config.client_pass
59
+ }
60
+ response = @auth["/client_identity"].post client.to_json, json_payloads
61
+ @auth.options[:cookies] = response.cookies # save the cookie data
62
+ return false unless response.code == 200
63
+ auth = JSON.parse(response.body)
64
+ auth_code = auth['authorizationCode']
65
+ return false if auth_code.nil?
66
+ # 2. The client POSTs user credentials for a container, which modifies
67
+ # content in the cookies.
68
+ return false if @config.container_user.empty? && @config.container_workgroups.empty?
69
+ user = {
70
+ userId: @config.container_user,
71
+ workgroups: @config.container_workgroups
72
+ }
73
+ client_auth = "?code=#{auth_code}"
74
+ response = @auth["/login#{client_auth}"].post user.to_json, json_payloads
75
+ @auth.options[:cookies] = response.cookies # save the cookie data
76
+ return false unless response.code == 200
77
+ # 3. The client, on behalf of user, obtains a long-lived access token.
78
+ response = @auth["/access_token#{client_auth}"].get # no content type
79
+ @auth.options[:cookies] = response.cookies # save the cookie data
80
+ return false unless response.code == 200
81
+ access = JSON.parse(response.body)
82
+ return false if access['accessToken'].nil?
83
+ @access_code = "Bearer #{access['accessToken']}"
84
+ @access_expiry = Time.now.to_i + access['expiresIn'].to_i
85
+ @site.headers[:Authorization] = @access_code
86
+ end
87
+ end
88
+
46
89
  # Delete an annotation
47
90
  # @param id [String] an annotation ID
48
91
  # @response [true|false] true when successful
49
92
  def delete_annotation(id)
50
93
  check_id(id)
94
+ tries = 0
51
95
  begin
96
+ tries += 1
97
+ authenticate if tries == 2
52
98
  response = @container[id].delete
53
99
  # HTTP DELETE response codes: A successful response SHOULD be
54
100
  # 200 (OK) if the response includes an entity describing the status,
55
101
  # 202 (Accepted) if the action has not yet been enacted, or
56
102
  # 204 (No Content) if the action has been enacted but the response
57
103
  # does not include an entity.
58
- [200, 202, 204].include?(response.code)
104
+ return [200, 202, 204].include?(response.code)
59
105
  rescue RestClient::Exception => e
106
+ msg = e.message
60
107
  response = e.response
61
108
  if response.is_a?(RestClient::Response)
62
- # If an annotation doesn't exist, consider the request a 'success'
63
- return true if [404, 410].include?(response.code)
109
+ case response.code
110
+ when 401
111
+ retry if tries == 1
112
+ when 403
113
+ # DELETE is not authorized
114
+ when 404, 410
115
+ # If an annotation doesn't exist, consider it a 'success'
116
+ return true
117
+ end
64
118
  msg = response.body
65
- else
66
- msg = e.message
67
119
  end
68
120
  @config.logger.error("Failed to DELETE annotation: #{id}, #{msg}")
69
121
  binding.pry if @config.debug
70
- false
71
122
  rescue => e
72
123
  binding.pry if @config.debug
73
124
  @config.logger.error("Failed to DELETE annotation: #{id}, #{e.message}")
74
- false
75
125
  end
126
+ false
76
127
  end
77
128
 
78
129
  # POST and open annotation to triannon; the response contains an ID
@@ -87,16 +138,23 @@ module TriannonClient
87
138
  tries = 0
88
139
  begin
89
140
  tries += 1
90
- response = @container.post post_data, :content_type => JSONLD_TYPE, :accept => JSONLD_TYPE
141
+ authenticate if tries == 2
142
+ response = @container.post post_data
91
143
  rescue RestClient::Exception => e
92
- sleep 1*tries
93
- retry if tries < 3
144
+ msg = e.message
94
145
  response = e.response
146
+ if response.is_a?(RestClient::Response)
147
+ case response.code
148
+ when 401
149
+ retry if tries == 1
150
+ when 403
151
+ # POST is not authorized
152
+ end
153
+ msg = "Failed to POST annotation: #{response.code}, #{response.body}"
154
+ end
95
155
  binding.pry if @config.debug
96
- @config.logger.error("Failed to POST annotation: #{response.code}, #{response.body}")
156
+ @config.logger.error(msg)
97
157
  rescue => e
98
- sleep 1*tries
99
- retry if tries < 3
100
158
  binding.pry if @config.debug
101
159
  @config.logger.error("Failed to POST annotation: #{e.message}")
102
160
  end
@@ -107,17 +165,26 @@ module TriannonClient
107
165
  # @param content_type [String] HTTP mime type (defaults to 'application/ld+json')
108
166
  # @response [RDF::Graph] RDF::Graph of open annotations (can be empty on failure)
109
167
  def get_annotations(content_type=JSONLD_TYPE)
110
- check_content_type(content_type)
168
+ content_type = check_content_type(content_type)
169
+ g = RDF::Graph.new
111
170
  begin
112
171
  response = @container.get({:accept => content_type})
113
- # TODO: switch yard for different response.code?
114
- # TODO: log a failure for a response.code == 404
115
- response2graph(response)
172
+ g = response2graph(response)
116
173
  rescue => e
174
+ msg = e.message
175
+ r = e.response rescue nil
176
+ if r.is_a?(RestClient::Response)
177
+ case r.code
178
+ when 404
179
+ msg = "Failed to GET annotations: #{r.code}"
180
+ else
181
+ msg = "Failed to GET annotations: #{r.code}, #{r.body}"
182
+ end
183
+ end
117
184
  binding.pry if @config.debug
118
- @config.logger.error("Failed to GET annotations: #{e.message}")
119
- RDF::Graph.new # return an empty graph
185
+ @config.logger.error(msg)
120
186
  end
187
+ g
121
188
  end
122
189
 
123
190
  # Get an annotation (with a default annotation context)
@@ -126,16 +193,26 @@ module TriannonClient
126
193
  # @response [RDF::Graph] RDF::Graph of the annotation (can be empty on failure)
127
194
  def get_annotation(id, content_type=JSONLD_TYPE)
128
195
  check_id(id)
129
- check_content_type(content_type)
196
+ content_type = check_content_type(content_type)
197
+ g = RDF::Graph.new
130
198
  begin
131
199
  response = @container[id].get({:accept => content_type})
132
- # TODO: switch yard for different response.code?
133
- response2graph(response)
200
+ g = response2graph(response)
134
201
  rescue => e
202
+ msg = e.message
203
+ r = e.response rescue nil
204
+ if r.is_a?(RestClient::Response)
205
+ case r.code
206
+ when 404
207
+ msg = "Failed to GET annotation: #{id}, #{r.code}"
208
+ else
209
+ msg = "Failed to GET annotation: #{id}, #{r.code}, #{r.body}"
210
+ end
211
+ end
135
212
  binding.pry if @config.debug
136
- @config.logger.error("Failed to GET annotation: #{id}, #{e.message}")
137
- RDF::Graph.new # return an empty graph
213
+ @config.logger.error(msg)
138
214
  end
215
+ g
139
216
  end
140
217
 
141
218
  # Get an annotation using a IIIF context
@@ -152,22 +229,31 @@ module TriannonClient
152
229
  get_annotation(id, CONTENT_TYPE_OA)
153
230
  end
154
231
 
155
- # Parse a Triannon response into an RDF::Graph
232
+ # Parse a Triannon response into an RDF::Graph; the graph can be empty
233
+ # on failure to parse input. The response must contain a content-type that
234
+ # is available in RDF::Format.content_types (see code specs for details).
156
235
  # @param response [RestClient::Response] A RestClient::Response from Triannon
157
236
  # @response graph [RDF::Graph] An RDF::Graph instance
158
237
  def response2graph(response)
159
238
  unless response.is_a? RestClient::Response
160
- raise ArgumentError, 'response must be a RestClient::Response'
239
+ raise ArgumentError, 'response2graph only accepts a RestClient::Response'
161
240
  end
162
241
  content_type = response.headers[:content_type]
163
- check_content_type(content_type)
242
+ content_type = check_content_type(content_type)
164
243
  g = RDF::Graph.new
165
244
  begin
166
- format = RDF::Format.for(:content_type => content_type)
167
- format.reader.new(response) do |reader|
168
- reader.each_statement {|s| g << s }
245
+ case content_type
246
+ when /ld\+json/
247
+ g = RDF::Graph.new.from_jsonld(response.body)
248
+ when /turtle/
249
+ g = RDF::Graph.new.from_ttl(response.body)
250
+ else
251
+ format = RDF::Format.for(:content_type => content_type)
252
+ format.reader.new(response.body) do |reader|
253
+ reader.each_statement {|s| g << s }
254
+ end
169
255
  end
170
- rescue
256
+ rescue => e
171
257
  binding.pry if @config.debug
172
258
  @config.logger.error("Failed to parse response into RDF::Graph: #{e.message}")
173
259
  end
@@ -198,6 +284,7 @@ module TriannonClient
198
284
  def check_content_type(content_type)
199
285
  type = content_type.split(';').first # strip off any parameters
200
286
  raise ArgumentError, CONTENT_ERROR unless CONTENT_TYPES.include? type
287
+ type
201
288
  end
202
289
 
203
290
  def check_id(id)
@@ -205,6 +292,14 @@ module TriannonClient
205
292
  raise ArgumentError, 'Invalid ID' if id.nil? || id.empty?
206
293
  end
207
294
 
295
+ def json_payloads
296
+ { accept: :json, content_type: :json }
297
+ end
298
+
299
+ def jsonld_payloads
300
+ { accept: JSONLD_TYPE, content_type: JSONLD_TYPE }
301
+ end
302
+
208
303
  end
209
304
 
210
305
  end