velocity_client_ruby 0.2.1 → 0.3.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 +4 -4
- data/Gemfile.lock +18 -4
- data/README.md +21 -11
- data/examples/contributors-list.csv +4 -4
- data/lib/velocity/api/base.rb +34 -9
- data/lib/velocity/api/invite.rb +3 -1
- data/lib/velocity/api/people.rb +32 -1
- data/lib/velocity/api/role.rb +1 -1
- data/lib/velocity/api/team.rb +9 -0
- data/lib/velocity/base.rb +11 -0
- data/lib/velocity/team.rb +5 -0
- data/lib/velocity/version.rb +1 -1
- data/lib/velocity.rb +2 -0
- data/velocity_client_ruby.gemspec +3 -1
- metadata +38 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5eec482e30a02e7f2ffb015d5fe6c192cf3f1fdcaaa4c3b6e7ceaf11994269dc
|
4
|
+
data.tar.gz: 8b141bb370fe3e3cdab469e59a75b269ef8cc2a4e15c66b8dccb87c74934c9e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6fdda65e7f609d69492e86aa2f304b30622645dc24768005def33e3fd02963b5ea3e31b0e17031e21205c729adc31a29e91dd3794982fcd90e9c84b305fb0ff
|
7
|
+
data.tar.gz: 30dd425047f3cfa9bc95b95e627e2d697ec31feabade6d6cf937b7c08be60bb321f5735b748be134754741be818f8947ead70ab21e1ce96497c28e1236759e5d
|
data/Gemfile.lock
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
velocity_client_ruby (0.
|
4
|
+
velocity_client_ruby (0.3.0)
|
5
5
|
dotenv (~> 2.7)
|
6
6
|
httparty (~> 0.18)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
addressable (2.8.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
13
|
coderay (1.1.3)
|
14
|
+
crack (0.4.5)
|
15
|
+
rexml
|
12
16
|
diff-lcs (1.4.4)
|
13
17
|
dotenv (2.7.6)
|
14
|
-
|
18
|
+
hashdiff (1.0.1)
|
19
|
+
httparty (0.20.0)
|
15
20
|
mime-types (~> 3.0)
|
16
21
|
multi_xml (>= 0.5.2)
|
17
22
|
method_source (1.0.0)
|
18
23
|
mime-types (3.3.1)
|
19
24
|
mime-types-data (~> 3.2015)
|
20
|
-
mime-types-data (3.2021.
|
25
|
+
mime-types-data (3.2021.0901)
|
21
26
|
multi_xml (0.6.0)
|
22
27
|
pry (0.14.1)
|
23
28
|
coderay (~> 1.1)
|
24
29
|
method_source (~> 1.0)
|
30
|
+
public_suffix (4.0.6)
|
25
31
|
rake (10.5.0)
|
32
|
+
rexml (3.2.5)
|
26
33
|
rspec (3.10.0)
|
27
34
|
rspec-core (~> 3.10.0)
|
28
35
|
rspec-expectations (~> 3.10.0)
|
@@ -36,16 +43,23 @@ GEM
|
|
36
43
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
44
|
rspec-support (~> 3.10.0)
|
38
45
|
rspec-support (3.10.2)
|
46
|
+
vcr (6.0.0)
|
47
|
+
webmock (3.14.0)
|
48
|
+
addressable (>= 2.8.0)
|
49
|
+
crack (>= 0.3.2)
|
50
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
39
51
|
|
40
52
|
PLATFORMS
|
41
53
|
ruby
|
42
54
|
|
43
55
|
DEPENDENCIES
|
44
|
-
bundler (~>
|
56
|
+
bundler (~> 2.2.3)
|
45
57
|
pry (~> 0.14)
|
46
58
|
rake (~> 10.0)
|
47
59
|
rspec (~> 3.0)
|
60
|
+
vcr (~> 6.0)
|
48
61
|
velocity_client_ruby!
|
62
|
+
webmock (~> 3.14)
|
49
63
|
|
50
64
|
BUNDLED WITH
|
51
65
|
2.2.3
|
data/README.md
CHANGED
@@ -18,30 +18,40 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install velocity_client_ruby
|
20
20
|
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
In order to be able to Access Velocity API you need to have a token.
|
24
|
+
You can set it up all your environemnt variables using configure method:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Velocity.configure do |config|
|
28
|
+
config.api_token = "<TOKEN>"
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
21
32
|
## Usage
|
22
33
|
|
23
34
|
```ruby
|
24
35
|
require "velocity"
|
25
36
|
|
26
|
-
|
37
|
+
list = CSV.parse(File.read('./examples/contributors.csv'), headers: true)
|
27
38
|
|
28
|
-
|
29
|
-
|
39
|
+
list.map do |contributor_data|
|
40
|
+
contributor = Velocity::Contributor.find_by(name: contributor_data['name'])
|
30
41
|
|
31
|
-
if
|
32
|
-
puts "Contributor #{
|
42
|
+
if contributor
|
43
|
+
puts "Contributor #{contributor.id} found."
|
33
44
|
else
|
34
|
-
role = Velocity::Role.find_by(name:
|
35
|
-
raise 'Role not found' if role.nil?
|
45
|
+
role = Velocity::Role.find_by(name: contributor_data['role_name'])
|
36
46
|
|
37
47
|
invite = Velocity::Invite.create(
|
38
|
-
name:
|
39
|
-
email:
|
40
|
-
job_function:
|
48
|
+
name: contributor_date['name'],
|
49
|
+
email: contributor_data['email'],
|
50
|
+
job_function: contributor_data['job_function'],
|
41
51
|
role_ids: [role.id]
|
42
52
|
)
|
43
53
|
|
44
|
-
puts "Invite #{invite.id} sent
|
54
|
+
puts "Invite #{invite.id} sent."
|
45
55
|
end
|
46
56
|
end
|
47
57
|
```
|
@@ -1,5 +1,5 @@
|
|
1
1
|
name,email,job_function,role_name
|
2
|
-
Vera Prot,vera@
|
3
|
-
Victor Antoniazzi,
|
4
|
-
Alex Oliveira,
|
5
|
-
Filipe Esperandio,filipe@
|
2
|
+
Vera Prot,vera@fakemail.com,Software Engineer,Engineer
|
3
|
+
Victor Antoniazzi,victor@fakemail.com,Software Engineer,Engineer
|
4
|
+
Alex Oliveira,alex@fakemail.com,Software Engineer,Engineer
|
5
|
+
Filipe Esperandio,filipe@fakemail.com,Software Engineer,Engineer
|
data/lib/velocity/api/base.rb
CHANGED
@@ -8,6 +8,8 @@ module Velocity
|
|
8
8
|
class InternalServerError < StandardError; end
|
9
9
|
class BadRequestError < StandardError; end
|
10
10
|
|
11
|
+
PAGE_SIZE = 100
|
12
|
+
|
11
13
|
include HTTParty
|
12
14
|
|
13
15
|
base_uri "https://api.velocity.codeclimate.com/v1"
|
@@ -18,15 +20,20 @@ module Velocity
|
|
18
20
|
@args = args
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
23
|
+
def get(url)
|
24
|
+
parse_response(self.class.get(url, options.merge(query: build_query)))
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(url, body)
|
28
|
+
parse_response(self.class.post("/invitations", options.merge(body)))
|
28
29
|
end
|
29
30
|
|
31
|
+
def put(url, body)
|
32
|
+
parse_response(self.class.put(url, options.merge(body)))
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
30
37
|
def parse_response(response)
|
31
38
|
case response.code
|
32
39
|
when 200..201
|
@@ -43,10 +50,28 @@ module Velocity
|
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
53
|
+
def options
|
54
|
+
{
|
55
|
+
headers: {
|
56
|
+
"Authorization" => "Bearer #{Velocity.configuration.api_token}",
|
57
|
+
"Content-Type" => "application/vnd.api+json",
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
46
62
|
def build_query
|
47
63
|
args.map do |key, value|
|
48
|
-
"filter[#{key.to_s}][
|
49
|
-
end.join("&")
|
64
|
+
"filter[#{key.to_s}][#{operation(key)}]=#{value}"
|
65
|
+
end.join("&") + "&page[size]=100"
|
66
|
+
end
|
67
|
+
|
68
|
+
def operation(key)
|
69
|
+
case key.to_sym
|
70
|
+
when :id
|
71
|
+
"eq"
|
72
|
+
else
|
73
|
+
"contains"
|
74
|
+
end
|
50
75
|
end
|
51
76
|
end
|
52
77
|
end
|
data/lib/velocity/api/invite.rb
CHANGED
data/lib/velocity/api/people.rb
CHANGED
@@ -2,7 +2,38 @@ module Velocity
|
|
2
2
|
module Api
|
3
3
|
class People < Velocity::Api::Base
|
4
4
|
def fetch
|
5
|
-
|
5
|
+
get("/people")
|
6
|
+
end
|
7
|
+
|
8
|
+
def update
|
9
|
+
put("/people/#{args.fetch(:id)}", body)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def body
|
15
|
+
{
|
16
|
+
body: {
|
17
|
+
data: {
|
18
|
+
id: args.fetch(:id),
|
19
|
+
type: "people",
|
20
|
+
relationships: relationships
|
21
|
+
}
|
22
|
+
}.to_json
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def relationships
|
27
|
+
{
|
28
|
+
teams: {
|
29
|
+
data: args.fetch(:team_ids).map do |team_id|
|
30
|
+
{
|
31
|
+
type: "teams",
|
32
|
+
id: team_id
|
33
|
+
}
|
34
|
+
end
|
35
|
+
}
|
36
|
+
}
|
6
37
|
end
|
7
38
|
end
|
8
39
|
end
|
data/lib/velocity/api/role.rb
CHANGED
data/lib/velocity/base.rb
CHANGED
@@ -19,6 +19,12 @@ module Velocity
|
|
19
19
|
new(data["attributes"].merge(id: data["id"]))
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.all
|
23
|
+
resource_class.new({}).fetch.map do |data|
|
24
|
+
new(data["attributes"].merge(id: data["id"]))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
22
28
|
def self.where(args)
|
23
29
|
resource_class.new(args).fetch.map do |data|
|
24
30
|
new(data["attributes"].merge(id: data["id"]))
|
@@ -32,5 +38,10 @@ module Velocity
|
|
32
38
|
def self.find_by!(args)
|
33
39
|
where(args).first or raise NotFoundError, "record not found with #{args.inspect}"
|
34
40
|
end
|
41
|
+
|
42
|
+
def update(args)
|
43
|
+
data = self.class.resource_class.new(args.merge(id: self.id)).update
|
44
|
+
self.class.new(data["attributes"].merge(id: data["id"]))
|
45
|
+
end
|
35
46
|
end
|
36
47
|
end
|
data/lib/velocity/version.rb
CHANGED
data/lib/velocity.rb
CHANGED
@@ -4,10 +4,12 @@ require "velocity/api/base"
|
|
4
4
|
require "velocity/api/role"
|
5
5
|
require "velocity/api/people"
|
6
6
|
require "velocity/api/invite"
|
7
|
+
require "velocity/api/team"
|
7
8
|
require "velocity/base"
|
8
9
|
require "velocity/role"
|
9
10
|
require "velocity/contributor"
|
10
11
|
require "velocity/invite"
|
12
|
+
require "velocity/team"
|
11
13
|
require "dotenv/load"
|
12
14
|
|
13
15
|
module Velocity
|
@@ -33,9 +33,11 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
|
-
spec.add_development_dependency "bundler", "~>
|
36
|
+
spec.add_development_dependency "bundler", "~> 2.2.3"
|
37
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
38
38
|
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
40
|
+
spec.add_development_dependency "webmock", "~> 3.14"
|
39
41
|
spec.add_development_dependency "pry", "~> 0.14"
|
40
42
|
|
41
43
|
spec.add_dependency "httparty", "~> 0.18"
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: velocity_client_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Antoniazzi
|
8
8
|
- Vera Protopopova
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 2.2.3
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 2.2.3
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +53,34 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: vcr
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '6.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '6.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: webmock
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.14'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.14'
|
56
84
|
- !ruby/object:Gem::Dependency
|
57
85
|
name: pry
|
58
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,10 +150,12 @@ files:
|
|
122
150
|
- lib/velocity/api/invite.rb
|
123
151
|
- lib/velocity/api/people.rb
|
124
152
|
- lib/velocity/api/role.rb
|
153
|
+
- lib/velocity/api/team.rb
|
125
154
|
- lib/velocity/base.rb
|
126
155
|
- lib/velocity/contributor.rb
|
127
156
|
- lib/velocity/invite.rb
|
128
157
|
- lib/velocity/role.rb
|
158
|
+
- lib/velocity/team.rb
|
129
159
|
- lib/velocity/version.rb
|
130
160
|
- velocity_client_ruby.gemspec
|
131
161
|
homepage: http://velocity.codeclimate.com
|
@@ -134,7 +164,7 @@ licenses:
|
|
134
164
|
metadata:
|
135
165
|
homepage_uri: http://velocity.codeclimate.com
|
136
166
|
source_code_uri: https://github.com/codeclimate/velocity-client-ruby
|
137
|
-
post_install_message:
|
167
|
+
post_install_message:
|
138
168
|
rdoc_options: []
|
139
169
|
require_paths:
|
140
170
|
- lib
|
@@ -149,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
179
|
- !ruby/object:Gem::Version
|
150
180
|
version: '0'
|
151
181
|
requirements: []
|
152
|
-
rubygems_version: 3.0.
|
153
|
-
signing_key:
|
182
|
+
rubygems_version: 3.0.8
|
183
|
+
signing_key:
|
154
184
|
specification_version: 4
|
155
185
|
summary: Ruby Gem to interact with Velocity Teams API
|
156
186
|
test_files: []
|