Skip to content

Commit

Permalink
Update category (#105)
Browse files Browse the repository at this point in the history
- API support
- Documented example

Co-authored-by: Steve Chaloner <[email protected]>
  • Loading branch information
schaloner and Steve Chaloner authored Apr 30, 2024
1 parent 0ed0b19 commit a69ab00
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<the chart key>', category_key: '<the category key>', label: "New label", color: "#bbbbbb", accessible: true)
```


### Listing all charts

```ruby
Expand Down
8 changes: 8 additions & 0 deletions lib/seatsio/charts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/charts/manage_categories_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a69ab00

Please sign in to comment.