bugherd_client 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +2 -1
- data/.travis.yml +4 -1
- data/README.md +23 -38
- data/Rakefile +6 -1
- data/bin/console +17 -0
- data/bugherd_client.gemspec +17 -13
- data/lib/bugherd_client.rb +19 -16
- data/lib/bugherd_client/client.rb +44 -18
- data/lib/bugherd_client/errors.rb +19 -5
- data/lib/bugherd_client/resources/v1/base.rb +2 -2
- data/lib/bugherd_client/resources/v1/comment.rb +1 -1
- data/lib/bugherd_client/resources/v1/project.rb +4 -4
- data/lib/bugherd_client/resources/v1/task.rb +11 -8
- data/lib/bugherd_client/resources/v2/attachment.rb +73 -0
- data/lib/bugherd_client/resources/v2/base.rb +24 -5
- data/lib/bugherd_client/resources/v2/comment.rb +2 -2
- data/lib/bugherd_client/resources/v2/organization.rb +5 -5
- data/lib/bugherd_client/resources/v2/project.rb +22 -13
- data/lib/bugherd_client/resources/v2/task.rb +34 -14
- data/lib/bugherd_client/resources/v2/webhook.rb +54 -0
- data/lib/bugherd_client/version.rb +1 -1
- data/spec/bugherd_client/client_spec.rb +63 -11
- data/spec/bugherd_client/v2/organization_spec.rb +21 -0
- data/spec/bugherd_client/v2/project_spec.rb +66 -0
- data/spec/bugherd_client/v2/task_spec.rb +46 -0
- data/spec/bugherd_client/v2/user_spec.rb +50 -0
- data/spec/bugherd_client/v2/webhook_spec.rb +20 -0
- data/spec/cassettes/guests_all.yml +64 -0
- data/spec/cassettes/members_all.yml +66 -0
- data/spec/cassettes/organizations_get.yml +62 -0
- data/spec/cassettes/projects_active.yml +65 -0
- data/spec/cassettes/projects_all.yml +65 -0
- data/spec/cassettes/projects_find_failure.yml +60 -0
- data/spec/cassettes/projects_find_success.yml +65 -0
- data/spec/cassettes/tasks_all.yml +87 -0
- data/spec/cassettes/tasks_find_success.yml +69 -0
- data/spec/cassettes/users_all.yml +66 -0
- data/spec/cassettes/webhooks_all.yml +64 -0
- data/spec/spec_helper.rb +23 -9
- data/spec/support/http_helper.rb +7 -0
- metadata +130 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 613db28bf8edb0ace5b32f050c8c4774dc072d3a
|
4
|
+
data.tar.gz: c0eaa375aefbecfdd0932489723a547660ae91f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de456845c1409857253cac60a58486b21da9f59cf9a5e9146ed4638a58ad8e6d4e0ff6fd66b4507029b92720a626acba33ac6cd066822093e60ec091e2023967
|
7
|
+
data.tar.gz: 8527719b03e5ecb6fc771c48b3a5c5d68239f8b92c352fb65cd9b324c1c5110e04e7dcf01859d6c5161cd89d6993f4594ff5702ded79e8930f4bbc6f0e8a43df
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
@@ -2,6 +2,8 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
+
- rbx-2.4.1
|
6
|
+
- rbx-2
|
5
7
|
- ruby-head
|
6
8
|
- jruby-19mode
|
7
9
|
- jruby-head
|
@@ -16,7 +18,8 @@ matrix:
|
|
16
18
|
allow_failures:
|
17
19
|
- rvm: ruby-head
|
18
20
|
- rvm: jruby-head
|
21
|
+
- rvm: rbx-2
|
19
22
|
|
20
23
|
notifications:
|
21
24
|
email:
|
22
|
-
- jwaterfaucett@gmail.com
|
25
|
+
- jwaterfaucett@gmail.com
|
data/README.md
CHANGED
@@ -5,60 +5,45 @@
|
|
5
5
|
|
6
6
|
# BugHerd Client
|
7
7
|
|
8
|
-
This is a Rest Client for the BugHerd API.
|
9
|
-
Another nifty feature is that its threadsafe so you could potentially have many instances floating around and don't
|
10
|
-
have to worry about collisions as is the case with ActiveResource.
|
8
|
+
This is a Rest Client for the BugHerd API.
|
11
9
|
|
12
|
-
|
10
|
+
**features:**
|
13
11
|
|
14
|
-
|
12
|
+
* Threadsafe
|
13
|
+
* Full V1 API support
|
14
|
+
* Full V2 API support
|
15
15
|
|
16
|
-
|
16
|
+
**ruby support:**
|
17
17
|
|
18
|
-
|
18
|
+
* JRuby
|
19
|
+
* Rubinius 2+
|
20
|
+
* MRI >= 1.9.3
|
19
21
|
|
20
|
-
$ bundle
|
21
22
|
|
22
|
-
|
23
|
+
## Installation
|
23
24
|
|
24
25
|
$ gem install bugherd_client
|
25
26
|
|
26
27
|
## Basic Usage
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
client = BugherdClient::Client.new(api_key: 'someapikey')
|
32
|
-
|
33
|
-
# Get information about your organization
|
34
|
-
client.organization.get # => returns your organization information
|
35
|
-
|
36
|
-
# Get a list of all users
|
37
|
-
all_users = client.users.all # => returns a list of all users
|
38
|
-
user = all_users.first
|
29
|
+
For usage look in the examples folders. Examples are only kept for the latest
|
30
|
+
version of the API so if you really want to use older versions you'll have to
|
31
|
+
look at the source.
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
requester_id: user[:id],
|
47
|
-
status: 'backlog',
|
48
|
-
priority: 'normal'
|
49
|
-
})
|
50
|
-
|
51
|
-
# Create a comment
|
52
|
-
client.comments.create(project[:id], task[:id], {
|
53
|
-
text: 'hey this is a comment'
|
54
|
-
})
|
55
|
-
|
56
|
-
```
|
33
|
+
* [Setup](examples/initialization.rb)
|
34
|
+
* [Projects](examples/projects.rb)
|
35
|
+
* [Users & Organization](examples/users_and_organization.rb)
|
36
|
+
* [Task & Comments](examples/tasks_and_comments.rb)
|
37
|
+
* [Attachments](examples/attachments.rb)
|
38
|
+
* [Webhooks](examples/webhooks.rb)
|
57
39
|
|
58
40
|
## Contributing
|
59
41
|
|
42
|
+
Please note that all contributions require tests.
|
43
|
+
|
60
44
|
1. Fork it ( http://github.com/<my-github-username>/bugherd_client/fork )
|
61
45
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
46
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
47
|
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
-
5.
|
48
|
+
5. Write some tests.
|
49
|
+
6. Create new Pull Request
|
data/Rakefile
CHANGED
data/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# setup bundler
|
4
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
require 'bundler/setup'
|
6
|
+
|
7
|
+
require 'bugherd_client'
|
8
|
+
|
9
|
+
# load and init pry
|
10
|
+
begin
|
11
|
+
require 'pry'
|
12
|
+
rescue LoadError
|
13
|
+
require 'rubygems'
|
14
|
+
require 'pry'
|
15
|
+
end
|
16
|
+
|
17
|
+
Pry::CLI.parse_options
|
data/bugherd_client.gemspec
CHANGED
@@ -4,24 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'bugherd_client/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'bugherd_client'
|
8
8
|
spec.version = BugherdClient::VERSION::STRING
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['John Faucett']
|
10
|
+
spec.email = ['jwaterfaucett@gmail.com']
|
11
11
|
spec.summary = %q{Ruby Client for the Bugherd API}
|
12
12
|
spec.description = %q{Ruby Client for the Bugherd Rest API}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'http://jwaterfaucett.github.io/bugherd_client'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").select { |p| !(/examples/ =~ p) }
|
18
17
|
spec.test_files = spec.files.grep(%r{^(spec|features)/})
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
20
|
+
spec.add_dependency 'rest-client', '~> 1.6'
|
21
|
+
spec.add_dependency 'hashie', '~> 3.0'
|
22
|
+
spec.add_dependency 'activesupport', '> 3.0', '< 5.0'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '>= 1.5'
|
25
|
+
spec.add_development_dependency 'rspec', '>= 3'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'webmock', '~> 1.20'
|
28
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
29
|
+
spec.add_development_dependency 'pry', '~> 0.10.1'
|
30
|
+
spec.add_development_dependency 'simplecov', '0.9.1'
|
27
31
|
end
|
data/lib/bugherd_client.rb
CHANGED
@@ -1,29 +1,32 @@
|
|
1
1
|
require 'rest_client'
|
2
|
+
require 'hashie'
|
2
3
|
require 'active_support'
|
3
4
|
require 'active_support/core_ext'
|
4
5
|
|
5
6
|
module BugherdClient
|
6
|
-
autoload :VERSION,
|
7
|
-
autoload :Client,
|
8
|
-
autoload :Errors,
|
9
|
-
|
7
|
+
autoload :VERSION, 'bugherd_client/version'
|
8
|
+
autoload :Client, 'bugherd_client/client'
|
9
|
+
autoload :Errors, 'bugherd_client/errors'
|
10
|
+
|
10
11
|
module Resources
|
11
12
|
module V1
|
12
|
-
autoload :Base,
|
13
|
-
autoload :Organization,
|
14
|
-
autoload :User,
|
15
|
-
autoload :Project,
|
16
|
-
autoload :Task,
|
17
|
-
autoload :Comment,
|
13
|
+
autoload :Base, 'bugherd_client/resources/v1/base'
|
14
|
+
autoload :Organization, 'bugherd_client/resources/v1/organization'
|
15
|
+
autoload :User, 'bugherd_client/resources/v1/user'
|
16
|
+
autoload :Project, 'bugherd_client/resources/v1/project'
|
17
|
+
autoload :Task, 'bugherd_client/resources/v1/task'
|
18
|
+
autoload :Comment, 'bugherd_client/resources/v1/comment'
|
18
19
|
end
|
19
20
|
|
20
21
|
module V2
|
21
|
-
autoload :Base,
|
22
|
-
autoload :Organization,
|
23
|
-
autoload :User,
|
24
|
-
autoload :Project,
|
25
|
-
autoload :Task,
|
26
|
-
autoload :Comment,
|
22
|
+
autoload :Base, 'bugherd_client/resources/v2/base'
|
23
|
+
autoload :Organization, 'bugherd_client/resources/v2/organization'
|
24
|
+
autoload :User, 'bugherd_client/resources/v2/user'
|
25
|
+
autoload :Project, 'bugherd_client/resources/v2/project'
|
26
|
+
autoload :Task, 'bugherd_client/resources/v2/task'
|
27
|
+
autoload :Comment, 'bugherd_client/resources/v2/comment'
|
28
|
+
autoload :Webhook, 'bugherd_client/resources/v2/webhook'
|
29
|
+
autoload :Attachment, 'bugherd_client/resources/v2/attachment'
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
@@ -1,49 +1,70 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'monitor'
|
2
3
|
|
3
4
|
module BugherdClient
|
4
5
|
class Client
|
5
6
|
|
6
7
|
API_VERSIONS = [1,2].freeze
|
7
8
|
|
9
|
+
RESOURCE_NAMES = [
|
10
|
+
:organization,
|
11
|
+
:user,
|
12
|
+
:project,
|
13
|
+
:task,
|
14
|
+
:comment,
|
15
|
+
:webhook,
|
16
|
+
:attachment
|
17
|
+
]
|
18
|
+
|
8
19
|
DEFAULT_OPTIONS = {
|
9
20
|
base_url: 'https://www.bugherd.com',
|
10
21
|
api_version: 2,
|
11
|
-
username:
|
12
|
-
password:
|
13
|
-
api_key:
|
22
|
+
username: nil,
|
23
|
+
password: nil,
|
24
|
+
api_key: nil,
|
14
25
|
api_rate_limiting_token: 'x',
|
15
26
|
debug: false
|
16
27
|
}.freeze
|
17
28
|
|
18
29
|
attr_accessor :options, :connection
|
19
30
|
|
31
|
+
DEFAULT_OPTIONS.each do |option_name, v|
|
32
|
+
define_method("#{option_name}") { @options[option_name] }
|
33
|
+
define_method("#{option_name}=") { |value| @options[option_name] = value }
|
34
|
+
end
|
35
|
+
|
20
36
|
def initialize(opts={}, &block)
|
21
|
-
|
22
|
-
|
23
|
-
|
37
|
+
mutex = Monitor.new
|
38
|
+
mutex.synchronize do
|
39
|
+
@options = DEFAULT_OPTIONS.merge(opts)
|
40
|
+
yield(self) if block_given?
|
41
|
+
establish_connection!
|
42
|
+
end
|
24
43
|
end
|
25
44
|
|
26
45
|
def establish_connection!
|
27
46
|
check_options!
|
28
47
|
username, password = build_credentials
|
29
|
-
|
48
|
+
|
30
49
|
if @options[:debug]
|
31
50
|
RestClient.log = ::Logger.new($stderr)
|
32
51
|
RestClient.log.level = ::Logger::DEBUG
|
33
52
|
end
|
34
|
-
|
53
|
+
|
54
|
+
resource_klass = Class.new(RestClient::Resource)
|
55
|
+
self.connection = resource_klass.new(base_url, user: username, password: password)
|
35
56
|
end
|
36
|
-
|
57
|
+
|
37
58
|
def base_url
|
38
59
|
File.join(options[:base_url], "api_v#{options[:api_version]}")
|
39
60
|
end
|
40
61
|
|
41
62
|
def check_options!
|
42
63
|
if !@options[:api_key] && !(@options[:username] && @options[:password])
|
43
|
-
raise BugherdClient::Errors::InvalidOption,
|
64
|
+
raise BugherdClient::Errors::InvalidOption, 'api_key or username and password is required'
|
44
65
|
end
|
45
66
|
unless API_VERSIONS.include?(@options[:api_version])
|
46
|
-
raise
|
67
|
+
raise(BugherdClient::Errors::InvalidOption.new("api_version must be #{API_VERSIONS.join(',')}"))
|
47
68
|
end
|
48
69
|
end
|
49
70
|
|
@@ -57,18 +78,23 @@ module BugherdClient
|
|
57
78
|
|
58
79
|
def resource(name)
|
59
80
|
version = self.options[:api_version]
|
60
|
-
|
81
|
+
version_base = "BugherdClient::Resources::V#{version}".constantize
|
82
|
+
klass_name = name.to_s.classify.to_sym
|
83
|
+
unless version_base.constants.include?(klass_name)
|
84
|
+
raise(BugherdClient::Errors::NotAvailable.new(version, klass_name))
|
85
|
+
end
|
86
|
+
klass = version_base.const_get(klass_name)
|
61
87
|
klass.new(self.connection, @options)
|
62
88
|
end
|
63
89
|
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
|
90
|
+
#
|
91
|
+
# generate RESTful resource factory methods
|
92
|
+
#
|
93
|
+
RESOURCE_NAMES.each do |resource_name|
|
68
94
|
define_method("#{resource_name.to_s.pluralize}") do
|
69
|
-
resource(
|
95
|
+
resource(resource_name.to_s)
|
70
96
|
end
|
71
97
|
end
|
72
98
|
|
73
99
|
end
|
74
|
-
end
|
100
|
+
end
|
@@ -2,27 +2,41 @@ module BugherdClient
|
|
2
2
|
module Errors
|
3
3
|
|
4
4
|
class InvalidOption < StandardError
|
5
|
-
def initialize(msg=
|
5
|
+
def initialize(msg='invalid option')
|
6
6
|
super(msg)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
class NotAvailable < StandardError
|
11
|
-
def initialize(api_version, msg=
|
11
|
+
def initialize(api_version, msg='')
|
12
12
|
super("#{msg} not available in API v#{api_version}")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
class InvalidQueryKey < StandardError
|
17
|
+
def initialize(given = '', valid_keys = [])
|
18
|
+
super("invalid query key: got #{given} but expected one of #{valid_keys.join(',')}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class HttpRequestError < StandardError
|
23
|
+
attr_accessor :http_code
|
24
|
+
def initialize(message = '', code = 500)
|
25
|
+
super(message)
|
26
|
+
@http_code = code
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
16
30
|
class UnsupportedMethod < StandardError
|
17
|
-
def initialize(api_version=
|
31
|
+
def initialize(api_version='')
|
18
32
|
super("Method supported in API version #{api_version}")
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
22
36
|
class UnsupportedAttribute < StandardError
|
23
|
-
def initialize(api_version=
|
37
|
+
def initialize(api_version='', attrs=[])
|
24
38
|
super("Attributes (#{attrs.join(',')}) supported in #{api_version}")
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
28
|
-
end
|
42
|
+
end
|
@@ -23,7 +23,7 @@ module BugherdClient
|
|
23
23
|
@connection, @options = conn, opts
|
24
24
|
end
|
25
25
|
|
26
|
-
def send_request(method=
|
26
|
+
def send_request(method='GET', path='', params={}, headers={})
|
27
27
|
headers = DEFAULT_HEADER_ATTRS.merge(headers)
|
28
28
|
params.merge!(headers)
|
29
29
|
method_name = method.to_s.downcase
|
@@ -52,4 +52,4 @@ module BugherdClient
|
|
52
52
|
|
53
53
|
end
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
@@ -25,7 +25,7 @@ module BugherdClient
|
|
25
25
|
# attributes: name, devurl, is_public, is_active
|
26
26
|
#
|
27
27
|
def create(attributes={})
|
28
|
-
raw_response = post_request(
|
28
|
+
raw_response = post_request('projects', project: attributes)
|
29
29
|
parse_response(raw_response, :project)
|
30
30
|
end
|
31
31
|
|
@@ -37,7 +37,7 @@ module BugherdClient
|
|
37
37
|
parse_response(raw_response, :project)
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# Delete a project and all associated data. Use with care, deleted projects cannot be recovered.
|
42
42
|
#
|
43
43
|
def delete(project_id)
|
@@ -46,7 +46,7 @@ module BugherdClient
|
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|