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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -1
  4. data/.travis.yml +4 -1
  5. data/README.md +23 -38
  6. data/Rakefile +6 -1
  7. data/bin/console +17 -0
  8. data/bugherd_client.gemspec +17 -13
  9. data/lib/bugherd_client.rb +19 -16
  10. data/lib/bugherd_client/client.rb +44 -18
  11. data/lib/bugherd_client/errors.rb +19 -5
  12. data/lib/bugherd_client/resources/v1/base.rb +2 -2
  13. data/lib/bugherd_client/resources/v1/comment.rb +1 -1
  14. data/lib/bugherd_client/resources/v1/project.rb +4 -4
  15. data/lib/bugherd_client/resources/v1/task.rb +11 -8
  16. data/lib/bugherd_client/resources/v2/attachment.rb +73 -0
  17. data/lib/bugherd_client/resources/v2/base.rb +24 -5
  18. data/lib/bugherd_client/resources/v2/comment.rb +2 -2
  19. data/lib/bugherd_client/resources/v2/organization.rb +5 -5
  20. data/lib/bugherd_client/resources/v2/project.rb +22 -13
  21. data/lib/bugherd_client/resources/v2/task.rb +34 -14
  22. data/lib/bugherd_client/resources/v2/webhook.rb +54 -0
  23. data/lib/bugherd_client/version.rb +1 -1
  24. data/spec/bugherd_client/client_spec.rb +63 -11
  25. data/spec/bugherd_client/v2/organization_spec.rb +21 -0
  26. data/spec/bugherd_client/v2/project_spec.rb +66 -0
  27. data/spec/bugherd_client/v2/task_spec.rb +46 -0
  28. data/spec/bugherd_client/v2/user_spec.rb +50 -0
  29. data/spec/bugherd_client/v2/webhook_spec.rb +20 -0
  30. data/spec/cassettes/guests_all.yml +64 -0
  31. data/spec/cassettes/members_all.yml +66 -0
  32. data/spec/cassettes/organizations_get.yml +62 -0
  33. data/spec/cassettes/projects_active.yml +65 -0
  34. data/spec/cassettes/projects_all.yml +65 -0
  35. data/spec/cassettes/projects_find_failure.yml +60 -0
  36. data/spec/cassettes/projects_find_success.yml +65 -0
  37. data/spec/cassettes/tasks_all.yml +87 -0
  38. data/spec/cassettes/tasks_find_success.yml +69 -0
  39. data/spec/cassettes/users_all.yml +66 -0
  40. data/spec/cassettes/webhooks_all.yml +64 -0
  41. data/spec/spec_helper.rb +23 -9
  42. data/spec/support/http_helper.rb +7 -0
  43. metadata +130 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ec7b13c5d4f63ae57892ccd4ef89e6d1ab7f17e
4
- data.tar.gz: 7e038d8e2144a1073d856444d13f2f5139b5aa27
3
+ metadata.gz: 613db28bf8edb0ace5b32f050c8c4774dc072d3a
4
+ data.tar.gz: c0eaa375aefbecfdd0932489723a547660ae91f9
5
5
  SHA512:
6
- metadata.gz: 5744125f1d34b0dfb92e385956fae6ff9501491b0a23a4cc1d276a4bcaf5cbd2f67a73f1a79247126c8b1bd2ca90794d23da766a22c8dbdbc25aa367d7e7338e
7
- data.tar.gz: c014c9e44d7c84690bc6653aad78dd1f8889e8feef09bc60186ed035cfa2ee9c30fb3003aac9b130a715f47219886120b3d6f751d923b619a6021d2acf10fd07
6
+ metadata.gz: de456845c1409857253cac60a58486b21da9f59cf9a5e9146ed4638a58ad8e6d4e0ff6fd66b4507029b92720a626acba33ac6cd066822093e60ec091e2023967
7
+ data.tar.gz: 8527719b03e5ecb6fc771c48b3a5c5d68239f8b92c352fb65cd9b324c1c5110e04e7dcf01859d6c5161cd89d6993f4594ff5702ded79e8930f4bbc6f0e8a43df
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .bundle
5
5
  .config
6
6
  .yardoc
7
+ .envrc
7
8
  Gemfile.lock
8
9
  InstalledFiles
9
10
  _yardoc
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
- --format progress
2
+ --format documentation
3
+ --tty
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. It fully covers all methods of the v1 and v2 API Implementations.
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
- ## Installation
10
+ **features:**
13
11
 
14
- Add this line to your application's Gemfile:
12
+ * Threadsafe
13
+ * Full V1 API support
14
+ * Full V2 API support
15
15
 
16
- gem 'bugherd_client'
16
+ **ruby support:**
17
17
 
18
- And then execute:
18
+ * JRuby
19
+ * Rubinius 2+
20
+ * MRI >= 1.9.3
19
21
 
20
- $ bundle
21
22
 
22
- Or install it yourself as:
23
+ ## Installation
23
24
 
24
25
  $ gem install bugherd_client
25
26
 
26
27
  ## Basic Usage
27
28
 
28
- ```ruby
29
-
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
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
- # Find a specific project
41
- project = client.projects.find(1023)
42
-
43
- # Create a new Task
44
- task = client.tasks.create(project[:id], {
45
- description: 'This is a description',
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. Create new Pull Request
48
+ 5. Write some tests.
49
+ 6. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
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
@@ -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 = "bugherd_client"
7
+ spec.name = 'bugherd_client'
8
8
  spec.version = BugherdClient::VERSION::STRING
9
- spec.authors = ["John Faucett"]
10
- spec.email = ["jwaterfaucett@gmail.com"]
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 = "MIT"
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 = ["lib"]
18
+ spec.require_paths = ['lib']
20
19
 
21
- spec.add_dependency "rest-client", "~> 1.6"
22
- spec.add_dependency "activesupport", "> 3.0", "< 5.0"
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 "bundler", "~> 1.5"
25
- spec.add_development_dependency "rspec", "~> 2.14"
26
- spec.add_development_dependency "rake"
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
@@ -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, "bugherd_client/version"
7
- autoload :Client, "bugherd_client/client"
8
- autoload :Errors, "bugherd_client/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, "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"
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, "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"
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
- @options = DEFAULT_OPTIONS.merge(opts)
22
- yield(self) if block_given?
23
- establish_connection!
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
- self.connection = RestClient::Resource.new(base_url, user: username, password: password)
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, "api_key or username and password is required"
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 BugherdClient::Errors::InvalidOption, "api_version must be #{API_VERSIONS.join(',')}"
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
- klass = "BugherdClient::Resources::V#{version}::#{name.to_s.classify}".constantize
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
- # Resources
66
- #
67
- [:organization, :user, :project, :task, :comment].each do |resource_name|
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("#{resource_name}")
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="invalid option")
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="", attrs=[])
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="GET", path="", params={}, headers={})
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
@@ -30,4 +30,4 @@ module BugherdClient
30
30
 
31
31
  end
32
32
  end
33
- end
33
+ 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("projects", project: attributes)
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