bullhorn-rest 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +22 -0
- data/README.md +117 -0
- data/Rakefile +1 -0
- data/bullhorn-rest.gemspec +26 -0
- data/lib/bullhorn/rest.rb +8 -0
- data/lib/bullhorn/rest/authentication.rb +79 -0
- data/lib/bullhorn/rest/client.rb +77 -0
- data/lib/bullhorn/rest/entities/appointment.rb +13 -0
- data/lib/bullhorn/rest/entities/appointment_attendee.rb +13 -0
- data/lib/bullhorn/rest/entities/base.rb +73 -0
- data/lib/bullhorn/rest/entities/business_sector.rb +13 -0
- data/lib/bullhorn/rest/entities/candidate.rb +13 -0
- data/lib/bullhorn/rest/entities/candidate_certification.rb +13 -0
- data/lib/bullhorn/rest/entities/candidate_education.rb +13 -0
- data/lib/bullhorn/rest/entities/candidate_reference.rb +13 -0
- data/lib/bullhorn/rest/entities/candidate_work_history.rb +13 -0
- data/lib/bullhorn/rest/entities/category.rb +13 -0
- data/lib/bullhorn/rest/entities/client_contact.rb +13 -0
- data/lib/bullhorn/rest/entities/client_corporation.rb +13 -0
- data/lib/bullhorn/rest/entities/corporate_user.rb +13 -0
- data/lib/bullhorn/rest/entities/corporation_department.rb +13 -0
- data/lib/bullhorn/rest/entities/country.rb +13 -0
- data/lib/bullhorn/rest/entities/custom_action.rb +13 -0
- data/lib/bullhorn/rest/entities/job_order.rb +13 -0
- data/lib/bullhorn/rest/entities/job_submission.rb +13 -0
- data/lib/bullhorn/rest/entities/note.rb +13 -0
- data/lib/bullhorn/rest/entities/note_entity.rb +13 -0
- data/lib/bullhorn/rest/entities/placement.rb +13 -0
- data/lib/bullhorn/rest/entities/placement_change_request.rb +13 -0
- data/lib/bullhorn/rest/entities/placement_commission.rb +13 -0
- data/lib/bullhorn/rest/entities/sendout.rb +13 -0
- data/lib/bullhorn/rest/entities/skill.rb +13 -0
- data/lib/bullhorn/rest/entities/specialty.rb +13 -0
- data/lib/bullhorn/rest/entities/state.rb +13 -0
- data/lib/bullhorn/rest/entities/task.rb +13 -0
- data/lib/bullhorn/rest/entities/tearsheet.rb +13 -0
- data/lib/bullhorn/rest/entities/tearsheet_recipient.rb +13 -0
- data/lib/bullhorn/rest/entities/time_unit.rb +13 -0
- data/lib/bullhorn/rest/version.rb +5 -0
- data/spec/bullhorn/rest/client_spec.rb +32 -0
- data/spec/bullhorn/rest/entities_spec.rb +69 -0
- data/spec/cassettes/Bullhorn_Rest_Client/authentication/when_username_and_password_set/authenticates.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/appointment/_appointments_returns_appointments.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/appointment_attendee/_appointment_attendees_returns_appointment_attendees.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/business_sector/_business_sectors_returns_business_sectors.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate/_candidates_returns_candidates.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate/_department_candidates_returns_candidates.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate/_user_candidates_returns_candidates.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate_certification/_candidate_certifications_returns_candidate_certifications.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate_education/_candidate_educations_returns_candidate_educations.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate_reference/_candidate_references_returns_candidate_references.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/candidate_work_history/_candidate_work_histories_returns_candidate_work_histories.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/category/_categories_returns_categories.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/client_contact/_client_contacts_returns_client_contacts.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/client_contact/_department_client_contacts_returns_client_contacts.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/client_contact/_user_client_contacts_returns_client_contacts.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/client_corporation/_client_corporations_returns_client_corporations.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/client_corporation/_department_client_corporations_returns_client_corporations.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/client_corporation/_user_client_corporations_returns_client_corporations.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/corporate_user/_corporate_users_returns_corporate_users.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/corporation_department/_corporation_departments_returns_corporation_departments.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/country/_countries_returns_countries.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/custom_action/_custom_actions_returns_custom_actions.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/job_order/_department_job_orders_returns_job_orders.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/job_order/_job_orders_returns_job_orders.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/job_order/_user_job_orders_returns_job_orders.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/job_submission/_job_submissions_returns_job_submissions.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/note/_department_notes_returns_notes.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/note/_notes_returns_notes.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/note/_user_notes_returns_notes.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/note_entity/_note_entities_returns_note_entities.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/placement/_department_placements_returns_placements.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/placement/_placements_returns_placements.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/placement/_user_placements_returns_placements.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/placement_change_request/_placement_change_requests_returns_placement_change_requests.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/placement_commission/_placement_commissions_returns_placement_commissions.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/sendout/_sendouts_returns_sendouts.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/skill/_skills_returns_skills.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/specialty/_specialties_returns_specialties.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/state/_states_returns_states.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/task/_tasks_returns_tasks.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/tearsheet/_tearsheets_returns_tearsheets.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/tearsheet_recipient/_tearsheet_recipients_returns_tearsheet_recipients.json +1 -0
- data/spec/cassettes/Bullhorn_Rest_Entities/time_unit/_time_units_returns_time_units.json +1 -0
- data/spec/spec_helper.rb +74 -0
- metadata +247 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df925ceec33ea8f68cab8201b075d54130cbaa15
|
4
|
+
data.tar.gz: 56a10614ebefb1208fbdee7096377bc19bf28cf0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d7e367a04e4ab26c17c228604f6bdaf4f2d24df9e117a180da947b5f7800dc867b24e173b6a130db131da6ff9139f6a59f1099fe3250752f8ec260b4febeb68
|
7
|
+
data.tar.gz: 5d2de081a563c8f72c52cf8d21d4b5e8cbeced42aec3c6621bd8fd481a2946da998dc9f61bc147a0e094925f398e6f29f0f14b95199cad43d96f56c26614699b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in bullhorn-rest.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test, :development do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'vcr'
|
9
|
+
gem 'webmock', ['>= 1.8.0', '< 1.16']
|
10
|
+
gem 'multi_json'
|
11
|
+
gem 'awesome_print', :require => 'ap'
|
12
|
+
gem 'pry'
|
13
|
+
gem 'byebug'
|
14
|
+
gem 'maybe'
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gordon L. Hempton
|
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,117 @@
|
|
1
|
+
# Bullhorn::Rest
|
2
|
+
|
3
|
+
Ruby wrapper for the [Bullhorn REST API](http://developer.bullhorn.com/articles/getting_started). For additional information on the API itself, see the official [Bullhorn documentation](http://developer.bullhorn.com/documentation).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bullhorn-rest'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bullhorn-rest
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'bullhorn/rest'
|
23
|
+
|
24
|
+
client = Bullhorn::Rest::Client.new(username: '<USERNAME>', password: '<PASSWORD>', client_id: '<CLIENT_ID>', client_secret: '<CLIENT_SECRET>')
|
25
|
+
|
26
|
+
# Returns all candidates
|
27
|
+
client.candidates
|
28
|
+
|
29
|
+
# Returns all candidates belonging to the current user
|
30
|
+
client.user_candidates
|
31
|
+
|
32
|
+
# Returns all candidates belonging to the user's department
|
33
|
+
client.department_candidates
|
34
|
+
|
35
|
+
# Get data for a particular candidate
|
36
|
+
client.candidate(id)
|
37
|
+
|
38
|
+
# Update a candidate
|
39
|
+
client.update_candidate(id, attributes)
|
40
|
+
|
41
|
+
# Create a candidate
|
42
|
+
client.create_candidate(attributes)
|
43
|
+
|
44
|
+
# Delete a candidate
|
45
|
+
client.delete_candidate(id)
|
46
|
+
|
47
|
+
# Query for candidates
|
48
|
+
client.query_candidates(where: "email = 'brogrammer@bigco.com'")
|
49
|
+
```
|
50
|
+
|
51
|
+
The above api methods generalize to all entities in the system. E.g. for the `JobOrder` entity simple replace occurences of `candidate` with `job_order` in all of the above methods.
|
52
|
+
|
53
|
+
### Entities
|
54
|
+
|
55
|
+
The following entities are exposed via the API:
|
56
|
+
|
57
|
+
* appointment
|
58
|
+
* appointment_attendee
|
59
|
+
* business_sector
|
60
|
+
* candidate
|
61
|
+
* candidate_certification
|
62
|
+
* candidate_education
|
63
|
+
* candidate_reference
|
64
|
+
* candidate_work_history
|
65
|
+
* category
|
66
|
+
* client_contact
|
67
|
+
* client_corporation
|
68
|
+
* corporate_user
|
69
|
+
* corporation_department
|
70
|
+
* country
|
71
|
+
* custom_action
|
72
|
+
* job_order
|
73
|
+
* job_submission
|
74
|
+
* note
|
75
|
+
* note_entity
|
76
|
+
* placement
|
77
|
+
* placement_change_request
|
78
|
+
* placement_commission
|
79
|
+
* sendout
|
80
|
+
* skill
|
81
|
+
* specialty
|
82
|
+
* state
|
83
|
+
* task
|
84
|
+
* tearsheet
|
85
|
+
* tearsheet_recipient
|
86
|
+
* time_unit
|
87
|
+
|
88
|
+
### User Entities
|
89
|
+
|
90
|
+
Additionally, the following entities have `user_<entity>` and `department_<entity>` methods available:
|
91
|
+
|
92
|
+
* candidate
|
93
|
+
* client_contact
|
94
|
+
* client_corporation
|
95
|
+
* job_order
|
96
|
+
* note
|
97
|
+
* placement
|
98
|
+
|
99
|
+
### Immutable Entities
|
100
|
+
|
101
|
+
The following entities are immutable and do not have any of the update/create/delete methods available:
|
102
|
+
|
103
|
+
* category
|
104
|
+
* corporate_user
|
105
|
+
* country
|
106
|
+
* skill
|
107
|
+
* specialty
|
108
|
+
* state
|
109
|
+
* time_unit
|
110
|
+
|
111
|
+
## Contributing
|
112
|
+
|
113
|
+
1. Fork it ( http://github.com/<my-github-username>/bullhorn-rest/fork )
|
114
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
115
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
116
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
117
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bullhorn/rest/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bullhorn-rest"
|
8
|
+
spec.version = Bullhorn::Rest::VERSION
|
9
|
+
spec.authors = ["Gordon L. Hempton"]
|
10
|
+
spec.email = ["ghempton@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for the Bullhorn REST API}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/GroupTalent/bullhorn-rest"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday"
|
22
|
+
spec.add_dependency "active_support"
|
23
|
+
spec.add_dependency "i18n"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Bullhorn
|
2
|
+
module Rest
|
3
|
+
|
4
|
+
# http://supportforums.bullhorn.com/viewtopic.php?f=104&t=14542
|
5
|
+
module Authentication
|
6
|
+
|
7
|
+
def auth_conn
|
8
|
+
@auth_conn ||= Faraday.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorize
|
12
|
+
url = "https://auth.bullhornstaffing.com/oauth/authorize"
|
13
|
+
params = {
|
14
|
+
client_id: client_id,
|
15
|
+
username: username,
|
16
|
+
password: password,
|
17
|
+
action: 'Login',
|
18
|
+
response_type: 'code'
|
19
|
+
}
|
20
|
+
res = auth_conn.get url, params
|
21
|
+
location = res.headers['location']
|
22
|
+
|
23
|
+
@auth_code = CGI::parse(URI(location).query)["code"].first
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def retrieve_tokens
|
28
|
+
url = "https://auth.bullhornstaffing.com/oauth/token"
|
29
|
+
params = {
|
30
|
+
grant_type: 'authorization_code',
|
31
|
+
code: auth_code,
|
32
|
+
client_id: client_id,
|
33
|
+
client_secret: client_secret
|
34
|
+
}
|
35
|
+
res = auth_conn.post url, params
|
36
|
+
hash = JSON.parse(res.body)
|
37
|
+
|
38
|
+
@access_token = hash['access_token']
|
39
|
+
@access_token_expires_in = hash['expires_in']
|
40
|
+
@refresh_token = hash['refresh_token']
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def login
|
45
|
+
url = "https://rest.bullhornstaffing.com/rest-services/login"
|
46
|
+
params = {
|
47
|
+
version: '*',
|
48
|
+
access_token: access_token
|
49
|
+
}
|
50
|
+
response = auth_conn.get url, params
|
51
|
+
hash = JSON.parse(response.body)
|
52
|
+
|
53
|
+
@rest_token = hash['BhRestToken']
|
54
|
+
@rest_url = hash['restUrl']
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def authenticate
|
59
|
+
unless rest_token
|
60
|
+
unless access_token
|
61
|
+
unless auth_code
|
62
|
+
authorize
|
63
|
+
end
|
64
|
+
retrieve_tokens
|
65
|
+
end
|
66
|
+
login
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def authenticated?
|
72
|
+
# TODO: check expires
|
73
|
+
!!rest_token
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
require 'bullhorn/rest/authentication'
|
4
|
+
|
5
|
+
require 'bullhorn/rest/entities/base'
|
6
|
+
Dir[File.dirname(__FILE__) + '/entities/*.rb'].each {|file| require file }
|
7
|
+
|
8
|
+
module Bullhorn
|
9
|
+
module Rest
|
10
|
+
|
11
|
+
class Client
|
12
|
+
|
13
|
+
include Bullhorn::Rest::Authentication
|
14
|
+
include Bullhorn::Rest::Entities::Appointment
|
15
|
+
include Bullhorn::Rest::Entities::AppointmentAttendee
|
16
|
+
include Bullhorn::Rest::Entities::BusinessSector
|
17
|
+
include Bullhorn::Rest::Entities::Candidate
|
18
|
+
include Bullhorn::Rest::Entities::CandidateCertification
|
19
|
+
include Bullhorn::Rest::Entities::CandidateEducation
|
20
|
+
include Bullhorn::Rest::Entities::CandidateReference
|
21
|
+
include Bullhorn::Rest::Entities::CandidateWorkHistory
|
22
|
+
include Bullhorn::Rest::Entities::Category
|
23
|
+
include Bullhorn::Rest::Entities::ClientContact
|
24
|
+
include Bullhorn::Rest::Entities::ClientCorporation
|
25
|
+
include Bullhorn::Rest::Entities::CorporateUser
|
26
|
+
include Bullhorn::Rest::Entities::CorporationDepartment
|
27
|
+
include Bullhorn::Rest::Entities::Country
|
28
|
+
include Bullhorn::Rest::Entities::CustomAction
|
29
|
+
include Bullhorn::Rest::Entities::JobOrder
|
30
|
+
include Bullhorn::Rest::Entities::JobSubmission
|
31
|
+
include Bullhorn::Rest::Entities::Note
|
32
|
+
include Bullhorn::Rest::Entities::NoteEntity
|
33
|
+
include Bullhorn::Rest::Entities::Placement
|
34
|
+
include Bullhorn::Rest::Entities::PlacementChangeRequest
|
35
|
+
include Bullhorn::Rest::Entities::PlacementCommission
|
36
|
+
include Bullhorn::Rest::Entities::Sendout
|
37
|
+
include Bullhorn::Rest::Entities::Skill
|
38
|
+
include Bullhorn::Rest::Entities::Specialty
|
39
|
+
include Bullhorn::Rest::Entities::State
|
40
|
+
include Bullhorn::Rest::Entities::Task
|
41
|
+
include Bullhorn::Rest::Entities::Tearsheet
|
42
|
+
include Bullhorn::Rest::Entities::TearsheetRecipient
|
43
|
+
include Bullhorn::Rest::Entities::TimeUnit
|
44
|
+
|
45
|
+
attr_reader :username, :password, :client_id, :client_secret, :auth_code, :access_token, :rest_token, :rest_url, :refresh_token
|
46
|
+
|
47
|
+
# Initializes a new Bullhorn REST Client
|
48
|
+
def initialize(options = {})
|
49
|
+
|
50
|
+
@username = options[:username]
|
51
|
+
@password = options[:password]
|
52
|
+
@client_id = options[:client_id]
|
53
|
+
@client_secret = options[:client_secret]
|
54
|
+
@auth_code = options[:auth_code]
|
55
|
+
@rest_url = options[:rest_url]
|
56
|
+
@rest_token = options[:rest_token]
|
57
|
+
@access_token = options[:access_token]
|
58
|
+
@refresh_token = options[:refresh_token]
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def conn
|
63
|
+
if !authenticated?
|
64
|
+
authenticate
|
65
|
+
end
|
66
|
+
|
67
|
+
params = {
|
68
|
+
BhRestToken: rest_token
|
69
|
+
}
|
70
|
+
|
71
|
+
@conn ||= Faraday.new(url: rest_url, params: params)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
module Bullhorn
|
4
|
+
module Rest
|
5
|
+
module Entities
|
6
|
+
|
7
|
+
# http://developer.bullhorn.com/sites/default/files/BullhornRESTAPI_0.pdf
|
8
|
+
module Base
|
9
|
+
|
10
|
+
def entity
|
11
|
+
@entity || self.name.demodulize.underscore
|
12
|
+
end
|
13
|
+
|
14
|
+
def define_methods(options={})
|
15
|
+
name = entity.to_s.classify
|
16
|
+
plural = entity.to_s.pluralize
|
17
|
+
name_plural = name.pluralize
|
18
|
+
|
19
|
+
|
20
|
+
if options[:owner_methods]
|
21
|
+
define_method("department_#{plural}") do |options={}|
|
22
|
+
params = {fields: '*'}.merge(options)
|
23
|
+
path = "department#{name_plural}"
|
24
|
+
conn.get path, params
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method("user_#{plural}") do |options={}|
|
28
|
+
params = {fields: '*'}.merge(options)
|
29
|
+
path = "my#{name_plural}"
|
30
|
+
conn.get path, params
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method plural, "department_#{plural}"
|
34
|
+
else
|
35
|
+
# Don't see an "all" entities api call. Instead we
|
36
|
+
# use a criteria that is always true
|
37
|
+
define_method(plural) do |options={}|
|
38
|
+
send "query_#{plural}", where: "id IS NOT NULL"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
define_method("query_#{plural}") do |options={}|
|
43
|
+
params = {fields: '*'}.merge(options)
|
44
|
+
path = "query/#{name}"
|
45
|
+
conn.get path, params
|
46
|
+
end
|
47
|
+
|
48
|
+
unless options[:immutable]
|
49
|
+
|
50
|
+
define_method("create_#{entity}") do |id, attributes={}|
|
51
|
+
path = "#{name}/#{id}"
|
52
|
+
conn.put path, attributes
|
53
|
+
end
|
54
|
+
|
55
|
+
define_method("update_#{entity}") do |id, attributes={}|
|
56
|
+
path = "#{name}/#{id}"
|
57
|
+
conn.post path, attributes
|
58
|
+
end
|
59
|
+
|
60
|
+
define_method("delete_#{entity}") do |id|
|
61
|
+
path = "#{name}/#{id}"
|
62
|
+
conn.delete path
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|