velocity_client_ruby 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -7
- data/examples/contributors-list.csv +5 -0
- data/examples/send_bulk_invites.rb +25 -0
- data/examples/send_invite.rb +21 -0
- data/lib/initializers/hash.rb +9 -0
- data/lib/initializers/string.rb +9 -0
- data/lib/velocity/api/base.rb +53 -0
- data/lib/velocity/api/invite.rb +42 -0
- data/lib/velocity/api/people.rb +9 -0
- data/lib/velocity/api/role.rb +9 -0
- data/lib/velocity/base.rb +36 -0
- data/lib/velocity/contributor.rb +3 -19
- data/lib/velocity/invite.rb +5 -0
- data/lib/velocity/role.rb +5 -0
- data/lib/velocity/version.rb +1 -1
- data/lib/velocity.rb +9 -1
- metadata +14 -3
- data/lib/velocity/api.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e2516b551ac58ec8b4f71195364e2cdb7400dc8efb70a4835cc0b3081e2bfe8
|
4
|
+
data.tar.gz: 95263628e3a1e4ae64d8a2f94e15df212c6c98917abbc89d66e4d288f25d22d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c0e28a0e9ad13a549878cec86787cc562098a942fe9b406b0022ea59203eae70fba46f2e55d100743d2c4ffd38e8616b1dd0f7e766e7739cfff9aab7be16130
|
7
|
+
data.tar.gz: fcffcc10ea15e93ac12d1f4e0318bb71e9562105d8eb3081a86afa6bd57243338769955a0ab29dd96b39b917ec5f267900910ab75fd4dd9566a2694178346f5b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,15 +21,27 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
require "velocity"
|
25
|
+
|
26
|
+
contributors_list = CSV.parse(File.read('./examples/contributors-list.csv'), headers: true)
|
27
|
+
|
28
|
+
contributors_list.map do |contributor|
|
29
|
+
velocity_contributor = Velocity::Contributor.find_by(name: contributor['name'])
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
if velocity_contributor
|
32
|
+
puts "Contributor #{velocity_contributor.id} found.\n#{velocity_contributor.inspect}"
|
33
|
+
else
|
34
|
+
role = Velocity::Role.find_by(name: contributor['role_name'])
|
35
|
+
raise 'Role not found' if role.nil?
|
30
36
|
|
31
|
-
|
32
|
-
|
37
|
+
invite = Velocity::Invite.create(
|
38
|
+
name: contributor['name'],
|
39
|
+
email: contributor['email'],
|
40
|
+
job_function: contributor['job_function'],
|
41
|
+
role_ids: [role.id]
|
42
|
+
)
|
43
|
+
|
44
|
+
puts "Invite #{invite.id} sent.\n#{invite.inspect}"
|
33
45
|
end
|
34
46
|
end
|
35
47
|
```
|
@@ -40,6 +52,16 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
40
52
|
|
41
53
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
54
|
|
55
|
+
|
56
|
+
## Publishing
|
57
|
+
|
58
|
+
1. Open version.rb file and version_spec.rb file and bump version
|
59
|
+
2. run:
|
60
|
+
|
61
|
+
```
|
62
|
+
rake release
|
63
|
+
```
|
64
|
+
|
43
65
|
## Contributing
|
44
66
|
|
45
67
|
Bug reports and pull requests are welcome on GitHub at https://github.com/codeclimate/velocity-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -0,0 +1,5 @@
|
|
1
|
+
name,email,job_function,role_name
|
2
|
+
Vera Prot,vera@codeclimate.com,Software Engineer,Engineer
|
3
|
+
Victor Antoniazzi,vantoniazzi@codeclimate.com,Software Engineer,Engineer
|
4
|
+
Alex Oliveira,aoliveira@codeclimate.com,Software Engineer,Engineer
|
5
|
+
Filipe Esperandio,filipe@codeclimate.com,Software Engineer,Engineer
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "velocity"
|
3
|
+
|
4
|
+
contributors_list = CSV.parse(File.read("./examples/contributors-list.csv"), headers: true)
|
5
|
+
|
6
|
+
contributors_list.map do |contributor|
|
7
|
+
velocity_contributor = Velocity::Contributor.find_by(name: contributor["name"])
|
8
|
+
|
9
|
+
if velocity_contributor
|
10
|
+
puts "Contributor #{velocity_contributor.id} found.\n#{velocity_contributor.inspect}"
|
11
|
+
else
|
12
|
+
role = Velocity::Role.find_by(name: contributor["role_name"])
|
13
|
+
|
14
|
+
raise "Role not found" if role.nil?
|
15
|
+
|
16
|
+
invite = Velocity::Invite.create(
|
17
|
+
name: contributor["name"],
|
18
|
+
email: contributor["email"],
|
19
|
+
job_function: contributor["job_function"],
|
20
|
+
role_ids: [role.id]
|
21
|
+
)
|
22
|
+
|
23
|
+
puts "Invite #{invite.id} sent.\n#{invite.inspect}"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "velocity"
|
3
|
+
|
4
|
+
contributor = Velocity::Contributor.find_by(email: "vgsantoniazzi@gmail.com")
|
5
|
+
|
6
|
+
if contributor
|
7
|
+
puts "Contributor #{contributor.id} found.\n#{contributor.inspect}"
|
8
|
+
else
|
9
|
+
engineer_role = Velocity::Role.find_by(name: "Engineer")
|
10
|
+
|
11
|
+
raise "Role not found" if engineer_role.nil?
|
12
|
+
|
13
|
+
invite = Velocity::Invite.create(
|
14
|
+
name: "Victor Antoniazzi",
|
15
|
+
email: "vgsantoniazzi@gmail.com",
|
16
|
+
job_function: "Software Engineer",
|
17
|
+
role_ids: [engineer_role.id]
|
18
|
+
)
|
19
|
+
|
20
|
+
puts "Invite #{invite.id} sent.\n#{invite.inspect}"
|
21
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module Velocity
|
4
|
+
module Api
|
5
|
+
class Base
|
6
|
+
class NotFoundError < StandardError; end
|
7
|
+
class UnauthorizedError < StandardError; end
|
8
|
+
class InternalServerError < StandardError; end
|
9
|
+
class BadRequestError < StandardError; end
|
10
|
+
|
11
|
+
include HTTParty
|
12
|
+
|
13
|
+
base_uri "https://api.velocity.codeclimate.com/v1"
|
14
|
+
|
15
|
+
attr_accessor :args
|
16
|
+
|
17
|
+
def initialize(args)
|
18
|
+
@args = args
|
19
|
+
end
|
20
|
+
|
21
|
+
def options
|
22
|
+
{
|
23
|
+
headers: {
|
24
|
+
"Authorization" => "Bearer #{Velocity.configuration.api_token}",
|
25
|
+
"Content-Type" => "application/vnd.api+json",
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_response(response)
|
31
|
+
case response.code
|
32
|
+
when 200..201
|
33
|
+
JSON.parse(response.body)["data"]
|
34
|
+
when 400
|
35
|
+
errors = JSON.parse(response.body)["errors"]
|
36
|
+
raise BadRequestError.new(errors.first["title"] + ": " + errors.first["detail"])
|
37
|
+
when 401
|
38
|
+
raise UnauthorizedError.new("401 Unauthorized");
|
39
|
+
when 404
|
40
|
+
raise NotFoundError.new("404 not found error");
|
41
|
+
else
|
42
|
+
raise InternalServerError.new("#{response.code} something went wrong: #{response.body}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_query
|
47
|
+
args.map do |key, value|
|
48
|
+
"filter[#{key.to_s}][contains]=#{value}"
|
49
|
+
end.join("&")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Velocity
|
2
|
+
module Api
|
3
|
+
class Invite < Velocity::Api::Base
|
4
|
+
def create
|
5
|
+
parse_response(self.class.post("/invitations", options.merge(body)))
|
6
|
+
end
|
7
|
+
|
8
|
+
def body
|
9
|
+
{
|
10
|
+
body: {
|
11
|
+
data: {
|
12
|
+
type: "invitations",
|
13
|
+
attributes: attributes,
|
14
|
+
relationships: relationships
|
15
|
+
}
|
16
|
+
}.to_json
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def attributes
|
21
|
+
{
|
22
|
+
name: args.fetch(:name),
|
23
|
+
email: args.fetch(:email),
|
24
|
+
jobFunction: args.fetch(:job_function)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def relationships
|
29
|
+
{
|
30
|
+
roles: {
|
31
|
+
data: args.fetch(:role_ids).map do |role_id|
|
32
|
+
{
|
33
|
+
type: "roles",
|
34
|
+
id: role_id
|
35
|
+
}
|
36
|
+
end
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Velocity
|
2
|
+
class Base < OpenStruct
|
3
|
+
class NotFoundError < StandardError; end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_reader :resource_class_name
|
7
|
+
|
8
|
+
def resource_class(class_name = nil)
|
9
|
+
@resource_class_name ||= class_name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args)
|
14
|
+
super(args.deep_transform_keys {|key| key.to_s.underscore })
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(args)
|
18
|
+
data = resource_class.new(args).create
|
19
|
+
new(data["attributes"].merge(id: data["id"]))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.where(args)
|
23
|
+
resource_class.new(args).fetch.map do |data|
|
24
|
+
new(data["attributes"].merge(id: data["id"]))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_by(args)
|
29
|
+
where(args).first
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.find_by!(args)
|
33
|
+
where(args).first or raise NotFoundError, "record not found with #{args.inspect}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/velocity/contributor.rb
CHANGED
@@ -1,21 +1,5 @@
|
|
1
1
|
module Velocity
|
2
|
-
class Contributor
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(id:, email:, name:)
|
6
|
-
@id = id
|
7
|
-
@email = email
|
8
|
-
@name = name
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.where(args)
|
12
|
-
perform_request(args).map do |contributor|
|
13
|
-
new(id: contributor["id"], name: contributor["attributes"]["name"], email: contributor["attributes"]["email"])
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.perform_request(args = {})
|
18
|
-
Velocity::Api.new.fetch_contributors(args)
|
19
|
-
end
|
2
|
+
class Contributor < Base
|
3
|
+
resource_class Velocity::Api::People
|
20
4
|
end
|
21
|
-
end
|
5
|
+
end
|
data/lib/velocity/version.rb
CHANGED
data/lib/velocity.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
|
-
require "
|
1
|
+
require "initializers/string"
|
2
|
+
require "initializers/hash"
|
3
|
+
require "velocity/api/base"
|
4
|
+
require "velocity/api/role"
|
5
|
+
require "velocity/api/people"
|
6
|
+
require "velocity/api/invite"
|
7
|
+
require "velocity/base"
|
8
|
+
require "velocity/role"
|
2
9
|
require "velocity/contributor"
|
10
|
+
require "velocity/invite"
|
3
11
|
require "dotenv/load"
|
4
12
|
|
5
13
|
module Velocity
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Antoniazzi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -112,9 +112,20 @@ files:
|
|
112
112
|
- Rakefile
|
113
113
|
- bin/console
|
114
114
|
- bin/setup
|
115
|
+
- examples/contributors-list.csv
|
116
|
+
- examples/send_bulk_invites.rb
|
117
|
+
- examples/send_invite.rb
|
118
|
+
- lib/initializers/hash.rb
|
119
|
+
- lib/initializers/string.rb
|
115
120
|
- lib/velocity.rb
|
116
|
-
- lib/velocity/api.rb
|
121
|
+
- lib/velocity/api/base.rb
|
122
|
+
- lib/velocity/api/invite.rb
|
123
|
+
- lib/velocity/api/people.rb
|
124
|
+
- lib/velocity/api/role.rb
|
125
|
+
- lib/velocity/base.rb
|
117
126
|
- lib/velocity/contributor.rb
|
127
|
+
- lib/velocity/invite.rb
|
128
|
+
- lib/velocity/role.rb
|
118
129
|
- lib/velocity/version.rb
|
119
130
|
- velocity_client_ruby.gemspec
|
120
131
|
homepage: http://velocity.codeclimate.com
|
data/lib/velocity/api.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
module Velocity
|
4
|
-
class Api
|
5
|
-
class NotFoundError < StandardError; end
|
6
|
-
class UnauthorizedError < StandardError; end
|
7
|
-
class InternalServerError < StandardError; end
|
8
|
-
class BadRequestError < StandardError; end
|
9
|
-
|
10
|
-
include HTTParty
|
11
|
-
|
12
|
-
base_uri "https://api.velocity.codeclimate.com/v1"
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@options = {
|
16
|
-
headers: {
|
17
|
-
authorization: "Bearer #{Velocity.configuration.api_token}"
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def fetch_contributors(args)
|
23
|
-
parse_response(self.class.get("/people", @options.merge({
|
24
|
-
query: build_query_attributes(args)
|
25
|
-
})))
|
26
|
-
end
|
27
|
-
|
28
|
-
def parse_response(response)
|
29
|
-
case response.code
|
30
|
-
when 200
|
31
|
-
JSON.parse(response.body)["data"]
|
32
|
-
when 400
|
33
|
-
errors = JSON.parse(response.body)["errors"]
|
34
|
-
raise BadRequestError.new(errors.first["title"] + ": " + errors.first["detail"])
|
35
|
-
when 401
|
36
|
-
raise UnauthorizedError.new("401 Unauthorized");
|
37
|
-
when 404
|
38
|
-
raise NotFoundError.new("404 not found error");
|
39
|
-
else
|
40
|
-
raise InternalServerError.new("#{response.code} something went wrong: #{response.body}")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def build_query_attributes(args)
|
45
|
-
args.map do |key, value|
|
46
|
-
"filter[#{key.to_s}][eq]=#{value}"
|
47
|
-
end.join("&")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|