Skip to content

Commit

Permalink
Add support for the story search API method.
Browse files Browse the repository at this point in the history
  • Loading branch information
recurser committed Nov 15, 2018
1 parent 4d8027a commit 48961f2
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Expand Up @@ -44,7 +44,7 @@ This gem is a lightweight API wrapper. That means you'll need to refer to the
[API documentation](https://clubhouse.io/api/rest/v2/) to figure out what resources
and actions exist.

On the plus side, once you know what you want to do, using this gem should be
On the plus side, once you know what you want to do, using this gem should be
simple.

Instantiate an object to interface with the API:
Expand All @@ -61,7 +61,7 @@ clubhouse = ClubhouseRuby::Clubhouse.new(<YOUR CLUBHOUSE API TOKEN>, response_fo

Then, call methods on the object matching the resource(s) and action you are
interested in. For example, if you want to list all available epics, you need to
access the endpoint at https://api.clubhouse.io/api/v1/epics. The
access the endpoint at https://api.clubhouse.io/api/v1/epics. The
clubhouse_ruby gem uses an explicit action:

```ruby
Expand Down Expand Up @@ -147,6 +147,28 @@ clubhouse.projects(<project_id>).stories.list
# }
```

You can search stories, using standard Clubhouse [search operators](https://help.clubhouse.io/hc/en-us/articles/360000046646-Search-Operators):

```ruby
clubhouse.search_stories(page_size: 25, query: 'state:500000016')
# => {
# code: "200",
# status: "OK",
# content: {
# "next" => "/api/v2/search/stories?query=state%3A500000016&page_size=25&next=a8acc6577548df7a213272f7f9f617bcb1f8a831~24",
# "data" => [
# {
# "entity_type" => "story",
# "archived" => false,
# "created_at" => "...",
# "updated_at" => "...",
# ...
# }, ...
# ]
# }
# }
```

You can build a path in steps rather than all at once, and execution is deferred
until the action call:

Expand Down
4 changes: 4 additions & 0 deletions lib/clubhouse_ruby/constants.rb
Expand Up @@ -53,6 +53,10 @@ module ClubhouseRuby
bulk_update: {
path: :bulk,
action: :Put
},
search_stories: {
path: 'search/stories',
action: :Get
}
}.freeze
end
14 changes: 14 additions & 0 deletions spec/clubhouse_ruby/request_spec.rb
Expand Up @@ -143,6 +143,20 @@
expect(clubhouse[:content].first['id']).to eq(29)
expect(clubhouse[:content].first['archived']).to eq(true)
end

it 'searches stories', :vcr do
params = {
query: '!is:archived ',
page_size: 5
}
clubhouse = new_clubhouse.search_stories(params)

expect(clubhouse[:code]).to eq('200')
expect(clubhouse[:status]).to eq('OK')
expect(clubhouse[:content]['data'].count).to eq(5)
expect(clubhouse[:content]['data'].first['id']).to eq(32)
expect(clubhouse[:content]['data'].first['archived']).to eq(false)
end
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48961f2

Please sign in to comment.