codeclimate-api-ruby-client 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +15 -0
  5. data/.travis.yml +5 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +25 -0
  8. data/Guardfile +49 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +49 -0
  11. data/Rakefile +6 -0
  12. data/TODO.md +22 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/codeclimate-api-ruby-client.gemspec +28 -0
  16. data/fixtures/vcr_cassettes/code_climate/builds/list.yml +60 -0
  17. data/fixtures/vcr_cassettes/code_climate/metrics/gpa.yml +60 -0
  18. data/fixtures/vcr_cassettes/code_climate/orgs/list.yml +60 -0
  19. data/fixtures/vcr_cassettes/code_climate/ref_points/list.yml +60 -0
  20. data/fixtures/vcr_cassettes/code_climate/repos/get.yml +60 -0
  21. data/fixtures/vcr_cassettes/code_climate/services/list.yml +61 -0
  22. data/fixtures/vcr_cassettes/code_climate/snapshots/show.yml +60 -0
  23. data/fixtures/vcr_cassettes/code_climate/test_reports/list.yml +63 -0
  24. data/fixtures/vcr_cassettes/code_climate/user.yml +61 -0
  25. data/lib/code_climate.rb +1 -0
  26. data/lib/code_climate/client.rb +83 -0
  27. data/lib/code_climate/middleware.rb +16 -0
  28. data/lib/code_climate/resources/base.rb +9 -0
  29. data/lib/code_climate/resources/build.rb +8 -0
  30. data/lib/code_climate/resources/metric.rb +8 -0
  31. data/lib/code_climate/resources/org.rb +9 -0
  32. data/lib/code_climate/resources/ref_point.rb +8 -0
  33. data/lib/code_climate/resources/repo.rb +37 -0
  34. data/lib/code_climate/resources/service.rb +8 -0
  35. data/lib/code_climate/resources/snapshot.rb +8 -0
  36. data/lib/code_climate/resources/test_report.rb +8 -0
  37. data/lib/code_climate/resources/user.rb +10 -0
  38. data/lib/code_climate/version.rb +3 -0
  39. metadata +123 -0
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/orgs
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:27 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"2f7f00d7f6925232d6ce911820aca337"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.013162'
47
+ X-Request-Id:
48
+ - 895d4521-11f6-4f93-9b4e-3ed4b2b28c0e
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":[],"links":{}}'
58
+ http_version:
59
+ recorded_at: Sat, 19 Aug 2017 13:20:21 GMT
60
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/repos/592e3170b12e120271000199/ref_points
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:29 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"f6f3d8e4c69a16cd02acbe8192d8538c"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.016548'
47
+ X-Request-Id:
48
+ - 0ef38922-a55d-441e-a95e-252cb858543d
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":[{"id":"592e35d241a3c10001000334","type":"ref_points","attributes":{"analyzed":true,"branch":"master","commit_sha":"bf8c7b6a430e8a27eb4a4f3c65d02bcbb9c1fe2e","created_at":"2017-05-31T03:17:38.970Z","ref":"refs/heads/master"},"relationships":{"snapshot":{"data":{"id":"599555991d132f0001014dd5","type":"snapshots"}}}},{"id":"592e35328b67b00001000341","type":"ref_points","attributes":{"analyzed":true,"branch":"build/add-codeclimate","commit_sha":"7e1ed81c1d81dcd21da5ed5aeb4478ca906998ed","created_at":"2017-05-31T03:14:58.691Z","ref":"refs/pull/8/head"},"relationships":{"snapshot":{"data":{"id":"592e353244016b0001011fa3","type":"snapshots"}}}},{"id":"592e317130ad8500010002e9","type":"ref_points","attributes":{"analyzed":true,"branch":"master","commit_sha":"aa025d1c7af2099642ce7dae7ae4d9f8d9875cc6","created_at":"2017-05-31T02:58:57.330Z","ref":"refs/heads/master"},"relationships":{"snapshot":{"data":{"id":"592e317144016b0001011d73","type":"snapshots"}}}}],"links":{}}'
58
+ http_version:
59
+ recorded_at: Sat, 19 Aug 2017 13:20:23 GMT
60
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/repos/592e3170b12e120271000199
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:21 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"7b76bdc17ec62989b4f890cc40801056"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.023425'
47
+ X-Request-Id:
48
+ - e673b8f7-ca91-481b-a5d9-6391b473001a
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":{"id":"592e3170b12e120271000199","type":"repos","attributes":{"analysis_version":3521,"badge_token":"60afde200c2dbeb3902b","branch":"master","created_at":"2017-05-31T02:58:56.948Z","github_slug":"wnuqui/cm","human_name":"cm","last_activity_at":"2017-08-17T08:36:52.472Z","score":4.0},"relationships":{"latest_default_branch_snapshot":{"data":{"id":"599555991d132f0001014dd5","type":"snapshots"}},"latest_default_branch_test_report":{"data":{"id":"592e361e9c3ce9000102b590","type":"test_reports"}},"account":{"data":null}},"links":{"self":"https://codeclimate.com/github/wnuqui/cm","services":"https://api.codeclimate.com/v1/repos/592e3170b12e120271000199/services","web_coverage":"https://codeclimate.com/github/wnuqui/cm/coverage","web_issues":"https://codeclimate.com/github/wnuqui/cm/issues"},"meta":{"permissions":{"admin":true}}}}'
58
+ http_version:
59
+ recorded_at: Sat, 19 Aug 2017 13:20:16 GMT
60
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/repos/592e3170b12e120271000199/services
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:30 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"86f7e738433d4d37acaeb33e0c755c19"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.011292'
47
+ X-Request-Id:
48
+ - 80aa6abf-c3a1-4f53-8ddc-585cb1522f0a
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":[{"id":"592e3171b12e12027100019d","type":"services","attributes":{"slug":"githubpullrequests","title":"GitHub
58
+ Pull Requests","description":"Update pull requests on GitHub"},"links":{"events":"https://api.codeclimate.com/v1/repos/592e3170b12e120271000199/services/592e3171b12e12027100019d/events"}}]}'
59
+ http_version:
60
+ recorded_at: Sat, 19 Aug 2017 13:20:24 GMT
61
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/repos/592e3170b12e120271000199/snapshots/5976875ea05a4400010030b1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:32 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"01cd0790f260c0c449597867e5458b3a"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.019020'
47
+ X-Request-Id:
48
+ - 02424130-c63f-4111-b05d-e940e9e372d6
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":{"id":"5976875ea05a4400010030b1","type":"snapshots","attributes":{"commit_sha":"bf8c7b6a430e8a27eb4a4f3c65d02bcbb9c1fe2e","committed_at":"2017-05-31T03:17:38.970Z","created_at":"2017-07-24T23:48:53.474Z","ratings":[],"gpa":4.0,"worker_version":3434},"meta":{"issues_count":0}}}'
58
+ http_version:
59
+ recorded_at: Sat, 19 Aug 2017 13:20:26 GMT
60
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/repos/592e3170b12e120271000199/test_reports
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:34 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"2df04eacc173845516828b02c78e6abd"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.010618'
47
+ X-Request-Id:
48
+ - acbe6744-f857-4682-8fac-3ab97ca707de
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":[{"id":"592e361e9c3ce9000102b590","type":"test_reports","attributes":{"commit_sha":"bf8c7b6a430e8a27eb4a4f3c65d02bcbb9c1fe2e","committed_at":"2017-05-31T03:17:37.000Z","covered_percent":100.0,"rating":{"path":"/","letter":"A","measure":{"value":100.0,"unit":"percent"},"pillar":"Test
58
+ Coverage"},"state":"done"}},{"id":"592e35409c3ce9000102b3cb","type":"test_reports","attributes":{"commit_sha":"7e1ed81c1d81dcd21da5ed5aeb4478ca906998ed","committed_at":"2017-05-31T03:13:15.000Z","covered_percent":100.0,"rating":{"path":"/","letter":"A","measure":{"value":100.0,"unit":"percent"},"pillar":"Test
59
+ Coverage"},"state":"done"}},{"id":"592e34839c3ce9000102b1ee","type":"test_reports","attributes":{"commit_sha":"aa025d1c7af2099642ce7dae7ae4d9f8d9875cc6","committed_at":"2017-05-31T02:53:05.000Z","covered_percent":100.0,"rating":{"path":"/","letter":"A","measure":{"value":100.0,"unit":"percent"},"pillar":"Test
60
+ Coverage"},"state":"done"}}],"links":{}}'
61
+ http_version:
62
+ recorded_at: Sat, 19 Aug 2017 13:20:28 GMT
63
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.codeclimate.com/v1/user?page%5Bnumber%5D=1&page%5Bsize%5D=1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.12.2
12
+ Content-Type:
13
+ - application/vnd.api+json
14
+ Accept:
15
+ - application/vnd.api+json
16
+ Authorization:
17
+ - Token token=TOKEN
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Sat, 19 Aug 2017 13:26:35 GMT
27
+ Content-Type:
28
+ - application/vnd.api+json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Status:
34
+ - 200 OK
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ Etag:
38
+ - W/"01f87483b8f76f6d24e76d011f489314"
39
+ X-Frame-Options:
40
+ - SAMEORIGIN
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Runtime:
46
+ - '0.020608'
47
+ X-Request-Id:
48
+ - 03d09ed5-eb93-4c43-8ea4-22a87a11a13b
49
+ X-Powered-By:
50
+ - Phusion Passenger 5.1.1
51
+ Server:
52
+ - nginx + Phusion Passenger 5.1.1
53
+ Strict-Transport-Security:
54
+ - max-age=31536000;
55
+ body:
56
+ encoding: UTF-8
57
+ string: '{"data":{"id":"58b90c67c0ec0b0286002146","type":"users","attributes":{"email":"dofreewill22@gmail.com","enabled_features":["builder_pull_engines","disable_transactions","encrypted_ssh_private_keys","ignore_owners_team","manage_issues_permission","open_source_repo_list","time_series_metrics","trends_via_time_series","use_kafka_for_test_report_created","use_kafka_for_vcs_pull_request_changed","use_kafka_for_vcs_repo_added","use_kafka_for_vcs_repo_push","use_kafka_for_vcs_repo_refresh","use_kafka_for_vcs_repo_updated"],"full_name":"Wilfrido
58
+ Nuqui","staff":false},"links":{"avatar":"https://avatars.githubusercontent.com/u/1292222"}}}'
59
+ http_version:
60
+ recorded_at: Sat, 19 Aug 2017 13:20:29 GMT
61
+ recorded_with: VCR 3.0.3
@@ -0,0 +1 @@
1
+ require 'code_climate/client'
@@ -0,0 +1,83 @@
1
+ require 'active_support/core_ext/module/attribute_accessors'
2
+ require 'json_api_client'
3
+
4
+ require 'code_climate/version'
5
+ require 'code_climate/resources/base'
6
+
7
+ module CodeClimate
8
+ # :nodoc:
9
+ module Client
10
+ mattr_accessor :base_uri, :api_token, :http_verbose
11
+
12
+ class << self
13
+ def configure
14
+ yield self if block_given?
15
+ CodeClimate::Resource::Base.site = base_uri
16
+ connect!
17
+ require_code_climate_resources
18
+ self
19
+ end
20
+
21
+ def current_user
22
+ Resource::User.first
23
+ end
24
+
25
+ def repos
26
+ Resource::Repo
27
+ end
28
+
29
+ def ref_points
30
+ Resource::RefPoint
31
+ end
32
+
33
+ def builds
34
+ Resource::Build
35
+ end
36
+
37
+ def metrics
38
+ Resource::Metric
39
+ end
40
+
41
+ def snapshots
42
+ Resource::Snapshot
43
+ end
44
+
45
+ def test_reports
46
+ Resource::TestReport
47
+ end
48
+
49
+ def services
50
+ Resource::Service
51
+ end
52
+
53
+ def orgs
54
+ Resource::Org
55
+ end
56
+
57
+ private
58
+
59
+ def http_verbose?
60
+ ENV['HTTP_VERBOSE'] == 'true' || http_verbose
61
+ end
62
+
63
+ def connect!
64
+ CodeClimate::Resource::Base.connection do |connection|
65
+ connection.use Faraday::Response::Logger if http_verbose?
66
+ connection.use CodeClimate::Middleware
67
+ end
68
+ end
69
+
70
+ def require_code_climate_resources
71
+ require 'code_climate/resources/ref_point'
72
+ require 'code_climate/resources/repo'
73
+ require 'code_climate/resources/user'
74
+ require 'code_climate/resources/build'
75
+ require 'code_climate/resources/metric'
76
+ require 'code_climate/resources/snapshot'
77
+ require 'code_climate/resources/test_report'
78
+ require 'code_climate/resources/service'
79
+ require 'code_climate/resources/org'
80
+ end
81
+ end
82
+ end
83
+ end