bugsnag-api 1.0.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -3
  3. data/CHANGELOG.md +32 -0
  4. data/CONTRIBUTING.md +40 -0
  5. data/README.md +126 -111
  6. data/bugsnag-api.gemspec +4 -3
  7. data/lib/bugsnag/api/client.rb +18 -9
  8. data/lib/bugsnag/api/client/collaborators.rb +87 -0
  9. data/lib/bugsnag/api/client/comments.rb +31 -40
  10. data/lib/bugsnag/api/client/currentuser.rb +33 -0
  11. data/lib/bugsnag/api/client/errors.rb +45 -51
  12. data/lib/bugsnag/api/client/eventfields.rb +50 -0
  13. data/lib/bugsnag/api/client/events.rb +38 -32
  14. data/lib/bugsnag/api/client/organizations.rb +46 -0
  15. data/lib/bugsnag/api/client/pivots.rb +43 -0
  16. data/lib/bugsnag/api/client/projects.rb +37 -63
  17. data/lib/bugsnag/api/client/trends.rb +38 -0
  18. data/lib/bugsnag/api/error.rb +4 -0
  19. data/lib/bugsnag/api/version.rb +1 -1
  20. data/spec/bugsnag/api/client/collaborators_spec.rb +101 -0
  21. data/spec/bugsnag/api/client/comments_spec.rb +42 -30
  22. data/spec/bugsnag/api/client/currentuser_spec.rb +57 -0
  23. data/spec/bugsnag/api/client/errors_spec.rb +44 -41
  24. data/spec/bugsnag/api/client/eventfields_spec.rb +56 -0
  25. data/spec/bugsnag/api/client/events_spec.rb +41 -29
  26. data/spec/bugsnag/api/client/organizations_spec.rb +53 -0
  27. data/spec/bugsnag/api/client/pivots_spec.rb +49 -0
  28. data/spec/bugsnag/api/client/projects_spec.rb +35 -59
  29. data/spec/bugsnag/api/client/trends_spec.rb +44 -0
  30. data/spec/bugsnag/api/client_spec.rb +8 -3
  31. data/spec/cassettes/Bugsnag_Api_Client/_get/handles_query_params.yml +45 -27
  32. data/spec/cassettes/Bugsnag_Api_Client/_last_response/caches_the_last_agent_response.yml +45 -27
  33. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/_invitecollaborator/creates_and_returns_a_collaborator.yml +80 -0
  34. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/_invitecollaborator/invites_multiple_collaborators.yml +80 -0
  35. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborator/returns_a_collaborator.yml +157 -0
  36. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/returns_a_list_of_all_organization_collaborators.yml +160 -0
  37. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/returns_a_list_of_all_project_collaborators.yml +160 -0
  38. 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 +80 -0
  39. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_delete_collaborator/deletes_a_collaborator.yml +80 -0
  40. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_update_collaborator_permissions/updates_and_returns_the_collaborator.yml +157 -0
  41. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_view_collaborator_projects/returns_a_list_of_projects_belonging_to_the_collaborator.yml +159 -0
  42. data/spec/cassettes/Bugsnag_Api_Client_Comments/_create_comment/creates_a_comment_on_the_error.yml +82 -0
  43. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_comment/retrieves_the_comment_specified.yml +159 -0
  44. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_comments/retrieves_all_comments_on_an_error.yml +161 -0
  45. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_delete_comment/deletes_the_comment_and_returns_true.yml +82 -0
  46. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_update_comment/updates_the_message_on_a_comment.yml +159 -0
  47. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_organizations/when_using_auth_token/returns_the_organization_the_auth_token_belongs_to.yml +81 -0
  48. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_organizations/when_using_user_credentials/returns_users_organizations.yml +85 -0
  49. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_projects/when_using_auth_token/lists_current_user_s_projects_in_the_organization.yml +82 -0
  50. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_projects/when_using_user_credentials/lists_current_user_s_projects_in_the_organization.yml +86 -0
  51. data/spec/cassettes/Bugsnag_Api_Client_Errors/_error/returns_a_single_error.yml +82 -0
  52. data/spec/cassettes/Bugsnag_Api_Client_Errors/_errors/returns_errors_on_the_project.yml +84 -0
  53. data/spec/cassettes/Bugsnag_Api_Client_Errors/_update_errors/updates_and_returns_the_updated_errors.yml +80 -0
  54. data/spec/cassettes/Bugsnag_Api_Client_Events/_error_events/lists_all_error_events.yml +84 -0
  55. data/spec/cassettes/Bugsnag_Api_Client_Events/_event/returns_the_specified_event.yml +253 -0
  56. data/spec/cassettes/Bugsnag_Api_Client_Events/_events/returns_the_a_list_of_project_errors.yml +84 -0
  57. data/spec/cassettes/Bugsnag_Api_Client_Events/_latest_event/returns_the_last_event_on_an_error.yml +253 -0
  58. data/spec/cassettes/Bugsnag_Api_Client_Organizations/_create_organization/creates_a_new_organization.yml +84 -0
  59. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_delete_organization/deletes_the_organization.yml +159 -0
  60. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_organization/returns_the_requested_organization.yml +165 -0
  61. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_update_organization/updates_and_returns_the_organization.yml +165 -0
  62. data/spec/cassettes/Bugsnag_Api_Client_Projects/_create_project/creates_a_new_project.yml +80 -0
  63. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_delete_project/deletes_the_project.yml +151 -0
  64. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_project/returns_the_requested_project.yml +157 -0
  65. 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 +157 -0
  66. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_update_project/updates_and_returns_the_project.yml +157 -0
  67. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_buckets/returns_a_list_of_error_trends_in_bucket_form.yml +80 -0
  68. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_buckets/returns_a_list_of_project_trends_in_bucket_form.yml +80 -0
  69. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_resolution/returns_a_list_of_project_trends_in_resolution_form.yml +80 -0
  70. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_resolution/returns_a_list_of_trends_in_resolution_form.yml +80 -0
  71. data/spec/spec_helper.rb +29 -27
  72. metadata +124 -83
  73. data/lib/bugsnag/api/client/accounts.rb +0 -44
  74. data/lib/bugsnag/api/client/users.rb +0 -99
  75. data/spec/bugsnag/api/client/accounts_spec.rb +0 -45
  76. data/spec/bugsnag/api/client/users_spec.rb +0 -105
  77. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_account/returns_the_requested_account.yml +0 -49
  78. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_account/when_using_account_credentials/returns_the_account.yml +0 -51
  79. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_accounts/returns_all_accounts.yml +0 -49
  80. data/spec/cassettes/Bugsnag_Api_Client_Comments/_comments/returns_all_comments_on_an_error.yml +0 -107
  81. data/spec/cassettes/Bugsnag_Api_Client_Comments/_create_comment/created_a_comment.yml +0 -51
  82. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_comment/returns_a_comment.yml +0 -97
  83. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_delete_comment/deletes_an_existing_comment.yml +0 -92
  84. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_update_comment/updates_an_existing_comment.yml +0 -97
  85. data/spec/cassettes/Bugsnag_Api_Client_Errors/_errors/returns_all_errors_on_an_project.yml +0 -48
  86. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_error/returns_an_error.yml +0 -48
  87. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_reopen_error/reopens_the_error.yml +0 -48
  88. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_resolve_error/resolves_the_error.yml +0 -48
  89. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_update_error/updates_the_error.yml +0 -48
  90. data/spec/cassettes/Bugsnag_Api_Client_Events/_error_events/returns_all_events_on_an_error.yml +0 -64
  91. data/spec/cassettes/Bugsnag_Api_Client_Events/_project_events/returns_all_events_on_a_project.yml +0 -64
  92. data/spec/cassettes/Bugsnag_Api_Client_Events/with_event/_event/returns_an_event.yml +0 -56
  93. data/spec/cassettes/Bugsnag_Api_Client_Projects/_account_projects/returns_all_projects_on_an_account.yml +0 -61
  94. data/spec/cassettes/Bugsnag_Api_Client_Projects/_account_projects/when_using_account_credentials/returns_all_projects.yml +0 -63
  95. data/spec/cassettes/Bugsnag_Api_Client_Projects/_create_project/creates_a_project_on_an_account.yml +0 -50
  96. data/spec/cassettes/Bugsnag_Api_Client_Projects/_user_projects/returns_all_projects_for_a_user.yml +0 -61
  97. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_delete_project/deletes_an_existing_project.yml +0 -91
  98. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_project/returns_a_project.yml +0 -95
  99. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_update_project/updates_an_existing_project.yml +0 -95
  100. data/spec/cassettes/Bugsnag_Api_Client_Users/_account_users/returns_all_users_on_an_account.yml +0 -49
  101. data/spec/cassettes/Bugsnag_Api_Client_Users/_account_users/when_using_account_credentials/returns_all_users.yml +0 -51
  102. data/spec/cassettes/Bugsnag_Api_Client_Users/_invite_user/invites_a_user_to_an_account.yml +0 -48
  103. data/spec/cassettes/Bugsnag_Api_Client_Users/_project_users/returns_all_users_for_a_project.yml +0 -49
  104. data/spec/cassettes/Bugsnag_Api_Client_Users/_user/returns_a_user.yml +0 -48
  105. data/spec/cassettes/Bugsnag_Api_Client_Users/_user/when_using_user_credentials/returns_the_authed_user.yml +0 -48
  106. data/spec/cassettes/Bugsnag_Api_Client_Users/with_user/_remove_user/removes_a_user_from_an_account.yml +0 -89
  107. data/spec/cassettes/Bugsnag_Api_Client_Users/with_user/_update_user_permissions/updates_a_users_permissions.yml +0 -93
@@ -2,56 +2,68 @@ require "spec_helper"
2
2
 
3
3
  describe Bugsnag::Api::Client::Comments do
4
4
  before do
5
+ @client = auth_token_client
6
+ @project_id = test_bugsnag_project_id
7
+ @error_id = test_bugsnag_error_id
5
8
  Bugsnag::Api.reset!
6
- @client = basic_auth_client
7
- end
8
-
9
- describe ".comments", :vcr do
10
- it "returns all comments on an error" do
11
- comments = @client.comments(test_bugsnag_error)
12
- expect(comments).to be_kind_of(Array)
13
- expect(comments.first.message).not_to be_nil
14
-
15
- assert_requested :get, basic_bugsnag_url("/errors/#{test_bugsnag_error}/comments")
16
- end
17
9
  end
18
10
 
19
11
  describe ".create_comment", :vcr do
20
- it "created a comment" do
21
- comment = @client.create_comment(test_bugsnag_error, "Comment message")
22
- expect(comment.message).to eq("Comment message")
12
+ it "creates a comment on the error" do
13
+ comment = @client.create_comment @project_id, @error_id, "test_message"
14
+ expect(comment.message).to eq("test_message")
15
+ expect(comment.id).to_not be_nil
23
16
 
24
- assert_requested :post, basic_bugsnag_url("/errors/#{test_bugsnag_error}/comments")
17
+ assert_requested :post, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/comments")
25
18
  end
26
19
  end
27
20
 
28
- context "with comment", :vcr do
21
+ context "given a comment has been created" do
29
22
  before do
30
- @comment = @client.create_comment(test_bugsnag_error, "Comment message")
23
+ @comment = @client.create_comment @project_id, @error_id, "message"
31
24
  end
32
25
 
33
- describe ".comment" do
34
- it "returns a comment" do
35
- comment = @client.comment(@comment.id)
26
+ describe ".comments", :vcr do
27
+ it "retrieves all comments on an error" do
28
+ comments = @client.comments @project_id, @error_id
29
+
30
+ expect(comments).to be_kind_of(Array)
31
+ expect(comments.first.message).to_not be_nil
32
+
33
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/comments")
34
+ end
35
+ end
36
+
37
+ describe ".comment", :vcr do
38
+ it "retrieves the comment specified" do
39
+ comment = @client.comment @comment.id
40
+
41
+ expect(comment.message).to eq("message")
36
42
  expect(comment.id).to eq(@comment.id)
37
43
 
38
- assert_requested :get, basic_bugsnag_url("/comments/#{@comment.id}")
44
+ assert_requested :get, bugsnag_url("/comments/#{@comment.id}")
39
45
  end
40
46
  end
41
47
 
42
- describe ".update_comment" do
43
- it "updates an existing comment" do
44
- updated_comment = @client.update_comment(@comment.id, "Example new message")
45
- expect(updated_comment.id).to eq(@comment.id)
46
- assert_requested :patch, basic_bugsnag_url("/comments/#{@comment.id}")
48
+ describe ".update_comment", :vcr do
49
+ it "updates the message on a comment" do
50
+ comment = @client.update_comment @comment.id, "updated"
51
+
52
+ expect(comment.message).to eq("updated")
53
+ expect(comment.id).to eq(@comment.id)
54
+
55
+ assert_requested :patch, bugsnag_url("/comments/#{@comment.id}")
47
56
  end
48
57
  end
49
58
 
50
- describe ".delete_comment" do
51
- it "deletes an existing comment" do
52
- response = @client.delete_comment(@comment.id)
59
+ describe ".delete_comment", :vcr do
60
+ it "deletes the comment and returns true" do
61
+ stub_request(:delete, bugsnag_url("/comments/#{@comment.id}")).to_return(:status => [204, "No Content"])
62
+
63
+ response = @client.delete_comment @comment.id
53
64
  expect(response).to be true
54
- assert_requested :delete, basic_bugsnag_url("/comments/#{@comment.id}")
65
+
66
+ assert_requested :delete, bugsnag_url("/comments/#{@comment.id}")
55
67
  end
56
68
  end
57
69
  end
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::CurrentUser do
4
+ before do
5
+ Bugsnag::Api.reset!
6
+ end
7
+
8
+ describe ".list_organizations", :vcr do
9
+ context "when using user credentials" do
10
+ it "returns users organizations" do
11
+ client = basic_auth_client
12
+ organizations = client.organizations
13
+ expect(organizations).to be_kind_of(Array)
14
+ expect(organizations.first.name).not_to be_nil
15
+
16
+ assert_requested :get, bugsnag_url("/user/organizations")
17
+ end
18
+ end
19
+ context "when using auth token" do
20
+ it "returns the organization the auth token belongs to" do
21
+ client = auth_token_client
22
+ organizations = client.organizations
23
+ expect(organizations).to be_kind_of(Array)
24
+ expect(organizations.length).to eq(1)
25
+ expect(organizations.first.name).not_to be_nil
26
+
27
+ assert_requested :get, bugsnag_url("/user/organizations")
28
+ end
29
+ end
30
+ end
31
+
32
+ describe ".list_projects", :vcr do
33
+ context "when using auth token" do
34
+ it "lists current user's projects in the organization" do
35
+ client = auth_token_client
36
+ org_id = test_bugsnag_org_id
37
+ projects = client.projects org_id
38
+ expect(projects).to be_kind_of(Array)
39
+ expect(projects.first.name).not_to be_nil
40
+
41
+ assert_requested :get, bugsnag_url("/organizations/#{org_id}/projects")
42
+ end
43
+ end
44
+
45
+ context "when using user credentials" do
46
+ it "lists current user's projects in the organization" do
47
+ client = basic_auth_client
48
+ org_id = test_bugsnag_org_id
49
+ projects = client.projects org_id
50
+ expect(projects).to be_kind_of(Array)
51
+ expect(projects.first.name).not_to be_nil
52
+
53
+ assert_requested :get, bugsnag_url("/organizations/#{org_id}/projects")
54
+ end
55
+ end
56
+ end
57
+ end
@@ -2,68 +2,71 @@ require "spec_helper"
2
2
 
3
3
  describe Bugsnag::Api::Client::Errors do
4
4
  before do
5
+ @client = auth_token_client
6
+ @project_id = test_bugsnag_project_id
7
+ @error_id = test_bugsnag_error_id
5
8
  Bugsnag::Api.reset!
6
- @client = basic_auth_client
7
9
  end
8
10
 
9
11
  describe ".errors", :vcr do
10
- it "returns all errors on an project" do
11
- errors = @client.errors(test_bugsnag_project)
12
- expect(errors).to be_kind_of(Array)
13
- expect(errors.first.class).not_to be_nil
12
+ it "returns errors on the project" do
13
+ errors = @client.errors @project_id
14
+ expect(errors).to be_a_kind_of(Array)
15
+ expect(errors.first.id).to_not be_nil
16
+ expect(errors.first.context).to_not be_nil
14
17
 
15
- assert_requested :get, basic_bugsnag_url("/projects/#{test_bugsnag_project}/errors")
18
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors")
16
19
  end
17
20
  end
18
21
 
19
- context "with error", :vcr do
20
- let(:error_url) { basic_bugsnag_url("/errors/#{test_bugsnag_error}") }
22
+ describe ".error", :vcr do
23
+ it "returns a single error" do
24
+ error = @client.error @project_id, @error_id
25
+ expect(error.id).to_not be_nil
26
+ expect(error.context).to_not be_nil
21
27
 
22
- describe ".error" do
23
- it "returns an error" do
24
- error = @client.error(test_bugsnag_error)
25
- expect(error.class).not_to be_nil
26
-
27
- assert_requested :get, error_url
28
- end
28
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}")
29
29
  end
30
+ end
30
31
 
31
- describe ".resolve_error", :vcr do
32
- it "resolves the error" do
33
- error = @client.resolve_error(test_bugsnag_error)
34
- expect(error.resolved).to be true
32
+ describe ".update_errors", :vcr do
33
+ it "updates and returns the updated error" do
34
+ skip "overridden_severity not being updated through API"
35
+ error = @client.update_errors @project_id, @error_id, "open", {:severity => "info"}
36
+ expect(error.id).to_not be_nil
37
+ expect(error.context).to_not be_nil
38
+ expect(error.severity).to eq("info")
39
+ expect(error.status).to eq("open")
35
40
 
36
- assert_requested :patch, error_url
37
- end
41
+ assert_requested :patch, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}")
38
42
  end
43
+
44
+ it "updates and returns the updated errors" do
45
+ errors = @client.update_errors @project_id, [@error_id], "fix", {:severity => "warn"}
46
+ expect(errors.operation).to_not be_nil
47
+ expect(errors[@error_id].status).to eq("fixed")
39
48
 
40
- describe ".reopen_error", :vcr do
41
- it "reopens the error" do
42
- error = @client.reopen_error(test_bugsnag_error)
43
- expect(error.resolved).to be false
44
-
45
- assert_requested :patch, error_url
46
- end
49
+ assert_requested :patch, bugsnag_url("/projects/#{@project_id}/errors?error_ids=#{@error_id}")
47
50
  end
51
+ end
48
52
 
49
- describe ".update_error", :vcr do
50
- it "updates the error" do
51
- error = @client.update_error(test_bugsnag_error, :resolved => true)
52
- expect(error.resolved).to be true
53
+ describe ".delete_errors" do
54
+ it "deletes the error and returns true" do
55
+ stub_request(:delete, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}")).to_return(:status => [204, "No Content"])
56
+
57
+ response = @client.delete_errors @project_id, @error_id
58
+ expect(response).to be true
53
59
 
54
- assert_requested :patch, error_url
55
- end
60
+ assert_requested :delete, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}")
56
61
  end
57
62
 
58
- describe ".delete_error", :vcr do
59
- it "deletes the error" do
60
- stub_request(:delete, error_url).to_return(:status => [204, "No Content"])
63
+ it "deletes all errors and returns true" do
64
+ stub_request(:delete, bugsnag_url("/projects/#{@project_id}/errors")).to_return(:status => [204, "No Content"])
61
65
 
62
- response = @client.delete_error(test_bugsnag_error)
63
- expect(response).to be true
66
+ response = @client.delete_errors @project_id
67
+ expect(response).to be true
64
68
 
65
- assert_requested :delete, error_url
66
- end
69
+ assert_requested :delete, bugsnag_url("/projects/#{@project_id}/errors")
67
70
  end
68
71
  end
69
72
  end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::EventFields do
4
+
5
+ before do
6
+ skip "event_fields API has issues currently"
7
+ @client = auth_token_client
8
+ @project_id = test_bugsnag_project_id
9
+ Bugsnag::Api.reset!
10
+ end
11
+
12
+ describe ".create_event_field" do
13
+ it "create a new eventfield for the project" do
14
+ newEventfield = @client.create_event_field @project_id, "event_field_test_id", "metadata/user", {:name => "test"}
15
+ expect(newEventfield.display_id).to eq("event_field_test_id")
16
+
17
+ assert_requested :post, bugsnag_url("/projects/#{@project_id}/event_fields")
18
+ end
19
+ end
20
+
21
+ context "given an event field exists", :vcr do
22
+ before do
23
+ @eventfield = @client.create_event_field @project_id, "event_field_test", "metadata/pivot", {:name => "test"}
24
+ end
25
+
26
+ describe ".event_fields", :vcr do
27
+ it "lists project eventfields" do
28
+ eventfields = @client.event_fields @project_id
29
+ expect(eventfields).to be_kind_of(Array)
30
+ expect(eventfields.first.display_id).to_not be_nil
31
+ expect(eventfields.first.custom).to_not be_nil
32
+
33
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/event_fields")
34
+ end
35
+ end
36
+
37
+ describe ".update_event_field", :vcr do
38
+ it "updates and returns the event field" do
39
+ updatedEventfield = @client.update_event_field @project_id, @eventfield.display_id, "metadata/test", {:pivot_options => {:name => "pivot_test"}}
40
+ expect(updatedEventfield.display_id).to eq(@eventfield.display_id)
41
+ expect(updatedEventfield.pivot_options.name).to eq("pivot_test")
42
+
43
+ assert_requested :patch, bugsnag_url("/projects/#{@project_id}/event_fields/#{@eventfield.display_id}")
44
+ end
45
+ end
46
+
47
+ describe ".delete_event_field", :vcr do
48
+ it "deletes the event field" do
49
+ deletedEventfield = @client.delete_event_field @project_id, @eventfield.display_id
50
+ expect(deletedEventfield).to be true
51
+
52
+ assert_requested :delete, bugsnag_url("/projects/#{@project_id}/event_fields/#{@eventfield.display_id}")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -2,51 +2,63 @@ require "spec_helper"
2
2
 
3
3
  describe Bugsnag::Api::Client::Events do
4
4
  before do
5
+ @client = auth_token_client
6
+ @project_id = test_bugsnag_project_id
7
+ @error_id = test_bugsnag_error_id
8
+ @event_id = test_bugsnag_event_id
5
9
  Bugsnag::Api.reset!
6
- @client = basic_auth_client
7
10
  end
8
11
 
9
- describe ".project_events", :vcr do
10
- it "returns all events on a project" do
11
- events = @client.project_events(test_bugsnag_project)
12
- expect(events).to be_kind_of(Array)
13
- expect(events.first.context).not_to be_nil
12
+ describe ".event", :vcr do
13
+ it "returns the specified event" do
14
+ event = @client.event @project_id, @event_id
15
+ expect(event.id).to_not be_nil
16
+ expect(event.context).to_not be_nil
14
17
 
15
- assert_requested :get, basic_bugsnag_url("/projects/#{test_bugsnag_project}/events")
18
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/events/#{@event_id}")
16
19
  end
17
20
  end
18
21
 
19
- describe ".error_events", :vcr do
20
- it "returns all events on an error" do
21
- events = @client.error_events(test_bugsnag_error)
22
- expect(events).to be_kind_of(Array)
23
- expect(events.first.context).not_to be_nil
22
+ describe ".delete_event", :vcr do
23
+ it "deletes the specified event" do
24
+ stub_request(:delete, bugsnag_url("/projects/#{@project_id}/events/#{@event_id}")).to_return(:status => [204, "No Content"])
25
+
26
+ response = @client.delete_event @project_id, @event_id
27
+ expect(response).to be true
24
28
 
25
- assert_requested :get, basic_bugsnag_url("/errors/#{test_bugsnag_error}/events")
29
+ assert_requested :delete, bugsnag_url("/projects/#{@project_id}/events/#{@event_id}")
26
30
  end
27
31
  end
28
32
 
29
- context "with event", :vcr do
30
- let(:event_url) { basic_bugsnag_url("/events/#{test_bugsnag_event}") }
33
+ describe ".error_events", :vcr do
34
+ it "lists all error events" do
35
+ events = @client.error_events @project_id, @error_id
36
+ expect(events).to be_a_kind_of(Array)
37
+ expect(events.first.id).to_not be_nil
38
+ expect(events.first.context).to_not be_nil
39
+
40
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/events")
41
+ end
42
+ end
31
43
 
32
- describe ".event" do
33
- it "returns an event" do
34
- event = @client.event(test_bugsnag_event)
35
- expect(event.context).not_to be_nil
44
+ describe ".latest_event", :vcr do
45
+ it "returns the last event on an error" do
46
+ event = @client.latest_event @error_id
47
+ expect(event.id).to_not be_nil
48
+ expect(event.context).to_not be_nil
36
49
 
37
- assert_requested :get, event_url
38
- end
50
+ assert_requested :get, bugsnag_url("/errors/#{@error_id}/latest_event")
39
51
  end
52
+ end
40
53
 
41
- describe ".delete_event", :vcr do
42
- it "deletes the event" do
43
- stub_request(:delete, event_url).to_return(:status => [204, "No Content"])
44
-
45
- response = @client.delete_event(test_bugsnag_event)
46
- expect(response).to be true
54
+ describe ".events", :vcr do
55
+ it "returns the a list of project errors" do
56
+ events = @client.events @project_id
57
+ expect(events).to be_a_kind_of(Array)
58
+ expect(events.first.id).to_not be_nil
59
+ expect(events.first.context).to_not be_nil
47
60
 
48
- assert_requested :delete, event_url
49
- end
61
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/events")
50
62
  end
51
63
  end
52
64
  end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Organizations do
4
+ before do
5
+ @client = basic_auth_client
6
+ Bugsnag::Api.reset!
7
+ end
8
+
9
+ describe ".create_organization", :vcr do
10
+ it "creates a new organization" do
11
+ organization = @client.create_organization "testOrg"
12
+ expect(organization).to be_kind_of(Object)
13
+ expect(organization.name).to eq("testOrg")
14
+
15
+ assert_requested :post, bugsnag_url("/organizations")
16
+ end
17
+ end
18
+
19
+ context "with organization", :vcr do
20
+ before do
21
+ @organization = @client.create_organization "testOrg"
22
+ end
23
+
24
+ describe ".organization", :vcr do
25
+ it "returns the requested organization" do
26
+ organization = @client.organization @organization.id
27
+ expect(organization.id).to eq(@organization.id)
28
+
29
+ assert_requested :get, bugsnag_url("/organizations/#{@organization.id}")
30
+ end
31
+ end
32
+
33
+ describe ".update_organization", :vcr do
34
+ it "updates and returns the organization" do
35
+ updatedOrg = @client.update_organization @organization.id, "updated_name", false, {:invoice_address => "test_string"}
36
+ expect(updatedOrg.id).to eq(@organization.id)
37
+ expect(updatedOrg.name).to eq("updated_name")
38
+ expect(updatedOrg.auto_upgrade).to be false
39
+
40
+ assert_requested :patch, bugsnag_url("/organizations/#{@organization.id}")
41
+ end
42
+ end
43
+
44
+ describe ".delete_organization", :vcr do
45
+ it "deletes the organization" do
46
+ deletedOrg = @client.delete_organization @organization.id
47
+ expect(deletedOrg).to be true
48
+
49
+ assert_requested :delete, bugsnag_url("/organizations/#{@organization.id}")
50
+ end
51
+ end
52
+ end
53
+ end