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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0bcd4453cc95825470d7c96cd95a694dc4942bd
4
- data.tar.gz: d3a15e2ac22b153ae89fabf103a7c8123f4a2d5c
3
+ metadata.gz: 4ec7b13c5d4f63ae57892ccd4ef89e6d1ab7f17e
4
+ data.tar.gz: 7e038d8e2144a1073d856444d13f2f5139b5aa27
5
5
  SHA512:
6
- metadata.gz: ffd91b8c06845d81ea2d86210e927b1e678bbed9ef931b9d3cfda2e0af9ed04a043847f9714dd4ad5ebf5d3038181f920c4aecd4e49085f8552952ee58eab8b2
7
- data.tar.gz: 980f304b6c230cfcd048d67c8d7bcd3f10bae346906d543327493850acd2be7bfc1508c572e3eabf764943cbd7437a6f96ddaa56d1e6fe172429dbc754f77e95
6
+ metadata.gz: 5744125f1d34b0dfb92e385956fae6ff9501491b0a23a4cc1d276a4bcaf5cbd2f67a73f1a79247126c8b1bd2ca90794d23da766a22c8dbdbc25aa367d7e7338e
7
+ data.tar.gz: c014c9e44d7c84690bc6653aad78dd1f8889e8feef09bc60186ed035cfa2ee9c30fb3003aac9b130a715f47219886120b3d6f751d923b619a6021d2acf10fd07
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
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
- # BugherdClient
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
- This is a Rest Client for the Bugherd API. It fully covers all methods of the v1 and v2 API Implementations.
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 = BugherdClient::Client.new(api_key: 'someapikey', api_version: 2) # api_version 2 is the default
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
- client.users.all # => returns a list of all users
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
- client.tasks.create(project[:id], {
32
- description: 'Some description',
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: BugherdClient::Resources::Task::STATUS_BACKLOG,
35
- priority: BugherdClient::Resources::Task::PRIORITY_NORMAL,
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
- VALID_API_VERSIONS = [1,2].freeze
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(options={}, &block)
21
- @options = DEFAULT_OPTIONS.merge(options)
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 VALID_API_VERSIONS.include?(@options[:api_version])
48
- raise BugherdClient::Errors::InvalidOption, "api_version must be #{VALID_API_VERSIONS.join(',')}"
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, opts={})
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, self.options)
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
- DEFAULT_HEADERS = { content_type: :json, accept: :json }
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 = DEFAULT_HEADERS.merge(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)[root_element.to_s]
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
- attr_accessor :connection, :options
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
@@ -2,7 +2,7 @@ module BugherdClient
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 5
5
+ PATCH = 6
6
6
 
7
7
  STRING = [MAJOR,MINOR,PATCH].join('.')
8
8
  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
@@ -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.5
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