diff --git a/README.md b/README.md index 3b3f307..bc399d0 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,15 @@ category_list.each_with_index do |category, index| end ``` +### Updating a category + +```ruby +require('seatsio') +client = Seatsio::Client.new(Seatsio::Region.EU(), "my-company-admin-key", "my-workspace-public-key") +@seatsio.charts.update_category(chart_key: '', category_key: '', label: "New label", color: "#bbbbbb", accessible: true) +``` + + ### Listing all charts ```ruby diff --git a/lib/seatsio/charts.rb b/lib/seatsio/charts.rb index 2f26cfb..b64a6f4 100644 --- a/lib/seatsio/charts.rb +++ b/lib/seatsio/charts.rb @@ -51,6 +51,14 @@ def list_categories(chart_key) Category.create_list(response['categories']) end + def update_category(chart_key:, category_key:, label: nil, color: nil, accessible: nil) + payload = {} + payload['label'] = label if label != nil + payload['color'] = color if color != nil + payload['accessible'] = accessible if accessible != nil + @http_client.post("/charts/#{chart_key}/categories/#{category_key}", payload) + end + def add_tag(key, tag) @http_client.post("charts/#{key}/tags/#{CGI::escape(tag)}") end diff --git a/test/charts/manage_categories_test.rb b/test/charts/manage_categories_test.rb index a38644c..971806e 100644 --- a/test/charts/manage_categories_test.rb +++ b/test/charts/manage_categories_test.rb @@ -48,4 +48,18 @@ def test_list_categories assert_equal(categories[index]['key'], category.key) end end + + def test_update_category + categories = [ + { 'key' => 1, 'label' => 'Category 1', 'color' => '#aaaaaa', 'accessible' => false } + ] + chart = @seatsio.charts.create categories: categories + + @seatsio.charts.update_category(chart_key: chart.key, category_key: 1, label: "New label", color: "#bbbbbb", accessible: true) + + category_list = @seatsio.charts.list_categories(chart.key) + assert_equal(category_list[0].label, "New label") + assert_equal(category_list[0].color, "#bbbbbb") + assert_equal(category_list[0].accessible, true) + end end