teamtailor 0.0.1 → 0.2.3
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/CHANGELOG.md +20 -0
- data/Gemfile +11 -3
- data/Gemfile.lock +43 -1
- data/README.md +93 -7
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/lib/teamtailor.rb +5 -3
- data/lib/teamtailor/client.rb +89 -0
- data/lib/teamtailor/error.rb +29 -0
- data/lib/teamtailor/page_result.rb +47 -0
- data/lib/teamtailor/parser.rb +46 -0
- data/lib/teamtailor/parser/candidate.rb +11 -0
- data/lib/teamtailor/parser/company.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 +44 -0
- data/lib/teamtailor/relationship.rb +37 -0
- data/lib/teamtailor/request.rb +48 -0
- data/lib/teamtailor/version.rb +3 -1
- data/teamtailor.gemspec +22 -16
- metadata +31 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2ea15733d89440836cd11873349b83f5036f63f5e1ea16232ec3c442548ce4a7
|
|
4
|
+
data.tar.gz: a8793472aef8a5374f7ac1da3ad3aa9dc79a6ca77d2e12010e5d6c5d0bc6066c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77f8ed12b1e1d3145a32dfd7c351f8ffa9d7b19cfd59eb2776deee136dc05e7cf0167e50e77b26b1698f6ebca9f1107ad9874c13f3b13fef93ec7d3d5f7556a6
|
|
7
|
+
data.tar.gz: '09e87150351d60b41a898afaf14f028ab685726a50a929168868cd400636f6439ef927d92722bc07ad234e100cfb2b41e5a5129f07fcb84c18d33744ccf0140d'
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
## Unreleased
|
|
2
|
+
|
|
3
|
+
## v0.2.3 - 2020-04-06
|
|
4
|
+
|
|
5
|
+
- Add `Teamtailor::Company` and `Client#company` for fetching it (`05dde0`)
|
|
6
|
+
|
|
7
|
+
## v0.2.2 - 2020-03-31
|
|
8
|
+
|
|
9
|
+
- Move serialization logic in the `Teamtailor::Record` base class (`9ec63a0`)
|
|
10
|
+
- Fix serializing/deserializing loaded relationships for
|
|
11
|
+
`Teamtailor::JobApplication` (`428e2d`)
|
|
12
|
+
|
|
13
|
+
## v0.2.1 - 2020-03-31
|
|
14
|
+
|
|
15
|
+
- Add `Teamtailor::JobApplication` and `Client#job_applications` (`062fa7`)
|
|
16
|
+
|
|
17
|
+
## v0.2.0 - 2020-03-31
|
|
18
|
+
|
|
19
|
+
- Add support for accessing relationships on records (`1218aa`)
|
|
20
|
+
- Add support for including relationships when querying the API (`90f25d`)
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
2
4
|
|
|
3
5
|
# Specify your gem's dependencies in teamtailor.gemspec
|
|
4
6
|
gemspec
|
|
5
7
|
|
|
6
|
-
gem
|
|
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
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
teamtailor (0.
|
|
4
|
+
teamtailor (0.2.3)
|
|
5
|
+
typhoeus (~> 1.3.1)
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
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)
|
|
9
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)
|
|
10
27
|
rake (12.3.3)
|
|
28
|
+
rexml (3.2.4)
|
|
11
29
|
rspec (3.9.0)
|
|
12
30
|
rspec-core (~> 3.9.0)
|
|
13
31
|
rspec-expectations (~> 3.9.0)
|
|
@@ -21,6 +39,27 @@ GEM
|
|
|
21
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
40
|
rspec-support (~> 3.9.0)
|
|
23
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)
|
|
24
63
|
|
|
25
64
|
PLATFORMS
|
|
26
65
|
ruby
|
|
@@ -28,7 +67,10 @@ PLATFORMS
|
|
|
28
67
|
DEPENDENCIES
|
|
29
68
|
rake (~> 12.0)
|
|
30
69
|
rspec (~> 3.0)
|
|
70
|
+
rubocop
|
|
71
|
+
simplecov
|
|
31
72
|
teamtailor!
|
|
73
|
+
webmock (~> 3.4, >= 3.4.2)
|
|
32
74
|
|
|
33
75
|
BUNDLED WITH
|
|
34
76
|
2.1.2
|
data/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# Teamtailor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](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/
|
|
4
9
|
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
6
10
|
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
@@ -20,21 +24,103 @@ Or install it yourself as:
|
|
|
20
24
|
|
|
21
25
|
$ gem install teamtailor
|
|
22
26
|
|
|
27
|
+
|
|
23
28
|
## Usage
|
|
24
29
|
|
|
25
|
-
|
|
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
|
+
```
|
|
26
103
|
|
|
27
104
|
## Development
|
|
28
105
|
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
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).
|
|
30
115
|
|
|
31
|
-
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).
|
|
32
116
|
|
|
33
117
|
## Contributing
|
|
34
118
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at
|
|
119
|
+
Bug reports and pull requests are welcome on GitHub at
|
|
120
|
+
https://github.com/bzf/teamtailor-rb.
|
|
36
121
|
|
|
37
122
|
|
|
38
123
|
## License
|
|
39
124
|
|
|
40
|
-
The gem is available as open source under the terms of the [MIT
|
|
125
|
+
The gem is available as open source under the terms of the [MIT
|
|
126
|
+
License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'teamtailor'
|
|
5
6
|
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -10,5 +11,5 @@ require "teamtailor"
|
|
|
10
11
|
# require "pry"
|
|
11
12
|
# Pry.start
|
|
12
13
|
|
|
13
|
-
require
|
|
14
|
+
require 'irb'
|
|
14
15
|
IRB.start(__FILE__)
|
data/lib/teamtailor.rb
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
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 company(include: [])
|
|
14
|
+
Teamtailor::Request.new(
|
|
15
|
+
base_url: base_url,
|
|
16
|
+
api_token: api_token,
|
|
17
|
+
api_version: api_version,
|
|
18
|
+
path: '/v1/company',
|
|
19
|
+
params: {
|
|
20
|
+
'include' => include.join(',')
|
|
21
|
+
}
|
|
22
|
+
).call
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def candidates(page: 1, include: [])
|
|
26
|
+
Teamtailor::Request.new(
|
|
27
|
+
base_url: base_url,
|
|
28
|
+
api_token: api_token,
|
|
29
|
+
api_version: api_version,
|
|
30
|
+
path: '/v1/candidates',
|
|
31
|
+
params: {
|
|
32
|
+
'page[number]' => page,
|
|
33
|
+
'page[size]' => 30,
|
|
34
|
+
'include' => include.join(',')
|
|
35
|
+
}
|
|
36
|
+
).call
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def jobs(page: 1, include: [])
|
|
40
|
+
Teamtailor::Request.new(
|
|
41
|
+
base_url: base_url,
|
|
42
|
+
api_token: api_token,
|
|
43
|
+
api_version: api_version,
|
|
44
|
+
path: '/v1/jobs',
|
|
45
|
+
params: {
|
|
46
|
+
'page[number]' => page,
|
|
47
|
+
'page[size]' => 30,
|
|
48
|
+
'include' => include.join(',')
|
|
49
|
+
}
|
|
50
|
+
).call
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def job_applications(page: 1, include: [])
|
|
54
|
+
Teamtailor::Request.new(
|
|
55
|
+
base_url: base_url,
|
|
56
|
+
api_token: api_token,
|
|
57
|
+
api_version: api_version,
|
|
58
|
+
path: '/v1/job-applications',
|
|
59
|
+
params: {
|
|
60
|
+
'page[number]' => page,
|
|
61
|
+
'page[size]' => 30,
|
|
62
|
+
'include' => include.join(',')
|
|
63
|
+
}
|
|
64
|
+
).call
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def users(page: 1, include: [])
|
|
68
|
+
Teamtailor::Request.new(
|
|
69
|
+
base_url: base_url,
|
|
70
|
+
api_token: api_token,
|
|
71
|
+
api_version: api_version,
|
|
72
|
+
path: '/v1/users',
|
|
73
|
+
params: {
|
|
74
|
+
'page[number]' => page,
|
|
75
|
+
'page[size]' => 30,
|
|
76
|
+
'include' => include.join(',')
|
|
77
|
+
}
|
|
78
|
+
).call
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
attr_reader :base_url, :api_token, :api_version
|
|
84
|
+
|
|
85
|
+
def response_error(response)
|
|
86
|
+
Teamtailor::Error.from_response body: response.body, status: response.code
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
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,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'teamtailor/parser/candidate'
|
|
4
|
+
require 'teamtailor/parser/job'
|
|
5
|
+
require 'teamtailor/parser/user'
|
|
6
|
+
require 'teamtailor/parser/job_application'
|
|
7
|
+
require 'teamtailor/parser/company'
|
|
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
|
+
when 'companies' then Teamtailor::Company.new(record, included)
|
|
23
|
+
|
|
24
|
+
else
|
|
25
|
+
raise Teamtailor::UnknownResponseTypeError, record&.dig('type')
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
attr_reader :payload
|
|
33
|
+
|
|
34
|
+
def initialize(payload)
|
|
35
|
+
@payload = payload
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def data
|
|
39
|
+
[payload&.dig('data')].flatten
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def included
|
|
43
|
+
payload&.dig('included')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'teamtailor/relationship'
|
|
2
|
+
|
|
3
|
+
module Teamtailor
|
|
4
|
+
class Record
|
|
5
|
+
def initialize(data, included = {})
|
|
6
|
+
@data = data
|
|
7
|
+
@included = included
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.deserialize(value)
|
|
11
|
+
payload = JSON.parse value
|
|
12
|
+
new(payload['data'], payload['included'])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def serialize
|
|
16
|
+
{
|
|
17
|
+
data: data,
|
|
18
|
+
included: included
|
|
19
|
+
}.to_json
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def method_missing(m)
|
|
23
|
+
if m == :id
|
|
24
|
+
data.dig('id').to_i
|
|
25
|
+
elsif relationship_keys.include?(m.to_s.gsub('_', '-'))
|
|
26
|
+
build_relationship(m.to_s.gsub('_', '-'))
|
|
27
|
+
else
|
|
28
|
+
data.dig('attributes', m.to_s.gsub('_', '-'))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
attr_reader :data, :included
|
|
35
|
+
|
|
36
|
+
def build_relationship(name)
|
|
37
|
+
Teamtailor::Relationship.new(name, data.dig('relationships'), included)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def relationship_keys
|
|
41
|
+
data.dig('relationships')&.keys || {}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
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/lib/teamtailor/version.rb
CHANGED
data/teamtailor.gemspec
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'lib/teamtailor/version'
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |spec|
|
|
4
|
-
spec.name =
|
|
6
|
+
spec.name = 'teamtailor'
|
|
5
7
|
spec.version = Teamtailor::VERSION
|
|
6
|
-
spec.authors = [
|
|
7
|
-
spec.email = [
|
|
8
|
+
spec.authors = ['André Ligné']
|
|
9
|
+
spec.email = ['hi@andreligne.se']
|
|
8
10
|
|
|
9
|
-
spec.summary =
|
|
10
|
-
spec.homepage =
|
|
11
|
-
spec.license =
|
|
12
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
|
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')
|
|
13
15
|
|
|
14
|
-
spec.metadata[
|
|
15
|
-
spec.metadata[
|
|
16
|
-
spec.metadata[
|
|
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'
|
|
17
19
|
|
|
18
|
-
spec.add_development_dependency
|
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
|
21
|
+
spec.add_dependency 'typhoeus', '~> 1.3.1'
|
|
19
22
|
|
|
20
23
|
# Specify which files should be added to the gem when it is released.
|
|
21
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
24
30
|
end
|
|
25
|
-
spec.bindir =
|
|
31
|
+
spec.bindir = 'exe'
|
|
26
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
27
|
-
spec.require_paths = [
|
|
33
|
+
spec.require_paths = ['lib']
|
|
28
34
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: teamtailor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- André Ligné
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-04-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -24,6 +24,20 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
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
|
|
27
41
|
description:
|
|
28
42
|
email:
|
|
29
43
|
- hi@andreligne.se
|
|
@@ -34,6 +48,7 @@ files:
|
|
|
34
48
|
- ".gitignore"
|
|
35
49
|
- ".rspec"
|
|
36
50
|
- ".travis.yml"
|
|
51
|
+
- CHANGELOG.md
|
|
37
52
|
- Gemfile
|
|
38
53
|
- Gemfile.lock
|
|
39
54
|
- LICENSE.txt
|
|
@@ -42,6 +57,18 @@ files:
|
|
|
42
57
|
- bin/console
|
|
43
58
|
- bin/setup
|
|
44
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/company.rb
|
|
66
|
+
- lib/teamtailor/parser/job.rb
|
|
67
|
+
- lib/teamtailor/parser/job_application.rb
|
|
68
|
+
- lib/teamtailor/parser/user.rb
|
|
69
|
+
- lib/teamtailor/record.rb
|
|
70
|
+
- lib/teamtailor/relationship.rb
|
|
71
|
+
- lib/teamtailor/request.rb
|
|
45
72
|
- lib/teamtailor/version.rb
|
|
46
73
|
- teamtailor.gemspec
|
|
47
74
|
homepage: https://github.com/bzf/teamtailor-gem
|
|
@@ -49,8 +76,8 @@ licenses:
|
|
|
49
76
|
- MIT
|
|
50
77
|
metadata:
|
|
51
78
|
homepage_uri: https://github.com/bzf/teamtailor-gem
|
|
52
|
-
source_code_uri: https://github.com/bzf/teamtailor-
|
|
53
|
-
changelog_uri: https://github.com/bzf/teamtailor-
|
|
79
|
+
source_code_uri: https://github.com/bzf/teamtailor-rb
|
|
80
|
+
changelog_uri: https://github.com/bzf/teamtailor-rb/master/CHANGELOG.md
|
|
54
81
|
post_install_message:
|
|
55
82
|
rdoc_options: []
|
|
56
83
|
require_paths:
|