teamtailor 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/teamtailor.rb +8 -0
- data/lib/teamtailor/client.rb +77 -0
- data/lib/teamtailor/error.rb +29 -0
- data/lib/teamtailor/page_result.rb +47 -0
- data/lib/teamtailor/parser.rb +45 -0
- data/lib/teamtailor/parser/candidate.rb +11 -0
- data/lib/teamtailor/parser/job.rb +11 -0
- data/lib/teamtailor/parser/job_application.rb +8 -0
- data/lib/teamtailor/parser/user.rb +8 -0
- data/lib/teamtailor/record.rb +42 -0
- data/lib/teamtailor/relationship.rb +37 -0
- data/lib/teamtailor/request.rb +48 -0
- data/lib/teamtailor/version.rb +5 -0
- data/teamtailor.gemspec +34 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0fb58dde09bf88aeefb1583c34f8b55dfeb27420a8bac2e0287d707ce28af0d0
|
4
|
+
data.tar.gz: 8c6bad2854c056272020d5d9b3f774ac418d0f6a9f1558a3a29791422d959588
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d946ffac4d073ad2bb82fc79c82c13abcaba7810334b870b50e3fce6ebce4158df4cc1080d0261b82603c98843d6e0b36920f2849c1f0db05e3fd5d67bc43d54
|
7
|
+
data.tar.gz: d31194eae620d640623843109fe448b431b25feb278c2f1c85b248eeee15269cdaa0f264252bcc1275c476ab0569a0e945bf87e3b8dc2ffc3fe3e27a4c047246
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## v0.2.2 - 2020-03-31
|
4
|
+
|
5
|
+
- Move serialization logic in the `Teamtailor::Record` base class (`9ec63a0`)
|
6
|
+
- Fix serializing/deserializing loaded relationships for
|
7
|
+
`Teamtailor::JobApplication` (`428e2d`)
|
8
|
+
|
9
|
+
## v0.2.1 - 2020-03-31
|
10
|
+
|
11
|
+
- Add `Teamtailor::JobApplication` and `Client#job_applications` (`062fa7`)
|
12
|
+
|
13
|
+
## v0.2.0 - 2020-03-31
|
14
|
+
|
15
|
+
- Add support for accessing relationships on records (`1218aa`)
|
16
|
+
- Add support for including relationships when querying the API (`90f25d`)
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in teamtailor.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake', '~> 12.0'
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'rspec', '~> 3.0'
|
12
|
+
gem 'rubocop'
|
13
|
+
gem 'webmock', '~> 3.4', '>= 3.4.2'
|
14
|
+
gem 'simplecov', require: false
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
teamtailor (0.2.2)
|
5
|
+
typhoeus (~> 1.3.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.0)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
docile (1.3.2)
|
17
|
+
ethon (0.12.0)
|
18
|
+
ffi (>= 1.3.0)
|
19
|
+
ffi (1.12.2)
|
20
|
+
hashdiff (1.0.1)
|
21
|
+
jaro_winkler (1.5.4)
|
22
|
+
parallel (1.19.1)
|
23
|
+
parser (2.7.0.5)
|
24
|
+
ast (~> 2.4.0)
|
25
|
+
public_suffix (4.0.3)
|
26
|
+
rainbow (3.0.0)
|
27
|
+
rake (12.3.3)
|
28
|
+
rexml (3.2.4)
|
29
|
+
rspec (3.9.0)
|
30
|
+
rspec-core (~> 3.9.0)
|
31
|
+
rspec-expectations (~> 3.9.0)
|
32
|
+
rspec-mocks (~> 3.9.0)
|
33
|
+
rspec-core (3.9.1)
|
34
|
+
rspec-support (~> 3.9.1)
|
35
|
+
rspec-expectations (3.9.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-mocks (3.9.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.9.0)
|
41
|
+
rspec-support (3.9.2)
|
42
|
+
rubocop (0.80.1)
|
43
|
+
jaro_winkler (~> 1.5.1)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 2.7.0.1)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
rexml
|
48
|
+
ruby-progressbar (~> 1.7)
|
49
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
50
|
+
ruby-progressbar (1.10.1)
|
51
|
+
safe_yaml (1.0.5)
|
52
|
+
simplecov (0.18.5)
|
53
|
+
docile (~> 1.1)
|
54
|
+
simplecov-html (~> 0.11)
|
55
|
+
simplecov-html (0.12.2)
|
56
|
+
typhoeus (1.3.1)
|
57
|
+
ethon (>= 0.9.0)
|
58
|
+
unicode-display_width (1.6.1)
|
59
|
+
webmock (3.8.3)
|
60
|
+
addressable (>= 2.3.6)
|
61
|
+
crack (>= 0.3.2)
|
62
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
rake (~> 12.0)
|
69
|
+
rspec (~> 3.0)
|
70
|
+
rubocop
|
71
|
+
simplecov
|
72
|
+
teamtailor!
|
73
|
+
webmock (~> 3.4, >= 3.4.2)
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
2.1.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 André Ligné
|
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,126 @@
|
|
1
|
+
# Teamtailor
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/teamtailor.svg)](https://badge.fury.io/rb/teamtailor)
|
4
|
+
|
5
|
+
The `teamtailor` gem helps Ruby developers interact with their Teamtailor
|
6
|
+
account, using classes that wrap the [Teamtailor API][teamtailor-api].
|
7
|
+
|
8
|
+
[teamtailor-api]: https://docs.teamtailor.com/
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'teamtailor'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install teamtailor
|
26
|
+
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
To use the library, you need an API key for a specific Teamtailor account, which
|
31
|
+
you can create by signing in as an Admin in Teamtailor and generating a new
|
32
|
+
key under _Settings_.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
@client = Teamtailor::Client.new(
|
36
|
+
base_url: 'https://api.teamtailor.com',
|
37
|
+
api_token: '<PRIVATE API KEY>',
|
38
|
+
api_version: 20161108
|
39
|
+
)
|
40
|
+
```
|
41
|
+
|
42
|
+
### Pagination
|
43
|
+
|
44
|
+
The gem does not automatically paginate through all the pages of an API
|
45
|
+
endpoint is something you can do. The `#has_next_page?` method is
|
46
|
+
helpful when knowing if there's more to fetch.
|
47
|
+
|
48
|
+
To fetch all jobs, you could do something like this:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
current_page = 1
|
52
|
+
jobs = []
|
53
|
+
|
54
|
+
while (page_result = @client.jobs(page: current_page))
|
55
|
+
jobs.append *page_result.records
|
56
|
+
break unless page_result.has_next_page?
|
57
|
+
current_page += 1
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
You can get all the titles through the `#title` method.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
irb(main):041:0> jobs.map &:title
|
65
|
+
=> ["EmberJS Developer", "Ruby on Rails developer"]
|
66
|
+
```
|
67
|
+
|
68
|
+
### Relationships
|
69
|
+
|
70
|
+
The API allows you to include associated data when requesting data to help
|
71
|
+
you load associations without having to make any additional requests.
|
72
|
+
To do this, you can pass what you want to include when making the request.
|
73
|
+
|
74
|
+
To fetch jobs with all associated `user`s loaded, you can call `Client#jobs`
|
75
|
+
like this:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
irb(main):006:0> page_result = @client.jobs(page: 1, include: [:user])
|
79
|
+
irb(main):007:0> page_result.records.first.user.record.login_email
|
80
|
+
=> "admin@teamtailor.localhost"
|
81
|
+
```
|
82
|
+
|
83
|
+
If you try to access a relationship, without having included it when loading it
|
84
|
+
from the server, it'll raise a `Teamtailor::UnloadedRelationError`:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
irb(main):010:0> page_result = @client.jobs(page: 1, include: [])
|
88
|
+
irb(main):011:0> page_result.records.first.user.record
|
89
|
+
Traceback (most recent call last):
|
90
|
+
...
|
91
|
+
1: from ~/teamtailor/lib/teamtailor/relationship.rb:16:in `record'
|
92
|
+
Teamtailor::UnloadedRelationError (Teamtailor::UnloadedRelationError)
|
93
|
+
```
|
94
|
+
|
95
|
+
To check if a relation has been loaded or not you can use the
|
96
|
+
`Relationship#loaded?` method to check before calling it:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
irb(main):012:0> page_result = @client.jobs(page: 1, include: [:user])
|
100
|
+
irb(main):013:0> page_result.records.first.user.loaded?
|
101
|
+
=> true
|
102
|
+
```
|
103
|
+
|
104
|
+
## Development
|
105
|
+
|
106
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
107
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
108
|
+
prompt that will allow you to experiment.
|
109
|
+
|
110
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
111
|
+
release a new version, update the version number in `version.rb`, and then run
|
112
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
113
|
+
git commits and tags, and push the `.gem` file to
|
114
|
+
[rubygems.org](https://rubygems.org).
|
115
|
+
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at
|
120
|
+
https://github.com/bzf/teamtailor-rb.
|
121
|
+
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the [MIT
|
126
|
+
License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'teamtailor'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/teamtailor.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'teamtailor/request'
|
4
|
+
|
5
|
+
module Teamtailor
|
6
|
+
class Client
|
7
|
+
def initialize(base_url:, api_token:, api_version:)
|
8
|
+
@base_url = base_url
|
9
|
+
@api_token = api_token
|
10
|
+
@api_version = api_version
|
11
|
+
end
|
12
|
+
|
13
|
+
def candidates(page: 1, include: [])
|
14
|
+
Teamtailor::Request.new(
|
15
|
+
base_url: base_url,
|
16
|
+
api_token: api_token,
|
17
|
+
api_version: api_version,
|
18
|
+
path: '/v1/candidates',
|
19
|
+
params: {
|
20
|
+
'page[number]' => page,
|
21
|
+
'page[size]' => 30,
|
22
|
+
'include' => include.join(',')
|
23
|
+
}
|
24
|
+
).call
|
25
|
+
end
|
26
|
+
|
27
|
+
def jobs(page: 1, include: [])
|
28
|
+
Teamtailor::Request.new(
|
29
|
+
base_url: base_url,
|
30
|
+
api_token: api_token,
|
31
|
+
api_version: api_version,
|
32
|
+
path: '/v1/jobs',
|
33
|
+
params: {
|
34
|
+
'page[number]' => page,
|
35
|
+
'page[size]' => 30,
|
36
|
+
'include' => include.join(',')
|
37
|
+
}
|
38
|
+
).call
|
39
|
+
end
|
40
|
+
|
41
|
+
def job_applications(page: 1, include: [])
|
42
|
+
Teamtailor::Request.new(
|
43
|
+
base_url: base_url,
|
44
|
+
api_token: api_token,
|
45
|
+
api_version: api_version,
|
46
|
+
path: '/v1/job-applications',
|
47
|
+
params: {
|
48
|
+
'page[number]' => page,
|
49
|
+
'page[size]' => 30,
|
50
|
+
'include' => include.join(',')
|
51
|
+
}
|
52
|
+
).call
|
53
|
+
end
|
54
|
+
|
55
|
+
def users(page: 1, include: [])
|
56
|
+
Teamtailor::Request.new(
|
57
|
+
base_url: base_url,
|
58
|
+
api_token: api_token,
|
59
|
+
api_version: api_version,
|
60
|
+
path: '/v1/users',
|
61
|
+
params: {
|
62
|
+
'page[number]' => page,
|
63
|
+
'page[size]' => 30,
|
64
|
+
'include' => include.join(',')
|
65
|
+
}
|
66
|
+
).call
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
attr_reader :base_url, :api_token, :api_version
|
72
|
+
|
73
|
+
def response_error(response)
|
74
|
+
Teamtailor::Error.from_response body: response.body, status: response.code
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Teamtailor
|
4
|
+
class Error < StandardError
|
5
|
+
def self.from_response(body:, status:)
|
6
|
+
case status
|
7
|
+
when 401
|
8
|
+
Teamtailor::UnauthorizedRequestError.new
|
9
|
+
when 406
|
10
|
+
json_response = JSON.parse(body)
|
11
|
+
Teamtailor::InvalidApiVersionError.new(
|
12
|
+
json_response.dig('errors', 'detail')
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class ClientError < Error; end
|
19
|
+
|
20
|
+
class UnauthorizedRequestError < ClientError; end
|
21
|
+
|
22
|
+
class InvalidApiVersionError < ClientError; end
|
23
|
+
|
24
|
+
class JSONError < ClientError; end
|
25
|
+
|
26
|
+
class UnknownResponseTypeError < ClientError; end
|
27
|
+
|
28
|
+
class UnloadedRelationError < ClientError; end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'teamtailor/parser'
|
4
|
+
|
5
|
+
module Teamtailor
|
6
|
+
class PageResult
|
7
|
+
def initialize(response_body)
|
8
|
+
@json_response = JSON.parse(response_body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def records
|
12
|
+
Teamtailor::Parser.parse json_response
|
13
|
+
end
|
14
|
+
|
15
|
+
def data
|
16
|
+
json_response.dig('data')
|
17
|
+
end
|
18
|
+
|
19
|
+
def page_count
|
20
|
+
json_response.dig('meta', 'page-count')
|
21
|
+
end
|
22
|
+
|
23
|
+
def record_count
|
24
|
+
json_response.dig('meta', 'record-count')
|
25
|
+
end
|
26
|
+
|
27
|
+
def next_page_url
|
28
|
+
json_response.dig('links', 'next')
|
29
|
+
end
|
30
|
+
|
31
|
+
def first_page_url
|
32
|
+
json_response.dig('links', 'first')
|
33
|
+
end
|
34
|
+
|
35
|
+
def last_page_url
|
36
|
+
json_response.dig('links', 'last')
|
37
|
+
end
|
38
|
+
|
39
|
+
def has_next_page?
|
40
|
+
!next_page_url.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :json_response
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'teamtailor/relationship'
|
4
|
+
require 'teamtailor/parser/candidate'
|
5
|
+
require 'teamtailor/parser/job'
|
6
|
+
require 'teamtailor/parser/user'
|
7
|
+
require 'teamtailor/parser/job_application'
|
8
|
+
|
9
|
+
module Teamtailor
|
10
|
+
class Parser
|
11
|
+
def self.parse(payload)
|
12
|
+
new(payload).parse
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse
|
16
|
+
data.map do |record|
|
17
|
+
case record&.dig('type')
|
18
|
+
when 'candidates' then Teamtailor::Candidate.new(record, included)
|
19
|
+
when 'jobs' then Teamtailor::Job.new(record, included)
|
20
|
+
when 'users' then Teamtailor::User.new(record, included)
|
21
|
+
when 'job-applications' then Teamtailor::JobApplication.new(record, included)
|
22
|
+
|
23
|
+
else
|
24
|
+
raise Teamtailor::UnknownResponseTypeError, record&.dig('type')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :payload
|
32
|
+
|
33
|
+
def initialize(payload)
|
34
|
+
@payload = payload
|
35
|
+
end
|
36
|
+
|
37
|
+
def data
|
38
|
+
[payload&.dig('data')].flatten
|
39
|
+
end
|
40
|
+
|
41
|
+
def included
|
42
|
+
payload&.dig('included')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Teamtailor
|
2
|
+
class Record
|
3
|
+
def initialize(data, included = {})
|
4
|
+
@data = data
|
5
|
+
@included = included
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.deserialize(value)
|
9
|
+
payload = JSON.parse value
|
10
|
+
new(payload['data'], payload['included'])
|
11
|
+
end
|
12
|
+
|
13
|
+
def serialize
|
14
|
+
{
|
15
|
+
data: data,
|
16
|
+
included: included
|
17
|
+
}.to_json
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(m)
|
21
|
+
if m == :id
|
22
|
+
data.dig('id').to_i
|
23
|
+
elsif relationship_keys.include?(m.to_s.gsub('_', '-'))
|
24
|
+
build_relationship(m.to_s.gsub('_', '-'))
|
25
|
+
else
|
26
|
+
data.dig('attributes', m.to_s.gsub('_', '-'))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :data, :included
|
33
|
+
|
34
|
+
def build_relationship(name)
|
35
|
+
Teamtailor::Relationship.new(name, data.dig('relationships'), included)
|
36
|
+
end
|
37
|
+
|
38
|
+
def relationship_keys
|
39
|
+
data.dig('relationships')&.keys || {}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Teamtailor
|
4
|
+
class Relationship
|
5
|
+
def initialize(relation_name, relationships = {}, included = {})
|
6
|
+
@relation_name = relation_name
|
7
|
+
@relationships = relationships
|
8
|
+
@included = included
|
9
|
+
end
|
10
|
+
|
11
|
+
def loaded?
|
12
|
+
!record_id.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def record
|
16
|
+
raise Teamtailor::UnloadedRelationError unless loaded?
|
17
|
+
|
18
|
+
record_json = included.find do |k|
|
19
|
+
k['id'] == record_id && k['type'] == record_type
|
20
|
+
end
|
21
|
+
|
22
|
+
Teamtailor::Parser.parse({ 'data' => record_json }).first
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def record_id
|
28
|
+
relationships&.dig(relation_name, 'data', 'id')
|
29
|
+
end
|
30
|
+
|
31
|
+
def record_type
|
32
|
+
relationships&.dig(relation_name, 'data', 'type')
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_reader :relation_name, :relationships, :included
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'teamtailor/page_result'
|
5
|
+
|
6
|
+
module Teamtailor
|
7
|
+
class Request
|
8
|
+
def initialize(base_url:, api_token:, api_version:, path:, params: {})
|
9
|
+
@base_url = base_url
|
10
|
+
@api_token = api_token
|
11
|
+
@api_version = api_version
|
12
|
+
@path = path
|
13
|
+
@params = params
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
request = Typhoeus::Request.new(
|
18
|
+
"#{base_url}#{path}",
|
19
|
+
method: :get,
|
20
|
+
params: params,
|
21
|
+
headers: request_headers
|
22
|
+
)
|
23
|
+
response = request.run
|
24
|
+
|
25
|
+
if response.code == 200
|
26
|
+
Teamtailor::PageResult.new response.body
|
27
|
+
else
|
28
|
+
raise Teamtailor::Error.from_response(
|
29
|
+
body: response.body,
|
30
|
+
status: response.code
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :base_url, :path, :api_token, :api_version, :params
|
38
|
+
|
39
|
+
def request_headers
|
40
|
+
{
|
41
|
+
"Authorization": "Token token=#{api_token}",
|
42
|
+
'X-Api-Version' => api_version,
|
43
|
+
'User-Agent' => "teamtailor-rb v#{Teamtailor::VERSION}",
|
44
|
+
'Content-Type' => 'application/vnd.api+json; charset=utf-8'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/teamtailor.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/teamtailor/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'teamtailor'
|
7
|
+
spec.version = Teamtailor::VERSION
|
8
|
+
spec.authors = ['André Ligné']
|
9
|
+
spec.email = ['hi@andreligne.se']
|
10
|
+
|
11
|
+
spec.summary = 'Library for interacting with the Teamtailor API'
|
12
|
+
spec.homepage = 'https://github.com/bzf/teamtailor-gem'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/bzf/teamtailor-rb'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/bzf/teamtailor-rb/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
21
|
+
spec.add_dependency 'typhoeus', '~> 1.3.1'
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
25
|
+
# into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teamtailor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- André Ligné
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: typhoeus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.1
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- hi@andreligne.se
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CHANGELOG.md
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- lib/teamtailor.rb
|
60
|
+
- lib/teamtailor/client.rb
|
61
|
+
- lib/teamtailor/error.rb
|
62
|
+
- lib/teamtailor/page_result.rb
|
63
|
+
- lib/teamtailor/parser.rb
|
64
|
+
- lib/teamtailor/parser/candidate.rb
|
65
|
+
- lib/teamtailor/parser/job.rb
|
66
|
+
- lib/teamtailor/parser/job_application.rb
|
67
|
+
- lib/teamtailor/parser/user.rb
|
68
|
+
- lib/teamtailor/record.rb
|
69
|
+
- lib/teamtailor/relationship.rb
|
70
|
+
- lib/teamtailor/request.rb
|
71
|
+
- lib/teamtailor/version.rb
|
72
|
+
- teamtailor.gemspec
|
73
|
+
homepage: https://github.com/bzf/teamtailor-gem
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
homepage_uri: https://github.com/bzf/teamtailor-gem
|
78
|
+
source_code_uri: https://github.com/bzf/teamtailor-rb
|
79
|
+
changelog_uri: https://github.com/bzf/teamtailor-rb/master/CHANGELOG.md
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.3.0
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.1.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Library for interacting with the Teamtailor API
|
99
|
+
test_files: []
|