honeybadger-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +189 -0
  5. data/Rakefile +1 -0
  6. data/honeybadger-api.gemspec +26 -0
  7. data/lib/honeybadger-api.rb +41 -0
  8. data/lib/honeybadger-api/client.rb +48 -0
  9. data/lib/honeybadger-api/comment.rb +47 -0
  10. data/lib/honeybadger-api/configuration.rb +12 -0
  11. data/lib/honeybadger-api/deploy.rb +46 -0
  12. data/lib/honeybadger-api/environment.rb +27 -0
  13. data/lib/honeybadger-api/fault.rb +63 -0
  14. data/lib/honeybadger-api/notice.rb +45 -0
  15. data/lib/honeybadger-api/paginator.rb +72 -0
  16. data/lib/honeybadger-api/project.rb +71 -0
  17. data/lib/honeybadger-api/request.rb +44 -0
  18. data/lib/honeybadger-api/team.rb +42 -0
  19. data/lib/honeybadger-api/team_invitation.rb +61 -0
  20. data/lib/honeybadger-api/team_member.rb +58 -0
  21. data/lib/honeybadger-api/user.rb +19 -0
  22. data/lib/honeybadger-api/version.rb +5 -0
  23. data/spec/comment_spec.rb +89 -0
  24. data/spec/deploy_spec.rb +82 -0
  25. data/spec/environment_spec.rb +31 -0
  26. data/spec/factories/comment_factory.rb +16 -0
  27. data/spec/factories/deploy_factory.rb +15 -0
  28. data/spec/factories/environment_factory.rb +14 -0
  29. data/spec/factories/fault_factory.rb +29 -0
  30. data/spec/factories/notice_factory.rb +14 -0
  31. data/spec/factories/project_factory.rb +44 -0
  32. data/spec/factories/team_factory.rb +16 -0
  33. data/spec/factories/team_invitation_factory.rb +27 -0
  34. data/spec/factories/team_member_factory.rb +17 -0
  35. data/spec/factories/user_factory.rb +10 -0
  36. data/spec/fault_spec.rb +132 -0
  37. data/spec/notice_spec.rb +81 -0
  38. data/spec/paginator_spec.rb +106 -0
  39. data/spec/project_spec.rb +151 -0
  40. data/spec/spec_helper.rb +13 -0
  41. data/spec/team_invitation_spec.rb +98 -0
  42. data/spec/team_member_spec.rb +112 -0
  43. data/spec/team_spec.rb +68 -0
  44. data/spec/user_spec.rb +17 -0
  45. data/spec/version_spec.rb +7 -0
  46. metadata +195 -0
@@ -0,0 +1,27 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Environment
4
+
5
+ attr_reader :id, :name, :project_id, :updated_at, :created_at
6
+
7
+ # Public: Build a new instance of Environment
8
+ #
9
+ # opts - A Hash of attributes to initialize a Environment
10
+ #
11
+ # Returns a new Environment
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @name = opts[:name]
15
+ @notifications = opts[:notifications]
16
+ @project_id = opts[:project_id]
17
+ @updated_at = opts[:updated_at].nil? ? nil : DateTime.parse(opts[:updated_at])
18
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
19
+ end
20
+
21
+ # Public: Whether notification are raised.
22
+ def notifications?
23
+ @notifications
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Fault
4
+
5
+ attr_reader :id, :project_id, :klass, :action, :component, :message,
6
+ :environment, :notices_count, :comments_count, :last_notice_at, :created_at
7
+
8
+ # Public: Build a new instance of Fault
9
+ #
10
+ # opts - A Hash of attributes to initialize a Fault
11
+ #
12
+ # Returns a new Fault
13
+ def initialize(opts)
14
+ @id = opts[:id]
15
+ @project_id = opts[:project_id]
16
+ @klass = opts[:klass]
17
+ @action = opts[:action]
18
+ @component = opts[:component]
19
+ @message = opts[:message]
20
+ @environment = opts[:environment]
21
+ @ignored = opts[:ignored]
22
+ @resolved = opts[:resolved]
23
+ @notices_count = opts[:notices_count]
24
+ @comments_count = opts[:comments_count]
25
+ @last_notice_at = opts[:last_notice_at].nil? ? nil : DateTime.parse(opts[:last_notice_at])
26
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
27
+ end
28
+
29
+ # Public: Whether tha fault has been marked as ignored.
30
+ def ignored?
31
+ @ignored == true
32
+ end
33
+
34
+ # Public: Whether tha fault has been marked as resolved.
35
+ def resolved?
36
+ @resolved == true
37
+ end
38
+
39
+ # Public: Find all faults for a given project.
40
+ def self.all(project_id)
41
+ path = "projects/#{project_id}/faults"
42
+ Honeybadger::Api::Request.all(path, handler)
43
+ end
44
+
45
+ # Public: Paginate all faults for a given project.
46
+ def self.paginate(project_id, filters = {})
47
+ path = "projects/#{project_id}/faults"
48
+ Honeybadger::Api::Request.paginate(path, handler, filters)
49
+ end
50
+
51
+ # Public: Find a fault for a given project.
52
+ def self.find(project_id, fault_id)
53
+ path = "projects/#{project_id}/faults/#{fault_id}"
54
+ Honeybadger::Api::Request.find(path, handler)
55
+ end
56
+
57
+ # Internal: The handler used to build objects from API responses.
58
+ def self.handler
59
+ Proc.new { |response| Fault.new(response) }
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,45 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Notice
4
+
5
+ attr_reader :id, :fault_id, :environment, :message, :request, :created_at
6
+
7
+ # Public: Build a new instance of Notice
8
+ #
9
+ # opts - A Hash of attributes to initialize a Notice
10
+ #
11
+ # Returns a new Notice
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @fault_id = opts[:fault_id]
15
+ @environment = opts[:environment]
16
+ @message = opts[:message]
17
+ @request = opts[:request]
18
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
19
+ end
20
+
21
+ # Public: Find all notices on a fault for a project.
22
+ def self.all(project_id, fault_id)
23
+ path = "projects/#{project_id}/faults/#{fault_id}/notices"
24
+ Honeybadger::Api::Request.all(path, handler)
25
+ end
26
+
27
+ # Public: Paginate all notices on a fault for a project
28
+ def self.paginate(project_id, fault_id, filters = {})
29
+ path = "projects/#{project_id}/faults/#{fault_id}/notices"
30
+ Honeybadger::Api::Request.paginate(path, handler, filters)
31
+ end
32
+
33
+ # Public: Find a notice on a fault for a project.
34
+ def self.find(project_id, fault_id, notice_id)
35
+ path = "projects/#{project_id}/faults/#{fault_id}/notices/#{notice_id}"
36
+ Honeybadger::Api::Request.find(path, handler)
37
+ end
38
+
39
+ # Internal: The handler used to build objects from API responses.
40
+ def self.handler
41
+ Proc.new { |response| Notice.new(response) }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,72 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Paginator
4
+
5
+ attr_reader :current_page, :total_page_count, :pages
6
+
7
+ def initialize(path, filters, handler)
8
+ @path = path
9
+ @filters = filters
10
+ @handler = handler
11
+
12
+ @pages = {}
13
+
14
+ @filters.merge!({ :page => 1 }) if !@filters.has_key?(:page)
15
+ response = Honeybadger::Api.client.get(@path, @filters)
16
+
17
+ @current_page = response[:current_page]
18
+ @total_page_count = response[:num_pages]
19
+
20
+ @pages[current_page] = response[:results].map do |r|
21
+ @handler.call(r)
22
+ end
23
+ end
24
+
25
+ def next?
26
+ current_page < total_page_count
27
+ end
28
+
29
+ def previous?
30
+ current_page > 1
31
+ end
32
+
33
+ def next
34
+ if next?
35
+ response = Honeybadger::Api.client.get(@path, @filters.merge({:page => current_page + 1}))
36
+
37
+ @current_page = response[:current_page]
38
+ @total_page_count = response[:num_pages]
39
+
40
+ @pages[current_page] = response[:results].map do |r|
41
+ @handler.call(r)
42
+ end
43
+
44
+ @pages[current_page]
45
+ else
46
+ nil
47
+ end
48
+ end
49
+
50
+ def previous
51
+ if previous?
52
+ response = Honeybadger::Api.client.get(@path, @filters.merge({:page => current_page - 1}))
53
+
54
+ @current_page = response[:current_page]
55
+ @total_page_count = response[:num_pages]
56
+
57
+ @pages[current_page] = response[:results].map do |r|
58
+ @handler.call(r)
59
+ end
60
+
61
+ @pages[current_page]
62
+ else
63
+ nil
64
+ end
65
+ end
66
+
67
+ def collection
68
+ @pages.values.flatten
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,71 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Project
4
+
5
+ attr_reader :id, :name, :owner, :users, :token, :environments,
6
+ :fault_count, :unresolved_fault_count, :last_notice_at, :created_at
7
+
8
+ # Public: Build a new instance of Project
9
+ #
10
+ # opts - A Hash of attributes to initialize a Project
11
+ #
12
+ # Returns a new Project
13
+ def initialize(opts)
14
+ @id = opts[:id]
15
+ @name = opts[:name]
16
+ @owner = User.new(opts[:owner][:name], opts[:owner][:email])
17
+ @users = opts[:users].collect { |user| User.new(user[:name], user[:email]) }
18
+ @token = opts[:token]
19
+ @environments = opts[:environments].collect do |env|
20
+ Environment.new(env)
21
+ end
22
+ @active = opts[:active]
23
+ @disable_public_links = opts[:disable_public_links]
24
+ @fault_count = opts[:fault_count]
25
+ @unresolved_fault_count = opts[:unresolved_fault_count]
26
+ @last_notice_at = opts[:last_notice_at].nil? ? nil : DateTime.parse(opts[:last_notice_at])
27
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
28
+ end
29
+
30
+ # Public: Whether the project is active.
31
+ def active?
32
+ @active == true
33
+ end
34
+
35
+ # Public: Whether the project is inactive.
36
+ def inactive?
37
+ @active == false
38
+ end
39
+
40
+ # Public: Whether links are public.
41
+ def public_links?
42
+ @disable_public_links == false
43
+ end
44
+
45
+ # Public: Whether links are private.
46
+ def private_links?
47
+ @disable_public_links == true
48
+ end
49
+
50
+ # Public: Find all of the project.
51
+ def self.all
52
+ Honeybadger::Api::Request.all("projects", handler)
53
+ end
54
+
55
+ # Public: Paginate all of the project.
56
+ def self.paginate(filters = {})
57
+ Honeybadger::Api::Request.paginate("projects", handler, filters)
58
+ end
59
+
60
+ # Public: Find a project.
61
+ def self.find(project_id)
62
+ Honeybadger::Api::Request.find("projects/#{project_id}", handler)
63
+ end
64
+
65
+ # Internal: The handler used to build objects from API responses.
66
+ def self.handler
67
+ Proc.new { |response| Project.new(response) }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,44 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Request
4
+
5
+ def initialize(path, handler, filters = {})
6
+ @path = path
7
+ @handler = handler
8
+ @filters = filters
9
+ end
10
+
11
+ def self.all(path, handler)
12
+ request = Honeybadger::Api::Request.new(path, handler)
13
+ request.all
14
+ end
15
+
16
+ def all
17
+ paginator = Honeybadger::Api::Paginator.new(@path, @filters, @handler)
18
+ while paginator.next?
19
+ paginator.next
20
+ end
21
+ paginator.collection
22
+ end
23
+
24
+ def self.find(path, handler)
25
+ request = Honeybadger::Api::Request.new(path, handler)
26
+ request.find
27
+ end
28
+
29
+ def find
30
+ response = Honeybadger::Api.client.get(@path)
31
+ @handler.call(response)
32
+ end
33
+
34
+ def self.paginate(path, handler, filters)
35
+ request = Honeybadger::Api::Request.new(path, handler, filters)
36
+ request.paginate
37
+ end
38
+
39
+ def paginate
40
+ Honeybadger::Api::Paginator.new(@path, @filters, @handler)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,42 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Team
4
+
5
+ attr_reader :id, :name, :owner, :team_members, :projects, :created_at
6
+
7
+ # Public: Build a new instance of Team
8
+ #
9
+ # opts - A Hash of attributes to initialize a Team
10
+ #
11
+ # Returns a new Team
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @name = opts[:name]
15
+ @owner = User.new(opts[:owner][:name], opts[:owner][:email])
16
+ @team_members = opts[:members].collect { |m| TeamMember.new(m) }
17
+ @projects = opts[:projects].collect { |p| Project.new(p) }
18
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
19
+ end
20
+
21
+ # Public: Find all of the teams.
22
+ def self.all
23
+ Honeybadger::Api::Request.all("teams", handler)
24
+ end
25
+
26
+ # Public: Paginate all of the teams.
27
+ def self.paginate(filters = {})
28
+ Honeybadger::Api::Request.paginate("teams", handler, filters)
29
+ end
30
+
31
+ # Public: Find a team.
32
+ def self.find(team_id)
33
+ Honeybadger::Api::Request.find("teams/#{team_id}", handler)
34
+ end
35
+
36
+ # Internal: The handler used to build objects from API responses.
37
+ def self.handler
38
+ Proc.new { |response| Team.new(response) }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,61 @@
1
+ module Honeybadger
2
+ module Api
3
+ class TeamInvitation
4
+
5
+ attr_reader :id, :token, :email, :created_by, :accepted_by, :created_at, :accepted_at, :message
6
+
7
+ # Public: Build a new instance of TeamInvitation
8
+ #
9
+ # opts - A Hash of attributes to initialize a TeamInvitation
10
+ #
11
+ # Returns a new TeamInvitation
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @token = opts[:token]
15
+ @email = opts[:email]
16
+ if opts[:created_by].nil?
17
+ @created_by = nil
18
+ else
19
+ @created_by = User.new(opts[:created_by][:name], opts[:created_by][:email])
20
+ end
21
+ if opts[:accepted_by].nil?
22
+ @accepted_by = nil
23
+ else
24
+ @accepted_by = User.new(opts[:accepted_by][:name], opts[:accepted_by][:email])
25
+ end
26
+ @admin = opts[:admin]
27
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
28
+ @accepted_at = opts[:accepted_at].nil? ? nil : DateTime.parse(opts[:accepted_at])
29
+ @message = opts[:message]
30
+ end
31
+
32
+ # Public: Whether the invitation was for an admin user.
33
+ def admin?
34
+ @admin
35
+ end
36
+
37
+ # Public: Find all team invitations for a team.
38
+ def self.all(team_id)
39
+ path = "teams/#{team_id}/team_invitations"
40
+ Honeybadger::Api::Request.all(path, handler)
41
+ end
42
+
43
+ # Public: Paginate all team invitations for a team.
44
+ def self.paginate(team_id, filters = {})
45
+ path = "teams/#{team_id}/team_invitations"
46
+ Honeybadger::Api::Request.paginate(path, handler, filters)
47
+ end
48
+
49
+ # Public: Find a team invitation for a given team.
50
+ def self.find(team_id, team_invitation_id)
51
+ path = "teams/#{team_id}/team_invitations/#{team_invitation_id}"
52
+ Honeybadger::Api::Request.find(path, handler)
53
+ end
54
+
55
+ # Internal: The handler used to build objects from API responses.
56
+ def self.handler
57
+ Proc.new { |response| TeamInvitation.new(response) }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,58 @@
1
+ module Honeybadger
2
+ module Api
3
+ class TeamMember
4
+
5
+ attr_reader :id, :admin, :created_at
6
+
7
+ # Public: Build a new instance of TeamMember
8
+ #
9
+ # opts - A Hash of attributes to initialize a TeamMember
10
+ #
11
+ # Returns a new TeamMember
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @user = User.new(opts[:name], opts[:email])
15
+ @admin = opts[:admin]
16
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
17
+ end
18
+
19
+ # Public: Whether the team member is an admin
20
+ def admin?
21
+ @admin
22
+ end
23
+
24
+ # Public: The name of the team member
25
+ def name
26
+ @user.name
27
+ end
28
+
29
+ # Public: The email address of the team member
30
+ def email
31
+ @user.email
32
+ end
33
+
34
+ # Public: Find all team members for a team.
35
+ def self.all(team_id)
36
+ path = "teams/#{team_id}/team_members"
37
+ Honeybadger::Api::Request.all(path, handler)
38
+ end
39
+
40
+ # Public: Paginate all team members for a team.
41
+ def self.paginate(team_id, filters = {})
42
+ path = "teams/#{team_id}/team_members"
43
+ Honeybadger::Api::Request.paginate(path, handler, filters)
44
+ end
45
+
46
+ # Public: Find a team member for a given team.
47
+ def self.find(team_id, team_member_id)
48
+ path = "teams/#{team_id}/team_members/#{team_member_id}"
49
+ Honeybadger::Api::Request.find(path, handler)
50
+ end
51
+
52
+ # Internal: The handler used to build objects from API responses.
53
+ def self.handler
54
+ Proc.new { |response| TeamMember.new(response) }
55
+ end
56
+ end
57
+ end
58
+ end