ruby_code_climate 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db4ecf9c8a5b7ee3fab988097d515da67b7344aa
4
+ data.tar.gz: 8142843b5827ca93569a4afe4a52a19eb7495f1c
5
+ SHA512:
6
+ metadata.gz: d634c008d8875b6a0d193aa9b374ebd7eac8d52e393d8243c2bf7afc4b42e4b4b93422712b0da5d2cf690e2d7579b181d362318f9c0c653ae8541330ca672e80
7
+ data.tar.gz: 296f1914b50b9834449a6d99af60c9198db6bddea33e9e84c0546f0878a9d13501ecfda2083d172213034e0612cb00dda218f85044de00e512835a1d0f60d243
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ruby_code_climate
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_code_climate.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Zach Colon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,159 @@
1
+ [![Code Climate](https://codeclimate.com/github/wzcolon/ruby_code_climate/badges/gpa.svg)](https://codeclimate.com/github/wzcolon/ruby_code_climate)
2
+
3
+ # RubyCodeClimate
4
+
5
+ Simple Ruby Wrapper for the Code Climate API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruby_code_climate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruby_code_climate
22
+
23
+
24
+ ## Configure
25
+
26
+ ```ruby
27
+ # config/initializers/code_climate.rb
28
+ CodeClimate.configuration do |config|
29
+ config.api_token = 'your_token_here'
30
+ end
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### GET /api/repos
36
+ ```ruby
37
+ CodeClimate.get_repos
38
+ ```
39
+
40
+ Example Response:
41
+ ```
42
+ [
43
+ {
44
+ "id": "4906075af3ea000dc6000740",
45
+ "url": "ssh://git@github.com/redsox/soxtalk.git",
46
+ "branch": "master"
47
+ },
48
+ {
49
+ "id": "1222075af3ea000dc6000799",
50
+ "url": "ssh://git@github.com/redsox/baseball.git",
51
+ "branch": "dev"
52
+ }
53
+ ]
54
+ ```
55
+
56
+ GET /api/repos/:repo_id
57
+ ```ruby
58
+ CodeClimate.get_repo(repo_id: '123')
59
+ ```
60
+
61
+ Example Reponse:
62
+ ```
63
+ {
64
+ "id": "4906075af3ea000dc6000740",
65
+ "account_id": "3d415d14a1747d5991000001",
66
+ "name": "Sox Talk",
67
+ "url": "ssh://git@github.com/redsox/soxtalk.git",
68
+ "branch": "master",
69
+ "created_at": 1343686490,
70
+ "last_snapshot": {
71
+ "id": "407c8d1d13d637023100016c",
72
+ "repo_id": "4907075af3ea000dc6000740",
73
+ "commit_sha": "72f1c6ae07cc465df70aa372dc972e835f355972",
74
+ "committed_at": 1368165656,
75
+ "finished_at": 1368165666,
76
+ "gpa": 3.05,
77
+ "covered_percent": 46
78
+ },
79
+ "previous_snapshot": {
80
+ "id": "4074d085c7f3a364f100667a",
81
+ "repo_id": "4907075af3ea000dc6000740",
82
+ "commit_sha": "02bcca40eafc7832160a08eef8f091e0896e2cec",
83
+ "committed_at": 1367646334,
84
+ "finished_at": 1367658637,
85
+ "gpa": 3.04,
86
+ "covered_percent": 23
87
+ }
88
+ }
89
+ ```
90
+
91
+ POST /api/repos/:repo_id/refresh
92
+ ```ruby
93
+ CodeClimate.refresh_repo(repo_id: '123')
94
+ ```
95
+
96
+ This will return either true or false based on the response from CodeClimate
97
+
98
+
99
+ GET /api/repos/:repo_id/branches/:branch_name
100
+ ```ruby
101
+ CodeClimate.get_branch(repo_id: '123', branch_name: 'master')
102
+ ```
103
+
104
+ Example Response:
105
+ ```
106
+ {
107
+ "id": "4906075af3ea000dc6000740",
108
+ "account_id": "3d415d14a1747d5991000001",
109
+ "name": "Sox Talk",
110
+ "url": "ssh://git@github.com/redsox/soxtalk.git",
111
+ "branch": "master",
112
+ "created_at": 1343686490,
113
+ "last_snapshot": {
114
+ "id": "407c8d1d13d637023100016c",
115
+ "repo_id": "4907075af3ea000dc6000740",
116
+ "commit_sha": "72f1c6ae07cc465df70aa372dc972e835f355972",
117
+ "committed_at": 1368165656,
118
+ "finished_at": 1368165666,
119
+ "gpa": 3.05,
120
+ "covered_percent": 46
121
+ },
122
+ "previous_snapshot": {
123
+ "id": "4074d085c7f3a364f100667a",
124
+ "repo_id": "4907075af3ea000dc6000740",
125
+ "commit_sha": "02bcca40eafc7832160a08eef8f091e0896e2cec",
126
+ "committed_at": 1367646334,
127
+ "finished_at": 1367658637,
128
+ "gpa": 3.04,
129
+ "covered_percent": 23
130
+ }
131
+ }
132
+ ```
133
+ POST /api/repos/:repo_id/branches/:branch_name/refresh
134
+ ```ruby
135
+ CodeClimate.refresh_branch(repo_id: '123', branch_name: 'master')
136
+ ```
137
+
138
+ This will return either true or false based on the response from CodeClimate
139
+
140
+ ## Other Info
141
+
142
+ All attributes of objects returned can be accessed with method calls. For instance, if you request a single repo, you can ask it for it's gpa directly.
143
+
144
+ ```ruby
145
+ repo = CodeClimate.get_repo(repo_id: '123')
146
+ repo.name # 'Sox Talk'
147
+ repo.gpa # 3.05
148
+ repo.last_gpa # 3.04
149
+ ```
150
+
151
+ ## Contributing
152
+
153
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wzcolon/ruby_code_climate.
154
+
155
+
156
+ ## License
157
+
158
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
159
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_code_climate"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/branch.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Branch < Repo
2
+ end
@@ -0,0 +1,53 @@
1
+ class CodeClimate
2
+ BASE_URL='https://codeclimate.com'
3
+
4
+ # GET /api/repos
5
+ def self.get_repos
6
+ connection = connection('/api/repos')
7
+ response = connection.get(query: { api_token: api_token })
8
+
9
+ repos = JSON.parse(response.body)
10
+ repos.map { |repo| Repo.new(repo) }
11
+ end
12
+
13
+ # GET /api/repos/:repo_id
14
+ def self.get_repo(repo_id:)
15
+ connection = connection("/api/repos/#{repo_id}")
16
+ response = connection.get(query: { api_token: api_token })
17
+
18
+ Repo.new(JSON.parse(response.body))
19
+ end
20
+
21
+ # POST /api/repos/:repo_id/refresh
22
+ def self.refresh_repo(repo_id:)
23
+ connection = connection("/api/repos/#{repo_id}/refresh")
24
+ response = connection.post(query: { api_token: api_token })
25
+
26
+ response.status == 200 ? true : false
27
+ end
28
+
29
+ # GET /api/repos/:repo_id/branches/:branch_name
30
+ def self.get_branch(repo_id:, branch_name:)
31
+ connection = connection("/api/repos/#{repo_id}/branches/#{branch_name}")
32
+ response = connection.get(query: { api_token: api_token })
33
+
34
+ Branch.new(JSON.parse(response.body))
35
+ end
36
+
37
+ # POST /api/repos/:repo_id/branches/:branch_name/refresh
38
+ def self.refresh_branch(repo_id:, branch_name:)
39
+ connection = connection("/api/repos/#{repo_id}/branches/#{branch_name}/refresh")
40
+ response = connection.post(query: { api_token: api_token })
41
+
42
+ response.status == 200 ? true : false
43
+ end
44
+ private
45
+
46
+ def self.connection(url)
47
+ Excon.new(BASE_URL+url)
48
+ end
49
+
50
+ def self.api_token
51
+ RubyCodeClimate.configuration.api_token
52
+ end
53
+ end
data/lib/repo.rb ADDED
@@ -0,0 +1,10 @@
1
+ class Repo < Hashie::Mash
2
+
3
+ def current_gpa
4
+ last_snapshot.gpa
5
+ end
6
+
7
+ def previous_gpa
8
+ previous_snapshot.gpa
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ require "ruby_code_climate/version"
2
+ require 'excon'
3
+ require 'hashie'
4
+ require 'json'
5
+
6
+ require 'code_climate'
7
+ require 'repo'
8
+ require 'branch' # include after Repo
9
+
10
+ module RubyCodeClimate
11
+
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configure
17
+ self.configuration ||= Configuration.new
18
+ yield(configuration)
19
+ end
20
+
21
+ class Configuration
22
+ attr_accessor :api_token
23
+
24
+ def initialize
25
+ @api_token = ''
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module RubyCodeClimate
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_code_climate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_code_climate"
8
+ spec.version = RubyCodeClimate::VERSION
9
+ spec.authors = ["Zach Colon, Jeremy Ward"]
10
+ spec.email = ["zcolon80@gmail.com, jcward10@gmail.com"]
11
+
12
+ spec.summary = %q{Wrapper for Code Climate API}
13
+ spec.description = %q{Wrapper for Code Climate API}
14
+ spec.homepage = "https://github.com/wzcolon/ruby_code_climate"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "webmock"
35
+
36
+ spec.add_dependency "excon"
37
+ spec.add_dependency "hashie"
38
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_code_climate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zach Colon, Jeremy Ward
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: excon
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hashie
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Wrapper for Code Climate API
112
+ email:
113
+ - zcolon80@gmail.com, jcward10@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".ruby-gemset"
121
+ - ".ruby-version"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/branch.rb
130
+ - lib/code_climate.rb
131
+ - lib/repo.rb
132
+ - lib/ruby_code_climate.rb
133
+ - lib/ruby_code_climate/version.rb
134
+ - ruby_code_climate.gemspec
135
+ homepage: https://github.com/wzcolon/ruby_code_climate
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.5
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Wrapper for Code Climate API
160
+ test_files: []