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
@@ -1,22 +1,74 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe(BugherdClient::Client) do
4
+ let(:client_klass) { BugherdClient::Client }
5
+ context 'supported_versions' do
3
6
 
4
- describe BugherdClient::Client do
7
+ it 'should list API_VERSIONS 1 and 2' do
8
+ expect(BugherdClient::Client::API_VERSIONS).to eq([1,2])
9
+ end
5
10
 
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
11
  end
10
12
 
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)
13
+ context 'default_options' do
14
+ it 'should have a default api_version of 2' do
15
+ expect(client_klass::DEFAULT_OPTIONS[:api_version]).to eq(2)
16
+ end
17
+
18
+
19
+ it 'should have an api_rate_limiting_token that defaults to x' do
20
+ expect(client_klass::DEFAULT_OPTIONS[:api_rate_limiting_token]).to eq('x')
21
+ end
22
+
23
+ it 'should have a base_url with https as scheme and www.bugherd.com as host' do
24
+ u = URI.parse(client_klass::DEFAULT_OPTIONS[:base_url])
25
+ expect(u.scheme).to eq('https')
26
+ expect(u.host).to eq('www.bugherd.com')
15
27
  end
16
28
 
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')
29
+ end
30
+
31
+ context '#initialize' do
32
+ it 'should set options when taking a block' do
33
+ client = BugherdClient::Client.new do |c|
34
+ c.username = 'user'
35
+ c.password = 'pass'
36
+ c.api_key = 'foo'
37
+ c.debug = false
38
+ end
39
+
40
+ expect(client.options[:username]).to eq('user')
41
+ expect(client.options[:password]).to eq('pass')
42
+ expect(client.options[:api_key]).to eq('foo')
43
+ expect(client.options[:debug]).to eq(false)
19
44
  end
20
45
 
46
+ it 'should create debug logging when the debug flag is set' do
47
+ expect(RestClient.log).to eq(nil)
48
+ client = BugherdClient::Client.new(api_key: 'apikey', debug: true)
49
+ expect(RestClient.log.level).to eq(Logger::DEBUG)
50
+ end
21
51
  end
22
- end
52
+
53
+ context 'initialization_errors' do
54
+
55
+ it 'should raise an error when no api_key or username and password is passed' do
56
+ expect {
57
+ c = BugherdClient::Client.new
58
+ }.to raise_error(BugherdClient::Errors::InvalidOption)
59
+ end
60
+
61
+ it 'should raise an error when a username but no password is passed' do
62
+ expect {
63
+ c = BugherdClient::Client.new(username: 'bob')
64
+ }.to raise_error(BugherdClient::Errors::InvalidOption)
65
+ end
66
+
67
+ it 'should raise an error when an invalid api_version is passed' do
68
+ expect {
69
+ c = BugherdClient::Client.new(api_version: 99)
70
+ }.to raise_error(BugherdClient::Errors::InvalidOption)
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'http_helper'
3
+
4
+
5
+ describe(BugherdClient::Resources::V2::Organization) do
6
+
7
+ let(:client) do
8
+ client = BugherdClient::Client.new(api_key: 'testing')
9
+ end
10
+
11
+ context 'get', vcr: { cassette_name: "organizations_get", record: :new_episodes } do
12
+
13
+ it 'should return the id and name of the organization' do
14
+ response = client.organizations.get
15
+ expect(response.id).to eq(21203)
16
+ expect(response.name).to eq('testCloud')
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'http_helper'
3
+
4
+ describe(BugherdClient::Resources::V2::Project) do
5
+
6
+ let(:client) do
7
+ client = BugherdClient::Client.new(api_key: 'testing')
8
+ end
9
+
10
+ context 'all', vcr: { cassette_name: "projects_all", record: :new_episodes } do
11
+ it 'should return a list of projects containing id and name' do
12
+ response = client.projects.all
13
+ expect(response).to be_an(Array)
14
+ expect(response.count).to eq(2)
15
+
16
+ p1 = response.first
17
+ expect(p1.id).to eq(40093)
18
+ expect(p1.name).to eq('MyTestProject')
19
+ end
20
+ end
21
+
22
+ context 'find_success', vcr: { cassette_name: "projects_find_success", record: :new_episodes } do
23
+ it 'should return a project when the project exists' do
24
+ response = client.projects.find(40093)
25
+
26
+ expect(response.id).to eq(40093)
27
+ expect(response.name).to eq('MyTestProject')
28
+ expect(response.devurl).to be_a(String)
29
+ expect(response.api_key).to be_a(String)
30
+ expect(response.is_active).to eq(true)
31
+ expect(response.members).to be_an(Array)
32
+ expect(response.guests).to be_an(Array)
33
+
34
+ m = response.members.first
35
+ expect(m.id).to eq(50190)
36
+ expect(m.display_name).to eq('John Faucett')
37
+
38
+ g = response.guests.first
39
+ expect(g.id).to eq(50536)
40
+ expect(g.display_name).to eq('tilman.bahls@testcloud.de')
41
+ end
42
+ end
43
+
44
+ context 'find_failure', vcr: { cassette_name: "projects_find_failure", record: :new_episodes } do
45
+ it 'should raise an error when project does not exist' do
46
+ expect {
47
+ client.projects.find(1)
48
+ }.to raise_error(BugherdClient::Errors::HttpRequestError, /404 Resource Not Found/)
49
+ end
50
+ end
51
+
52
+ context 'active', vcr: { cassette_name: "projects_active", record: :new_episodes } do
53
+ it 'should return all active projects' do
54
+ response = client.projects.active
55
+
56
+ expect(response).to be_an(Array)
57
+ expect(response.count).to eq(2)
58
+
59
+ p1 = response.first
60
+ expect(p1.id).to eq(40093)
61
+ expect(p1.name).to eq('MyTestProject')
62
+ end
63
+ end
64
+
65
+
66
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'http_helper'
3
+
4
+ describe(BugherdClient::Resources::V2::Project) do
5
+
6
+ let(:client) do
7
+ client = BugherdClient::Client.new(api_key: 'testing')
8
+ end
9
+ let(:project_id) { 40093 }
10
+
11
+ context 'all', vcr: { cassette_name: 'tasks_all', record: :new_episodes } do
12
+ it 'should return a list of tasks in a project' do
13
+ tasks = client.tasks.all(project_id)
14
+ expect(tasks).to be_an(Array)
15
+ expect(tasks.count).to eq(7)
16
+ t = tasks.first
17
+
18
+ expect(t).to have_key(:id)
19
+ expect(t).to have_key(:created_at)
20
+ expect(t).to have_key(:updated_at)
21
+ expect(t).to have_key(:local_task_id)
22
+ expect(t).to have_key(:priority_id)
23
+ expect(t).to have_key(:assigned_to_id)
24
+ expect(t).to have_key(:status_id)
25
+ expect(t).to have_key(:description)
26
+ expect(t).to have_key(:tag_names)
27
+ expect(t.tag_names).to be_an(Array)
28
+ expect(t).to have_key(:external_id)
29
+ expect(t).to have_key(:requester_id)
30
+ expect(t).to have_key(:requester_email)
31
+ end
32
+ end
33
+
34
+ context 'find_success', vcr: { cassette_name: 'tasks_find_success', record: :new_episodes } do
35
+ let(:task_id) { 1035995 }
36
+ it 'should return a task when it exists' do
37
+ t = client.tasks.find(project_id, task_id)
38
+
39
+ expect(t).to have_key(:id)
40
+ expect(t).to have_key(:created_at)
41
+ expect(t).to have_key(:updated_at)
42
+ expect(t).to have_key(:priority)
43
+ expect(t).to have_key(:status)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'http_helper'
3
+
4
+ describe(BugherdClient::Resources::V2::User) do
5
+
6
+ let(:client) do
7
+ client = BugherdClient::Client.new(api_key: 'testing')
8
+ end
9
+
10
+ context 'all', vcr: { cassette_name: 'users_all', record: :new_episodes } do
11
+ it 'should return a list of all users in an organization' do
12
+ users = client.users.all
13
+ expect(users).to be_an(Array)
14
+
15
+ u = users.first
16
+ expect(u).to have_key(:id)
17
+ expect(u).to have_key(:email)
18
+ expect(u).to have_key(:display_name)
19
+ expect(u).to have_key(:avatar_url)
20
+ end
21
+ end
22
+
23
+ context 'members', vcr: { cassette_name: 'members_all', record: :new_episodes } do
24
+ it 'should return a list of all members in an organization' do
25
+ members = client.users.members
26
+ expect(members).to be_an(Array)
27
+
28
+ m = members.first
29
+
30
+ expect(m).to have_key(:id)
31
+ expect(m).to have_key(:email)
32
+ expect(m).to have_key(:display_name)
33
+ expect(m).to have_key(:avatar_url)
34
+ end
35
+ end
36
+
37
+ context 'guests', vcr: { cassette_name: 'guests_all', record: :new_episodes } do
38
+ it 'should return a list of all guests in an organization' do
39
+ guests = client.users.guests
40
+ expect(guests).to be_an(Array)
41
+
42
+ g = guests.first
43
+
44
+ expect(g).to have_key(:id)
45
+ expect(g).to have_key(:email)
46
+ expect(g).to have_key(:display_name)
47
+ expect(g).to have_key(:avatar_url)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'http_helper'
3
+
4
+
5
+ describe(BugherdClient::Resources::V2::Organization) do
6
+
7
+ let(:client) do
8
+ client = BugherdClient::Client.new(api_key: 'testing')
9
+ end
10
+
11
+ context 'all', vcr: { cassette_name: "webhooks_all", record: :new_episodes } do
12
+
13
+ it 'should return a list of webhooks' do
14
+ response = client.webhooks.all
15
+ expect(response).to be_an(Array)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,64 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://testing:x@www.bugherd.com/api_v2/users/guests
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ X-Rack-Cache:
26
+ - miss
27
+ Cache-Control:
28
+ - must-revalidate, private, max-age=0
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Date:
32
+ - Tue, 16 Dec 2014 12:27:10 GMT
33
+ Status:
34
+ - 200 OK
35
+ X-Request-Id:
36
+ - bab0226b3420f0cdc6015723754f638b
37
+ X-Xss-Protection:
38
+ - 1; mode=block
39
+ Transfer-Encoding:
40
+ - chunked
41
+ X-Runtime:
42
+ - '0.030071'
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ Etag:
46
+ - '"e408b3684383aaaccd5350fe2fed42a5"'
47
+ Connection:
48
+ - keep-alive
49
+ Set-Cookie:
50
+ - X-Mapping-fjhppofk=E1227771D62C08D6CA46945339FEFF4D; path=/
51
+ - landing=%7B%22utm_source%22%3Anull%2C%22utm_medium%22%3Anull%2C%22utm_campaign%22%3Anull%2C%22utm_term%22%3Anull%2C%22utm_content%22%3Anull%2C%22path%22%3A%22%2Fapi_v2%2Fusers%2Fguests%22%2C%22referer%22%3Anull%2C%22remote_ip%22%3A%2290.156.0.165%22%2C%22time%22%3A%222014-12-16T12%3A27%3A10%2B00%3A00%22%7D;
52
+ path=/; expires=Sat, 16-Dec-2034 12:27:10 GMT
53
+ X-Frame-Options:
54
+ - SAMEORIGIN
55
+ X-Ua-Compatible:
56
+ - IE=Edge,chrome=1
57
+ X-Powered-By:
58
+ - cloud66
59
+ body:
60
+ encoding: UTF-8
61
+ string: '{"users":[{"id":50536,"email":"tilman.bahls@testcloud.de","display_name":"tilman.bahls@testcloud.de","avatar_url":"https://bugherd-attachments.s3.amazonaws.com/zpyio6vsupbtvt82ofjx6w%2Favatar.png"}],"meta":{"count":1}}'
62
+ http_version:
63
+ recorded_at: Tue, 16 Dec 2014 12:27:10 GMT
64
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,66 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://testing:x@www.bugherd.com/api_v2/users/members
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ X-Rack-Cache:
26
+ - miss
27
+ Cache-Control:
28
+ - must-revalidate, private, max-age=0
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Date:
32
+ - Tue, 16 Dec 2014 12:27:09 GMT
33
+ Status:
34
+ - 200 OK
35
+ X-Request-Id:
36
+ - 304c41dfb4b07ed826ab349971fc7e2f
37
+ X-Xss-Protection:
38
+ - 1; mode=block
39
+ Transfer-Encoding:
40
+ - chunked
41
+ X-Runtime:
42
+ - '0.039134'
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ Etag:
46
+ - '"1cf31ec801872c093ed5e65c6a445d44"'
47
+ Connection:
48
+ - keep-alive
49
+ Set-Cookie:
50
+ - X-Mapping-fjhppofk=F79505634CB879F90FD744F06F62BF75; path=/
51
+ - landing=%7B%22utm_source%22%3Anull%2C%22utm_medium%22%3Anull%2C%22utm_campaign%22%3Anull%2C%22utm_term%22%3Anull%2C%22utm_content%22%3Anull%2C%22path%22%3A%22%2Fapi_v2%2Fusers%2Fmembers%22%2C%22referer%22%3Anull%2C%22remote_ip%22%3A%2290.156.0.165%22%2C%22time%22%3A%222014-12-16T12%3A27%3A09%2B00%3A00%22%7D;
52
+ path=/; expires=Sat, 16-Dec-2034 12:27:09 GMT
53
+ X-Frame-Options:
54
+ - SAMEORIGIN
55
+ X-Ua-Compatible:
56
+ - IE=Edge,chrome=1
57
+ X-Powered-By:
58
+ - cloud66
59
+ body:
60
+ encoding: UTF-8
61
+ string: '{"users":[{"id":50194,"email":"jan.schwenzien@testcloud.de","display_name":"Jan
62
+ Schwenzien","avatar_url":"https://www.bugherd.com/images/sidebar/avatar-generic.png"},{"id":50190,"email":"john.faucett@testcloud.de","display_name":"John
63
+ Faucett","avatar_url":"https://www.bugherd.com/images/sidebar/avatar-generic.png"}],"meta":{"count":2}}'
64
+ http_version:
65
+ recorded_at: Tue, 16 Dec 2014 12:27:09 GMT
66
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://testing:x@www.bugherd.com/api_v2/organization
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ X-Rack-Cache:
24
+ - miss
25
+ Cache-Control:
26
+ - must-revalidate, private, max-age=0
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Date:
30
+ - Tue, 16 Dec 2014 10:12:33 GMT
31
+ Status:
32
+ - 200 OK
33
+ X-Request-Id:
34
+ - a4556a70c2d77eacc98719a9cf1db61a
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ Transfer-Encoding:
38
+ - chunked
39
+ X-Runtime:
40
+ - '0.031217'
41
+ X-Content-Type-Options:
42
+ - nosniff
43
+ Etag:
44
+ - '"2268e965d1b289cb0de8af3514b1993c"'
45
+ Connection:
46
+ - keep-alive
47
+ Set-Cookie:
48
+ - X-Mapping-fjhppofk=F79505634CB879F90FD744F06F62BF75; path=/
49
+ - landing=%7B%22utm_source%22%3Anull%2C%22utm_medium%22%3Anull%2C%22utm_campaign%22%3Anull%2C%22utm_term%22%3Anull%2C%22utm_content%22%3Anull%2C%22path%22%3A%22%2Fapi_v2%2Forganization%22%2C%22referer%22%3Anull%2C%22remote_ip%22%3A%2290.156.0.165%22%2C%22time%22%3A%222014-12-16T10%3A12%3A33%2B00%3A00%22%7D;
50
+ path=/; expires=Sat, 16-Dec-2034 10:12:33 GMT
51
+ X-Frame-Options:
52
+ - SAMEORIGIN
53
+ X-Ua-Compatible:
54
+ - IE=Edge,chrome=1
55
+ X-Powered-By:
56
+ - cloud66
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"organization":{"id":21203,"name":"testCloud"}}'
60
+ http_version:
61
+ recorded_at: Tue, 16 Dec 2014 10:12:33 GMT
62
+ recorded_with: VCR 2.9.3