diff --git a/lib/mural/client.rb b/lib/mural/client.rb index 0db072f..fe83ec9 100644 --- a/lib/mural/client.rb +++ b/lib/mural/client.rb @@ -51,7 +51,6 @@ def get(path, query = {}) ) req = Net::HTTP::Get.new uri - # retryable_request(req) retryable_request(req) end diff --git a/lib/mural/client/mural_content.rb b/lib/mural/client/mural_content.rb index c22be8a..d159605 100644 --- a/lib/mural/client/mural_content.rb +++ b/lib/mural/client/mural_content.rb @@ -8,10 +8,16 @@ class MuralContent include Areas include Arrows include Chats + include Comments include FacilitationFeatures include Files + include Images + include Shapes include StickyNotes + include Tables include Tags + include TextBoxes + include Titles include Widgets def_delegators :@client, :get, :post, :patch, :delete diff --git a/lib/mural/client/mural_content/comments.rb b/lib/mural/client/mural_content/comments.rb new file mode 100644 index 0000000..ed5328f --- /dev/null +++ b/lib/mural/client/mural_content/comments.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Mural + class Client + class MuralContent + module Comments + # Create a comment widget on a mural. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/createcomment + def create_comment(mural_id, create_comment_params) + json = post( + "/api/public/v1/murals/#{mural_id}/widgets/comment", + create_comment_params.encode + ) + + Mural::Widget::Comment.decode(json['value']) + end + + # Update a comment widget on a mural. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/updatecomment + def update_comment(mural_id, comment_id, update_comment_params) + json = patch( + "/api/public/v1/murals/#{mural_id}/widgets/comment/#{comment_id}", + update_comment_params.encode + ) + + Mural::Widget::Comment.decode(json['value']) + end + end + end + end +end diff --git a/lib/mural/client/mural_content/images.rb b/lib/mural/client/mural_content/images.rb new file mode 100644 index 0000000..54368ca --- /dev/null +++ b/lib/mural/client/mural_content/images.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Mural + class Client + class MuralContent + module Images + # https://developers.mural.co/public/reference/createimage + def create_image(mural_id, create_image_params) + json = post( + "/api/public/v1/murals/#{mural_id}/widgets/image", + create_image_params.encode + ) + + Mural::Widget::Image.decode(json['value']) + end + + # https://developers.mural.co/public/reference/createimage + def update_image(mural_id, image_id, update_image_params) + json = patch( + "/api/public/v1/murals/#{mural_id}/widgets/image/#{image_id}", + update_image_params.encode + ) + + Mural::Widget::Image.decode(json['value']) + end + end + end + end +end diff --git a/lib/mural/client/mural_content/shapes.rb b/lib/mural/client/mural_content/shapes.rb new file mode 100644 index 0000000..5c21d79 --- /dev/null +++ b/lib/mural/client/mural_content/shapes.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Mural + class Client + class MuralContent + module Shapes + # Create one or more shape widgets on a mural. Limit 1000. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/createshapewidget + def create_shapes(mural_id, create_shape_params) + json = post( + "/api/public/v1/murals/#{mural_id}/widgets/shape", + [*create_shape_params].map(&:encode) + ) + json['value'].map do |json_shape| + Mural::Widget::Shape.decode(json_shape) + end + end + + # Update a shape widget on a mural. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/updateshapewidget + def update_shape(mural_id, shape_id, update_shape_params) + json = patch( + "/api/public/v1/murals/#{mural_id}/widgets/shape/#{shape_id}", + update_shape_params.encode + ) + + Mural::Widget::Shape.decode(json['value']) + end + end + end + end +end diff --git a/lib/mural/client/mural_content/sticky_notes.rb b/lib/mural/client/mural_content/sticky_notes.rb index 5ccd0a9..0e4de39 100644 --- a/lib/mural/client/mural_content/sticky_notes.rb +++ b/lib/mural/client/mural_content/sticky_notes.rb @@ -4,6 +4,10 @@ module Mural class Client class MuralContent module StickyNotes + # Create one or more sticky note widgets on a mural. Limit 1000. + # + # Authorization scope: murals:write + # # https://developers.mural.co/public/reference/createstickynote def create_sticky_notes(mural_id, create_sticky_note_params) json = post( @@ -14,11 +18,17 @@ def create_sticky_notes(mural_id, create_sticky_note_params) json['value'].map { |s| Mural::Widget::StickyNote.decode(s) } end + # Update a sticky note widget on a mural. + # + # Authorization scope: murals:write + # # https://developers.mural.co/public/reference/updatestickynote - def update_sticky_note(mural_id, widget_id, update_sticky_note_params) + def update_sticky_note( + mural_id, sticky_note_id, update_sticky_note_params + ) json = patch( "/api/public/v1/murals/#{mural_id}/widgets/sticky-note" \ - "/#{widget_id}", + "/#{sticky_note_id}", update_sticky_note_params.encode ) diff --git a/lib/mural/client/mural_content/tables.rb b/lib/mural/client/mural_content/tables.rb new file mode 100644 index 0000000..7a0661b --- /dev/null +++ b/lib/mural/client/mural_content/tables.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Mural + class Client + class MuralContent + module Tables + # Create a table widget on a mural. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/createtable + def create_table(mural_id, create_table_params) + json = post( + "/api/public/v1/murals/#{mural_id}/widgets/table", + create_table_params.encode + ) + + # We receive a mix of Table and TableCell widgets + json['value'].map { |widget| Mural::Widget.decode(widget) } + end + end + end + end +end diff --git a/lib/mural/client/mural_content/text_boxes.rb b/lib/mural/client/mural_content/text_boxes.rb new file mode 100644 index 0000000..c6c12e5 --- /dev/null +++ b/lib/mural/client/mural_content/text_boxes.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Mural + class Client + class MuralContent + module TextBoxes + # Create one or more text box widgets on a mural. Limit 1000. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/createtextbox + def create_text_boxes(mural_id, create_text_box_params) + json = post( + "/api/public/v1/murals/#{mural_id}/widgets/textbox", + [*create_text_box_params].map(&:encode) + ) + + json['value'].map { |text_box| Mural::Widget::Text.decode(text_box) } + end + + # Update a textbox on a mural + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/updatetextbox + def update_text_box(mural_id, text_box_id, update_text_box_params) + json = patch( + "/api/public/v1/murals/#{mural_id}/widgets/textbox/#{text_box_id}", + update_text_box_params.encode + ) + + Mural::Widget::Text.decode(json['value']) + end + end + end + end +end diff --git a/lib/mural/client/mural_content/titles.rb b/lib/mural/client/mural_content/titles.rb new file mode 100644 index 0000000..3af8ca1 --- /dev/null +++ b/lib/mural/client/mural_content/titles.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Mural + class Client + class MuralContent + module Titles + # Create one or more title widgets on a mural. Limit 1000. + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/createtitle + def create_titles(mural_id, create_title_params) + json = post( + "/api/public/v1/murals/#{mural_id}/widgets/title", + [*create_title_params].map(&:encode) + ) + + json['value'].map { |title| Mural::Widget::Text.decode(title) } + end + + # Update a title on a mural + # + # Authorization scope: murals:write + # + # https://developers.mural.co/public/reference/updatetitle + def update_title(mural_id, title_id, update_title_params) + json = patch( + "/api/public/v1/murals/#{mural_id}/widgets/title/#{title_id}", + update_title_params.encode + ) + + Mural::Widget::Text.decode(json['value']) + end + end + end + end +end diff --git a/lib/mural/create_sticky_note_params.rb b/lib/mural/create_sticky_note_params.rb deleted file mode 100644 index 51eae0f..0000000 --- a/lib/mural/create_sticky_note_params.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -module Mural - class CreateStickyNoteParams - include Mural::Codec - - define_attributes( - **Mural::Widget::StickyNote.attrs.reject do |attr| - %i[ - content_edited_by - content_edited_on - created_by - created_on - hide_editor - hide_owner - id - invisible - locked - locked_by_facilitator - min_lines - type - updated_by - updated_on - ].include?(attr) - end - ) - - def encode - super.tap do |json| - json['style'] = json['style']&.encode - end.compact - end - - # Exact same values, no restrictions - Style = Mural::Widget::StickyNote::Style - end -end diff --git a/lib/mural/update_sticky_note_params.rb b/lib/mural/update_sticky_note_params.rb deleted file mode 100644 index 0674eb3..0000000 --- a/lib/mural/update_sticky_note_params.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Mural - class UpdateStickyNoteParams - include Mural::Codec - - define_attributes( - **Mural::CreateStickyNoteParams.attrs.reject do |attr| - %i[ - stacking_order - shape - ].include?(attr) - end - ) - - def encode - super.tap do |json| - json['style'] = json['style']&.encode - end - end - - Style = Mural::Widget::StickyNote::Style - end -end diff --git a/lib/mural/widget/create_comment_params.rb b/lib/mural/widget/create_comment_params.rb new file mode 100644 index 0000000..3cbddc7 --- /dev/null +++ b/lib/mural/widget/create_comment_params.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateCommentParams + include Mural::Codec + + define_attributes( + **Mural::Widget::Comment.attrs.filter do |attr| + %i[ + reference_widget_id + message + stacking_order + x + y + ].include? attr + end, + + resolved: 'resolved' + ) + end + end +end diff --git a/lib/mural/widget/create_image_params.rb b/lib/mural/widget/create_image_params.rb new file mode 100644 index 0000000..c0a73cc --- /dev/null +++ b/lib/mural/widget/create_image_params.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateImageParams + include Mural::Codec + + define_attributes( + **Mural::Widget::Image.attrs.reject do |attr| + %i[ + aspect_ratio + content_edited_by + content_edited_on + created_by + created_on + expires_in_minutes + hide_editor + hide_owner + id + invisible + link + locked + locked_by_facilitator + mask + natural_height + natural_width + thumbnail_url + type + updated_by + updated_on + url + ].include? attr + end, + + # The name of the image. + # The allowed image formats are: bmp, ico, gif, jpeg, jpg, png, webp. + name: 'name', + + # The URL used in the widget. + hyperlink: 'hyperlink' + ) + end + end +end diff --git a/lib/mural/widget/create_shape_params.rb b/lib/mural/widget/create_shape_params.rb new file mode 100644 index 0000000..f8b672e --- /dev/null +++ b/lib/mural/widget/create_shape_params.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateShapeParams + include Mural::Codec + + define_attributes( + **Mural::Widget::Shape.attrs.filter do |attr| + %i[ + height + hidden + html_text + instruction + parent_id + presentation_index + rotation + shape + stacking_order + style + text + title + width + x + y + ].include? attr + end + ) + + Style = Mural::Widget::Shape::Style + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/lib/mural/widget/create_sticky_note_params.rb b/lib/mural/widget/create_sticky_note_params.rb new file mode 100644 index 0000000..5a5d189 --- /dev/null +++ b/lib/mural/widget/create_sticky_note_params.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateStickyNoteParams + include Mural::Codec + + define_attributes( + **Mural::Widget::StickyNote.attrs.filter do |attr| + %i[ + height + hidden + html_text + hyperlink + hyperlink_title + instruction + parent_id + presentation_index + rotation + shape + stacking_order + style + tags + text + title + width + x + y + ].include?(attr) + end + ) + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + + # Exact same values, no restrictions + Style = Mural::Widget::StickyNote::Style + end + end +end diff --git a/lib/mural/widget/create_table_cell_params.rb b/lib/mural/widget/create_table_cell_params.rb new file mode 100644 index 0000000..02a80bb --- /dev/null +++ b/lib/mural/widget/create_table_cell_params.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateTableCellParams + include Mural::Codec + + define_attributes( + **Mural::Widget::TableCell.attrs.filter do |attr| + %i[ + col_span + column_id + height + rotation + row_id + row_span + style + text_content + width + x + y + ].include? attr + end + ) + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + json['textContent'] = json['textContent']&.encode + end.compact + end + + Style = Mural::Widget::TableCell::Style + TextContent = Mural::Widget::TableCell::TextContent + end + end +end diff --git a/lib/mural/widget/create_table_params.rb b/lib/mural/widget/create_table_params.rb new file mode 100644 index 0000000..37af35b --- /dev/null +++ b/lib/mural/widget/create_table_params.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateTableParams + include Mural::Codec + + define_attributes( + **Mural::Widget::Table.attrs.filter do |attr| + %i[ + auto_resize + columns + height + hidden + instruction + parent_id + presentation_index + rotation + rows + stacking_order + style + title + width + x + y + ].include? attr + end, + + # The array of table cells. + cells: 'cells' + ) + + Row = Mural::Widget::Table::Row + Column = Mural::Widget::Table::Column + Style = Mural::Widget::Table::Style + + def encode # rubocop:disable Metrics/CyclomaticComplexity + super.tap do |json| + json['cells']&.map!(&:encode) + json['rows']&.map!(&:encode) + json['columns']&.map!(&:encode) + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/lib/mural/widget/create_text_box_params.rb b/lib/mural/widget/create_text_box_params.rb new file mode 100644 index 0000000..c11c82c --- /dev/null +++ b/lib/mural/widget/create_text_box_params.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateTextBoxParams + include Mural::Codec + + define_attributes( + **Mural::Widget::Text.attrs.filter do |attr| + %i[ + height + hidden + hyperlink + hyperlink_title + instruction + parent_id + presentation_index + rotation + stacking_order + style + text + title + width + x + y + ].include? attr + end + ) + + Style = Mural::Widget::Text::Style + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/lib/mural/widget/create_title_params.rb b/lib/mural/widget/create_title_params.rb new file mode 100644 index 0000000..413b565 --- /dev/null +++ b/lib/mural/widget/create_title_params.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Mural + class Widget + class CreateTitleParams + include Mural::Codec + + define_attributes( + **Mural::Widget::Text.attrs.filter do |attr| + %i[ + height + hidden + hyperlink + hyperlink_title + instruction + parent_id + presentation_index + rotation + stacking_order + style + text + title + width + x + y + ].include? attr + end + ) + + Style = Mural::Widget::Text::Style + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/lib/mural/widget/image.rb b/lib/mural/widget/image.rb index 12a245d..0ca70df 100644 --- a/lib/mural/widget/image.rb +++ b/lib/mural/widget/image.rb @@ -40,7 +40,7 @@ class Image show_caption: 'showCaption', # The URL of the image thumbnail. - thumbnailUrl: 'thumbnail_url', + thumbnail_url: 'thumbnailUrl', # The download URL of the image. This URL has expiration time. # May be null when download restriction is enabled. diff --git a/lib/mural/widget/table.rb b/lib/mural/widget/table.rb index d70a11f..ae86ebd 100644 --- a/lib/mural/widget/table.rb +++ b/lib/mural/widget/table.rb @@ -2,25 +2,33 @@ module Mural class Widget - # UNDOCUMENTED - # This widget is not documented within Mural public API documentation. class Table include Mural::Codec + # https://developers.mural.co/public/reference/createtable define_attributes( **Mural::Widget.attrs, - title: 'title', + # If true, the widget will automatically resize to fit its content. auto_resize: 'autoResize', + + # The title of the widget in the outline. + title: 'title', + + # The array of columns definition. columns: 'columns', + + # The array of rows definition. rows: 'rows', + + # Style properties of the widget. style: 'style' ) def self.decode(json) super.tap do |table| - table.columns = table.columns&.map { |col| Column.decode(col) } - table.rows = table.rows&.map { |row| Row.decode(row) } + table.columns&.map! { |col| Column.decode(col) } + table.rows&.map! { |row| Row.decode(row) } table.style = Style.decode(table.style) end end @@ -28,16 +36,27 @@ def self.decode(json) class Column include Mural::Codec - define_attributes(column_id: 'columnId', width: 'width') + define_attributes( + # The ID of the column. + column_id: 'columnId', + + # The width of the column. + width: 'width' + ) end class Row include Mural::Codec define_attributes( + # The height of the row. height: 'height', + + # The min height of the row. min_height: 'minHeight', - row_id: 'row_id' + + # The ID of the row. + row_id: 'rowId' ) end @@ -45,7 +64,10 @@ class Style include Mural::Codec define_attributes( + # The border color of the widget in hex with alpha format. border_color: 'borderColor', + + # The border width border_width: 'borderWidth' ) end diff --git a/lib/mural/widget/table_cell.rb b/lib/mural/widget/table_cell.rb index a2bc2b9..59ba227 100644 --- a/lib/mural/widget/table_cell.rb +++ b/lib/mural/widget/table_cell.rb @@ -2,21 +2,33 @@ module Mural class Widget - # UNDOCUMENTED - # This widget is not documented within Mural public API documentation. class TableCell include Mural::Codec + # # https://developers.mural.co/public/reference/createtable define_attributes( **Mural::Widget.attrs, - title: 'title', + # Number of columns a cell can span. col_span: 'colSpan', + + # The ID of the column. column_id: 'columnId', - row_id: 'rolId', + + # The ID of the row. + row_id: 'rowId', + + # Number of rows a cell can span. row_span: 'rowSpan', + + # Style properties of the widget. style: 'style', - text_content: 'textContent' + + # textContent properties of the widget. + text_content: 'textContent', + + # The title of the widget in the outline. + title: 'title' ) def self.decode(json) @@ -29,6 +41,7 @@ def self.decode(json) class Style include Mural::Codec + # The backgroud color of the cell in hex with alpha format. define_attributes(background_color: 'backgroundColor') end @@ -36,12 +49,29 @@ class TextContent include Mural::Codec define_attributes( + # Font-family of the text. font_family: 'fontFamily', + + # Text size. font_size: 'fontSize', + + # The orientation of the text content. + # ["horizontal", "vertical-left", "vertical-right"] orientation: 'orientation', + + # Padding of the text content. padding: 'padding', + + # The text in the widget. It supports inline formatting using HTML + # tags. text: 'text', + + # The alignment of the text. + # ["left", "center", "right"] text_align: 'textAlign', + + # The vertical alignment of the text. + # ["top", "middle", "bottom"] vertical_align: 'verticalAlign' ) end diff --git a/lib/mural/widget/text.rb b/lib/mural/widget/text.rb index c63e9af..2606eba 100644 --- a/lib/mural/widget/text.rb +++ b/lib/mural/widget/text.rb @@ -18,7 +18,7 @@ class Text hyperlink: 'hyperlink', # Text displayed on the hyperlink button. - hyperlinkTitle: 'hyperlinkTitle', + hyperlink_title: 'hyperlinkTitle', # When true, the text wraps to fit the widget. When false, the widget # grows to fit the text. True when widget is created as a textbox and diff --git a/lib/mural/widget/update_comment_params.rb b/lib/mural/widget/update_comment_params.rb new file mode 100644 index 0000000..a2d6c9d --- /dev/null +++ b/lib/mural/widget/update_comment_params.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Mural + class Widget + class UpdateCommentParams + include Mural::Codec + + define_attributes( + **Mural::Widget::CreateCommentParams.attrs.reject do |attr| + %i[stacking_order].include? attr + end, + + replies: 'replies' + ) + end + end +end diff --git a/lib/mural/widget/update_image_params.rb b/lib/mural/widget/update_image_params.rb new file mode 100644 index 0000000..bb510ac --- /dev/null +++ b/lib/mural/widget/update_image_params.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mural + class Widget + class UpdateImageParams + include Mural::Codec + + define_attributes( + **Mural::Widget::CreateImageParams.attrs.reject do |attr| + %i[name].include? attr + end + ) + end + end +end diff --git a/lib/mural/widget/update_shape_params.rb b/lib/mural/widget/update_shape_params.rb new file mode 100644 index 0000000..2262804 --- /dev/null +++ b/lib/mural/widget/update_shape_params.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Mural + class Widget + class UpdateShapeParams + include Mural::Codec + + define_attributes( + **Mural::Widget::CreateShapeParams.attrs.reject do |attr| + %i[shape stacking_order].include? attr + end + ) + + Style = Mural::Widget::Shape::Style + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/lib/mural/widget/update_sticky_note_params.rb b/lib/mural/widget/update_sticky_note_params.rb new file mode 100644 index 0000000..2cdb5fe --- /dev/null +++ b/lib/mural/widget/update_sticky_note_params.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module Mural + class Widget + class UpdateStickyNoteParams + include Mural::Codec + + define_attributes( + **Mural::Widget::CreateStickyNoteParams.attrs.reject do |attr| + %i[ + stacking_order + shape + ].include? attr + end + ) + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end + end + + Style = Mural::Widget::StickyNote::Style + end + end +end diff --git a/lib/mural/widget/update_text_box_params.rb b/lib/mural/widget/update_text_box_params.rb new file mode 100644 index 0000000..0010c00 --- /dev/null +++ b/lib/mural/widget/update_text_box_params.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Mural + class Widget + class UpdateTextBoxParams + include Mural::Codec + + define_attributes( + **Mural::Widget::CreateTextBoxParams.attrs.reject do |attr| + %i[stacking_order].include? attr + end + ) + + Style = Mural::Widget::Text::Style + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/lib/mural/widget/update_title_params.rb b/lib/mural/widget/update_title_params.rb new file mode 100644 index 0000000..f2eb3b7 --- /dev/null +++ b/lib/mural/widget/update_title_params.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Mural + class Widget + class UpdateTitleParams + include Mural::Codec + + define_attributes( + **Mural::Widget::CreateTitleParams.attrs.reject do |attr| + %i[stacking_order].include? attr + end + ) + + Style = Mural::Widget::Text::Style + + def encode + super.tap do |json| + json['style'] = json['style']&.encode + end.compact + end + end + end +end diff --git a/test/mural/client/mural_content/test_comments.rb b/test/mural/client/mural_content/test_comments.rb new file mode 100644 index 0000000..f973717 --- /dev/null +++ b/test/mural/client/mural_content/test_comments.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +class TestComments < Minitest::Test + def setup + @client = Mural::Client.new + end + + def test_create_comment + mural_id = 'mural-1' + + stub_request( + :post, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets/comment" + ) + .with(body: { message: 'This is a test', x: 0, y: 0 }) + .to_return_json( + body: { value: { id: 'comment-1', message: 'This is a test' } }, + status: 201 + ) + + create_comment_params = Mural::Widget::CreateCommentParams.new.tap do |c| + c.message = 'This is a test' + c.x = 0 + c.y = 0 + end + + comment = @client + .mural_content + .create_comment(mural_id, create_comment_params) + + assert_instance_of Mural::Widget::Comment, comment + assert_equal 'comment-1', comment.id + assert_equal 'This is a test', comment.message + end + + def test_update_comment + mural_id = 'mural-1' + comment_id = 'comment-1' + + stub_request( + :patch, + "https://app.mural.co/api/public/v1/murals/#{mural_id}" \ + "/widgets/comment/#{comment_id}" + ) + .with(body: { replies: ['And it succeeded'] }) + .to_return_json( + body: { + value: { + id: comment_id, + message: 'This is a test', + replies: [ + { created: 1, message: 'And it succeeded', user: 'user-1' } + ] + } + }, + status: 201 + ) + + update_comment_params = Mural::Widget::UpdateCommentParams.new.tap do |c| + c.replies = ['And it succeeded'] + end + + comment = @client + .mural_content + .update_comment(mural_id, comment_id, update_comment_params) + + assert_instance_of Mural::Widget::Comment, comment + assert_equal 'comment-1', comment.id + assert_equal 'This is a test', comment.message + assert_equal 'And it succeeded', comment.replies.first.message + end +end diff --git a/test/mural/client/mural_content/test_images.rb b/test/mural/client/mural_content/test_images.rb new file mode 100644 index 0000000..e9f52c1 --- /dev/null +++ b/test/mural/client/mural_content/test_images.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'test_helper' + +class TestImages < Minitest::Test + def setup + @client = Mural::Client.new + end + + def test_create_image + mural_id = 'mural-1' + + stub_request( + :post, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets/image" + ) + .with(body: { name: 'my image' }) + .to_return_json( + body: { + value: { + id: 'image-1', + thumbnailUrl: 'https://example.com/thumbnail.jpg' + } + }, + status: 201 + ) + + params = Mural::Widget::CreateImageParams.new.tap do |params| + params.name = 'my image' + end + + image = @client.mural_content.create_image(mural_id, params) + + assert_instance_of Mural::Widget::Image, image + assert_equal 'image-1', image.id + assert_equal 'https://example.com/thumbnail.jpg', image.thumbnail_url + end + + def test_update_image + mural_id = 'mural-1' + image_id = 'image-1' + + stub_request( + :patch, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets" \ + "/image/#{image_id}" + ) + .with(body: { showCaption: false }) + .to_return_json( + body: { value: { id: 'image-1' } }, + status: 201 + ) + + params = Mural::Widget::UpdateImageParams.new.tap do |params| + params.show_caption = false + end + + image = @client.mural_content.update_image(mural_id, image_id, params) + + assert_instance_of Mural::Widget::Image, image + assert_equal 'image-1', image.id + end +end diff --git a/test/mural/client/mural_content/test_shapes.rb b/test/mural/client/mural_content/test_shapes.rb new file mode 100644 index 0000000..0458e11 --- /dev/null +++ b/test/mural/client/mural_content/test_shapes.rb @@ -0,0 +1,139 @@ +# frozen_string_literal: true + +class TestShapes < Minitest::Test + def setup + @client = Mural::Client.new + end + + def test_create_shapes + mural_id = 'mural-1' + + stub_request( + :post, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets/shape" + ) + .with( + body: [ + { shape: 'rectangle', x: 0, y: 0 }, + { + shape: 'ellipse', + x: 1, + y: 1, + style: { backgroundColor: '#FAFAFAFF' } + } + ] + ) + .to_return_json( + body: { + value: [ + { id: 'shape-1', shape: 'rectangle' }, + { + id: 'shape-2', + shape: 'ellipse', + style: { backgroundColor: '#FAFAFAFF' } + } + ] + }, + status: 201 + ) + + create_shape_params = [ + Mural::Widget::CreateShapeParams.new.tap do |params| + params.shape = 'rectangle' + params.x = 0 + params.y = 0 + end, + Mural::Widget::CreateShapeParams.new.tap do |params| + params.shape = 'ellipse' + params.x = 1 + params.y = 1 + params.style = + Mural::Widget::UpdateShapeParams::Style.new.tap do |style| + style.background_color = '#FAFAFAFF' + end + end + ] + + shapes = @client.mural_content.create_shapes( + mural_id, + create_shape_params + ) + + assert_equal 2, shapes.size + + rectangle = shapes.find { |s| s.shape == 'rectangle' } + + assert_instance_of Mural::Widget::Shape, rectangle + assert_equal 'shape-1', rectangle.id + + ellipse = shapes.find { |s| s.shape == 'ellipse' } + + assert_instance_of Mural::Widget::Shape, ellipse + assert_equal 'shape-2', ellipse.id + assert_equal '#FAFAFAFF', ellipse.style.background_color + end + + def test_update_shape + mural_id = 'mural-1' + shape_id = 'shape-1' + + stub_request( + :patch, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets" \ + "/shape/#{shape_id}" + ) + .with(body: { title: 'dat shape' }) + .to_return_json( + body: { value: { id: 'shape-1', title: 'dat shape' } }, + status: 201 + ) + + update_shape_params = + Mural::Widget::UpdateShapeParams.new.tap do |params| + params.title = 'dat shape' + end + + shape = @client.mural_content.update_shape( + mural_id, + shape_id, + update_shape_params + ) + + assert_instance_of Mural::Widget::Shape, shape + assert_equal 'shape-1', shape.id + assert_equal 'dat shape', shape.title + end + + def test_update_shape_with_style + mural_id = 'mural-1' + shape_id = 'shape-1' + + stub_request( + :patch, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets" \ + "/shape/#{shape_id}" + ) + .with(body: { style: { backgroundColor: '#FAFAFAFF' } }) + .to_return_json( + body: { value: { id: 'shape-1' } }, + status: 201 + ) + + update_shape_params = + Mural::Widget::UpdateShapeParams.new.tap do |params| + params.style = + Mural::Widget::UpdateShapeParams::Style.new.tap do |style| + style.background_color = '#FAFAFAFF' + end + end + + shape = @client.mural_content.update_shape( + mural_id, + shape_id, + update_shape_params + ) + + assert_instance_of Mural::Widget::Shape, shape + assert_equal 'shape-1', shape.id + end +end diff --git a/test/mural/client/mural_content/test_sticky_notes.rb b/test/mural/client/mural_content/test_sticky_notes.rb index 257f538..f60c974 100644 --- a/test/mural/client/mural_content/test_sticky_notes.rb +++ b/test/mural/client/mural_content/test_sticky_notes.rb @@ -19,7 +19,7 @@ def test_create_sticky_notes .to_return_json(body: { value: [{ id: 'sticky-1' }] }, status: 201) create_sticky_note_params = - Mural::CreateStickyNoteParams.new.tap do |sticky_note| + Mural::Widget::CreateStickyNoteParams.new.tap do |sticky_note| sticky_note.text = 'My sticky' end @@ -48,14 +48,13 @@ def test_create_sticky_notes_with_style status: 201 ) - sticky_note_style = Mural::CreateStickyNoteParams::Style.new.tap do |style| - style.background_color = '#FAFAFAFF' - end - create_sticky_note_params = - Mural::CreateStickyNoteParams.new.tap do |sticky_note| + Mural::Widget::CreateStickyNoteParams.new.tap do |sticky_note| sticky_note.text = 'My sticky' - sticky_note.style = sticky_note_style + sticky_note.style = + Mural::Widget::CreateStickyNoteParams::Style.new.tap do |style| + style.background_color = '#FAFAFAFF' + end end created_sticky_notes = @@ -79,9 +78,10 @@ def test_update_sticky_note .with(body: { text: 'updated text' }) .to_return_json(body: { value: { id: widget_id } }) - update_params = Mural::UpdateStickyNoteParams.new.tap do |params| - params.text = 'updated text' - end + update_params = + Mural::Widget::UpdateStickyNoteParams.new.tap do |params| + params.text = 'updated text' + end updated = @client.mural_content .update_sticky_note(mural_id, widget_id, update_params) @@ -101,11 +101,13 @@ def test_update_sticky_note_with_style .with(body: { style: { bold: true } }) .to_return_json(body: { value: { id: widget_id } }) - update_params = Mural::UpdateStickyNoteParams.new.tap do |params| - params.style = Mural::UpdateStickyNoteParams::Style.new.tap do |style| - style.bold = true + update_params = + Mural::Widget::UpdateStickyNoteParams.new.tap do |params| + params.style = + Mural::Widget::UpdateStickyNoteParams::Style.new.tap do |style| + style.bold = true + end end - end updated = @client.mural_content .update_sticky_note(mural_id, widget_id, update_params) diff --git a/test/mural/client/mural_content/test_tables.rb b/test/mural/client/mural_content/test_tables.rb new file mode 100644 index 0000000..76d35ea --- /dev/null +++ b/test/mural/client/mural_content/test_tables.rb @@ -0,0 +1,415 @@ +# frozen_string_literal: true + +class TestTables < Minitest::Test + def setup + @client = Mural::Client.new + end + + def test_create_table + mural_id = 'mural-1' + + stub_request( + :post, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets/table" + ).with( + body: {} + ).to_return_json( + body: { + value: [ + { + contentEditedBy: { + firstName: 'Lara', + id: 'user-1', + lastName: 'Croft' + }, + contentEditedOn: 1_757_857_758_121, + createdBy: { + firstName: 'Lara', + id: 'user-1', + lastName: 'Croft' + }, + createdOn: 1_757_857_758_121, + height: 150, + hidden: false, + hideEditor: false, + hideOwner: false, + id: 'e11ae0a8-7fc3-4e2f-a474-5d56b1b643de', + instruction: '', + invisible: false, + locked: false, + lockedByFacilitator: false, + parentId: nil, + presentationIndex: -1, + rotation: 0, + stackingOrder: 0, + title: '', + updatedBy: { + firstName: 'Lara', + id: 'user-1', + lastName: 'Croft' + }, + updatedOn: 1_757_857_758_121, + width: 100, + x: 20, + y: 148, + autoResize: true, + columns: [ + { + columnId: 'column-1', + width: 100 + } + ], + rows: [ + { + height: 50, + minHeight: 30, + rowId: 'row-1' + } + ], + style: { + borderColor: 'rgba(250,250,250,1)', + borderWidth: 5 + }, + type: 'table' + }, + { + contentEditedBy: { + firstName: 'Lara', + id: 'user-1', + lastName: 'Croft' + }, + contentEditedOn: 1_757_857_758_121, + createdBy: { + firstName: 'Lara', + id: 'user-1', + lastName: 'Croft' + }, + createdOn: 1_757_857_758_121, + height: 150, + hidden: false, + hideEditor: false, + hideOwner: false, + id: '26c3b066-fd09-4a6e-9e4d-d5072c875f6e', + instruction: '', + invisible: false, + locked: false, + lockedByFacilitator: false, + parentId: 'e11ae0a8-7fc3-4e2f-a474-5d56b1b643de', + presentationIndex: -1, + rotation: 0, + stackingOrder: 0, + title: '', + updatedBy: { + firstName: 'Lara', + id: 'user-1', + lastName: 'Croft' + }, + updatedOn: 1_757_857_758_121, + width: 140, + x: 0, + y: 0, + colSpan: 1, + columnId: 'column-1', + rowId: 'row-1', + rowSpan: 1, + style: { + backgroundColor: '#FFFFFFFF' + }, + textContent: { + fontFamily: 'proxima-nova', + fontSize: 24, + orientation: 'horizontal', + padding: 23, + text: 'Hello', + textAlign: 'center', + verticalAlign: 'middle' + }, + type: 'table cell' + } + ] + }, + status: 201 + ) + + params = Mural::Widget::CreateTableParams.new.tap do |table| # rubocop:disable Metrics/BlockLength + table.cells = [ + Mural::Widget::CreateTableCellParams.new.tap do |cell| + cell.text_content = + Mural::Widget::CreateTableCellParams::TextContent.new.tap do |text_content| + text_content.text = 'Hello' + text_content.font_family = 'proxima-nova' + text_content.orientation = 'horizontal' + text_content.text_align = 'center' + text_content.vertical_align = 'middle' + text_content.font_size = 24 + text_content.padding = 23 + end + + cell.column_id = 'column-1' + cell.col_span = 1 + cell.height = 150 + cell.width = 140 + cell.x = 0 + cell.y = 0 + cell.row_id = 'row-1' + cell.row_span = 1 + end + ] + + table.columns = [ + Mural::Widget::CreateTableParams::Column.new.tap do |col| + col.width = 100 + col.column_id = 'column-1' + end + ] + + table.rows = [ + Mural::Widget::CreateTableParams::Row.new.tap do |row| + row.height = 50 + row.min_height = 30 + row.row_id = 'row-1' + end + ] + + table.style = Mural::Widget::CreateTableParams::Style.new.tap do |style| + style.border_color = '#FAFAFAFF' + style.border_width = 5 + end + + table.width = 100 + table.height = 150 + table.x = 20 + table.y = 148 + end + + widgets = @client.mural_content.create_table(mural_id, params) + + assert_equal 2, widgets.size + end + + def test_create_table_with_empty_cell + mural_id = 'mural-1' + + stub_request( + :post, + "https://app.mural.co/api/public/v1/murals/#{mural_id}/widgets/table" + ).with( + body: {} + ).to_return_json( + body: { + value: [ + { + contentEditedBy: { + firstName: 'Nathan', + id: 'user-2', + lastName: 'West' + }, + contentEditedOn: 1_757_858_678_513, + createdBy: { + firstName: 'Nathan', + id: 'user-2', + lastName: 'West' + }, + createdOn: 1_757_858_678_513, + height: 150, + hidden: false, + hideEditor: false, + hideOwner: false, + id: 'da059257-5fc6-4b92-8a54-c8e6f98b554f', + instruction: '', + invisible: false, + locked: false, + lockedByFacilitator: false, + parentId: nil, + presentationIndex: -1, + rotation: 0, + stackingOrder: 0, + title: '', + updatedBy: { + firstName: 'Nathan', + id: 'user-2', + lastName: 'West' + }, + updatedOn: 1_757_858_678_513, + width: 100, + x: 20, + y: 148, + autoResize: true, + columns: [ + { + columnId: 'column-1', + width: 100 + } + ], + rows: [ + { + height: 50, + minHeight: 30, + rowId: 'row-1' + } + ], + style: { + borderColor: '#9E9E9E', + borderWidth: 3 + }, + type: 'table' + }, + { + contentEditedBy: { + firstName: 'Nathan', + id: 'user-2', + lastName: 'West' + }, + contentEditedOn: 1_757_858_678_513, + createdBy: { + firstName: 'Nathan', + id: 'user-2', + lastName: 'West' + }, + createdOn: 1_757_858_678_513, + height: 150, + hidden: false, + hideEditor: false, + hideOwner: false, + id: 'f49a96c7-c2a5-435b-bed6-4415312445b6', + instruction: '', + invisible: false, + locked: false, + lockedByFacilitator: false, + parentId: 'da059257-5fc6-4b92-8a54-c8e6f98b554f', + presentationIndex: -1, + rotation: 0, + stackingOrder: 0, + title: '', + updatedBy: { + firstName: 'Nathan', + id: 'user-2', + lastName: 'West' + }, + updatedOn: 1_757_858_678_513, + width: 140, + x: 0, + y: 0, + colSpan: 1, + columnId: 'column-1', + rowId: 'row-1', + rowSpan: 1, + style: { + backgroundColor: '#FFFFFFFF' + }, + textContent: { + fontFamily: 'proxima-nova', + fontSize: 23, + orientation: 'horizontal', + padding: 36, + text: '