bugsnag-api 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/.yardopts +4 -0
  6. data/CHANGELOG.md +11 -0
  7. data/README.md +12 -4
  8. data/Rakefile +9 -0
  9. data/bugsnag-api.gemspec +5 -0
  10. data/lib/bugsnag/api.rb +20 -4
  11. data/lib/bugsnag/api/client.rb +47 -42
  12. data/lib/bugsnag/api/client/accounts.rb +8 -1
  13. data/lib/bugsnag/api/client/comments.rb +1 -1
  14. data/lib/bugsnag/api/client/errors.rb +1 -1
  15. data/lib/bugsnag/api/client/events.rb +3 -3
  16. data/lib/bugsnag/api/client/projects.rb +15 -4
  17. data/lib/bugsnag/api/client/users.rb +22 -4
  18. data/lib/bugsnag/api/configuration.rb +9 -6
  19. data/lib/bugsnag/api/error.rb +11 -1
  20. data/lib/bugsnag/api/version.rb +1 -1
  21. data/spec/bugsnag/api/client/accounts_spec.rb +45 -0
  22. data/spec/bugsnag/api/client/comments_spec.rb +58 -0
  23. data/spec/bugsnag/api/client/errors_spec.rb +69 -0
  24. data/spec/bugsnag/api/client/events_spec.rb +52 -0
  25. data/spec/bugsnag/api/client/projects_spec.rb +87 -0
  26. data/spec/bugsnag/api/client/users_spec.rb +105 -0
  27. data/spec/bugsnag/api/client_spec.rb +130 -0
  28. data/spec/bugsnag/api_spec.rb +44 -0
  29. data/spec/cassettes/Bugsnag_Api_Client/_get/handles_query_params.yml +56 -0
  30. data/spec/cassettes/Bugsnag_Api_Client/_last_response/caches_the_last_agent_response.yml +56 -0
  31. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_account/returns_the_requested_account.yml +49 -0
  32. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_account/when_using_account_credentials/returns_the_account.yml +51 -0
  33. data/spec/cassettes/Bugsnag_Api_Client_Accounts/_accounts/returns_all_accounts.yml +49 -0
  34. data/spec/cassettes/Bugsnag_Api_Client_Comments/_comments/returns_all_comments_on_an_error.yml +107 -0
  35. data/spec/cassettes/Bugsnag_Api_Client_Comments/_create_comment/created_a_comment.yml +51 -0
  36. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_comment/returns_a_comment.yml +97 -0
  37. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_delete_comment/deletes_an_existing_comment.yml +92 -0
  38. data/spec/cassettes/Bugsnag_Api_Client_Comments/with_comment/_update_comment/updates_an_existing_comment.yml +97 -0
  39. data/spec/cassettes/Bugsnag_Api_Client_Errors/_errors/returns_all_errors_on_an_project.yml +48 -0
  40. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_error/returns_an_error.yml +48 -0
  41. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_reopen_error/reopens_the_error.yml +48 -0
  42. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_resolve_error/resolves_the_error.yml +48 -0
  43. data/spec/cassettes/Bugsnag_Api_Client_Errors/with_error/_update_error/updates_the_error.yml +48 -0
  44. data/spec/cassettes/Bugsnag_Api_Client_Events/_error_events/returns_all_events_on_an_error.yml +64 -0
  45. data/spec/cassettes/Bugsnag_Api_Client_Events/_project_events/returns_all_events_on_a_project.yml +64 -0
  46. data/spec/cassettes/Bugsnag_Api_Client_Events/with_event/_event/returns_an_event.yml +56 -0
  47. data/spec/cassettes/Bugsnag_Api_Client_Projects/_account_projects/returns_all_projects_on_an_account.yml +61 -0
  48. data/spec/cassettes/Bugsnag_Api_Client_Projects/_account_projects/when_using_account_credentials/returns_all_projects.yml +63 -0
  49. data/spec/cassettes/Bugsnag_Api_Client_Projects/_create_project/creates_a_project_on_an_account.yml +50 -0
  50. data/spec/cassettes/Bugsnag_Api_Client_Projects/_user_projects/returns_all_projects_for_a_user.yml +61 -0
  51. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_delete_project/deletes_an_existing_project.yml +91 -0
  52. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_project/returns_a_project.yml +95 -0
  53. data/spec/cassettes/Bugsnag_Api_Client_Projects/with_project/_update_project/updates_an_existing_project.yml +95 -0
  54. data/spec/cassettes/Bugsnag_Api_Client_Users/_account_users/returns_all_users_on_an_account.yml +49 -0
  55. data/spec/cassettes/Bugsnag_Api_Client_Users/_account_users/when_using_account_credentials/returns_all_users.yml +51 -0
  56. data/spec/cassettes/Bugsnag_Api_Client_Users/_invite_user/invites_a_user_to_an_account.yml +48 -0
  57. data/spec/cassettes/Bugsnag_Api_Client_Users/_project_users/returns_all_users_for_a_project.yml +49 -0
  58. data/spec/cassettes/Bugsnag_Api_Client_Users/_user/returns_a_user.yml +48 -0
  59. data/spec/cassettes/Bugsnag_Api_Client_Users/_user/when_using_user_credentials/returns_the_authed_user.yml +48 -0
  60. data/spec/cassettes/Bugsnag_Api_Client_Users/with_user/_remove_user/removes_a_user_from_an_account.yml +89 -0
  61. data/spec/cassettes/Bugsnag_Api_Client_Users/with_user/_update_user_permissions/updates_a_users_permissions.yml +93 -0
  62. data/spec/spec_helper.rb +122 -0
  63. metadata +161 -4
@@ -36,7 +36,7 @@ module Bugsnag
36
36
 
37
37
  def initialize(response=nil)
38
38
  @response = response
39
- super(response_error)
39
+ super(build_error_message)
40
40
  end
41
41
 
42
42
  private
@@ -60,6 +60,16 @@ module Bugsnag
60
60
  def response_error
61
61
  "Error: #{data[:error]}" if data.is_a?(Hash) && data[:error]
62
62
  end
63
+
64
+ def build_error_message
65
+ return nil if @response.nil?
66
+
67
+ message = "#{@response[:method].to_s.upcase} "
68
+ message << @response[:url].to_s + ": "
69
+ message << "#{@response[:status]} - "
70
+ message << "#{response_error}" unless response_error.nil?
71
+ message
72
+ end
63
73
  end
64
74
 
65
75
  # Raised on errors in the 400-499 range
@@ -1,5 +1,5 @@
1
1
  module Bugsnag
2
2
  module Api
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Accounts do
4
+ before do
5
+ Bugsnag::Api.reset!
6
+ @client = basic_auth_client
7
+ end
8
+
9
+ describe ".accounts", :vcr do
10
+ it "returns all accounts" do
11
+ accounts = @client.accounts
12
+ expect(accounts).to be_kind_of(Array)
13
+ expect(accounts.first.name).not_to be_nil
14
+
15
+ assert_requested :get, basic_bugsnag_url("/accounts")
16
+ end
17
+ end
18
+
19
+ describe ".account", :vcr do
20
+ context "when using account credentials" do
21
+ it "returns the account" do
22
+ client = auth_token_client
23
+ account = client.account
24
+ expect(account.name).not_to be_nil
25
+
26
+ assert_requested :get, bugsnag_url("/account")
27
+ end
28
+ end
29
+
30
+ context "when using user credentials" do
31
+ it "raises an error" do
32
+ expect { @client.account }.to raise_error Bugsnag::Api::AccountCredentialsRequired
33
+
34
+ assert_not_requested :get, basic_bugsnag_url("/account")
35
+ end
36
+ end
37
+
38
+ it "returns the requested account" do
39
+ account = @client.account(test_bugsnag_account)
40
+ expect(account.id).to eq(test_bugsnag_account)
41
+
42
+ assert_requested :get, basic_bugsnag_url("/accounts/#{test_bugsnag_account}")
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Comments do
4
+ before do
5
+ 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
+ end
18
+
19
+ 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")
23
+
24
+ assert_requested :post, basic_bugsnag_url("/errors/#{test_bugsnag_error}/comments")
25
+ end
26
+ end
27
+
28
+ context "with comment", :vcr do
29
+ before do
30
+ @comment = @client.create_comment(test_bugsnag_error, "Comment message")
31
+ end
32
+
33
+ describe ".comment" do
34
+ it "returns a comment" do
35
+ comment = @client.comment(@comment.id)
36
+ expect(comment.id).to eq(@comment.id)
37
+
38
+ assert_requested :get, basic_bugsnag_url("/comments/#{@comment.id}")
39
+ end
40
+ end
41
+
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}")
47
+ end
48
+ end
49
+
50
+ describe ".delete_comment" do
51
+ it "deletes an existing comment" do
52
+ response = @client.delete_comment(@comment.id)
53
+ expect(response).to be true
54
+ assert_requested :delete, basic_bugsnag_url("/comments/#{@comment.id}")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Errors do
4
+ before do
5
+ Bugsnag::Api.reset!
6
+ @client = basic_auth_client
7
+ end
8
+
9
+ 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
14
+
15
+ assert_requested :get, basic_bugsnag_url("/projects/#{test_bugsnag_project}/errors")
16
+ end
17
+ end
18
+
19
+ context "with error", :vcr do
20
+ let(:error_url) { basic_bugsnag_url("/errors/#{test_bugsnag_error}") }
21
+
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
29
+ end
30
+
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
35
+
36
+ assert_requested :patch, error_url
37
+ end
38
+ end
39
+
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
47
+ end
48
+
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
+
54
+ assert_requested :patch, error_url
55
+ end
56
+ end
57
+
58
+ describe ".delete_error", :vcr do
59
+ it "deletes the error" do
60
+ stub_request(:delete, error_url).to_return(:status => [204, "No Content"])
61
+
62
+ response = @client.delete_error(test_bugsnag_error)
63
+ expect(response).to be true
64
+
65
+ assert_requested :delete, error_url
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Events do
4
+ before do
5
+ Bugsnag::Api.reset!
6
+ @client = basic_auth_client
7
+ end
8
+
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
14
+
15
+ assert_requested :get, basic_bugsnag_url("/projects/#{test_bugsnag_project}/events")
16
+ end
17
+ end
18
+
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
24
+
25
+ assert_requested :get, basic_bugsnag_url("/errors/#{test_bugsnag_error}/events")
26
+ end
27
+ end
28
+
29
+ context "with event", :vcr do
30
+ let(:event_url) { basic_bugsnag_url("/events/#{test_bugsnag_event}") }
31
+
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
36
+
37
+ assert_requested :get, event_url
38
+ end
39
+ end
40
+
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
47
+
48
+ assert_requested :delete, event_url
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,87 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Projects do
4
+ before do
5
+ 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
+ end
47
+
48
+ 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")
52
+
53
+ assert_requested :post, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/projects")
54
+ end
55
+ end
56
+
57
+ context "with project", :vcr do
58
+ before do
59
+ @project = @client.create_project(test_bugsnag_account, :name => "Example")
60
+ end
61
+
62
+ describe ".project" do
63
+ it "returns a project" do
64
+ project = @client.project(@project.id)
65
+ expect(project.id).to eq(@project.id)
66
+
67
+ assert_requested :get, basic_bugsnag_url("/projects/#{@project.id}")
68
+ end
69
+ end
70
+
71
+ describe ".update_project" do
72
+ it "updates an existing project" do
73
+ updated_project = @client.update_project(@project.id, :name => "New project name")
74
+ expect(updated_project.id).to eq(@project.id)
75
+ assert_requested :patch, basic_bugsnag_url("/projects/#{@project.id}")
76
+ end
77
+ end
78
+
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}")
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,105 @@
1
+ require "spec_helper"
2
+
3
+ describe Bugsnag::Api::Client::Users do
4
+ before do
5
+ Bugsnag::Api.reset!
6
+ @client = basic_auth_client
7
+ end
8
+
9
+ describe ".account_users", :vcr do
10
+ context "when using account credentials" do
11
+ it "returns all users" do
12
+ users = auth_token_client.account_users
13
+ expect(users).to be_kind_of(Array)
14
+ expect(users.first.email).not_to be_nil
15
+
16
+ assert_requested :get, bugsnag_url("/account/users")
17
+ end
18
+ end
19
+
20
+ context "when using user credentials" do
21
+ it "raises an error" do
22
+ expect { @client.account_users }.to raise_error Bugsnag::Api::AccountCredentialsRequired
23
+
24
+ assert_not_requested :get, basic_bugsnag_url("/account/users")
25
+ end
26
+ end
27
+
28
+ it "returns all users on an account" do
29
+ users = @client.account_users(test_bugsnag_account)
30
+ expect(users).to be_kind_of(Array)
31
+ expect(users.first.email).not_to be_nil
32
+
33
+ assert_requested :get, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/users")
34
+ end
35
+ end
36
+
37
+ describe ".project_users", :vcr do
38
+ it "returns all users for a project" do
39
+ users = @client.project_users(test_bugsnag_project)
40
+ expect(users).to be_kind_of(Array)
41
+ expect(users.first.email).not_to be_nil
42
+
43
+ assert_requested :get, basic_bugsnag_url("/projects/#{test_bugsnag_project}/users")
44
+ end
45
+ end
46
+
47
+ describe ".invite_user", :vcr do
48
+ it "invites a user to an account", :beta do
49
+ user = @client.invite_user(test_bugsnag_account, "example@example.com")
50
+ expect(user.email).to eq("example@example.com")
51
+
52
+ assert_requested :post, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/users")
53
+ end
54
+ end
55
+
56
+ describe ".user", :vcr do
57
+ context "when using user credentials" do
58
+ it "returns the authed user" do
59
+ user = @client.user
60
+ expect(user.email).not_to be_nil
61
+
62
+ assert_requested :get, basic_bugsnag_url("/user")
63
+ end
64
+ end
65
+
66
+ context "when using account credentials" do
67
+ it "raises an error" do
68
+ expect { auth_token_client.user }.to raise_error Bugsnag::Api::UserCredentialsRequired
69
+
70
+ assert_not_requested :get, bugsnag_url("/user")
71
+ end
72
+ end
73
+ end
74
+
75
+ describe ".user", :vcr do
76
+ it "returns a user" do
77
+ user = @client.user(test_bugsnag_user)
78
+ expect(user.id).to eq(test_bugsnag_user)
79
+
80
+ assert_requested :get, basic_bugsnag_url("/users/#{test_bugsnag_user}")
81
+ end
82
+ end
83
+
84
+ context "with user", :vcr do
85
+ before do
86
+ @user = @client.invite_user(test_bugsnag_account, "example@example.com", :admin => false)
87
+ end
88
+
89
+ describe ".update_user_permissions" do
90
+ it "updates a users permissions" do
91
+ updated_user = @client.update_user_permissions(test_bugsnag_account, @user.id, :admin => true)
92
+ expect(updated_user.account_admin).to eq(true)
93
+ assert_requested :patch, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/users/#{@user.id}")
94
+ end
95
+ end
96
+
97
+ describe ".remove_user" do
98
+ it "removes a user from an account" do
99
+ response = @client.remove_user(test_bugsnag_account, @user.id)
100
+ expect(response).to be true
101
+ assert_requested :delete, basic_bugsnag_url("/accounts/#{test_bugsnag_account}/users/#{@user.id}")
102
+ end
103
+ end
104
+ end
105
+ end