Coder Social home page Coder Social logo

bamboohr's Introduction

bamboohr

An API wrapper for the BambooHR platform

Usage

Create a new client with bamboohr.New()

bbhr, err := bamboohr.New(BBHRNewInput{
  "company": "TestCompany",
  "apikey": "KEYHERE",
})
if err != nil {
  panic(err)
}

Use any of the built-in functions to query against your BambooHR instance.

resp, err := bbhr.GetEmployees()
if err != nil {
    panic(err)
}

fmt.Println(string(resp))

bamboohr's People

Contributors

fbs avatar helixspiral avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

fbs

bamboohr's Issues

leaking http con

From the go docs:

func (*Client) Do

[...]
If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close. If the Body is not both read to EOF and closed, the Client's underlying RoundTripper (typically Transport) may not be able to re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.

But the connection is never closed, only when http 200 but readall fails.

bamboohr/bamboohr.go

Lines 42 to 62 in e75fe04

func (b *Client) sendRequest(req *http.Request) ([]byte, error) {
req.Header.Add("ACCEPT", "application/json")
req.SetBasicAuth(b.APIKey, "x")
resp, err := b.HTTPClient.Do(req)
if err != nil {
return []byte{}, err
}
if resp.StatusCode != 200 {
return []byte{}, fmt.Errorf("status code not 200: %d", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []byte{}, err
}
defer resp.Body.Close()
return body, err

Change returns from []byte to struct

Currently we're just returning the raw []byte from BambooHR, this would be nicer if we actually handled parsing all the information into structs and returned that to the user instead.

We could also create "raw" functions that would continue returning the raw []byte for users with more specific needs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.