Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
hopefully finalized README, some changes to the gemspec (not final) a…
Browse files Browse the repository at this point in the history
…nd to the resource
  • Loading branch information
Thomas Stachl committed Dec 12, 2013
1 parent 0b4b900 commit fb538fe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
48 changes: 11 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,20 @@ DeskApi.delete '/api/v2/topics/1'

## Working with Resources and Collections

The API supports RESTful resources and so does this wrapper. These resources are automatically discovered, meaning you can navigate around without having to worry about anything. We also support two finder methods `by_url` and `find`, the former works with any resource, the latter needs a collection.
The API supports RESTful resources and so does this wrapper. These resources are automatically discovered, meaning you can navigate around without having to worry about anything. We also support two finder methods `by_url` and `find`.

### Finders

The method `by_url` can be called on all `DeskApi::Resource` instances and will return a lazy loaded instance of the resource. Since the update to v0.5 of the API wrapper the `find` method can now be called on all `DeskApi::Resource` instances too. _Gotcha:_ It will rebuild the base path based on the resource/collection it is called on. So if you call it on the cases collection "`DeskApi.cases.find 1`" the path will look like this: `/api/v2/cases/:id`.

<table>
<thead>
<tr>
<th>Method</th>
<th>Path</th>
</tr>
</thead>
<tbody>
<tr>
<td>`DeskApi.cases.find(1)`</td>
<td>`/api/v2/cases/1</td>
</tr>
<tr>
<td>`DeskApi.cases.entries.first.find(1)`</td>
<td>`/api/v2/cases/1</td>
</tr>
<tr>
<td>`DeskApi.cases.search.find(1)`</td>
<td>`/api/v2/cases/1</td>
</tr>
<tr>
<td>`DeskApi.cases.search.entries.first.find(1)`</td>
<td>`/api/v2/cases/1</td>
</tr>
<tr>
<td>`DeskApi.cases.entries.first.replies.find(1)`</td>
<td>`/api/v2/cases/1/replies/1</td>
</tr>
<tr>
<td>`DeskApi.cases.entries.first.replies.entries.first.find(1)`</td>
<td>`/api/v2/cases/1/replies/1</td>
</tr>
</tbody>
</table>
The method `by_url` can be called on all `DeskApi::Resource` instances and will return a lazy loaded instance of the resource. Since the update to v0.5 of the API wrapper the `find` method can now be called on all `DeskApi::Resource` instances too. _Gotcha:_ It will rebuild the base path based on the resource/collection it is called on. So if you call it on the cases collection `DeskApi.cases.find 1` the path will look like this: `/api/v2/cases/:id`.

| Method | Path |
| ----------------------------------------------------------- | --------------------------- |
| `DeskApi.cases.find(1)` | `/api/v2/cases/1` |
| `DeskApi.cases.entries.find(1)` | `/api/v2/cases/1` |
| `DeskApi.cases.search(subject: 'Test').find(1)` | `/api/v2/cases/1` |
| `DeskApi.cases.search(subject: 'Test').entries.find(1)` | `/api/v2/cases/1` |
| `DeskApi.cases.entries.first.replies.find(1)` | `/api/v2/cases/1/replies/1` |
| `DeskApi.cases.entries.first.replies.entries.first.find(1)` | `/api/v2/cases/1/replies/1` |

### Pagination

Expand Down
4 changes: 1 addition & 3 deletions desk_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
gem.version = DeskApi::VERSION

gem.authors = ['Thomas Stachl']
gem.email = 'tom@desk.com'
gem.email = 'thomas@desk.com'

gem.require_paths = ['lib']
gem.files = `git ls-files`.split("\n")
Expand All @@ -20,12 +20,10 @@ Gem::Specification.new do |gem|
gem.extra_rdoc_files = ['README.md']
gem.rdoc_options = ['--line-numbers', '--inline--source', '--title', 'desk.rb']

gem.add_runtime_dependency('multi_json')
gem.add_runtime_dependency('faraday')
gem.add_runtime_dependency('faraday_middleware')
gem.add_runtime_dependency('simple_oauth')
gem.add_runtime_dependency('addressable')
gem.add_runtime_dependency('activesupport')
gem.add_runtime_dependency('hashie')

gem.add_development_dependency('rspec')
Expand Down
2 changes: 1 addition & 1 deletion lib/desk_api/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def search(params = {})
params = { q: params } if params.kind_of?(String)
url = Addressable::URI.parse(clean_base_url + '/search')
url.query_values = params
self.class.new(@_client, @_client.get(url.to_s).body, true)
self.class.new(@_client, self.class.build_self_link(url.to_s))
end

def find(id, options = {})
Expand Down
4 changes: 0 additions & 4 deletions spec/desk_api/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@
it 'allows searching on search enabled resources', :vcr do
subject.articles.search(text: 'Lorem Ipsum').total_entries.should eq(0)
end

it 'throws an error if search is not enabled', :vcr do
lambda { subject.users.search(test: 'something') }.should raise_error(DeskApi::Error::NotFound)
end
end

context '#create' do
Expand Down

0 comments on commit fb538fe

Please sign in to comment.