teamtailor 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebfcfeb03d901b4ce684049c447631262ce8b45a8934adf5546c02e13116e933
4
- data.tar.gz: 9de739e137ac1a687fac69fecb7d5c9a9ac6c76aaea518965a02f14bbe53fc1d
3
+ metadata.gz: c9464bec7bd58b5a5b47dc4cd5fd2aa91710f82602f658d4a1981cff33d42bc1
4
+ data.tar.gz: f1e218de0ce3dd7ebb78ebdd29c44ad2bfb49680b226186a18b5f18e23d2c654
5
5
  SHA512:
6
- metadata.gz: 98958cee29aa6ab5372bb36b16f4b9ab8184974b9937c62115eac8911a02003b8fa5310ed87e2f8b6db138d072f01905db528234b9066f1a247733c34068bb7f
7
- data.tar.gz: d2c550d684dc760746cf318b834736883471a82f085bb9b8b13417ce35db57ac03ab3a856d49110b17c6866eb9cbb470ef5678c635d536f368ddb4edc0f2ec12
6
+ metadata.gz: db6d877077e001925903a29694918110f02c85bdb3e3c10bc80df415bf5f9b0e463e2f606380f9c26f391e49ea0f6cb86416989afe00df4883df335fac947794
7
+ data.tar.gz: a27532d72dd0cfd872392af29ff3e81665a1fd61ff27f065801f815fc14b2928d72950e5cef3b14e27fd058308faaba2afd5ed1285c4c67ada6826599a841e39
data/Gemfile CHANGED
@@ -1,7 +1,15 @@
1
- source "https://rubygems.org"
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 "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
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
@@ -2,12 +2,30 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  teamtailor (0.1.0)
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/teamtailor`. To experiment with that code, run `bin/console` for an interactive prompt.
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/
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
6
10
 
7
11
  ## Installation
8
12
 
@@ -20,21 +24,68 @@ Or install it yourself as:
20
24
 
21
25
  $ gem install teamtailor
22
26
 
27
+
23
28
  ## Usage
24
29
 
25
- TODO: Write usage instructions here
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
+
26
68
 
27
69
  ## Development
28
70
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
72
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
73
+ prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To
76
+ release a new version, update the version number in `version.rb`, and then run
77
+ `bundle exec rake release`, which will create a git tag for the version, push
78
+ git commits and tags, and push the `.gem` file to
79
+ [rubygems.org](https://rubygems.org).
30
80
 
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
81
 
33
82
  ## Contributing
34
83
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/teamtailor.
84
+ Bug reports and pull requests are welcome on GitHub at
85
+ https://github.com/bzf/teamtailor-rb.
36
86
 
37
87
 
38
88
  ## License
39
89
 
40
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
90
+ The gem is available as open source under the terms of the [MIT
91
+ License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "teamtailor"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -0,0 +1,60 @@
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)
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
+ }
23
+ ).call
24
+ end
25
+
26
+ def jobs(page: 1)
27
+ Teamtailor::Request.new(
28
+ base_url: base_url,
29
+ api_token: api_token,
30
+ api_version: api_version,
31
+ path: '/v1/jobs',
32
+ params: {
33
+ 'page[number]' => page,
34
+ 'page[size]' => 30
35
+ }
36
+ ).call
37
+ end
38
+
39
+ def users(page: 1)
40
+ Teamtailor::Request.new(
41
+ base_url: base_url,
42
+ api_token: api_token,
43
+ api_version: api_version,
44
+ path: '/v1/users',
45
+ params: {
46
+ 'page[number]' => page,
47
+ 'page[size]' => 30
48
+ }
49
+ ).call
50
+ end
51
+
52
+ private
53
+
54
+ attr_reader :base_url, :api_token, :api_version
55
+
56
+ def response_error(response)
57
+ Teamtailor::Error.from_response body: response.body, status: response.code
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,27 @@
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
+ 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,31 @@
1
+ module Teamtailor
2
+ class Candidate
3
+ def initialize(payload)
4
+ @payload = payload
5
+ end
6
+
7
+ def self.deserialize(value)
8
+ new(value)
9
+ end
10
+
11
+ def serialize
12
+ payload
13
+ end
14
+
15
+ def id
16
+ payload.dig('id').to_i
17
+ end
18
+
19
+ def connected?
20
+ payload.dig('attributes', 'connected')
21
+ end
22
+
23
+ def method_missing(m)
24
+ payload.dig('attributes', m.to_s.gsub('_', '-'))
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :payload
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Teamtailor
2
+ class Job
3
+ def initialize(payload)
4
+ @payload = payload
5
+ end
6
+
7
+ def self.deserialize(value)
8
+ new(value)
9
+ end
10
+
11
+ def serialize
12
+ payload
13
+ end
14
+
15
+ def id
16
+ payload.dig('id').to_i
17
+ end
18
+
19
+ def careersite_job_url
20
+ payload.dig('links', 'careersite-job-url')
21
+ end
22
+
23
+ def method_missing(m)
24
+ payload.dig('attributes', m.to_s.gsub('_', '-'))
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :payload
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module Teamtailor
2
+ class User
3
+ def initialize(payload)
4
+ @payload = payload
5
+ end
6
+
7
+ def self.deserialize(value)
8
+ new(value)
9
+ end
10
+
11
+ def serialize
12
+ payload
13
+ end
14
+
15
+ def id
16
+ payload.dig('id').to_i
17
+ end
18
+
19
+ def method_missing(m)
20
+ payload.dig('attributes', m.to_s.gsub('_', '-'))
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :payload
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'teamtailor/parser/candidate'
4
+ require 'teamtailor/parser/job'
5
+ require 'teamtailor/parser/user'
6
+
7
+ module Teamtailor
8
+ class Parser
9
+ def self.parse(payload)
10
+ new(payload).parse
11
+ end
12
+
13
+ def parse
14
+ data.map do |record|
15
+ case record&.dig('type')
16
+ when 'candidates' then Teamtailor::Candidate.new(record)
17
+ when 'jobs' then Teamtailor::Job.new(record)
18
+ when 'users' then Teamtailor::User.new(record)
19
+
20
+ else
21
+ raise Teamtailor::UnknownResponseTypeError.new(record&.dig('type'))
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :payload
29
+
30
+ def initialize(payload)
31
+ @payload = payload
32
+ end
33
+
34
+ def data
35
+ [payload&.dig('data')].flatten
36
+ end
37
+ end
38
+ 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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Teamtailor
2
- VERSION = "0.0.1"
4
+ VERSION = '0.1.0'
3
5
  end
data/lib/teamtailor.rb CHANGED
@@ -1,6 +1,8 @@
1
- require "teamtailor/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'teamtailor/error'
4
+ require 'teamtailor/client'
5
+ require 'teamtailor/version'
2
6
 
3
7
  module Teamtailor
4
- class Error < StandardError; end
5
- # Your code goes here...
6
8
  end
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 = "teamtailor"
6
+ spec.name = 'teamtailor'
5
7
  spec.version = Teamtailor::VERSION
6
- spec.authors = ["André Ligné"]
7
- spec.email = ["hi@andreligne.se"]
8
+ spec.authors = ['André Ligné']
9
+ spec.email = ['hi@andreligne.se']
8
10
 
9
- spec.summary = %q{Library for interacting with the Teamtailor API}
10
- spec.homepage = "https://github.com/bzf/teamtailor-gem"
11
- spec.license = "MIT"
12
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
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["homepage_uri"] = spec.homepage
15
- spec.metadata["source_code_uri"] = "https://github.com/bzf/teamtailor-gem"
16
- spec.metadata["changelog_uri"] = "https://github.com/bzf/teamtailor-gem/master/CHANGELOG.md"
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/bzf/teamtailor-gem'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/bzf/teamtailor-gem/master/CHANGELOG.md'
17
19
 
18
- spec.add_development_dependency "rspec", "~> 3.2"
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 into git.
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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 = "exe"
31
+ spec.bindir = 'exe'
26
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
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.0.1
4
+ version: 0.1.0
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-03-24 00:00:00.000000000 Z
11
+ date: 2020-03-27 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
@@ -42,6 +56,14 @@ files:
42
56
  - bin/console
43
57
  - bin/setup
44
58
  - lib/teamtailor.rb
59
+ - lib/teamtailor/client.rb
60
+ - lib/teamtailor/error.rb
61
+ - lib/teamtailor/page_result.rb
62
+ - lib/teamtailor/parser.rb
63
+ - lib/teamtailor/parser/candidate.rb
64
+ - lib/teamtailor/parser/job.rb
65
+ - lib/teamtailor/parser/user.rb
66
+ - lib/teamtailor/request.rb
45
67
  - lib/teamtailor/version.rb
46
68
  - teamtailor.gemspec
47
69
  homepage: https://github.com/bzf/teamtailor-gem