bugherd_client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f346acfb08946d59c1dade9ed8a1b0833635873d
4
+ data.tar.gz: 6a6cb56ee578115522efb27db7faad2a67a00d0b
5
+ SHA512:
6
+ metadata.gz: af84b3628df12bf6d67b4ea2abad7512e172264fd677bd01a0f352d9ca8ad9d78a4cbc231de28fc58fe93fbfc1ef06622f8f6cf0a0beee3a202fd739c0e2ea14
7
+ data.tar.gz: a84dfb06abc083abfc151daa822d604c85515a8e374a626fb429115feb3905862ca342825daeb04469bd34f50ab26755a4cf23d85d847dfdb08e6861739868b6
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bugherd_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John Faucett
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,49 @@
1
+ # BugherdClient
2
+
3
+ This is a Rest Client for the Bugherd API. It fully covers all methods of the v1 and v2 API Implementations.
4
+ Another nifty feature is that its threadsafe so you could potentially have many instances floating around and don't
5
+ have to worry about collisions as is the case with ActiveResource.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'bugherd_client'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bugherd_client
20
+
21
+ ## Basic Usage
22
+
23
+ ```ruby
24
+
25
+ client = BugherdClient::Client.new(api_key: 'someapikey', api_version: 2) # api_version 2 is the default
26
+ client.organization.get # => returns your organization information
27
+ client.users.all # => returns a list of all users
28
+ project = client.projects.find(1023)
29
+ user = client.users.all.first
30
+
31
+ client.tasks.create(project[:id], {
32
+ description: 'Some description',
33
+ requester_id: user[:id],
34
+ status: BugherdClient::Resources::Task::STATUS_BACKLOG,
35
+ priority: BugherdClient::Resources::Task::PRIORITY_NORMAL,
36
+ external_id: 'my-external-app-123'
37
+ })
38
+
39
+
40
+
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/<my-github-username>/bugherd_client/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bugherd_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bugherd_client"
8
+ spec.version = BugherdClient::VERSION::STRING
9
+ spec.authors = ["John Faucett"]
10
+ spec.email = ["jwaterfaucett@gmail.com"]
11
+ spec.summary = %q{Ruby Client for the Bugherd API}
12
+ spec.description = %q{Ruby Client for the Bugherd Rest API}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rest-client", "~> 1.6"
22
+ spec.add_dependency "activesupport", "> 3.0", "< 5.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rspec", "~> 2.14"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,30 @@
1
+ require 'rest_client'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module BugherdClient
6
+ autoload :VERSION, "bugherd_client/version"
7
+ autoload :Client, "bugherd_client/client"
8
+ autoload :Errors, "bugherd_client/errors"
9
+
10
+ module Resources
11
+ module V1
12
+ autoload :Base, "bugherd_client/resources/v1/base"
13
+ autoload :Organization, "bugherd_client/resources/v1/organization"
14
+ autoload :User, "bugherd_client/resources/v1/user"
15
+ autoload :Project, "bugherd_client/resources/v1/project"
16
+ autoload :Task, "bugherd_client/resources/v1/task"
17
+ autoload :Comment, "bugherd_client/resources/v1/comment"
18
+ end
19
+
20
+ module V2
21
+ autoload :Base, "bugherd_client/resources/v2/base"
22
+ autoload :Organization, "bugherd_client/resources/v2/organization"
23
+ autoload :User, "bugherd_client/resources/v2/user"
24
+ autoload :Project, "bugherd_client/resources/v2/project"
25
+ autoload :Task, "bugherd_client/resources/v2/task"
26
+ autoload :Comment, "bugherd_client/resources/v2/comment"
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,75 @@
1
+ require 'logger'
2
+
3
+ module BugherdClient
4
+ class Client
5
+
6
+ VALID_API_VERSIONS = [1,2].freeze
7
+
8
+ DEFAULT_OPTIONS = {
9
+ base_url: 'https://www.bugherd.com',
10
+ api_version: 2,
11
+ username: '',
12
+ password: '',
13
+ api_key: '',
14
+ debug: false
15
+ }
16
+
17
+ attr_accessor :options, :connection
18
+
19
+ def initialize(options={}, &block)
20
+ @options = DEFAULT_OPTIONS.merge(options)
21
+ yield(self) if block_given?
22
+ establish_connection!
23
+ end
24
+
25
+ def establish_connection!
26
+ check_options!
27
+ username, password = build_credentials
28
+
29
+ if @options[:debug]
30
+ RestClient.log = ::Logger.new($stderr)
31
+ RestClient.log.level = Logger::DEBUG
32
+ end
33
+
34
+ self.connection = RestClient::Resource.new(base_url, user: username, password: password)
35
+
36
+ end
37
+
38
+ def base_url
39
+ File.join(options[:base_url], "api_v#{options[:api_version]}")
40
+ end
41
+
42
+ def check_options!
43
+ if !@options[:api_key] && !(@options[:username] && @options[:password])
44
+ raise BugherdClient::Errors::InvalidOption, "api_key or username and password is required"
45
+ end
46
+ unless VALID_API_VERSIONS.include?(@options[:api_version])
47
+ raise BugherdClient::Errors::InvalidOption, "api_version must be #{VALID_API_VERSIONS.join(',')}"
48
+ end
49
+ end
50
+
51
+ def build_credentials
52
+ if @options[:api_key]
53
+ [@options[:api_key], 'x']
54
+ else
55
+ [@options[:username], @options[:password]]
56
+ end
57
+ end
58
+
59
+ def resource(name, opts={})
60
+ version = self.options[:api_version]
61
+ klass = Object.const_get("BugherdClient::Resources::V#{version}::#{name.to_s.classify}")
62
+ klass.new(self.connection, self.options)
63
+ end
64
+
65
+ #
66
+ # Resources
67
+ #
68
+ [:organization, :user, :project, :task, :comment].each do |resource_name|
69
+ define_method("#{resource_name.to_s.pluralize}") do
70
+ resource("#{resource_name}")
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,22 @@
1
+ module BugherdClient
2
+ module Errors
3
+
4
+ class InvalidOption < StandardError
5
+ def initialize(msg="invalid option")
6
+ super(msg)
7
+ end
8
+ end
9
+
10
+ class UnsupportedMethod < StandardError
11
+ def initialize(api_version="")
12
+ super("Method supported in API version #{api_version}")
13
+ end
14
+ end
15
+
16
+ class UnsupportedAttribute < StandardError
17
+ def initialize(api_version="", attrs=[])
18
+ super("Attributes (#{attrs.join(',')}) supported in #{api_version}")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+
3
+ module BugherdClient
4
+ module Resources
5
+ class Base
6
+
7
+ DEFAULT_HEADERS = { content_type: :json, accept: :json }
8
+
9
+ attr_accessor :connection, :options
10
+ def initialize(conn, opts={})
11
+ @connection, @options = conn, opts
12
+ end
13
+
14
+ def send_request(method="GET", path="", params={}, headers={})
15
+ headers = DEFAULT_HEADERS.merge(headers)
16
+ params.merge!(headers)
17
+ method_name = method.to_s.downcase
18
+ self.connection[path].__send__(method_name, params)
19
+ end
20
+
21
+ [:get, :post, :put, :patch, :delete].each do |method_name|
22
+ define_method("#{method_name}_request") do |path, params={}|
23
+ send_request(method_name, path, params)
24
+ end
25
+ end
26
+
27
+ def parse_response(response, root_element=nil)
28
+ if root_element
29
+ JSON.parse(response)[root_element.to_s]
30
+ else
31
+ JSON.parse(response)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ module BugherdClient
2
+ module Resources
3
+ class Comment < Base
4
+
5
+ #
6
+ # Get a paginated list of comments for a task.
7
+ #
8
+ def all(project_id, task_id)
9
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}/comments")
10
+ parse_response(raw_response, :comments)
11
+ end
12
+
13
+ #
14
+ # Create a comment
15
+ # attributes: text, user_id or email
16
+ def create(project_id, task_id, attributes={})
17
+ raw_response = post_request("projects/#{project_id}/tasks/#{task_id}/comments", comment: attributes)
18
+ parse_response(raw_response)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module BugherdClient
2
+ module Resources
3
+ class Organization < Base
4
+
5
+ #
6
+ # Get more detail of your account.
7
+ #
8
+ def get
9
+ raw_response = self.connection['organization'].get
10
+ parse_response(raw_response, :organization)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,76 @@
1
+ module BugherdClient
2
+ module Resources
3
+ class Project < Base
4
+
5
+ #
6
+ # Get more detail of your account.
7
+ #
8
+ def all
9
+ raw_response = get_request('projects')
10
+ parse_response(raw_response, :projects)
11
+ end
12
+
13
+ #
14
+ # Show details for a specific project
15
+ #
16
+ def find(project_id)
17
+ raw_response = get_request("projects/#{project_id}")
18
+ parse_response(raw_response, :project)
19
+ end
20
+
21
+ #
22
+ # Create a Project, will initially have no members
23
+ # attributes: name, devurl, is_public, is_active
24
+ #
25
+ def create(attributes={})
26
+ raw_response = post_request("projects", project: attributes)
27
+ parse_response(raw_response, :project)
28
+ end
29
+
30
+ #
31
+ # Update settings for an existing project under your control (ie: only the ones you own).
32
+ # API: 1,2
33
+ def update(project_id, attributes={})
34
+ raw_response = put_request("projects/#{project_id}", project: attributes)
35
+ parse_response(raw_response, :project)
36
+ end
37
+
38
+ #
39
+ # Delete a project and all associated data. Use with care, deleted projects cannot be recovered.
40
+ # API: 1,2
41
+ def delete(project_id)
42
+ raw_response = delete_request("projects/#{project_id}")
43
+ parse_response(raw_response)
44
+ end
45
+
46
+ #
47
+ # Add an existing guest to a project, or invite someone by email address.
48
+ # required: project_id
49
+ # attributes: user_id, email
50
+ # API: 2
51
+ def add_guest(project_id, attributes={})
52
+ raw_response = post_request("projects/#{project_id}/add_guest", attributes)
53
+ parse_response(raw_response)
54
+ end
55
+
56
+ #
57
+ # Add an existing guest to a project, or invite someone by email address.
58
+ # required: project_id
59
+ # attributes: user_id
60
+ #
61
+ def add_member(project_id, attributes={})
62
+ raw_response = post_request("projects/#{project_id}/add_member", attributes)
63
+ parse_response(raw_response)
64
+ end
65
+
66
+
67
+ #
68
+ # Get all active projects
69
+ #
70
+ def active
71
+ raw_response = get_request('projects/active')
72
+ parse_response(raw_response, :projects)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,56 @@
1
+ module BugherdClient
2
+ module Resources
3
+ class Task < Base
4
+
5
+ PRIORITIES = ['not set', 'critical', 'important', 'normal','minor']
6
+ PRIORITIES.each do |priority|
7
+ Task.const_set("PRIORITY_#{priority.gsub(' ', '').upcase}", priority)
8
+ end
9
+
10
+ STATUSES = ['backlog','todo','doing','done','closed']
11
+ STATUSES.each do |status|
12
+ Task.const_set("STATUS_#{status.upcase}", status)
13
+ end
14
+
15
+ #
16
+ # Get a full list of tasks for a project, including archived tasks.
17
+ # filters: updated_since, created_since, status, priority, tag and external_id
18
+ def all(project_id, filter_attributes={})
19
+ params = filter_attributes.empty? ? {} : { params: filter_attributes }
20
+ raw_response = get_request("projects/#{project_id}/tasks", params)
21
+ parse_response(raw_response, :tasks)
22
+ end
23
+
24
+ #
25
+ # List details of a task in a given project, includes all data including comments, attachments, etc.
26
+ #
27
+ def find(project_id, task_id)
28
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}")
29
+ parse_response(raw_response)
30
+ end
31
+
32
+ #
33
+ # Create a new Task
34
+ # attributes:
35
+ # description, priority, status, tag_names(Array),
36
+ # requester_id or requester_email,
37
+ # assigned_to_id or assigned_to_email
38
+ # external_id
39
+ # if status is null the Task is automatically put in the Feedback panel
40
+ # "requester_email" can be any email address while "assigned_to_email" needs to be of a current project member.
41
+ # Values for "priority" are not set, critical, important, normal, and minor.
42
+ # Values for "status" are backlog, todo, doing, done, and closed. Omit this field or set as "null" to send tasks to the Feedback panel.
43
+ # External ID is an API-only field. It cannot be set from the BugHerd application, only using the API. An external ID can be used to track originating IDs from other systems in BugHerd bugs.
44
+ def create(project_id, attributes={})
45
+ raw_response = post_request("projects/#{project_id}/tasks", task: attributes)
46
+ parse_response(raw_response)
47
+ end
48
+
49
+ def update(project_id, task_id, attributes={})
50
+ raw_response = put_request("projects/#{project_id}/tasks/#{task_id}", task: attributes)
51
+ parse_response(raw_response)
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,31 @@
1
+ module BugherdClient
2
+ module Resources
3
+ class User < Base
4
+
5
+ #
6
+ # See all the people in your account.
7
+ # API: 1,2
8
+ def all
9
+ raw_response = get_request('users')
10
+ parse_response(raw_response, :users)
11
+ end
12
+
13
+ #
14
+ # See all your account members
15
+ #
16
+ def members
17
+ raw_response = get_request('users/members')
18
+ parse_response(raw_response, :users)
19
+ end
20
+
21
+ #
22
+ # See all the guest in your account
23
+ #
24
+ def guests
25
+ raw_response = get_request('users/guests')
26
+ parse_response(raw_response, :users)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+
3
+ module BugherdClient
4
+ module Resources
5
+ module V1
6
+
7
+ class Base
8
+
9
+ DEFAULT_HEADERS = { content_type: :json, accept: :json }
10
+
11
+ #
12
+ # Return a list of available methods in a Resource
13
+ #
14
+ def api_methods
15
+ self.class.instance_methods(false)
16
+ end
17
+
18
+ attr_accessor :connection, :options
19
+ def initialize(conn, opts={})
20
+ @connection, @options = conn, opts
21
+ end
22
+
23
+ def send_request(method="GET", path="", params={}, headers={})
24
+ headers = DEFAULT_HEADERS.merge(headers)
25
+ params.merge!(headers)
26
+ method_name = method.to_s.downcase
27
+ self.connection[path].__send__(method_name, params)
28
+ end
29
+
30
+ [:get, :post, :put, :patch, :delete].each do |method_name|
31
+ define_method("#{method_name}_request") do |path, params={}|
32
+ send_request(method_name, path, params)
33
+ end
34
+ end
35
+
36
+ def parse_response(response, root_element=nil)
37
+ if root_element
38
+ JSON.parse(response)[root_element.to_s]
39
+ else
40
+ JSON.parse(response)
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V1
4
+ class Comment < Base
5
+
6
+ #
7
+ # Get a paginated list of comments for a task.
8
+ #
9
+ def all(project_id, task_id)
10
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}/comments")
11
+ parse_response(raw_response, :comments)
12
+ end
13
+
14
+ #
15
+ # Get a single comment of a Task
16
+ #
17
+ def find(project_id, task_id, comment_id)
18
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}/comments/#{comment_id}")
19
+ parse_response(raw_response, :comment)
20
+ end
21
+
22
+ #
23
+ # Create a comment
24
+ # attributes: text, user_id or email
25
+ def create(project_id, task_id, attributes={})
26
+ raw_response = post_request("projects/#{project_id}/tasks/#{task_id}/comments", comment: attributes)
27
+ parse_response(raw_response)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,52 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V1
4
+
5
+ class Project < Base
6
+
7
+ #
8
+ # Get more detail of your account.
9
+ #
10
+ def all
11
+ raw_response = get_request('projects')
12
+ parse_response(raw_response, :projects)
13
+ end
14
+
15
+ #
16
+ # Show details for a specific project
17
+ #
18
+ def find(project_id)
19
+ raw_response = get_request("projects/#{project_id}")
20
+ parse_response(raw_response, :project)
21
+ end
22
+
23
+ #
24
+ # Create a Project, will initially have no members
25
+ # attributes: name, devurl, is_public, is_active
26
+ #
27
+ def create(attributes={})
28
+ raw_response = post_request("projects", project: attributes)
29
+ parse_response(raw_response, :project)
30
+ end
31
+
32
+ #
33
+ # Update settings for an existing project under your control (ie: only the ones you own).
34
+ #
35
+ def update(project_id, attributes={})
36
+ raw_response = put_request("projects/#{project_id}", project: attributes)
37
+ parse_response(raw_response, :project)
38
+ end
39
+
40
+ #
41
+ # Delete a project and all associated data. Use with care, deleted projects cannot be recovered.
42
+ #
43
+ def delete(project_id)
44
+ raw_response = delete_request("projects/#{project_id}")
45
+ parse_response(raw_response)
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,64 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V1
4
+
5
+ class Task < Base
6
+
7
+ PRIORITIES = ['not set', 'critical', 'important', 'normal','minor']
8
+ PRIORITIES.each.with_index do |priority, index|
9
+ Task.const_set("PRIORITY_#{priority.gsub(' ', '').upcase}", index)
10
+ end
11
+
12
+ STATUSES = ['feedback', 'backlog','todo','doing','done','closed']
13
+ STATUSES.each.with_index do |status, index|
14
+ if index == 0
15
+ Task.const_set("STATUS_#{status.upcase}", nil)
16
+ else
17
+ Task.const_set("STATUS_#{status.upcase}", index-1)
18
+ end
19
+ end
20
+
21
+ #
22
+ # Get a full list of tasks for a project, including archived tasks.
23
+ # filters: updated_since, created_since, status, priority, tag and external_id
24
+ def all(project_id, filter_attributes={})
25
+ params = filter_attributes.empty? ? {} : { params: filter_attributes }
26
+ raw_response = get_request("projects/#{project_id}/tasks", params)
27
+ parse_response(raw_response, :tasks)
28
+ end
29
+
30
+ #
31
+ # List details of a task in a given project, includes all data including comments, attachments, etc.
32
+ #
33
+ def find(project_id, task_id)
34
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}")
35
+ parse_response(raw_response)
36
+ end
37
+
38
+ #
39
+ # Create a new Task
40
+ # attributes:
41
+ # description, priority, status, tag_names(Array),
42
+ # requester_id or requester_email,
43
+ # assigned_to_id or assigned_to_email
44
+ # external_id
45
+ # if status is null the Task is automatically put in the Feedback panel
46
+ # "requester_email" can be any email address while "assigned_to_email" needs to be of a current project member.
47
+ # Values for "priority" are not set, critical, important, normal, and minor.
48
+ # Values for "status" are backlog, todo, doing, done, and closed. Omit this field or set as "null" to send tasks to the Feedback panel.
49
+ # External ID is an API-only field. It cannot be set from the BugHerd application, only using the API. An external ID can be used to track originating IDs from other systems in BugHerd bugs.
50
+ def create(project_id, attributes={})
51
+ raw_response = post_request("projects/#{project_id}/tasks", task: attributes)
52
+ parse_response(raw_response)
53
+ end
54
+
55
+ def update(project_id, task_id, attributes={})
56
+ raw_response = put_request("projects/#{project_id}/tasks/#{task_id}", task: attributes)
57
+ parse_response(raw_response)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V1
4
+ class User < Base
5
+
6
+ #
7
+ # See all the people in your account.
8
+ #
9
+ def all
10
+ raw_response = get_request('users')
11
+ parse_response(raw_response, :users)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ require 'json'
2
+
3
+ module BugherdClient
4
+ module Resources
5
+ module V2
6
+
7
+ class Base
8
+
9
+ DEFAULT_HEADERS = { content_type: :json, accept: :json }
10
+
11
+ attr_accessor :connection, :options
12
+ def initialize(conn, opts={})
13
+ @connection, @options = conn, opts
14
+ end
15
+
16
+ def send_request(method="GET", path="", params={}, headers={})
17
+ headers = DEFAULT_HEADERS.merge(headers)
18
+ params.merge!(headers)
19
+ method_name = method.to_s.downcase
20
+ self.connection[path].__send__(method_name, params)
21
+ end
22
+
23
+ [:get, :post, :put, :patch, :delete].each do |method_name|
24
+ define_method("#{method_name}_request") do |path, params={}|
25
+ send_request(method_name, path, params)
26
+ end
27
+ end
28
+
29
+ def parse_response(response, root_element=nil)
30
+ if root_element
31
+ JSON.parse(response)[root_element.to_s]
32
+ else
33
+ JSON.parse(response)
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V2
4
+
5
+ class Comment < Base
6
+
7
+ #
8
+ # Get a paginated list of comments for a task.
9
+ #
10
+ def all(project_id, task_id)
11
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}/comments")
12
+ parse_response(raw_response, :comments)
13
+ end
14
+
15
+ #
16
+ # Get a single comment of a Task
17
+ #
18
+ def find(project_id, task_id, comment_id)
19
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}/comments/#{comment_id}")
20
+ parse_response(raw_response, :comment)
21
+ end
22
+
23
+ #
24
+ # Create a comment
25
+ # attributes: text, user_id or email
26
+ def create(project_id, task_id, attributes={})
27
+ raw_response = post_request("projects/#{project_id}/tasks/#{task_id}/comments", comment: attributes)
28
+ parse_response(raw_response)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V2
4
+
5
+ class Organization < Base
6
+
7
+ #
8
+ # Get more detail of your account.
9
+ #
10
+ def get
11
+ raw_response = self.connection['organization'].get
12
+ parse_response(raw_response, :organization)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,80 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V2
4
+
5
+ class Project < Base
6
+
7
+ #
8
+ # Get more detail of your account.
9
+ #
10
+ def all
11
+ raw_response = get_request('projects')
12
+ parse_response(raw_response, :projects)
13
+ end
14
+
15
+ #
16
+ # Show details for a specific project
17
+ #
18
+ def find(project_id)
19
+ raw_response = get_request("projects/#{project_id}")
20
+ parse_response(raw_response, :project)
21
+ end
22
+
23
+ #
24
+ # Create a Project, will initially have no members
25
+ # attributes: name, devurl, is_public, is_active
26
+ #
27
+ def create(attributes={})
28
+ raw_response = post_request("projects", project: attributes)
29
+ parse_response(raw_response, :project)
30
+ end
31
+
32
+ #
33
+ # Update settings for an existing project under your control (ie: only the ones you own).
34
+ # API: 1,2
35
+ def update(project_id, attributes={})
36
+ raw_response = put_request("projects/#{project_id}", project: attributes)
37
+ parse_response(raw_response, :project)
38
+ end
39
+
40
+ #
41
+ # Delete a project and all associated data. Use with care, deleted projects cannot be recovered.
42
+ # API: 1,2
43
+ def delete(project_id)
44
+ raw_response = delete_request("projects/#{project_id}")
45
+ parse_response(raw_response)
46
+ end
47
+
48
+ #
49
+ # Add an existing guest to a project, or invite someone by email address.
50
+ # required: project_id
51
+ # attributes: user_id, email
52
+ # API: 2
53
+ def add_guest(project_id, attributes={})
54
+ raw_response = post_request("projects/#{project_id}/add_guest", attributes)
55
+ parse_response(raw_response)
56
+ end
57
+
58
+ #
59
+ # Add an existing guest to a project, or invite someone by email address.
60
+ # required: project_id
61
+ # attributes: user_id
62
+ #
63
+ def add_member(project_id, attributes={})
64
+ raw_response = post_request("projects/#{project_id}/add_member", attributes)
65
+ parse_response(raw_response)
66
+ end
67
+
68
+
69
+ #
70
+ # Get all active projects
71
+ #
72
+ def active
73
+ raw_response = get_request('projects/active')
74
+ parse_response(raw_response, :projects)
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,60 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V2
4
+
5
+ class Task < Base
6
+
7
+ PRIORITIES = ['not set', 'critical', 'important', 'normal','minor']
8
+ PRIORITIES.each do |priority|
9
+ Task.const_set("PRIORITY_#{priority.gsub(' ', '').upcase}", priority)
10
+ end
11
+
12
+ STATUSES = ['backlog','todo','doing','done','closed']
13
+ STATUSES.each do |status|
14
+ Task.const_set("STATUS_#{status.upcase}", status)
15
+ end
16
+
17
+ #
18
+ # Get a full list of tasks for a project, including archived tasks.
19
+ # filters: updated_since, created_since, status, priority, tag and external_id
20
+ def all(project_id, filter_attributes={})
21
+ params = filter_attributes.empty? ? {} : { params: filter_attributes }
22
+ raw_response = get_request("projects/#{project_id}/tasks", params)
23
+ parse_response(raw_response, :tasks)
24
+ end
25
+
26
+ #
27
+ # List details of a task in a given project, includes all data including comments, attachments, etc.
28
+ #
29
+ def find(project_id, task_id)
30
+ raw_response = get_request("projects/#{project_id}/tasks/#{task_id}")
31
+ parse_response(raw_response)
32
+ end
33
+
34
+ #
35
+ # Create a new Task
36
+ # attributes:
37
+ # description, priority, status, tag_names(Array),
38
+ # requester_id or requester_email,
39
+ # assigned_to_id or assigned_to_email
40
+ # external_id
41
+ # if status is null the Task is automatically put in the Feedback panel
42
+ # "requester_email" can be any email address while "assigned_to_email" needs to be of a current project member.
43
+ # Values for "priority" are not set, critical, important, normal, and minor.
44
+ # Values for "status" are backlog, todo, doing, done, and closed. Omit this field or set as "null" to send tasks to the Feedback panel.
45
+ # External ID is an API-only field. It cannot be set from the BugHerd application, only using the API. An external ID can be used to track originating IDs from other systems in BugHerd bugs.
46
+ def create(project_id, attributes={})
47
+ raw_response = post_request("projects/#{project_id}/tasks", task: attributes)
48
+ parse_response(raw_response)
49
+ end
50
+
51
+ def update(project_id, task_id, attributes={})
52
+ raw_response = put_request("projects/#{project_id}/tasks/#{task_id}", task: attributes)
53
+ parse_response(raw_response)
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,33 @@
1
+ module BugherdClient
2
+ module Resources
3
+ module V2
4
+ class User < Base
5
+
6
+ #
7
+ # See all the people in your account.
8
+ #
9
+ def all
10
+ raw_response = get_request('users')
11
+ parse_response(raw_response, :users)
12
+ end
13
+
14
+ #
15
+ # See all your account members
16
+ #
17
+ def members
18
+ raw_response = get_request('users/members')
19
+ parse_response(raw_response, :users)
20
+ end
21
+
22
+ #
23
+ # See all the guest in your account
24
+ #
25
+ def guests
26
+ raw_response = get_request('users/guests')
27
+ parse_response(raw_response, :users)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module BugherdClient
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 2
6
+
7
+ STRING = [MAJOR,MINOR,PATCH].join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bugherd_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John Faucett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>'
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '5.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>'
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.5'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.5'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '2.14'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '2.14'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Ruby Client for the Bugherd Rest API
90
+ email:
91
+ - jwaterfaucett@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - .gitignore
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bugherd_client.gemspec
102
+ - lib/bugherd_client.rb
103
+ - lib/bugherd_client/client.rb
104
+ - lib/bugherd_client/errors.rb
105
+ - lib/bugherd_client/resources/base.rb
106
+ - lib/bugherd_client/resources/comment.rb
107
+ - lib/bugherd_client/resources/organization.rb
108
+ - lib/bugherd_client/resources/project.rb
109
+ - lib/bugherd_client/resources/task.rb
110
+ - lib/bugherd_client/resources/user.rb
111
+ - lib/bugherd_client/resources/v1/base.rb
112
+ - lib/bugherd_client/resources/v1/comment.rb
113
+ - lib/bugherd_client/resources/v1/project.rb
114
+ - lib/bugherd_client/resources/v1/task.rb
115
+ - lib/bugherd_client/resources/v1/user.rb
116
+ - lib/bugherd_client/resources/v2/base.rb
117
+ - lib/bugherd_client/resources/v2/comment.rb
118
+ - lib/bugherd_client/resources/v2/organization.rb
119
+ - lib/bugherd_client/resources/v2/project.rb
120
+ - lib/bugherd_client/resources/v2/task.rb
121
+ - lib/bugherd_client/resources/v2/user.rb
122
+ - lib/bugherd_client/version.rb
123
+ homepage: ''
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.0.3
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Ruby Client for the Bugherd API
147
+ test_files: []