Skip to content

Commit 5afb636

Browse files
committed
finish events and issues apis
1 parent a2e396a commit 5afb636

18 files changed

+2284
-107
lines changed

README.md

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,36 @@
1-
# Sentry Ruby API
1+
# Sentry
22

3-
Sentry Ruby API is a Ruby wrapper for the [getsentry/sentry API](https://docs.sentry.io/hosted/api/). **And it still being developed, and not published yet.**
3+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sentry`. To experiment with that code, run `bin/console` for an interactive prompt.
44

5-
## Installation
6-
7-
add to a Gemfile:
8-
9-
```ruby
10-
gem 'sentry', :path => '/path/to/sentry'
11-
```
5+
TODO: Delete this and the text above, and describe your gem
126

13-
## Usage
7+
## Installation
148

15-
Configuration example:
9+
Add this line to your application's Gemfile:
1610

1711
```ruby
18-
Sentry.configure do |config|
19-
config.endpoint = 'http://example.com/api/0'
20-
config.auth_token = 'your_auth_token'
21-
config.default_org_slug = 'sentry-sc'
22-
end
12+
gem 'sentry'
2313
```
2414

25-
(Note: If you are using getsentry.com's hosted service, your endpoint will be `https://app.getsentry.com/api/0`)
15+
And then execute:
2616

27-
Usage examples:
28-
29-
```ruby
30-
# set an API endpoint
31-
Sentry.endpoint = 'http://example.com/api/0'
32-
# => "http://example.com/api/0"
17+
$ bundle
3318

34-
# set a user private token
35-
Sentry.auth_token = 'your_auth_token'
36-
# => "your_auth_token"
19+
Or install it yourself as:
3720

38-
# configure a proxy server
39-
Sentry.http_proxy('proxyhost', 8888)
40-
# proxy server w/ basic auth
41-
Sentry.http_proxy('proxyhost', 8888, 'user', 'pass')
21+
$ gem install sentry
4222

43-
# list projects
44-
Sentry.projects
45-
46-
# initialize a new client
47-
s = Sentry.client(endpoint: 'https://api.example.com', auth_token: 'your_auth_token', default_org_slug: 'sentry-sc')
48-
49-
# a paginated response
50-
projects = Sentry.projects
51-
52-
# check existence of the next page
53-
projects.has_next_page?
54-
55-
# retrieve the next page
56-
projects.next_page
57-
58-
# iterate all projects
59-
projects.auto_paginate do |project|
60-
# do something
61-
end
23+
## Usage
6224

63-
# retrieve all projects as an array
64-
projects.auto_paginate
65-
```
25+
TODO: Write usage instructions here
6626

6727
## Development
68-
The basic framework had been finished, meanwhile the APIs of Organizations and Projects had been added, more APIs will be added later. You are welcome to help me with it.
6928

70-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
71-
`rake spec` to run the tests. You can also run `bin/console` for an interactive
72-
prompt that will allow you to experiment.
29+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30+
31+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
7332

74-
## License
33+
## Contributing
7534

76-
Released under the BSD 2-clause license. See LICENSE.txt for details.
35+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sentry.
7736

78-
## Special Thank
79-
Thanks to NARKOZ's [gitlab](https://github.com/NARKOZ/gitlab) ruby wrapper which really gives me a lot of inspiration.

Rakefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
require "bundler/gem_tasks"
2-
require "rspec/core/rake_task"
3-
RSpec::Core::RakeTask.new
4-
52
task :default => :spec
6-
task :test => :spec

lib/sentry/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ class Client < API
55

66
include Organizations
77
include Projects
8+
include Events
89
end
910
end

lib/sentry/client/events.rb

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,87 @@ class Sentry::Client
22

33
module Events
44

5-
# Return details on an individual issue.
6-
def issue
5+
# Retrieve an Issue
6+
#
7+
# @example
8+
# Sentry.issue('120732258')
9+
#
10+
# @param issue_id [String] the ID of the issue to retrieve.
11+
# @return Sentry::ObjectifiedHash
12+
def issue(issue_id)
13+
get("/issues/#{issue_id}/")
714
end
815

9-
# Return a list of aggregates bound to a project
16+
# List an Issue’s Events
1017
#
1118
# @example
12-
# Sentry.projects
19+
# Sentry.issue_events('120732258')
1320
#
21+
# @param issue_id [String] the ID of the issue to retrieve.
1422
# @return [Array<Sentry::ObjectifiedHash>]
15-
def issues
23+
def issue_events(issue_id)
24+
get("/issues/#{issue_id}/events/")
1625
end
1726

18-
# This endpoint lists an issue’s events.
19-
def issues_events
20-
21-
end
22-
23-
# This endpoint lists an issue’s hashes, which are the generated checksums used to aggregate individual events.
24-
def issues_hashes
25-
27+
# List an Issue’s Hashes
28+
#
29+
# @example
30+
# Sentry.issues_hashes('120732258')
31+
#
32+
# @param issue_id [String] the ID of the issue to retrieve.
33+
# @return [Array<Sentry::ObjectifiedHash>]
34+
def issue_hashes(issue_id)
35+
get("/issues/#{issue_id}/hashes/")
2636
end
2737

2838
# Removes an individual issue.
29-
def remove_issue
30-
39+
#
40+
# @example
41+
# Sentry.remove_issue('120732258')
42+
#
43+
# @param issue_id [String] the ID of the issue to retrieve.
44+
def remove_issue(issue_id)
45+
delete("/issues/#{issue_id}/")
3146
end
3247

33-
# Return a list of sampled events bound to a project.
48+
# Update an individual issue.
3449
#
3550
# @example
36-
# Sentry.projects
51+
# Sentry.update_issue('120732258')
52+
# Sentry.update_issue('120732258',{status:'resolved'})
53+
# Sentry.update_issue('120732258',{status:'resolved', assignedTo:'[email protected]'})
3754
#
38-
# @return [Array<Sentry::ObjectifiedHash>]
39-
def events
55+
# @param issue_id [String] the ID of the issue to retrieve.
56+
# @param [Hash] options A customizable set of options.
57+
# @option options [String] :status the new status for the groups. Valid values are "resolved", "unresolved" and "muted".
58+
# @option options [String] :assignedTo the username of the user that should be assigned to this issue.
59+
# @option options [Boolean] :hasSeen in case this API call is invoked with a user context this allows changing of the flag that indicates if the user has seen the event.
60+
# @option options [Boolean] :isBookmarked in case this API call is invoked with a user context this allows changing of the bookmark flag.
61+
# @option options [Boolean] :isSubscribed in case this API call is invoked with a user context this allows changing of the subscribed flag.
62+
def update_issue(issue_id, options={})
63+
put("/issues/#{issue_id}/", body: options)
4064
end
4165

42-
# Retrieves the details of the latest sample for an aggregate.
66+
# Retrieves the details of the latest event.
4367
#
4468
# @example
45-
# Sentry.projects
69+
# Sentry.latest_event('120633628')
4670
#
47-
# @return [Array<Sentry::ObjectifiedHash>]
48-
def latest_events
71+
# @param issue_id [String] the ID of the issue to retrieve.
72+
# @return Sentry::ObjectifiedHash
73+
def latest_event(issue_id)
74+
get("/issues/#{issue_id}/events/latest/")
4975
end
5076

51-
# Retrieves the details of the oldest sample for an aggregate.
77+
# Retrieves the details of the oldest event.
5278
#
5379
# @example
54-
# Sentry.projects
80+
# Sentry.oldest_event('120633628')
5581
#
56-
# @return [Array<Sentry::ObjectifiedHash>]
57-
def oldest_events
82+
# @param issue_id [String] the ID of the issue to retrieve.
83+
# @return Sentry::ObjectifiedHash
84+
def oldest_event(issue_id)
85+
get("/issues/#{issue_id}/events/oldest/")
5886
end
5987

6088
end

lib/sentry/client/organizations.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def organization_projects(organization_slug="")
3232
# Sentry.organization('slug')
3333
#
3434
# @param organization_slug [String] the slug of the organization the team should be created for.
35-
# @return <Sentry::ObjectifiedHash>
35+
# @return Sentry::ObjectifiedHash
3636
def organization(organization_slug="")
3737
organization_slug = @default_org_slug if organization_slug == ""
3838
get("/organizations/#{organization_slug}/")
@@ -46,9 +46,10 @@ def organization(organization_slug="")
4646
# Sentry.update_organization('slug',{name:'new-name', slug:'new-slug'})
4747
#
4848
# @param organization_slug [String] the slug of the organization the team should be created for.
49-
# @param options [String] :name an optional new name for the organization.
50-
# @param options [String] :slug an optional new slug for the organization. Needs to be available and unique.
51-
# @return <Sentry::ObjectifiedHash>
49+
# @param [Hash] options A customizable set of options.
50+
# @option options [String] :name an optional new name for the organization.
51+
# @option options [String] :slug an optional new slug for the organization. Needs to be available and unique.
52+
# @return Sentry::ObjectifiedHash
5253
def update_organization(organization_slug, options={})
5354
put("/organizations/#{organization_slug}/", body: options)
5455
end
@@ -60,7 +61,7 @@ def update_organization(organization_slug, options={})
6061
# Sentry.organization_stats('slug', {stat:'received', since:'1472158800'})
6162
#
6263
# @param organization_slug [String] the slug of the organization for which the stats should be retrieved.
63-
# @param [Hash] options A customizable set of options.
64+
# @param [Hash] options A customizable set of options.
6465
# @option options [String] :stat the name of the stat to query ("received", "rejected", "blacklisted")
6566
# @option options [Timestamp] :since a timestamp to set the start of the query in seconds since UNIX epoch.
6667
# @option options [Timestamp] :until a timestamp to set the end of the query in seconds since UNIX epoch.

lib/sentry/client/projects.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ def projects
1111
get("/projects/")
1212
end
1313

14-
# Retrieve a Project¶.
14+
# Retrieve a Project
1515
#
1616
# @example
1717
# Sentry.project('project-slug')
1818
#
1919
# @param project_slug [String] the slug of the project to retrieve.
2020
# @param organization_slug [String] the slug of the organization the project belong to.
21+
# @return Sentry::ObjectifiedHash
2122
def project(project_slug, organization_slug="")
2223
organization_slug = @default_org_slug if organization_slug == ""
2324
get("/projects/#{organization_slug}/#{project_slug}/")
@@ -35,6 +36,7 @@ def project(project_slug, organization_slug="")
3536
# @option options [String] :isBookmarked in case this API call is invoked with a user context this allows changing of the bookmark flag.
3637
# @option options [Hash] optional options to override in the project settings.
3738
# @param organization_slug [String] the slug of the organization the project belong to.
39+
# @return Sentry::ObjectifiedHash
3840
def update_project(project_slug, options={}, organization_slug="")
3941
organization_slug = @default_org_slug if organization_slug == ""
4042
put("/projects/#{organization_slug}/#{project_slug}/", body: options)
@@ -59,7 +61,7 @@ def delete_project(project_slug, organization_slug="")
5961
# Sentry.project_stats('slug', {stat:'received', since:'1472158800'})
6062
#
6163
# @param project_slug [String] the slug of the project.
62-
# @param [Hash] options A customizable set of options.
64+
# @param [Hash] options A customizable set of options.
6365
# @option options [String] :stat the name of the stat to query ("received", "rejected", "blacklisted")
6466
# @option options [Timestamp] :since a timestamp to set the start of the query in seconds since UNIX epoch.
6567
# @option options [Timestamp] :until a timestamp to set the end of the query in seconds since UNIX epoch.
@@ -102,10 +104,10 @@ def client_keys(project_slug, organization_slug="")
102104
# Sentry.create_client_key('project-slug','new-name')
103105
#
104106
# @param project_slug [String] the slug of the project the client keys belong to.
105-
# @param [Hash] options A customizable set of options.
107+
# @param [Hash] options A customizable set of options.
106108
# @option options [String] :name the name for the new key.
107109
# @param organization_slug [String] the slug of the organization the client keys belong to.
108-
# @return <Sentry::ObjectifiedHash>
110+
# @return Sentry::ObjectifiedHash
109111
def create_client_key(project_slug, options={}, organization_slug="")
110112
organization_slug = @default_org_slug if organization_slug == ""
111113
post("/projects/#{organization_slug}/#{project_slug}/keys/", body: options)
@@ -131,7 +133,7 @@ def delete_client_key(project_slug, key_id, organization_slug="")
131133
#
132134
# @param project_slug [String] the slug of the project the client keys belong to.
133135
# @param key_id [String] the ID of the key to update.
134-
# @param [Hash] options A customizable set of options.
136+
# @param [Hash] options A customizable set of options.
135137
# @option options [String] :name the new name for the client key.
136138
# @param organization_slug [String] the slug of the organization the client keys belong to.
137139
# @return [Array<Sentry::ObjectifiedHash>]
@@ -161,7 +163,7 @@ def project_events(project_slug, organization_slug="")
161163
# @param project_slug [String] the slug of the project the client keys belong to.
162164
# @param event_id [String] the slug of the project the event belongs to.
163165
# @param organization_slug [String] the slug of the organization the client keys belong to.
164-
# @return <Sentry::ObjectifiedHash>
166+
# @return Sentry::ObjectifiedHash
165167
def project_event(project_slug, event_id, organization_slug="")
166168
organization_slug = @default_org_slug if organization_slug == ""
167169
get("/projects/#{organization_slug}/#{project_slug}/events/#{event_id}/")

lib/sentry/objectified_hash.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def initialize(hash)
1515
def to_hash
1616
@hash
1717
end
18+
1819
alias_method :to_h, :to_hash
1920

2021
# @return [String] Formatted string with the class name, object id and original hash.

lib/sentry/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Sentry
2-
VERSION = "1.0.0"
2+
VERSION = "0.1.0"
33
end

sentry.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Gem::Specification.new do |spec|
1010
spec.email = ["[email protected]"]
1111

1212
spec.summary = %q{Ruby client for Sentry API}
13-
spec.description = %q{A Ruby wrapper and CLI for the Sentry API}
14-
spec.homepage = "https://github.com/thierryxing/sentry-api"
13+
spec.description = %q{A Ruby wrapper for the Sentry API}
14+
spec.homepage = "https://github.com/thierryxing/sentry-ruby-api"
1515

1616
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
1717
# to allow pushing to a single host or delete this section to allow pushing to any host.
1818
if spec.respond_to?(:metadata)
19-
spec.metadata['allowed_push_host'] = "TODO: Set to 'https://github.com/thierryxing/sentry-api.git'"
19+
spec.metadata['allowed_push_host'] = "TODO: Set to 'https://github.com/thierryxing/sentry-ruby-api.git'"
2020
else
2121
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
2222
end
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
3131
spec.add_development_dependency "rake", "~> 10.0"
3232
spec.add_development_dependency 'rspec'
3333
spec.add_development_dependency 'webmock'
34+
spec.add_development_dependency 'yard'
3435
end

0 commit comments

Comments
 (0)