bugsnag-api 1.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +5 -5
  2. data/.buildkite/pipeline.yml +6 -0
  3. data/.github/ISSUE_TEMPLATE/A.md +14 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +47 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +24 -0
  6. data/.github/PULL_REQUEST_TEMPLATE.md +16 -0
  7. data/.github/support.md +19 -0
  8. data/.github/workflows/tests.yml +53 -0
  9. data/.rubocop.yml +2 -0
  10. data/.rubocop_todo.yml +271 -0
  11. data/CHANGELOG.md +59 -0
  12. data/CONTRIBUTING.md +40 -0
  13. data/Gemfile +9 -0
  14. data/README.md +178 -109
  15. data/bugsnag-api.gemspec +42 -6
  16. data/config/.gitignore +1 -0
  17. data/docker-compose.yml +9 -0
  18. data/dockerfiles/Dockerfile.audit +5 -0
  19. data/lib/bugsnag/api/client.rb +32 -10
  20. data/lib/bugsnag/api/client/collaborators.rb +86 -0
  21. data/lib/bugsnag/api/client/comments.rb +31 -40
  22. data/lib/bugsnag/api/client/currentuser.rb +32 -0
  23. data/lib/bugsnag/api/client/errors.rb +48 -53
  24. data/lib/bugsnag/api/client/eventfields.rb +49 -0
  25. data/lib/bugsnag/api/client/events.rb +37 -32
  26. data/lib/bugsnag/api/client/organizations.rb +45 -0
  27. data/lib/bugsnag/api/client/pivots.rb +42 -0
  28. data/lib/bugsnag/api/client/projects.rb +36 -63
  29. data/lib/bugsnag/api/client/trends.rb +41 -0
  30. data/lib/bugsnag/api/configuration.rb +1 -1
  31. data/lib/bugsnag/api/error.rb +5 -1
  32. data/lib/bugsnag/api/response/raise_error.rb +0 -2
  33. data/lib/bugsnag/api/version.rb +1 -1
  34. data/scripts/license_finder.sh +4 -0
  35. data/spec/bugsnag/api/client/collaborators_spec.rb +101 -0
  36. data/spec/bugsnag/api/client/comments_spec.rb +42 -30
  37. data/spec/bugsnag/api/client/currentuser_spec.rb +57 -0
  38. data/spec/bugsnag/api/client/errors_spec.rb +44 -41
  39. data/spec/bugsnag/api/client/eventfields_spec.rb +56 -0
  40. data/spec/bugsnag/api/client/events_spec.rb +41 -29
  41. data/spec/bugsnag/api/client/organizations_spec.rb +53 -0
  42. data/spec/bugsnag/api/client/pivots_spec.rb +49 -0
  43. data/spec/bugsnag/api/client/projects_spec.rb +35 -59
  44. data/spec/bugsnag/api/client/trends_spec.rb +44 -0
  45. data/spec/bugsnag/api/client_spec.rb +76 -9
  46. data/spec/bugsnag/api_spec.rb +2 -0
  47. data/spec/cassettes/Bugsnag_Api_Client/_get/handles_query_params.yml +36 -26
  48. data/spec/cassettes/Bugsnag_Api_Client/_last_response/caches_the_last_agent_response.yml +36 -26
  49. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/_invitecollaborator/creates_and_returns_a_collaborator.yml +68 -0
  50. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/_invitecollaborator/invites_multiple_collaborators.yml +68 -0
  51. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborator/returns_a_collaborator.yml +133 -0
  52. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/returns_a_list_of_all_organization_collaborators.yml +135 -0
  53. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/returns_a_list_of_all_project_collaborators.yml +135 -0
  54. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/throws_an_argument_error_if_neither_org_id_or_project_id_are_provided.yml +68 -0
  55. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_delete_collaborator/deletes_a_collaborator.yml +68 -0
  56. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_update_collaborator_permissions/updates_and_returns_the_collaborator.yml +133 -0
  57. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_view_collaborator_projects/returns_a_list_of_projects_belonging_to_the_collaborator.yml +153 -0
  58. data/spec/cassettes/Bugsnag_Api_Client_Comments/_create_comment/creates_a_comment_on_the_error.yml +70 -0
  59. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_comment/retrieves_the_comment_specified.yml +135 -0
  60. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_comments/retrieves_all_comments_on_an_error.yml +137 -0
  61. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_delete_comment/deletes_the_comment_and_returns_true.yml +70 -0
  62. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_update_comment/updates_the_message_on_a_comment.yml +135 -0
  63. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_organizations/when_using_auth_token/returns_the_organization_the_auth_token_belongs_to.yml +68 -0
  64. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_organizations/when_using_user_credentials/returns_users_organizations.yml +71 -0
  65. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_projects/when_using_auth_token/lists_current_user_s_projects_in_the_organization.yml +88 -0
  66. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_projects/when_using_user_credentials/lists_current_user_s_projects_in_the_organization.yml +91 -0
  67. data/spec/cassettes/Bugsnag_Api_Client_Errors/_error/returns_a_single_error.yml +68 -0
  68. data/spec/cassettes/Bugsnag_Api_Client_Errors/_errors/returns_errors_on_the_project.yml +70 -0
  69. data/spec/cassettes/Bugsnag_Api_Client_Errors/_update_errors/updates_and_returns_the_updated_errors.yml +68 -0
  70. data/spec/cassettes/Bugsnag_Api_Client_Events/_error_events/lists_all_error_events.yml +73 -0
  71. data/spec/cassettes/Bugsnag_Api_Client_Events/_event/returns_the_specified_event.yml +70 -0
  72. data/spec/cassettes/Bugsnag_Api_Client_Events/_events/returns_the_a_list_of_project_errors.yml +73 -0
  73. data/spec/cassettes/Bugsnag_Api_Client_Events/_latest_event/returns_the_last_event_on_an_error.yml +70 -0
  74. data/spec/cassettes/Bugsnag_Api_Client_Organizations/_create_organization/creates_a_new_organization.yml +71 -0
  75. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_delete_organization/deletes_the_organization.yml +133 -0
  76. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_organization/returns_the_requested_organization.yml +139 -0
  77. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_update_organization/updates_and_returns_the_organization.yml +139 -0
  78. data/spec/cassettes/Bugsnag_Api_Client_Projects/_create_project/creates_a_new_project.yml +68 -0
  79. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_delete_project/deletes_the_project.yml +127 -0
  80. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_project/returns_the_requested_project.yml +133 -0
  81. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_regenerate_api_key/removes_the_current_api_key_and_replaces_it_with_a_new_api_key.yml +133 -0
  82. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_update_project/updates_and_returns_the_project.yml +133 -0
  83. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_buckets/returns_a_list_of_error_trends_in_bucket_form.yml +68 -0
  84. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_buckets/returns_a_list_of_project_trends_in_bucket_form.yml +68 -0
  85. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_resolution/returns_a_list_of_project_trends_in_resolution_form.yml +68 -0
  86. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_resolution/returns_a_list_of_trends_in_resolution_form.yml +68 -0
  87. data/spec/spec_helper.rb +32 -30
  88. metadata +167 -115
  89. data/.travis.yml +0 -9
  90. data/lib/bugsnag/api/client/accounts.rb +0 -44
  91. data/lib/bugsnag/api/client/users.rb +0 -99
  92. data/spec/bugsnag/api/client/accounts_spec.rb +0 -45
  93. data/spec/bugsnag/api/client/users_spec.rb +0 -105
  94. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_account/returns_the_requested_account.yml +0 -49
  95. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_account/when_using_account_credentials/returns_the_account.yml +0 -51
  96. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_accounts/returns_all_accounts.yml +0 -49
  97. data/spec/cassettes/Bugsnag_Api_Client_Comments/_comments/returns_all_comments_on_an_error.yml +0 -107
  98. data/spec/cassettes/Bugsnag_Api_Client_Comments/_create_comment/created_a_comment.yml +0 -51
  99. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_comment/returns_a_comment.yml +0 -97
  100. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_delete_comment/deletes_an_existing_comment.yml +0 -92
  101. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_update_comment/updates_an_existing_comment.yml +0 -97
  102. data/spec/cassettes/Bugsnag_Api_Client_Errors/_errors/returns_all_errors_on_an_project.yml +0 -48
  103. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_error/returns_an_error.yml +0 -48
  104. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_reopen_error/reopens_the_error.yml +0 -48
  105. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_resolve_error/resolves_the_error.yml +0 -48
  106. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_update_error/updates_the_error.yml +0 -48
  107. data/spec/cassettes/Bugsnag_Api_Client_Events/_error_events/returns_all_events_on_an_error.yml +0 -64
  108. data/spec/cassettes/Bugsnag_Api_Client_Events/_project_events/returns_all_events_on_a_project.yml +0 -64
  109. data/spec/cassettes/Bugsnag_Api_Client_Events/with_event/_event/returns_an_event.yml +0 -56
  110. data/spec/cassettes/Bugsnag_Api_Client_Projects/_account_projects/returns_all_projects_on_an_account.yml +0 -61
  111. data/spec/cassettes/Bugsnag_Api_Client_Projects/_account_projects/when_using_account_credentials/returns_all_projects.yml +0 -63
  112. data/spec/cassettes/Bugsnag_Api_Client_Projects/_create_project/creates_a_project_on_an_account.yml +0 -50
  113. data/spec/cassettes/Bugsnag_Api_Client_Projects/_user_projects/returns_all_projects_for_a_user.yml +0 -61
  114. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_delete_project/deletes_an_existing_project.yml +0 -91
  115. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_project/returns_a_project.yml +0 -95
  116. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_update_project/updates_an_existing_project.yml +0 -95
  117. data/spec/cassettes/Bugsnag_Api_Client_Users/_account_users/returns_all_users_on_an_account.yml +0 -49
  118. data/spec/cassettes/Bugsnag_Api_Client_Users/_account_users/when_using_account_credentials/returns_all_users.yml +0 -51
  119. data/spec/cassettes/Bugsnag_Api_Client_Users/_invite_user/invites_a_user_to_an_account.yml +0 -48
  120. data/spec/cassettes/Bugsnag_Api_Client_Users/_project_users/returns_all_users_for_a_project.yml +0 -49
  121. data/spec/cassettes/Bugsnag_Api_Client_Users/_user/returns_a_user.yml +0 -48
  122. data/spec/cassettes/Bugsnag_Api_Client_Users/_user/when_using_user_credentials/returns_the_authed_user.yml +0 -48
  123. data/spec/cassettes/Bugsnag_Api_Client_Users/with_user/_remove_user/removes_a_user_from_an_account.yml +0 -89
  124. data/spec/cassettes/Bugsnag_Api_Client_Users/with_user/_update_user_permissions/updates_a_users_permissions.yml +0 -93
data/bugsnag-api.gemspec CHANGED
@@ -18,13 +18,49 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "sawyer", '~> 0.5.3'
21
+ if RUBY_VERSION < "2.2.0"
22
+ spec.add_dependency "sawyer", '0.8.1'
23
+
24
+ spec.add_development_dependency "rake", "< 12.0.0"
25
+ spec.add_development_dependency "rubocop", "0.41.2"
26
+ spec.add_development_dependency "faker", "1.3.0"
27
+
28
+ # i18n is used by faker
29
+ spec.add_development_dependency "i18n", "< 1.0.0"
30
+
31
+ # crack is used by webmock
32
+ spec.add_development_dependency "crack", "< 0.4.5"
33
+ else
34
+ spec.add_dependency "sawyer", '~> 0.8.1'
35
+
36
+ spec.add_development_dependency "rake"
37
+ spec.add_development_dependency "rubocop", "~> 0.52.1"
38
+ spec.add_development_dependency "faker", "> 1.7.3"
39
+ end
40
+
41
+ if RUBY_VERSION < "2.0.0"
42
+ spec.add_development_dependency "json", "< 2.0.0"
43
+ spec.add_development_dependency "webmock", "2.3.2"
44
+ spec.add_development_dependency "addressable", "2.3.6"
45
+
46
+ # hashdiff is used by webmock
47
+ spec.add_development_dependency "hashdiff", "< 0.3.8"
48
+
49
+ # parser is used by rubocop
50
+ spec.add_development_dependency "parser", "< 2.5.0"
51
+ else
52
+ spec.add_development_dependency "json"
53
+ spec.add_development_dependency "webmock", "> 2.3.2"
54
+ spec.add_development_dependency "addressable", "> 2.3.6"
55
+ end
56
+
57
+ # public_suffix is used by addressable & sawyer
58
+ if RUBY_VERSION < "2.0.0"
59
+ spec.add_development_dependency "public_suffix", "< 1.5.0"
60
+ elsif RUBY_VERSION < "2.1.0"
61
+ spec.add_development_dependency "public_suffix", "< 3.0.0"
62
+ end
22
63
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
64
  spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "webmock"
27
- spec.add_development_dependency "faker"
28
65
  spec.add_development_dependency "vcr", "~> 2.9"
29
- spec.add_development_dependency "json"
30
66
  end
data/config/.gitignore ADDED
@@ -0,0 +1 @@
1
+ global.yml
@@ -0,0 +1,9 @@
1
+ version: '3.6'
2
+ services:
3
+
4
+ license_finder:
5
+ build:
6
+ dockerfile: dockerfiles/Dockerfile.audit
7
+ context: .
8
+ volumes:
9
+ - ./:/scan
@@ -0,0 +1,5 @@
1
+ FROM licensefinder/license_finder
2
+
3
+ WORKDIR /scan
4
+
5
+ CMD /scan/scripts/license_finder.sh
@@ -1,25 +1,33 @@
1
1
  require "sawyer"
2
2
 
3
- require "bugsnag/api/client/accounts"
4
- require "bugsnag/api/client/comments"
3
+ require "bugsnag/api/client/organizations"
4
+ require "bugsnag/api/client/collaborators"
5
+ require "bugsnag/api/client/projects"
6
+ require "bugsnag/api/client/eventfields"
7
+ require "bugsnag/api/client/currentuser"
5
8
  require "bugsnag/api/client/errors"
6
9
  require "bugsnag/api/client/events"
7
- require "bugsnag/api/client/projects"
8
- require "bugsnag/api/client/users"
10
+ require "bugsnag/api/client/pivots"
11
+ require "bugsnag/api/client/trends"
12
+ require "bugsnag/api/client/comments"
9
13
 
10
14
  module Bugsnag
11
15
  module Api
12
16
 
13
17
  # Client for the Bugsnag API
14
18
  #
15
- # @see https://bugsnag.com/docs/api
19
+ # @see http://docs.bugsnagapiv2.apiary.io/
16
20
  class Client
17
- include Bugsnag::Api::Client::Accounts
18
- include Bugsnag::Api::Client::Comments
21
+ include Bugsnag::Api::Client::Organizations
22
+ include Bugsnag::Api::Client::Collaborators
23
+ include Bugsnag::Api::Client::Projects
24
+ include Bugsnag::Api::Client::EventFields
25
+ include Bugsnag::Api::Client::CurrentUser
19
26
  include Bugsnag::Api::Client::Errors
20
27
  include Bugsnag::Api::Client::Events
21
- include Bugsnag::Api::Client::Projects
22
- include Bugsnag::Api::Client::Users
28
+ include Bugsnag::Api::Client::Pivots
29
+ include Bugsnag::Api::Client::Trends
30
+ include Bugsnag::Api::Client::Comments
23
31
 
24
32
  # Header keys that can be passed in options hash to {#get},{#head}
25
33
  CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
@@ -135,11 +143,25 @@ module Bugsnag
135
143
  !!configuration.auth_token
136
144
  end
137
145
 
146
+ # Merges hashes together cleanly, favouring RHS values
147
+ #
148
+ # @return [Hash]
149
+ def deep_merge(l_hash, r_hash)
150
+ l_hash.merge(r_hash) do |_key, l_val, r_val|
151
+ if l_val.is_a?(Hash) && r_val.is_a?(Hash)
152
+ deep_merge(l_val, r_val)
153
+ else
154
+ r_val
155
+ end
156
+ end
157
+ end
138
158
 
139
159
  private
140
160
  def agent
141
161
  @agent ||= Sawyer::Agent.new(configuration.endpoint, sawyer_options) do |http|
142
162
  http.headers[:content_type] = "application/json"
163
+ http.headers[:'X-Version'] = "2"
164
+ http.headers[:'X-Bugsnag-Api'] = "true"
143
165
  http.headers[:user_agent] = configuration.user_agent
144
166
 
145
167
  if basic_authenticated?
@@ -163,7 +185,7 @@ module Bugsnag
163
185
  end
164
186
  end
165
187
 
166
- @last_response = response = agent.call(method, URI.escape(path.to_s), data, options)
188
+ @last_response = response = agent.call(method, path.to_s, data, options)
167
189
  response.data
168
190
  end
169
191
 
@@ -0,0 +1,86 @@
1
+ module Bugsnag
2
+ module Api
3
+ class Client
4
+
5
+ # Methods for the Organizations Collaborators API
6
+ #
7
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators
8
+ module Collaborators
9
+ # View a Collaborator
10
+ #
11
+ # @return [Sawyer::Resource] Collaborator
12
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/view-a-collaborator
13
+ def collaborator(org_id, collaborator_id, options = {})
14
+ get "organizations/#{org_id}/collaborators/#{collaborator_id}", options
15
+ end
16
+
17
+ # List Collaborators
18
+ #
19
+ # @argument project_id [String] ID of project to get collaborators from (conflicts with org_id)
20
+ # @argument org_id [String] ID of organization to get collaborators from (conflicts with project_id)
21
+ #
22
+ # @option per_page [Number] Amount of results per-page
23
+ # @return [Array<Sawyer::Resource>] List of Collaborators
24
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/list-collaborators
25
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/list-collaborators-on-a-project
26
+ def collaborators(org_id = nil, project_id = nil, options = {})
27
+ if !org_id.nil?
28
+ paginate "organizations/#{org_id}/collaborators", options
29
+ elsif !project_id.nil?
30
+ paginate "projects/#{project_id}/collaborators", options
31
+ else
32
+ raise ArgumentError, "Must supply either an org_id or a project_id"
33
+ end
34
+ end
35
+
36
+ # Invite Collaborators
37
+ #
38
+ # @argument emails [(Array<String>/String)] A (list of emails/singular email) to invite
39
+ #
40
+ # @option project_ids [Array<String>] The ids in the organization the user(s) should have access to
41
+ # @option admin [Boolean] Whether to give admin permissions. Admins have access to all projects
42
+ # @return [Array<Sawyer::Resource>] Collaborator details
43
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/bulk-invite-collaborators
44
+ def invite_collaborators(org_id, emails, options = {})
45
+ case emails
46
+ when String
47
+ post "organizations/#{org_id}/collaborators", options.merge({:email => emails})
48
+ when Array
49
+ post "organizations/#{org_id}/collaborators/bulk_invite", options.merge({:emails => emails})
50
+ else
51
+ raise ArgumentError, "Emails must be a String or an Array"
52
+ end
53
+ end
54
+
55
+ # Update a Collaborator's permissions
56
+ #
57
+ # @option project_ids [Array<String>] Ids in the organziation the user should have access to
58
+ # @option admin [Boolean] Whether to give admin permissions. Admins have access to all projects
59
+ # @return [Sawyer::Resource] Collaborator details
60
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/update-a-collaborator's-permissions
61
+ def update_collaborator_permissions(org_id, id, options = {})
62
+ patch "organizations/#{org_id}/collaborators/#{id}", options
63
+ end
64
+
65
+ # Delete a Collaborator
66
+ #
67
+ # @return
68
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/delete-a-collaborator
69
+ def delete_collaborator(org_id, id, options = {})
70
+ boolean_from_response :delete, "organizations/#{org_id}/collaborators/#{id}", options
71
+ end
72
+
73
+ # View Projects a Collaborator has access to
74
+ #
75
+ # @option sort [String] Which field to sort the results by. Possible values: created_at
76
+ # @option direction [String] Which direction to sort the results by. Possible values: asc, desc
77
+ # @option per_page [Number] Number of results per page
78
+ # @return [Array<Sawyer::Resource>] A list of projects the collaborator belongs to
79
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/organizations/collaborators/view-projects-a-collaborator-has-access-to
80
+ def view_collaborator_projects(org_id, id, options = {})
81
+ paginate "organizations/#{org_id}/collaborators/#{id}/projects", options
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -2,61 +2,52 @@ module Bugsnag
2
2
  module Api
3
3
  class Client
4
4
 
5
- # Methods for the Comments API
5
+ # Methods for the Errors API
6
6
  #
7
- # @see https://bugsnag.com/docs/api/comments
7
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/comments
8
8
  module Comments
9
- # List an error's comments
9
+ # List Comments on an Error
10
10
  #
11
- # @param error [String] Bugsnag error for which to list comments
12
- # @return [Array<Sawyer::Resource>] List of comments
13
- # @see https://bugsnag.com/docs/api/comments#list-an-error-s-comments
14
- # @example
15
- # Bugsnag::Api.comments("515fb9337c1074f6fd000009")
16
- def comments(error, options = {})
17
- paginate "errors/#{error}/comments", options
11
+ # @option offset [Number] The pagination offset (not required for general use)
12
+ # @option sort [String] Comments are only sortable by creation time e.g. "created_at"
13
+ # @option direction [String] Which direction to sort the result by, one of: asc, desc
14
+ # @option per_page [Number] How many results to return per page
15
+ # @return [Array<Sawyer::Resource>] List of Error Comments
16
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/comments/list-comments-on-an-error
17
+ def comments(project_id, error_id, options = {})
18
+ paginate "projects/#{project_id}/errors/#{error_id}/comments", options
18
19
  end
19
20
 
20
- # Get a single comment
21
+ # View an Comment
21
22
  #
22
- # @param comment [String] A Bugsnag comment ID
23
- # @return [Sawyer::Resource] The comment you requested, if it exists
24
- # @see https://bugsnag.com/docs/api/comments#get-comment-details
25
- # @example
26
- # Bugsnag::Api.comment("50baed119bf39c1431000004")
27
- def comment(comment, options = {})
28
- get "comments/#{comment}", options
23
+ # @return [Sawyer::Resource] Requested Comment
24
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/comments/view-a-comment
25
+ def comment(id, options = {})
26
+ get "comments/#{id}", options
29
27
  end
30
28
 
31
- # Create a comment
29
+ # Create a Comment on an Error
32
30
  #
33
- # @param error [String] The Bugsnag error to create the comment on
34
- # @option message [String] The comment's message
35
- # @see https://bugsnag.com/docs/api/comments#create-a-comment
36
- # @example
37
- # Bugsnag::Api.create_comment("515fb9337c1074f6fd000009", message: "Oops!")
38
- def create_comment(error, message, options = {})
39
- post "errors/#{error}/comments", options.merge({:message => message})
31
+ # @return [Sawyer::Resource] The new Comment
32
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/comments/create-a-comment-on-an-error
33
+ def create_comment(project_id, error_id, message, options = {})
34
+ post "projects/#{project_id}/errors/#{error_id}/comments", options.merge({:message => message})
40
35
  end
41
36
 
42
- # Update a comment
37
+ # Update a Comment
43
38
  #
44
- # @param error [String] The Bugsnag comment to update
45
- # @return [Sawyer::Resource] The updated comment
46
- # @see https://bugsnag.com/docs/api/comments#update-a-comment
47
- # @example
48
- # Bugsnag::Api.update_comment("50baed119bf39c1431000004", message: "Fixed!")
49
- def update_comment(comment, message, options = {})
50
- patch "comments/#{comment}", options.merge({:message => message})
39
+ # @return [Sawyer::Resource] The updated Comment
40
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/comments/update-a-comment
41
+ def update_comment(id, message, options = {})
42
+ patch "comments/#{id}", options.merge({:message => message})
51
43
  end
52
44
 
53
- # Delete a comment
45
+ # Delete a Comment
54
46
  #
55
- # @param comment [String] The Bugsnag comment to delete
56
- # @return [Boolean] `true` if comment was deleted
57
- # @see https://bugsnag.com/docs/api/comments#delete-a-comment
58
- def delete_comment(comment, options = {})
59
- boolean_from_response :delete, "comments/#{comment}", options
47
+ # @return
48
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/comments/delete-a-comment
49
+ def delete_comment(id, options = {})
50
+ boolean_from_response :delete, "comments/#{id}", options
60
51
  end
61
52
  end
62
53
  end
@@ -0,0 +1,32 @@
1
+ module Bugsnag
2
+ module Api
3
+ class Client
4
+
5
+ # Methods for theCurrent User API
6
+ #
7
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/current-user
8
+ module CurrentUser
9
+ # List the Current User's Organizations
10
+ #
11
+ # @option admin [Boolean] If only Organizations the user is an admin of should be returned
12
+ # @option per_page [Number] Number of results to return per-page
13
+ # @return [Array<Sawyer::Resource>] List of Organizations
14
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/current-user/organizations/list-the-current-user's-organizations
15
+ def organizations(options = {})
16
+ paginate "user/organizations", options
17
+ end
18
+
19
+ # List the Current User's Projects
20
+ #
21
+ # @option sort [String] Which field to sort the results by, one of: created_at
22
+ # @option direction [String] Which direction to sort the results by, on of: asc, desc
23
+ # @option per_page [Number] Number of results to return per-page
24
+ # @return [Array<Sawyer::Resource>] List of Projects
25
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/current-user/organizations/list-the-current-user's-projects
26
+ def projects(org_id, options = {})
27
+ paginate "organizations/#{org_id}/projects", options
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,70 +4,65 @@ module Bugsnag
4
4
 
5
5
  # Methods for the Errors API
6
6
  #
7
- # @see https://bugsnag.com/docs/api/errors
7
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors
8
8
  module Errors
9
- # List a project's errors
9
+ # List the Errors on a Project
10
10
  #
11
- # @param project [String] Bugsnag project for which to list errors
12
- # @return [Array<Sawyer::Resource>] List of errors
13
- # @see https://bugsnag.com/docs/api/errors#list-a-project-s-errors
14
- # @example
15
- # Bugsnag::Api.errors("50baed119bf39c1431000004")
16
- def errors(project, options = {})
17
- paginate "projects/#{project}/errors", options
18
- end
19
-
20
- # Get a single error
11
+ # @argument id [String] optional ID of error to retrieve
21
12
  #
22
- # @param error [String] A Bugsnag error
23
- # @return [Sawyer::Resource] The error you requested, if it exists
24
- # @see https://bugsnag.com/docs/api/errors#get-error-details
25
- # @example
26
- # Bugsnag::Api.error("518031bcd775355c48a1cd4e")
27
- def error(error, options = {})
28
- get "errors/#{error}", options
13
+ # @option base [String] Only Error Events occuring before this time will be returned
14
+ # @option sort [String] Which field to sort by, one of: last_seen, first_seen, users, events, unsorted
15
+ # @option direction [String] Which direction to sort the result by, one of: asc, desc
16
+ # @option filters [Filters] An optional filters object, see http://docs.bugsnagapiv2.apiary.io/#introduction/filtering
17
+ # @return [Array<Sawyer::Resource>] List of Project Errors
18
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/errors/list-the-errors-on-a-project
19
+ def errors(project_id, id=nil, options = {})
20
+ if id.nil?
21
+ paginate "projects/#{project_id}/errors", options
22
+ else
23
+ get "projects/#{project_id}/errors/#{id}", options
24
+ end
29
25
  end
30
26
 
31
- # Resolve an error
32
- #
33
- # @param error [String] A Bugsnag error
34
- # @return [Sawyer::Resource] The updated error
35
- # @see https://bugsnag.com/docs/api/errors#update-an-error-s-status
36
- # @example
37
- # Bugsnag::Api.resolve_error("518031bcd775355c48a1cd4e")
38
- def resolve_error(error, options = {})
39
- patch "errors/#{error}", options.merge({:resolved => true})
40
- end
27
+ alias error errors
41
28
 
42
- # Re-open an error
29
+ # Update an Error
43
30
  #
44
- # @param error [String] A Bugsnag error
45
- # @return [Sawyer::Resource] The updated error
46
- # @see https://bugsnag.com/docs/api/errors#update-an-error-s-status
47
- # @example
48
- # Bugsnag::Api.reopen_error("518031bcd775355c48a1cd4e")
49
- def reopen_error(error, options = {})
50
- patch "errors/#{error}", options.merge({:resolved => false})
51
- end
52
-
53
- # Update an error
31
+ # @argument ids [(Array<String>/String)] An Id, or array of Ids to update
54
32
  #
55
- # @param error [String] A Bugsnag error
56
- # @return [Sawyer::Resource] The updated error
57
- # @see https://bugsnag.com/docs/api/errors#update-an-error-s-status
58
- # @example
59
- # Bugsnag::Api.update_error("518031bcd775355c48a1cd4e")
60
- def update_error(error, options = {})
61
- patch "errors/#{error}", options
33
+ # @option severity [String] The Error's new severity. One of: info, warning, error
34
+ # @option assigned_collaborator_id [String] THe collaborator to assign to the Error
35
+ # @option issue_url [String] Updates to link to an existing 3rd party issue
36
+ # @option issue_title [String] Updates the issues title
37
+ # @option reopen_rules [Object] Snooze rules for automatically reopening the Error
38
+ # @return [Sawyer::Resource] Updated Error
39
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/errors/update-an-error
40
+ def update_errors(project_id, ids, operation, options = {})
41
+ case ids
42
+ when String
43
+ patch "projects/#{project_id}/errors/#{ids}", options.merge({:operation => operation})
44
+ when Array
45
+ defaults = {:operation => operation, :query => {:error_ids => ids.join(' ')}}
46
+ merged_opts = deep_merge(defaults, options)
47
+ patch "projects/#{project_id}/errors", merged_opts
48
+ else
49
+ raise ArgumentError, "ids must be a String or an Array"
50
+ end
62
51
  end
63
52
 
64
- # Delete an error
53
+ # Delete an Error
54
+ #
55
+ # @argument error_id [String] ID of error to delete (conflicts with project_id)
56
+ # @argument project_id [String] Id of project to delete all errors from (conflicts with error_id)
65
57
  #
66
- # @param error [String] A Bugsnag error
67
- # @return [Boolean] `true` if error was deleted
68
- # @see https://bugsnag.com/docs/api/errors#delete-an-error
69
- def delete_error(error, options = {})
70
- boolean_from_response :delete, "errors/#{error}", options
58
+ # @return
59
+ # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/errors/delete-an-error
60
+ def delete_errors(project_id, error_id=nil, options = {})
61
+ if !error_id.nil?
62
+ boolean_from_response :delete, "projects/#{project_id}/errors/#{error_id}", options
63
+ else
64
+ boolean_from_response :delete, "projects/#{project_id}/errors", options
65
+ end
71
66
  end
72
67
  end
73
68
  end