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
@@ -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
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Pivots do
4
+ before do
5
+ skip "event_fields API has issues currently"
6
+ @client = auth_token_client
7
+ @project_id = test_bugsnag_project_id
8
+ @error_id = test_bugsnag_error_id
9
+ @event_field_id = test_bugsnag_eventfield_id
10
+ Bugsnag::Api.reset!
11
+ end
12
+
13
+ describe ".pivots", :vcr do
14
+ it "returns a list of pivots on an error" do
15
+ pivots = @client.pivots @project_id, @error_id
16
+ expect(pivots).to be_a_kind_of(Array)
17
+ expect(pivots.length).to be > 0
18
+
19
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/pivots")
20
+ end
21
+
22
+ it "returns a list of pivots on a project" do
23
+ pivots = @client.pivots @project_id
24
+ expect(pivots).to be_a_kind_of(Array)
25
+ expect(pivots.length).to be > 0
26
+
27
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/pivots")
28
+ end
29
+ end
30
+
31
+ describe ".pivot_values", :vcr do
32
+ it "returns values of pivots on an error" do
33
+ values = @client.pivot_values @project_id, @event_field_id, @error_id
34
+ expect(values).to be_a_kind_of(Array)
35
+ expect(values.length).to be > 0
36
+
37
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/pivots/#{@event_field_id}/values")
38
+ end
39
+
40
+ it "returns values of pivots on a project" do
41
+ values = @client.pivot_values @project_id, @event_field_id
42
+ expect(values).to be_a_kind_of(Array)
43
+ expect(values.length).to be > 0
44
+
45
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/pivots/#{@event_field_id}/values")
46
+ end
47
+ end
48
+ end
49
+
@@ -2,85 +2,61 @@ require "spec_helper"
2
2
 
3
3
  describe Bugsnag::Api::Client::Projects do
4
4
  before do
5
+ @client = auth_token_client
6
+ @org_id = test_bugsnag_org_id
5
7
  Bugsnag::Api.reset!
6
- @client = basic_auth_client
7
- end
8
-
9
- describe ".account_projects", :vcr do
10
- context "when using account credentials" do
11
- it "returns all projects" do
12
- client = auth_token_client
13
- projects = client.account_projects
14
- expect(projects).to be_kind_of(Array)
15
- expect(projects.first.name).not_to be_nil
16
-
17
- assert_requested :get, bugsnag_url("/account/projects")
18
- end
19
- end
20
-
21
- context "when using user credentials" do
22
- it "raises an error" do
23
- expect { @client.account_projects }.to raise_error Bugsnag::Api::AccountCredentialsRequired
24
-
25
- assert_not_requested :get, basic_bugsnag_url("/account/projects")
26
- end
27
- end
28
-
29
- it "returns all projects on an account" do
30
- projects = @client.account_projects(test_bugsnag_account)
31
- expect(projects).to be_kind_of(Array)
32
- expect(projects.first.name).not_to be_nil
33
-
34
- assert_requested :get, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/projects")
35
- end
36
- end
37
-
38
- describe ".user_projects", :vcr do
39
- it "returns all projects for a user" do
40
- projects = @client.user_projects(test_bugsnag_user)
41
- expect(projects).to be_kind_of(Array)
42
- expect(projects.first.name).not_to be_nil
43
-
44
- assert_requested :get, basic_bugsnag_url("/users/#{test_bugsnag_user}/projects")
45
- end
46
8
  end
47
9
 
48
10
  describe ".create_project", :vcr do
49
- it "creates a project on an account" do
50
- project = @client.create_project(test_bugsnag_account, :name => "Example")
51
- expect(project.name).to eq("Example")
11
+ it "creates a new project" do
12
+ new_project = @client.create_project @org_id, "testProject", "other"
13
+ expect(new_project.name).to eq("testProject")
52
14
 
53
- assert_requested :post, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/projects")
15
+ assert_requested :post, bugsnag_url("/organizations/#{@org_id}/projects")
54
16
  end
55
17
  end
56
18
 
57
- context "with project", :vcr do
19
+ context "given a project", :vcr do
58
20
  before do
59
- @project = @client.create_project(test_bugsnag_account, :name => "Example")
21
+ @project = @client.create_project @org_id, "testProject", "other"
60
22
  end
61
23
 
62
- describe ".project" do
63
- it "returns a project" do
64
- project = @client.project(@project.id)
24
+ describe ".project", :vcr do
25
+ it "returns the requested project" do
26
+ project = @client.project @project.id
65
27
  expect(project.id).to eq(@project.id)
28
+ expect(project.name).to eq("testProject")
29
+
30
+ assert_requested :get, bugsnag_url("/projects/#{@project.id}")
31
+ end
32
+ end
33
+
34
+ describe ".update_project", :vcr do
35
+ it "updates and returns the project" do
36
+ updated_project = @client.update_project @project.id, {:name => "otherName"}
37
+ expect(updated_project.id).to eq(@project.id)
38
+ expect(updated_project.name).to eq("otherName")
66
39
 
67
- assert_requested :get, basic_bugsnag_url("/projects/#{@project.id}")
40
+ assert_requested :patch, bugsnag_url("/projects/#{@project.id}")
68
41
  end
69
42
  end
70
43
 
71
- describe ".update_project" do
72
- it "updates an existing project" do
73
- updated_project = @client.update_project(@project.id, :name => "New project name")
44
+ describe ".regenerate_api_key", :vcr do
45
+ it "removes the current api key and replaces it with a new api key" do
46
+ updated_project = @client.regenerate_api_key @project.id
74
47
  expect(updated_project.id).to eq(@project.id)
75
- assert_requested :patch, basic_bugsnag_url("/projects/#{@project.id}")
48
+ expect(updated_project.api_key).not_to eq(@project.api_key)
49
+
50
+ assert_requested :delete, bugsnag_url("/projects/#{@project.id}/api_key")
76
51
  end
77
52
  end
53
+
54
+ describe ".delete_project", :vcr do
55
+ it "deletes the project" do
56
+ deleted_project = @client.delete_project @project.id
57
+ expect(deleted_project).to be true
78
58
 
79
- describe ".delete_project" do
80
- it "deletes an existing project" do
81
- response = @client.delete_project(@project.id)
82
- expect(response).to be true
83
- assert_requested :delete, basic_bugsnag_url("/projects/#{@project.id}")
59
+ assert_requested :delete, bugsnag_url("/projects/#{@project.id}")
84
60
  end
85
61
  end
86
62
  end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Trends do
4
+ before do
5
+ @project_id = test_bugsnag_project_id
6
+ @error_id = test_bugsnag_error_id
7
+ @client = auth_token_client
8
+ Bugsnag::Api.reset!
9
+ end
10
+
11
+ describe ".trends_buckets", :vcr do
12
+ it "returns a list of error trends in bucket form" do
13
+ trends = @client.trends_buckets @project_id, 5, @error_id
14
+ expect(trends).to be_a_kind_of(Array)
15
+ expect(trends.length).to eq(5)
16
+
17
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/trend?buckets_count=5")
18
+ end
19
+
20
+ it "returns a list of project trends in bucket form" do
21
+ trends = @client.trends_buckets @project_id, 5
22
+ expect(trends).to be_a_kind_of(Array)
23
+ expect(trends.length).to eq(5)
24
+
25
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/trend?buckets_count=5")
26
+ end
27
+ end
28
+
29
+ describe ".trends_resolution", :vcr do
30
+ it "returns a list of trends in resolution form" do
31
+ trends = @client.trends_resolution @project_id, "12h", @error_id
32
+
33
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/errors/#{@error_id}/trend?resolution=12h")
34
+ end
35
+
36
+ it "returns a list of project trends in resolution form" do
37
+ trends = @client.trends_resolution @project_id, "12h"
38
+ expect(trends).to be_a_kind_of(Array)
39
+ expect(trends.length).to be > 0
40
+
41
+ assert_requested :get, bugsnag_url("/projects/#{@project_id}/trend?resolution=12h")
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,4 @@
1
+ require "spec_helper"
1
2
  require "json"
2
3
 
3
4
  describe Bugsnag::Api::Client do
@@ -44,14 +45,14 @@ describe Bugsnag::Api::Client do
44
45
  end
45
46
 
46
47
  it "handles query params", :vcr do
47
- Bugsnag::Api.get "/", :foo => "bar"
48
- assert_requested :get, "https://api.bugsnag.com?foo=bar"
48
+ Bugsnag::Api.get bugsnag_url("/"), :foo => "bar"
49
+ assert_requested :get, bugsnag_url("?foo=bar")
49
50
  end
50
51
 
51
52
  it "handles headers" do
52
53
  request = stub_get("/zen").
53
54
  with(:query => {:foo => "bar"}, :headers => {:accept => "text/plain"})
54
- Bugsnag::Api.get "/zen", :foo => "bar", :accept => "text/plain"
55
+ Bugsnag::Api.get bugsnag_url("/zen"), :foo => "bar", :accept => "text/plain"
55
56
  assert_requested request
56
57
  end
57
58
  end
@@ -62,7 +63,7 @@ describe Bugsnag::Api::Client do
62
63
  client = Bugsnag::Api.client
63
64
  expect(client.last_response).to be_nil
64
65
 
65
- client.get "/"
66
+ client.get bugsnag_url("/")
66
67
  expect(client.last_response.status).to eq(200)
67
68
  end
68
69
  end
@@ -81,15 +82,81 @@ describe Bugsnag::Api::Client do
81
82
  end
82
83
  end
83
84
 
85
+ describe ".deep_merge" do
86
+ it "returns a merged hash" do
87
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
88
+ lhs = {
89
+ :foo => "foo"
90
+ }
91
+ rhs = {
92
+ :bar => "bar"
93
+ }
94
+ merged = client.deep_merge(lhs, rhs)
95
+ expect(merged).to_not eq(lhs)
96
+ expect(merged).to_not eq(rhs)
97
+ expect(merged).to eq({
98
+ :foo => "foo",
99
+ :bar => "bar"
100
+ })
101
+ end
102
+
103
+ it "favors rhs over lhs" do
104
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
105
+ lhs = {
106
+ :foo => "foo"
107
+ }
108
+ rhs = {
109
+ :foo => "bar"
110
+ }
111
+ merged = client.deep_merge(lhs, rhs)
112
+ expect(merged).to eq({:foo => "bar"})
113
+ end
114
+
115
+ it "recursively merges hashes" do
116
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
117
+ lhs = {
118
+ :foo => {
119
+ :bar => "bar"
120
+ }
121
+ }
122
+ rhs = {
123
+ :foo => {
124
+ :foobar => "foobar"
125
+ }
126
+ }
127
+ merged = client.deep_merge(lhs, rhs)
128
+ expect(merged).to eq(
129
+ {:foo => {
130
+ :bar => "bar",
131
+ :foobar => "foobar"
132
+ }
133
+ })
134
+ end
135
+ end
136
+
84
137
  context "error handling" do
138
+
139
+ before do
140
+ VCR.turn_off!
141
+ end
142
+
143
+ after do
144
+ VCR.turn_on!
145
+ end
146
+
85
147
  it "raises on 404" do
86
148
  stub_get('/booya').to_return(:status => 404)
87
- expect { Bugsnag::Api.get('/booya') }.to raise_error(Bugsnag::Api::NotFound)
149
+ expect { Bugsnag::Api.get(bugsnag_url('/booya')) }.to raise_error(Bugsnag::Api::NotFound)
150
+ end
151
+
152
+ it "raises on 429" do
153
+ stub_get('/test').to_return(:status => 429)
154
+ expect { Bugsnag::Api.get(bugsnag_url('/test')) }.to raise_error(Bugsnag::Api::RateLimitExceeded)
88
155
  end
89
156
 
90
157
  it "raises on 500" do
91
158
  stub_get('/boom').to_return(:status => 500)
92
- expect { Bugsnag::Api.get('/boom') }.to raise_error(Bugsnag::Api::InternalServerError)
159
+ expect { Bugsnag::Api.get(bugsnag_url('/boom')) }.to raise_error(Bugsnag::Api::InternalServerError)
93
160
  end
94
161
 
95
162
  it "includes an error" do
@@ -101,7 +168,7 @@ describe Bugsnag::Api::Client do
101
168
  },
102
169
  :body => {:error => "Comments must contain a message"}.to_json
103
170
  begin
104
- Bugsnag::Api.get('/boom')
171
+ Bugsnag::Api.get(bugsnag_url('/boom'))
105
172
  rescue Bugsnag::Api::UnprocessableEntity => e
106
173
  expect(e.message).to include("Error: Comments must contain a message")
107
174
  end
@@ -114,7 +181,7 @@ describe Bugsnag::Api::Client do
114
181
  :content_type => "application/json",
115
182
  },
116
183
  :body => {:message => "I'm a teapot"}.to_json
117
- expect { Bugsnag::Api.get('/user') }.to raise_error(Bugsnag::Api::ClientError)
184
+ expect { Bugsnag::Api.get(bugsnag_url('/user')) }.to raise_error(Bugsnag::Api::ClientError)
118
185
  end
119
186
 
120
187
  it "raises on unknown server errors" do
@@ -124,7 +191,7 @@ describe Bugsnag::Api::Client do
124
191
  :content_type => "application/json",
125
192
  },
126
193
  :body => {:message => "Bandwidth exceeded"}.to_json
127
- expect { Bugsnag::Api.get('/user') }.to raise_error(Bugsnag::Api::ServerError)
194
+ expect { Bugsnag::Api.get(bugsnag_url('/user')) }.to raise_error(Bugsnag::Api::ServerError)
128
195
  end
129
196
  end
130
197
  end
@@ -1,3 +1,5 @@
1
+ require "spec_helper"
2
+
1
3
  describe Bugsnag::Api do
2
4
  before do
3
5
  Bugsnag::Api.reset!
@@ -8,49 +8,59 @@ http_interactions:
8
8
  string: ''
9
9
  headers:
10
10
  User-Agent:
11
- - Bugsnag API Ruby Gem 1.0.0
11
+ - Bugsnag API Ruby Gem 2.0.1
12
12
  Content-Type:
13
13
  - application/json
14
+ X-Version:
15
+ - '2'
16
+ X-Bugsnag-Api:
17
+ - 'true'
14
18
  Accept-Encoding:
15
19
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
20
  Accept:
17
- - '*/*'
21
+ - "*/*"
18
22
  response:
19
23
  status:
20
24
  code: 200
21
25
  message: OK
22
26
  headers:
23
- Cache-Control:
24
- - max-age=0, private, must-revalidate
25
27
  Content-Type:
26
28
  - application/json; charset=utf-8
27
- Date:
28
- - Tue, 02 Sep 2014 02:49:29 GMT
29
- Server:
30
- - nginx + Phusion Passenger
31
- Status:
32
- - 200 OK
33
- Strict-Transport-Security:
34
- - max-age=31536000
29
+ Etag:
30
+ - W/"ee46b5c82cf98ff0d1c89f4cf77ab144"
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ X-Request-Id:
34
+ - 0044fd8d-8cb8-43c6-95ed-c291bd55fdb2
35
+ X-Runtime:
36
+ - '0.286559'
37
+ Vary:
38
+ - Origin
39
+ X-Rack-Cors:
40
+ - miss; no-origin
41
+ Content-Security-Policy:
42
+ - 'default-src ''self''; child-src https://*.stripe.com headway-widget.net;
43
+ connect-src ''self'' https://api.bugsnag.com https://notify.bugsnag.com https://*.stripe.com
44
+ https://bugsnag.zendesk.com https://api.lever.co; font-src ''self'' https://maxcdn.bootstrapcdn.com;
45
+ img-src ''self'' data: https://notify.bugsnag.com https://*.stripe.com https://maxcdn.bootstrapcdn.com;
46
+ script-src ''self'' https://d2wy8f7a9ursnm.cloudfront.net https://*.stripe.com
47
+ https://maxcdn.bootstrapcdn.com https://code.jquery.com https://assets.zendesk.com
48
+ https://cdn.headwayapp.co; style-src ''self'' ''unsafe-inline'' https://maxcdn.bootstrapcdn.com'
35
49
  X-Content-Type-Options:
36
50
  - nosniff
51
+ X-Download-Options:
52
+ - noopen
37
53
  X-Frame-Options:
38
- - SAMEORIGIN
39
- X-Powered-By:
40
- - Phusion Passenger
41
- X-Request-Id:
42
- - d5805f6d-7f5f-4513-af4d-3a4a259a1707
43
- X-Runtime:
44
- - '0.004698'
54
+ - DENY
55
+ X-Permitted-Cross-Domain-Policies:
56
+ - none
45
57
  X-Xss-Protection:
46
58
  - 1; mode=block
47
- Content-Length:
48
- - '96'
49
- Connection:
50
- - keep-alive
59
+ Transfer-Encoding:
60
+ - chunked
51
61
  body:
52
62
  encoding: UTF-8
53
- string: '{"projects_url":"https://api.bugsnag.com/account/projects","users_url":"https://api.bugsnag.com/account/users"}'
63
+ string: '{"organizations_url":"https://api.bugsnag.com/user/organizations"}'
54
64
  http_version:
55
- recorded_at: Tue, 02 Sep 2014 02:49:29 GMT
56
- recorded_with: VCR 2.9.2
65
+ recorded_at: Tue, 12 Dec 2017 12:00:16 GMT
66
+ recorded_with: VCR 2.9.3