honeybadger-api 1.0.0

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 (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
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in honeybadger-api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Murray Summers
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # Honeybadger Read API
2
+
3
+ A Ruby Library for the [Honeybadger Read API](https://www.honeybadger.io/documentation/read_api) for easily pulling your data out of [Honeybadger](https://www.honeybadger.io/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'honeybadger-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install honeybadger-api
18
+
19
+ ## Usage
20
+
21
+ ### Introduction
22
+ Firstly require the library:
23
+
24
+ ```
25
+ require 'honeybadger-api'
26
+ ```
27
+
28
+ Then configure your personal API access token. Your personal API access token can be found on your [personal profile page](https://www.honeybadger.io/users/edit):
29
+
30
+ ```
31
+ Honeybadger::Api.configure do |c|
32
+ c.access_token = 'xxxxxxxxxxxxxxxxxxxx'
33
+ end
34
+ ```
35
+
36
+ After you have setup your API access token you can now make requests.
37
+
38
+ ### Projects
39
+
40
+ ```
41
+ # Find a project
42
+ Honeybadger::Api::Project.find(project_id)
43
+
44
+ # Find all the projects
45
+ Honeybadger::Api::Project.all
46
+
47
+ # Retrieve a paginator for projects
48
+ paginator = Honeybadger::Api::Project.paginate
49
+ ```
50
+
51
+ There are several methods that you should be aware of when using the paginator.
52
+
53
+ ```
54
+ # Get a paginator for a resource
55
+ paginator = Honeybadger::Api::Project.paginate
56
+
57
+
58
+ # Retrieve a paginator for projects starting at a page
59
+ paginator = Honeybadger::Api::Project.paginate(:page => 5)
60
+
61
+ # Whether there are any more previous or next pages
62
+ paginator.previous?
63
+ => true
64
+ paginator.next?
65
+ => true
66
+
67
+ # Retrieve the previous or next pages
68
+ paginator.previous
69
+ paginator.next
70
+
71
+ # Retrieve the current page number
72
+ paginator.current_page
73
+
74
+ # Retrieve the total number of pages
75
+ paginator.total_page_count
76
+
77
+ # Return all previously requested pages as a Hash
78
+ paginator.pages
79
+ => {
80
+ 1 => [
81
+ #<Honeybadger::Api::Project @id=1, @name="Example">,
82
+ #<Honeybadger::Api::Project @id=2, @name="Acme">
83
+ ],
84
+ 2 => [
85
+ #<Honeybadger::Api::Project @id=3, @name="Website">
86
+ ]
87
+ }
88
+
89
+ # Return all previously requested pages as a collection
90
+ paginator.collection
91
+ => [
92
+ #<Honeybadger::Api::Project @id=1, @name="Example">,
93
+ #<Honeybadger::Api::Project @id=2, @name="Acme">,
94
+ #<Honeybadger::Api::Project @id=3, @name="Website">
95
+ ]
96
+
97
+ ```
98
+
99
+ ### Deploys
100
+
101
+ ```
102
+ # Find a deploy
103
+ Honeybadger::Api::Deploy.find(project_id, deploy_id)
104
+
105
+ # Find all the deploys
106
+ Honeybadger::Api::Deploy.all(project_id)
107
+
108
+ # Retrieve a paginator for deploys
109
+ Honeybadger::Api::Deploy.paginate(project_id)
110
+ ```
111
+
112
+ ### Faults
113
+ ```
114
+ # Find a fault
115
+ Honeybadger::Api::Fault.find(project_id, fault_id)
116
+
117
+ # Find all the faults
118
+ Honeybadger::Api::Fault.all(project_id)
119
+
120
+ # Retrieve a paginator for faults
121
+ Honeybadger::Api::Fault.paginate(project_id)
122
+ ```
123
+
124
+ ### Notices
125
+ ```
126
+ # Find a notice
127
+ Honeybadger::Api::Notice.find(project_id, fault_id, notice_id)
128
+
129
+ # Find all the notices
130
+ Honeybadger::Api::Notice.all(project_id, fault_id)
131
+
132
+ # Retrieve a paginator for notices
133
+ Honeybadger::Api::Notice.paginate(project_id, fault_id)
134
+ ```
135
+ ### Comments
136
+ ```
137
+ # Find a comment
138
+ Honeybadger::Api::Comment.find(project_id, fault_id, comment_id)
139
+
140
+ # Find all the comments
141
+ Honeybadger::Api::Comment.all(project_id, fault_id)
142
+
143
+ # Retrieve a paginator for comments
144
+ Honeybadger::Api::Comment.paginate(project_id, fault_id)
145
+ ```
146
+
147
+ ### Teams
148
+ ```
149
+ # Find a team
150
+ Honeybadger::Api::Team.find(team_id)
151
+
152
+ # Find all the teams
153
+ Honeybadger::Api::Team.all
154
+
155
+ # Retrieve a paginator for teams
156
+ Honeybadger::Api::Team.paginate
157
+
158
+ ```
159
+ ### Team Members
160
+ ```
161
+ # Find a team member
162
+ Honeybadger::Api::TeamMember.find(team_id, team_member_id)
163
+
164
+ # Find all the team members
165
+ Honeybadger::Api::TeamMember.all(team_id)
166
+
167
+ # Retrieve a paginator for team members
168
+ Honeybadger::Api::TeamMember.paginate(team_id)
169
+ ```
170
+
171
+ ### Team Invitations
172
+ ```
173
+ # Find a team invitation
174
+ Honeybadger::Api::TeamInvitation.find(team_id, team_invitation_id)
175
+
176
+ # Find all the team invitations
177
+ Honeybadger::Api::TeamInvitation.all(team_id)
178
+
179
+ # Retrieve a paginator for team invitations
180
+ Honeybadger::Api::TeamInvitation.paginate(team_id)
181
+ ```
182
+
183
+ ## Contributing
184
+
185
+ 1. Fork it
186
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
187
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
188
+ 4. Push to the branch (`git push origin my-new-feature`)
189
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'honeybadger-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "honeybadger-api"
8
+ spec.version = Honeybadger::Api::VERSION
9
+ spec.authors = ["Murray Summers"]
10
+ spec.email = ["murray.sum@gmail.com"]
11
+ spec.summary = %q{Honeybadger Read API}
12
+ spec.description = %q{A Ruby Library for the Honeybadger Read API for easily pulling your data out of Honeybadger}
13
+ spec.homepage = "https://github.com/murraysum/honeybadger-api"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency 'json'
21
+
22
+ spec.add_development_dependency 'rspec', '2.14.1'
23
+ spec.add_development_dependency 'webmock'
24
+ spec.add_development_dependency 'mocha'
25
+ spec.add_development_dependency 'factory_girl'
26
+ end
@@ -0,0 +1,41 @@
1
+ require 'date'
2
+
3
+ require "honeybadger-api/version"
4
+ require "honeybadger-api/configuration"
5
+ require "honeybadger-api/paginator"
6
+ require "honeybadger-api/request"
7
+ require "honeybadger-api/team"
8
+ require "honeybadger-api/team_member"
9
+ require "honeybadger-api/user"
10
+ require "honeybadger-api/client"
11
+ require "honeybadger-api/deploy"
12
+ require "honeybadger-api/team_invitation"
13
+ require "honeybadger-api/comment"
14
+ require "honeybadger-api/project"
15
+ require "honeybadger-api/fault"
16
+ require "honeybadger-api/notice"
17
+ require "honeybadger-api/environment"
18
+
19
+ module Honeybadger
20
+ module Api
21
+
22
+ # Public: Configure the HoneyBadger Read API and set
23
+ # an access token to authenticate.
24
+ #
25
+ # Examples:
26
+ #
27
+ # Honeybadger::Api.configure do |c|
28
+ # c.access_token = "xxxxxxxxxxxxxxxxxxxx"
29
+ # end
30
+ def self.configure
31
+ @configuration = Honeybadger::Api::Configuration.new
32
+ yield @configuration
33
+ end
34
+
35
+ # Public: Query the HoneyBadger Read API directly.
36
+ def self.client
37
+ Honeybadger::Api::Client.new(@configuration.access_token)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Honeybadger
6
+ module Api
7
+ class Client
8
+
9
+ attr_reader :access_token
10
+
11
+ def initialize(access_token)
12
+ @access_token = access_token
13
+ end
14
+
15
+ def get(path, options = {})
16
+ response = request(path, options)
17
+ JSON.parse(response.body, :symbolize_names => true)
18
+ end
19
+
20
+ private
21
+
22
+ def request(path, options = {})
23
+ uri = build_uri(path, options)
24
+ http = Net::HTTP.new(uri.host, uri.port)
25
+ http.use_ssl = true
26
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
27
+
28
+ request = Net::HTTP::Get.new(uri.request_uri)
29
+
30
+ response = http.request(request)
31
+ end
32
+
33
+ def build_uri(path, opts)
34
+ uri = URI.join(host, path)
35
+ uri.query = build_query(opts)
36
+ uri
37
+ end
38
+
39
+ def build_query(opts)
40
+ URI.encode_www_form(opts.merge({:auth_token => access_token}))
41
+ end
42
+
43
+ def host
44
+ "https://api.honeybadger.io/v1/"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Comment
4
+
5
+ attr_reader :id, :fault_id, :event, :source, :notices_count, :author, :body, :created_at
6
+
7
+ # Public: Build a new instance of Comment
8
+ #
9
+ # opts - A Hash of attributes to initialize a Comment
10
+ #
11
+ # Returns a new Comment
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @fault_id = opts[:fault_id]
15
+ @event = opts[:event]
16
+ @source = opts[:source]
17
+ @notices_count = opts[:notices_count]
18
+ @author = opts[:author]
19
+ @body = opts[:body]
20
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
21
+ end
22
+
23
+ # Public: Find all comments on a fault for a project.
24
+ def self.all(project_id, fault_id)
25
+ path = "projects/#{project_id}/faults/#{fault_id}/comments"
26
+ Honeybadger::Api::Request.all(path, handler)
27
+ end
28
+
29
+ # Public: Paginate all comments on a fault for a project
30
+ def self.paginate(project_id, fault_id, filters = {})
31
+ path = "projects/#{project_id}/faults/#{fault_id}/comments"
32
+ Honeybadger::Api::Request.paginate(path, handler, filters)
33
+ end
34
+
35
+ # Public: Find a comment on a fault for a project.
36
+ def self.find(project_id, fault_id, comment_id)
37
+ path = "projects/#{project_id}/faults/#{fault_id}/comments/#{comment_id}"
38
+ Honeybadger::Api::Request.find(path, handler)
39
+ end
40
+
41
+ # Internal: The handler used to build objects from API responses.
42
+ def self.handler
43
+ Proc.new { |response| Comment.new(response) }
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Configuration
4
+
5
+ attr_accessor :access_token
6
+
7
+ def initialize
8
+ @access_token = nil
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ module Honeybadger
2
+ module Api
3
+ class Deploy
4
+
5
+ attr_reader :id, :project_id, :repository, :revision, :environment, :local_username, :created_at
6
+
7
+ # Public: Build a new instance of Deploy
8
+ #
9
+ # opts - A Hash of attributes to initialize a Deploy
10
+ #
11
+ # Returns a new Deploy
12
+ def initialize(opts)
13
+ @id = opts[:id]
14
+ @project_id = opts[:project_id]
15
+ @repository = opts[:repository]
16
+ @revision = opts[:revision]
17
+ @environment = opts[:environment]
18
+ @local_username = opts[:local_username]
19
+ @created_at = opts[:created_at].nil? ? nil : DateTime.parse(opts[:created_at])
20
+ end
21
+
22
+ # Public: Find all deploys for a given project.
23
+ def self.all(project_id)
24
+ path = "projects/#{project_id}/deploys"
25
+ Honeybadger::Api::Request.all(path, handler)
26
+ end
27
+
28
+ # Public: Paginate all deploys for a given project
29
+ def self.paginate(project_id, filters = {})
30
+ path = "projects/#{project_id}/deploys"
31
+ Honeybadger::Api::Request.paginate(path, handler, filters)
32
+ end
33
+
34
+ # Public: Find a deploy for a given project.
35
+ def self.find(project_id, deploy_id)
36
+ path = "projects/#{project_id}/deploys/#{deploy_id}"
37
+ Honeybadger::Api::Request.find(path, handler)
38
+ end
39
+
40
+ # Internal: The handler used to build objects from API responses.
41
+ def self.handler
42
+ Proc.new { |response| Deploy.new(response) }
43
+ end
44
+ end
45
+ end
46
+ end