greenhouse_io 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.travis.yml +4 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +8 -0
- data/greenhouse_io.gemspec +28 -0
- data/lib/greenhouse_io.rb +7 -0
- data/lib/greenhouse_io/api.rb +72 -0
- data/lib/greenhouse_io/error.rb +22 -0
- data/lib/greenhouse_io/version.rb +3 -0
- data/spec/fixtures/cassettes/apply_to_job.yml +44 -0
- data/spec/fixtures/cassettes/department.yml +45 -0
- data/spec/fixtures/cassettes/departments.yml +45 -0
- data/spec/fixtures/cassettes/invalid_application.yml +43 -0
- data/spec/fixtures/cassettes/invalid_application_id.yml +44 -0
- data/spec/fixtures/cassettes/invalid_id.yml +40 -0
- data/spec/fixtures/cassettes/invalid_organization.yml +40 -0
- data/spec/fixtures/cassettes/job.yml +80 -0
- data/spec/fixtures/cassettes/job_with_questions.yml +85 -0
- data/spec/fixtures/cassettes/jobs.yml +44 -0
- data/spec/fixtures/cassettes/jobs_with_content.yml +118 -0
- data/spec/fixtures/cassettes/office.yml +45 -0
- data/spec/fixtures/cassettes/offices.yml +45 -0
- data/spec/greenhouse/api_spec.rb +186 -0
- data/spec/greenhouse/error_spec.rb +25 -0
- data/spec/spec_helper.rb +16 -0
- metadata +207 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adrian Bautista
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Greenhouse
|
2
|
+
|
3
|
+
[![Gem
|
4
|
+
Version](https://badge.fury.io/rb/greenhouse-io.png)](http://badge.fury.io/rb/greenhouse-io)
|
5
|
+
[![Build
|
6
|
+
Status](https://travis-ci.org/adrianbautista/greenhouse.png)](https://travis-ci.org/adrianbautista/greenhouse)
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/adrianbautista/greenhouse/badge.png)](https://coveralls.io/r/adrianbautista/greenhouse)
|
8
|
+
|
9
|
+
A Ruby interface to
|
10
|
+
[Greenhouse.io's](https://app.greenhouse.io/jobboard/jsonp_instructions)
|
11
|
+
API.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'greenhouse-io'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install greenhouse-io
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Creating an instance of the API client:
|
30
|
+
```ruby
|
31
|
+
gh = GreenhouseIo::API.new("api_token")
|
32
|
+
```
|
33
|
+
|
34
|
+
The client will also use the environment variable `'GREENHOUSE_API_TOKEN'` by default:
|
35
|
+
```ruby
|
36
|
+
gh = GreenhouseIo::API.new
|
37
|
+
```
|
38
|
+
|
39
|
+
A default organization can be passed through an options hash:
|
40
|
+
```ruby
|
41
|
+
gh = GreenhouseIo::API.new("api_token", :organization => "your_organization")
|
42
|
+
```
|
43
|
+
|
44
|
+
### Fetching Office Data
|
45
|
+
```ruby
|
46
|
+
gh.offices
|
47
|
+
gh.offices(:organization => 'different_organization')
|
48
|
+
# returns a hash containing all of the organization's department and jobs grouped by office
|
49
|
+
```
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
gh.office(officeID)
|
53
|
+
gh.office(officeID, :organization => 'different_organization')
|
54
|
+
# returns a hash containing the departments and jobs of a specific office
|
55
|
+
```
|
56
|
+
|
57
|
+
### Fetching Department Data
|
58
|
+
```ruby
|
59
|
+
gh.departments
|
60
|
+
gh.departments(:organization => 'different_organizaton')
|
61
|
+
```
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
gh.department(departmentID)
|
65
|
+
gh.department(departmentID, :organization => 'different_organization')
|
66
|
+
```
|
67
|
+
|
68
|
+
### Fetching Job Data
|
69
|
+
```ruby
|
70
|
+
gh.jobs
|
71
|
+
gh.jobs(:content => 'true')
|
72
|
+
# includes the job description in the response
|
73
|
+
gh.jobs(:organization => 'different_organization')
|
74
|
+
```
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
gh.job(jobID)
|
78
|
+
gh.job(jobID, :questions => true)
|
79
|
+
# returns the specified job and the array of questions on the application
|
80
|
+
gh.job(jobID, :organization => 'different_organization')
|
81
|
+
```
|
82
|
+
|
83
|
+
### Submitting a Job Application
|
84
|
+
This is the only API method that **requires** an API token from Greenhouse
|
85
|
+
```ruby
|
86
|
+
gh.apply_to_job(form_parameter_hash)
|
87
|
+
|
88
|
+
# form_parameter_hash should match the questions array of a given job opening
|
89
|
+
# there should be a hidden input with name id in your form that
|
90
|
+
# has the value of the job ID on Greenhouse.io
|
91
|
+
```
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
1. Fork it
|
96
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
99
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'greenhouse_io/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "greenhouse_io"
|
8
|
+
spec.version = GreenhouseIo::VERSION
|
9
|
+
spec.authors = ["Adrian Bautista"]
|
10
|
+
spec.email = ["adrianbautista8@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby based wrapper for Greenhouse.io API}
|
12
|
+
spec.summary = %q{A Ruby based wrapper for Greenhouse.io API}
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency('httparty')
|
21
|
+
spec.add_dependency('multi_json', '~> 1.8.0')
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
26
|
+
spec.add_development_dependency "webmock", "~> 1.8.0"
|
27
|
+
spec.add_development_dependency "vcr", "~> 2.5.0"
|
28
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module GreenhouseIo
|
2
|
+
class API
|
3
|
+
attr_accessor :api_token, :organization
|
4
|
+
|
5
|
+
include HTTParty
|
6
|
+
base_uri 'https://api.greenhouse.io/v1'
|
7
|
+
|
8
|
+
def initialize(api_token = nil, default_options = {})
|
9
|
+
@api_token = api_token || ENV['GREENHOUSE_API_TOKEN']
|
10
|
+
@organization = default_options.delete(:organization)
|
11
|
+
end
|
12
|
+
|
13
|
+
def offices(options = {})
|
14
|
+
get_response_hash("/boards/#{ query_organization(options) }/embed/offices")
|
15
|
+
end
|
16
|
+
|
17
|
+
def office(id, options = {})
|
18
|
+
get_response_hash("/boards/#{ query_organization(options) }/embed/office?id=#{ id }")
|
19
|
+
end
|
20
|
+
|
21
|
+
def departments(options = {})
|
22
|
+
get_response_hash("/boards/#{ query_organization(options) }/embed/departments")
|
23
|
+
end
|
24
|
+
|
25
|
+
def department(id, options = {})
|
26
|
+
get_response_hash("/boards/#{ query_organization(options) }/embed/department?id=#{ id }")
|
27
|
+
end
|
28
|
+
|
29
|
+
def jobs(options = {})
|
30
|
+
get_response_hash("/boards/#{ query_organization(options) }/embed/jobs?content=#{ options[:content] }")
|
31
|
+
end
|
32
|
+
|
33
|
+
def job(id, options = { :questions => false })
|
34
|
+
get_response_hash("/boards/#{ query_organization(options) }/embed/job?id=#{ id }&questions=#{ options[:questions] }")
|
35
|
+
end
|
36
|
+
|
37
|
+
def apply_to_job(job_form_hash)
|
38
|
+
options = { :body => job_form_hash, :basic_auth => basic_auth }
|
39
|
+
post_response_hash('/applications', options)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def query_organization(options_hash)
|
45
|
+
org = options_hash[:organization] || @organization
|
46
|
+
org.nil? ? (raise GreenhouseIo::Error.new("organization can't be blank")) : org
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_response_hash(url)
|
50
|
+
response = self.class.get(url)
|
51
|
+
if response.code == 200
|
52
|
+
MultiJson.load(response.body, :symbolize_keys => true)
|
53
|
+
else
|
54
|
+
raise GreenhouseIo::Error.new(response.code)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def post_response_hash(url, options)
|
59
|
+
response = self.class.post(url, options)
|
60
|
+
if response.code == 200
|
61
|
+
response.include?("success") ? MultiJson.load(response.body, :symbolize_keys => true) : raise(GreenhouseIo::Error.new(response["reason"]))
|
62
|
+
else
|
63
|
+
raise GreenhouseIo::Error.new(response.code)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def basic_auth
|
68
|
+
{ :username => @api_token }
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module GreenhouseIo
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :msg, :code
|
4
|
+
|
5
|
+
def initialize(msg = nil, code = nil)
|
6
|
+
@msg = msg
|
7
|
+
@code = code
|
8
|
+
end
|
9
|
+
|
10
|
+
def inspect
|
11
|
+
if @code
|
12
|
+
"GreenhouseIo::Error: #{ @code } response from server"
|
13
|
+
else
|
14
|
+
"GreenhouseIo::Error: #{ @msg }"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
@msg
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://123FakeToken:@api.greenhouse.io/v1/applications
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: id=721&first_name=Richard&last_name=Feynman&email=richard123%40test.ga.co
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Cache-Control:
|
16
|
+
- max-age=0, private, must-revalidate
|
17
|
+
Content-Type:
|
18
|
+
- text/javascript; charset=utf-8
|
19
|
+
Date:
|
20
|
+
- Mon, 16 Sep 2013 18:25:13 GMT
|
21
|
+
Etag:
|
22
|
+
- ! '"60d45e24e36a2c0bbd1b09470dc4712c"'
|
23
|
+
Set-Cookie:
|
24
|
+
- _session_id=0b94e410bd34c2cefaae8257f0f4a6b4; path=/; HttpOnly
|
25
|
+
Status:
|
26
|
+
- 200 OK
|
27
|
+
Vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
X-Request-Id:
|
30
|
+
- e4ffe754f2c13976f8b77fb36794d7a4
|
31
|
+
X-Runtime:
|
32
|
+
- '0.438182'
|
33
|
+
X-Ua-Compatible:
|
34
|
+
- IE=Edge,chrome=1
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Connection:
|
38
|
+
- keep-alive
|
39
|
+
body:
|
40
|
+
encoding: US-ASCII
|
41
|
+
string: ! '{"success":"Candidate saved successfully"}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Mon, 16 Sep 2013 18:25:13 GMT
|
44
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.greenhouse.io/v1/boards/generalassembly/embed/department?id=187
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Cache-Control:
|
16
|
+
- max-age=0, private, must-revalidate
|
17
|
+
Content-Type:
|
18
|
+
- text/html; charset=utf-8
|
19
|
+
Date:
|
20
|
+
- Mon, 16 Sep 2013 16:10:23 GMT
|
21
|
+
Etag:
|
22
|
+
- ! '"bb32e60fd177f151cf0e062eab98a28e"'
|
23
|
+
Status:
|
24
|
+
- 200 OK
|
25
|
+
Vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
X-Request-Id:
|
28
|
+
- 3b821356ecf1bc276d417fc20cacacc7
|
29
|
+
X-Runtime:
|
30
|
+
- '0.032134'
|
31
|
+
X-Ua-Compatible:
|
32
|
+
- IE=Edge,chrome=1
|
33
|
+
Content-Length:
|
34
|
+
- '398'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
body:
|
38
|
+
encoding: US-ASCII
|
39
|
+
string: ! '{"id":187,"name":"Engineering","jobs":[{"id":721,"title":"Application
|
40
|
+
developer","updated_at":"2013-09-12T21:01:50Z","location":{"name":"New York,
|
41
|
+
NY"},"absolute_url":"http://boards.greenhouse.io/generalassembly/jobs/721"},{"id":722,"title":"Finance
|
42
|
+
Analyst","updated_at":"2013-09-12T21:01:50Z","location":{"name":"New York"},"absolute_url":"http://boards.greenhouse.io/generalassembly/jobs/722"}]}'
|
43
|
+
http_version:
|
44
|
+
recorded_at: Mon, 16 Sep 2013 16:10:28 GMT
|
45
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.greenhouse.io/v1/boards/generalassembly/embed/departments
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Cache-Control:
|
16
|
+
- max-age=0, private, must-revalidate
|
17
|
+
Content-Type:
|
18
|
+
- text/html; charset=utf-8
|
19
|
+
Date:
|
20
|
+
- Mon, 16 Sep 2013 16:08:54 GMT
|
21
|
+
Etag:
|
22
|
+
- ! '"f205d9810b3463764180a02bef17ee4b"'
|
23
|
+
Status:
|
24
|
+
- 200 OK
|
25
|
+
Vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
X-Request-Id:
|
28
|
+
- 9f6f27869358dfe950413e981e5238ba
|
29
|
+
X-Runtime:
|
30
|
+
- '0.013228'
|
31
|
+
X-Ua-Compatible:
|
32
|
+
- IE=Edge,chrome=1
|
33
|
+
Content-Length:
|
34
|
+
- '495'
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
body:
|
38
|
+
encoding: US-ASCII
|
39
|
+
string: ! '{"departments":[{"id":187,"name":"Engineering","jobs":[]},{"id":188,"name":"Finance","jobs":[{"id":722,"title":"Finance
|
40
|
+
Analyst","updated_at":"2013-09-12T21:01:50Z","location":{"name":"New York"},"absolute_url":"http://boards.greenhouse.io/generalassembly/jobs/722"}]},{"id":0,"name":"No
|
41
|
+
Department","jobs":[{"id":721,"title":"Application developer","updated_at":"2013-09-12T21:01:50Z","location":{"name":"New
|
42
|
+
York, NY"},"absolute_url":"http://boards.greenhouse.io/generalassembly/jobs/721"}]}]}'
|
43
|
+
http_version:
|
44
|
+
recorded_at: Mon, 16 Sep 2013 16:08:59 GMT
|
45
|
+
recorded_with: VCR 2.5.0
|