Skip to content

Commit

Permalink
Merge pull request #15 from danielwestendorf/master
Browse files Browse the repository at this point in the history
Add support for employee last changed API endpoint
  • Loading branch information
enriikke committed May 8, 2016
2 parents 44e3b6c + 09b4311 commit 4122a31
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ group :test do
end

group :development, :test do
gem "listen", "3.0.7"
gem "guard"
gem "guard-rspec", require: false
gem "rubocop", require: false
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ client.employee.all(:all) # Gets all fields for all employees
client.employee.all(["hireDate", "displayName"])
client.employee.all("hireDate,displayName")

# Get the employee records which have changed since a given date
client.employee.last_changed("2015-01-01T00:00:00-08:00", :updated)
client.employee.last_changed("2015-01-01T00:00:00-08:00", :inserted)
client.employee.last_changed("2015-01-01T00:00:00-08:00", :deleted)
client.employee.last_changed("2015-01-01T00:00:00-08:00") # Return all changes

# Returns a hash of a single employee
client.employee.find(employee_id, fields = nil)

Expand Down
2 changes: 1 addition & 1 deletion bamboozled.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Gem::Specification.new do |spec|

spec.add_dependency "httparty", "~> 0.13"
spec.add_dependency "json", "~> 1.8"
spec.add_dependency "activesupport", "~> 4.2"
spec.add_dependency "activesupport"
end
1 change: 1 addition & 0 deletions lib/bamboozled/api/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'json'
require "time"
require 'active_support/core_ext/hash/indifferent_access'

module Bamboozled
Expand Down
9 changes: 9 additions & 0 deletions lib/bamboozled/api/employee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ def find(employee_id, fields = nil)
request(:get, "employees/#{employee_id}?fields=#{fields}")
end

def last_changed(date = "2011-06-05T00:00:00+00:00", type = nil)
query = Hash.new
query[:since] = date.respond_to?(:iso8601) ? date.iso8601 : date
query[:type] = type unless type.nil?

response = request(:get, "employees/changed", query: query)
response["employees"]
end

# Tabular data
[:job_info, :employment_status, :compensation, :dependents, :contacts].each do |action|
define_method(action.to_s) do |argument_id|
Expand Down
28 changes: 28 additions & 0 deletions spec/fixtures/last_changed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
date: Tue, 17 Jun 2014 19:25:35 UTC

{
"employees": {
"3": {
"id":"3",
"action":"Inserted",
"lastChanged":"2011-06-02T19:26:23+00:00"
},
"4": {
"id":"4",
"action":"Updated",
"lastChanged":"2011-06-02T19:26:23+00:00"
},
"5": {
"id":"5",
"action":"Deleted",
"lastChanged":"2011-06-02T19:26:23+00:00"
},
"10": {
"id":"10",
"action":"Inserted",
"lastChanged":"2011-05-31T22:57:10+00:00"
}
}
}
10 changes: 10 additions & 0 deletions spec/lib/bamboozled/api/employee_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@
expect(url).to eq required_url
end

it "Gets all employee records which have changed since a given date" do
response = File.new("spec/fixtures/last_changed.json")
stub_request(:any, /.*api\.bamboohr\.com.*/).to_return(response)

employees = @client.employee.last_changed("2011-06-02T19:26:23+00:00")

expect(employees).to be_a Hash
expect(employees.keys.count).to eq 4
end

describe "#add" do
it "creates a new employee in BambooHR" do
xml = YAML.load_file("spec/fixtures/add_employee_xml.yml")
Expand Down

0 comments on commit 4122a31

Please sign in to comment.