bugherd_client 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +22 -0
- data/README.md +26 -11
- data/lib/bugherd_client/client.rb +9 -11
- data/lib/bugherd_client/resources/v1/base.rb +11 -3
- data/lib/bugherd_client/resources/v2/base.rb +7 -1
- data/lib/bugherd_client/version.rb +1 -1
- data/spec/bugherd_client/client_spec.rb +22 -0
- data/spec/spec_helper.rb +23 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ec7b13c5d4f63ae57892ccd4ef89e6d1ab7f17e
|
4
|
+
data.tar.gz: 7e038d8e2144a1073d856444d13f2f5139b5aa27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5744125f1d34b0dfb92e385956fae6ff9501491b0a23a4cc1d276a4bcaf5cbd2f67a73f1a79247126c8b1bd2ca90794d23da766a22c8dbdbc25aa367d7e7338e
|
7
|
+
data.tar.gz: c014c9e44d7c84690bc6653aad78dd1f8889e8feef09bc60186ed035cfa2ee9c30fb3003aac9b130a715f47219886120b3d6f751d923b619a6021d2acf10fd07
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- ruby-head
|
6
|
+
- jruby-19mode
|
7
|
+
- jruby-head
|
8
|
+
script:
|
9
|
+
- bundle exec rspec
|
10
|
+
|
11
|
+
branches:
|
12
|
+
only:
|
13
|
+
- master
|
14
|
+
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: ruby-head
|
18
|
+
- rvm: jruby-head
|
19
|
+
|
20
|
+
notifications:
|
21
|
+
email:
|
22
|
+
- jwaterfaucett@gmail.com
|
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/bugherd_client.svg)](http://badge.fury.io/rb/bugherd_client)
|
2
|
+
[![Dependency Status](https://gemnasium.com/jwaterfaucett/bugherd_client.svg)](https://gemnasium.com/jwaterfaucett/bugherd_client)
|
3
|
+
[![Build Status](https://travis-ci.org/jwaterfaucett/bugherd_client.svg?branch=master)](https://travis-ci.org/jwaterfaucett/bugherd_client)
|
2
4
|
|
3
|
-
|
5
|
+
|
6
|
+
# BugHerd Client
|
7
|
+
|
8
|
+
This is a Rest Client for the BugHerd API. It fully covers all methods of the v1 and v2 API Implementations.
|
4
9
|
Another nifty feature is that its threadsafe so you could potentially have many instances floating around and don't
|
5
10
|
have to worry about collisions as is the case with ActiveResource.
|
6
11
|
|
@@ -22,21 +27,31 @@ Or install it yourself as:
|
|
22
27
|
|
23
28
|
```ruby
|
24
29
|
|
25
|
-
client
|
30
|
+
# create a client form an api_key, it will automatically use v2 of the BugHerd API
|
31
|
+
client = BugherdClient::Client.new(api_key: 'someapikey')
|
32
|
+
|
33
|
+
# Get information about your organization
|
26
34
|
client.organization.get # => returns your organization information
|
27
|
-
|
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
|
39
|
+
|
40
|
+
# Find a specific project
|
28
41
|
project = client.projects.find(1023)
|
29
|
-
user = client.users.all.first
|
30
42
|
|
31
|
-
|
32
|
-
|
43
|
+
# Create a new Task
|
44
|
+
task = client.tasks.create(project[:id], {
|
45
|
+
description: 'This is a description',
|
33
46
|
requester_id: user[:id],
|
34
|
-
status:
|
35
|
-
priority:
|
36
|
-
external_id: 'my-external-app-123'
|
47
|
+
status: 'backlog',
|
48
|
+
priority: 'normal'
|
37
49
|
})
|
38
50
|
|
39
|
-
|
51
|
+
# Create a comment
|
52
|
+
client.comments.create(project[:id], task[:id], {
|
53
|
+
text: 'hey this is a comment'
|
54
|
+
})
|
40
55
|
|
41
56
|
```
|
42
57
|
|
@@ -3,7 +3,7 @@ require 'logger'
|
|
3
3
|
module BugherdClient
|
4
4
|
class Client
|
5
5
|
|
6
|
-
|
6
|
+
API_VERSIONS = [1,2].freeze
|
7
7
|
|
8
8
|
DEFAULT_OPTIONS = {
|
9
9
|
base_url: 'https://www.bugherd.com',
|
@@ -13,12 +13,12 @@ module BugherdClient
|
|
13
13
|
api_key: '',
|
14
14
|
api_rate_limiting_token: 'x',
|
15
15
|
debug: false
|
16
|
-
}
|
16
|
+
}.freeze
|
17
17
|
|
18
18
|
attr_accessor :options, :connection
|
19
19
|
|
20
|
-
def initialize(
|
21
|
-
@options = DEFAULT_OPTIONS.merge(
|
20
|
+
def initialize(opts={}, &block)
|
21
|
+
@options = DEFAULT_OPTIONS.merge(opts)
|
22
22
|
yield(self) if block_given?
|
23
23
|
establish_connection!
|
24
24
|
end
|
@@ -31,9 +31,7 @@ module BugherdClient
|
|
31
31
|
RestClient.log = ::Logger.new($stderr)
|
32
32
|
RestClient.log.level = ::Logger::DEBUG
|
33
33
|
end
|
34
|
-
|
35
34
|
self.connection = RestClient::Resource.new(base_url, user: username, password: password)
|
36
|
-
|
37
35
|
end
|
38
36
|
|
39
37
|
def base_url
|
@@ -44,23 +42,23 @@ module BugherdClient
|
|
44
42
|
if !@options[:api_key] && !(@options[:username] && @options[:password])
|
45
43
|
raise BugherdClient::Errors::InvalidOption, "api_key or username and password is required"
|
46
44
|
end
|
47
|
-
unless
|
48
|
-
raise BugherdClient::Errors::InvalidOption, "api_version must be #{
|
45
|
+
unless API_VERSIONS.include?(@options[:api_version])
|
46
|
+
raise BugherdClient::Errors::InvalidOption, "api_version must be #{API_VERSIONS.join(',')}"
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
50
|
def build_credentials
|
53
|
-
if @options[:api_key]
|
51
|
+
if @options[:api_key].present?
|
54
52
|
[@options[:api_key], @options[:api_rate_limiting_token]]
|
55
53
|
else
|
56
54
|
[@options[:username], @options[:password]]
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
|
-
def resource(name
|
58
|
+
def resource(name)
|
61
59
|
version = self.options[:api_version]
|
62
60
|
klass = "BugherdClient::Resources::V#{version}::#{name.to_s.classify}".constantize
|
63
|
-
klass.new(self.connection,
|
61
|
+
klass.new(self.connection, @options)
|
64
62
|
end
|
65
63
|
|
66
64
|
#
|
@@ -6,7 +6,10 @@ module BugherdClient
|
|
6
6
|
|
7
7
|
class Base
|
8
8
|
|
9
|
-
|
9
|
+
DEFAULT_HEADER_ATTRS = {
|
10
|
+
'Content-Type' => 'application/json',
|
11
|
+
'Accept' => 'application/json'
|
12
|
+
}.freeze
|
10
13
|
|
11
14
|
#
|
12
15
|
# Return a list of available methods in a Resource
|
@@ -21,7 +24,7 @@ module BugherdClient
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def send_request(method="GET", path="", params={}, headers={})
|
24
|
-
headers =
|
27
|
+
headers = DEFAULT_HEADER_ATTRS.merge(headers)
|
25
28
|
params.merge!(headers)
|
26
29
|
method_name = method.to_s.downcase
|
27
30
|
self.connection[path].__send__(method_name, params)
|
@@ -35,7 +38,12 @@ module BugherdClient
|
|
35
38
|
|
36
39
|
def parse_response(response, root_element=nil)
|
37
40
|
if root_element
|
38
|
-
JSON.parse(response)
|
41
|
+
pr = JSON.parse(response)
|
42
|
+
if pr.is_a?(Hash) and pr.has_key?(root_element)
|
43
|
+
pr[root_element]
|
44
|
+
else
|
45
|
+
pr
|
46
|
+
end
|
39
47
|
else
|
40
48
|
JSON.parse(response)
|
41
49
|
end
|
@@ -11,8 +11,14 @@ module BugherdClient
|
|
11
11
|
:accept => :json
|
12
12
|
}.freeze
|
13
13
|
|
14
|
-
|
14
|
+
#
|
15
|
+
# Return a list of available methods in a Resource
|
16
|
+
#
|
17
|
+
def api_methods
|
18
|
+
self.class.instance_methods(false)
|
19
|
+
end
|
15
20
|
|
21
|
+
attr_accessor :connection, :options
|
16
22
|
def initialize(conn, opts={})
|
17
23
|
@connection, @options = conn, opts
|
18
24
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe BugherdClient::Client do
|
5
|
+
|
6
|
+
it "should list API_VERSIONS 1 and 2" do
|
7
|
+
BugherdClient::Client::API_VERSIONS.should include(1)
|
8
|
+
BugherdClient::Client::API_VERSIONS.should include(2)
|
9
|
+
end
|
10
|
+
|
11
|
+
context "default options" do
|
12
|
+
|
13
|
+
it "should have a default api_version of 2" do
|
14
|
+
BugherdClient::Client::DEFAULT_OPTIONS[:api_version].should eq(2)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have an api_rate_limiting_token that defaults to x" do
|
18
|
+
BugherdClient::Client::DEFAULT_OPTIONS[:api_rate_limiting_token].should eq('x')
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
lib = File.expand_path("../lib", __FILE__)
|
9
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
10
|
+
|
11
|
+
require 'bugherd_client'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
config.order = 'random'
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bugherd_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Faucett
|
@@ -94,6 +94,8 @@ extensions: []
|
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
96
|
- .gitignore
|
97
|
+
- .rspec
|
98
|
+
- .travis.yml
|
97
99
|
- Gemfile
|
98
100
|
- LICENSE.txt
|
99
101
|
- README.md
|
@@ -114,6 +116,8 @@ files:
|
|
114
116
|
- lib/bugherd_client/resources/v2/task.rb
|
115
117
|
- lib/bugherd_client/resources/v2/user.rb
|
116
118
|
- lib/bugherd_client/version.rb
|
119
|
+
- spec/bugherd_client/client_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
117
121
|
homepage: ''
|
118
122
|
licenses:
|
119
123
|
- MIT
|
@@ -138,4 +142,6 @@ rubygems_version: 2.0.3
|
|
138
142
|
signing_key:
|
139
143
|
specification_version: 4
|
140
144
|
summary: Ruby Client for the Bugherd API
|
141
|
-
test_files:
|
145
|
+
test_files:
|
146
|
+
- spec/bugherd_client/client_spec.rb
|
147
|
+
- spec/spec_helper.rb
|