greenhouse_api 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7f90dea641cda5e0664489eaf2a4cc03eda246f4ee0c97cb072b29fab55599c
4
+ data.tar.gz: eaa7a3e88c7717b4e5e4f7aaaf3d80155596890d476006e53abf3c6cec681bc5
5
+ SHA512:
6
+ metadata.gz: 501c881a0e6f8aa98caca519419dfd8103a58e90a21651af54a68a3fc5382971ba45471a6e76011f353b6a30ea0cd8e2dbbe2affc599029059ca7084794cc03e
7
+ data.tar.gz: a7e993de6c9de71755f2aa84f39216d3dd38e1415ba97e40eb507f3ba3e655fef9d937d20dd0682c35f9c24f1038007ffc755d6863c582be74bb78a0562d776d
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "greenhouse_api/version"
4
+ require 'greenhouse_api/client'
5
+
6
+ module GreenhouseApi
7
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'base64'
5
+ require 'json'
6
+
7
+ module GreenhouseApi
8
+ class Response
9
+ attr_reader :headers, :body, :status
10
+
11
+ def initialize(headers:, body:, status:)
12
+ @headers = headers
13
+ @body = body
14
+ @status = status
15
+ end
16
+ end
17
+
18
+ class Client
19
+ MAX_PER_PAGE = 500
20
+ API_URL = 'https://harvest.greenhouse.io/v1'
21
+
22
+ def initialize(api_key)
23
+ @api_key = api_key
24
+ end
25
+
26
+ def list_candidates(params = {})
27
+ list_many('candidates', params)
28
+ end
29
+
30
+ def list_many(resource, params = {})
31
+ limit = params.delete(:limit)
32
+ page = 1
33
+ data = []
34
+ response = nil
35
+
36
+ loop do
37
+ per_page = limit ? [limit - data.length, MAX_PER_PAGE].min : MAX_PER_PAGE
38
+
39
+ response = request(
40
+ http_method: :get,
41
+ headers: headers,
42
+ endpoint: resource,
43
+ params: params.merge(page: page, per_page: per_page)
44
+ )
45
+ break if response.status != 200
46
+
47
+ data.concat(response.body)
48
+
49
+ if last_page?(response) || data_limit_reached?(data, limit)
50
+ break
51
+ else
52
+ page += 1
53
+ end
54
+ end
55
+
56
+ if response.status == 200
57
+ Response.new(
58
+ body: data,
59
+ headers: response.headers,
60
+ status: response.status
61
+ )
62
+ else
63
+ response
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def last_page?(response)
70
+ !response.headers['link'].to_s.include?('rel="next"')
71
+ end
72
+
73
+ def data_limit_reached?(data, limit)
74
+ limit && data.length >= limit
75
+ end
76
+
77
+ def headers
78
+ credential = Base64.strict_encode64(@api_key + ':')
79
+
80
+ {
81
+ 'Authorization' => 'Basic ' + credential,
82
+ }
83
+ end
84
+
85
+ def request(http_method:, headers:, endpoint:, params:, body: {})
86
+ response = Faraday.public_send(http_method) do |request|
87
+ request.headers = headers
88
+ request.path = "#{API_URL}/#{endpoint}"
89
+ request.params = params
90
+ request.body = body
91
+ end
92
+
93
+ Response.new(
94
+ body: response.body && !response.body.empty? ? JSON.parse(response.body) : '',
95
+ headers: response.headers,
96
+ status: response.status
97
+ )
98
+ end
99
+ end
100
+ end
101
+
@@ -0,0 +1,3 @@
1
+ module GreenhouseApi
2
+ VERSION = "0.1.10"
3
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greenhouse_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - Florence Lau
8
+ - Tanner Johnson
9
+ - Quan Nguyen
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2020-12-02 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.1'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '3.10'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.10'
43
+ - !ruby/object:Gem::Dependency
44
+ name: vcr
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '6'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '6'
57
+ - !ruby/object:Gem::Dependency
58
+ name: webmock
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.10'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.10'
71
+ description: API client for working with Greenhouse Harvest API
72
+ email:
73
+ - quan.nguyen@gusto.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - lib/greenhouse_api.rb
79
+ - lib/greenhouse_api/client.rb
80
+ - lib/greenhouse_api/version.rb
81
+ homepage: https://github.com/gusto/greenhouse_api
82
+ licenses: []
83
+ metadata:
84
+ homepage_uri: https://github.com/gusto/greenhouse_api
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 2.3.0
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.1.4
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: API client for working with Greenhouse Harvest API
104
+ test_files: []