Class: Matterhorn::Endpoint::Event
- Inherits:
-
Matterhorn::Endpoint
- Object
- Matterhorn::Endpoint
- Matterhorn::Endpoint::Event
- Defined in:
- lib/matterhorn/endpoint/event.rb
Overview
This endpoint is not a pure wrapper of the archive endpoint. Create should be done over ingest endpoint Update is implemented over the external API In the code the evnent_id is used. This id is equal to media_package_id.
Instance Attribute Summary
Attributes inherited from Matterhorn::Endpoint
#response_body, #response_code
Instance Method Summary collapse
-
#changeable_element?(element_name) ⇒ Boolean
————————————————————————————- update —.
-
#delete(event_id) ⇒ Object
————————————————————————————- delete —.
-
#read(event_id) ⇒ Object
————————————————————————————— read —.
- #update_dublin_core(event_id, dublin_core) ⇒ Object
Methods inherited from Matterhorn::Endpoint
#close, create, #error_code, #error_msg, #error_occurred?, #initialize, open
Constructor Details
This class inherits a constructor from Matterhorn::Endpoint
Instance Method Details
#changeable_element?(element_name) ⇒ Boolean
————————————————————————————- update —
39 40 41 42 |
# File 'lib/matterhorn/endpoint/event.rb', line 39 def changeable_element?(element_name) ['title', 'subject', 'description', 'language', 'license', 'source', 'isPartOf']. include?(element_name) end |
#delete(event_id) ⇒ Object
————————————————————————————- delete —
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/matterhorn/endpoint/event.rb', line 75 def delete(event_id) begin done = false split_response http_api_client.delete( "api/events/#{event_id}" ) done = true rescue => ex exception_handler('delete', ex, { 404 => "The Event[#{event_id}] could not be found!" } ) end done end |
#read(event_id) ⇒ Object
————————————————————————————— read —
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/matterhorn/endpoint/event.rb', line 20 def read(event_id) event = nil begin split_response http_api_client.get( "api/events/#{event_id}" ) event = JSON.parse(response_body) rescue => ex exception_handler('read', ex, { 404 => "The Event[#{event_id}] could not be found!" } ) end event end |
#update_dublin_core(event_id, dublin_core) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/matterhorn/endpoint/event.rb', line 45 def update_dublin_core(event_id, dublin_core) updated = false begin dc_field_arr = [] dublin_core.each_dcterms_element do |name, content| if changeable_element?(name) && !content.empty? dc_field_arr << { 'id' => name, 'value' => content } end end split_response http_api_client.put( "api/events/#{event_id}/metadata?type=dublincore/episode", { 'metadata' => dc_field_arr.to_json } ) updated = true rescue => ex exception_handler('update_dublin_core', ex, { 400 => "The request is invaldi or inconsistent.", 404 => "The media package of event[#{event_id}] could not be found." } ) end updated end |