gusto_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +209 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gusto_api.gemspec +28 -0
- data/lib/gusto_api.rb +25 -0
- data/lib/gusto_api/bearer_request.rb +7 -0
- data/lib/gusto_api/company.rb +32 -0
- data/lib/gusto_api/configuration.rb +13 -0
- data/lib/gusto_api/current_user.rb +11 -0
- data/lib/gusto_api/oauth.rb +39 -0
- data/lib/gusto_api/oauth_request.rb +13 -0
- data/lib/gusto_api/request.rb +53 -0
- data/lib/gusto_api/token_request.rb +7 -0
- data/lib/gusto_api/version.rb +3 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 285fdebd872f38aa6a87e1de29a100b3170b046bb2856f454c550c934165308d
|
4
|
+
data.tar.gz: d1d0cebc49f6569900fe2c1c83bca3b2676f87f9ba042d2d499ec2eb4819b211
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52049e71564be76fdf10348c62ef51c96eec5cb9957a01ab0b8395990b326fdfe7f51d43f8c32f0556c1a223b31d2552503b1332cbf110e22810389a33d01a91
|
7
|
+
data.tar.gz: e44de1d86d7b3f9a6e19bf2a6121eae0442158bde8bf5007c9898b820618cc71aea7ef8acb6a26583f97ceb0bc67e1d1102a09445961c6db6818d88d340e67d1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at joncodes+github@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gusto_api (0.1.0)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
httparty (0.18.1)
|
12
|
+
mime-types (~> 3.0)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
mime-types (3.3.1)
|
15
|
+
mime-types-data (~> 3.2015)
|
16
|
+
mime-types-data (3.2020.1104)
|
17
|
+
multi_xml (0.6.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
rspec (3.10.0)
|
20
|
+
rspec-core (~> 3.10.0)
|
21
|
+
rspec-expectations (~> 3.10.0)
|
22
|
+
rspec-mocks (~> 3.10.0)
|
23
|
+
rspec-core (3.10.1)
|
24
|
+
rspec-support (~> 3.10.0)
|
25
|
+
rspec-expectations (3.10.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.10.0)
|
28
|
+
rspec-mocks (3.10.1)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.10.0)
|
31
|
+
rspec-support (3.10.1)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
gusto_api!
|
38
|
+
rake (~> 12.0)
|
39
|
+
rspec (~> 3.0)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jon Evans
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
# GustoApi
|
2
|
+
|
3
|
+
This gem provides an easy way to talk with the API for [Gusto](https://gusto.com/).
|
4
|
+
|
5
|
+
The functionality for this gem is by no means exhaustive. If there's an endpoint
|
6
|
+
that is unsupported, please feel free to add and open a PR.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'gusto_api'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install gusto_api
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Configuration
|
27
|
+
|
28
|
+
In an initializer, say, `config/initializers/gusto_api.rb`, configure the gem
|
29
|
+
with settings provided by Gusto:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
GustoApi.configure do |config|
|
33
|
+
config.api_token = 'token'
|
34
|
+
config.client_id = 'client id'
|
35
|
+
config.client_secret = 'client secret'
|
36
|
+
config.redirect_url = 'redirect url'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
### OAuth flow
|
41
|
+
|
42
|
+
Details are documented here: https://docs.gusto.com/v1/basics/authentication
|
43
|
+
|
44
|
+
You'll have to set up a controller for the OAuth authorization callback. Set `redirect_url` to its URL.
|
45
|
+
|
46
|
+
To get the initial URL to trigger the OAuth flow, use
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
GustoApi::Oauth.auth_url
|
50
|
+
```
|
51
|
+
|
52
|
+
Link people to that URL and they'll see an authorization page on Gusto's site. After they accept, they'll be redirected to your `redirect_url` with `params[:code]` set to a temporary code that can be exchanged for an `access_token` and `refresh_token` with:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
GustoApi::Oauth.get_token(code)
|
56
|
+
```
|
57
|
+
This returns a hash:
|
58
|
+
```ruby
|
59
|
+
{
|
60
|
+
"access_token" => "ju53kDqMS0iPVsOECQF-H0ifxHDFBDTi2BHOopMrW1X",
|
61
|
+
"token_type" => "Bearer",
|
62
|
+
"expires_in" => 7200,
|
63
|
+
"refresh_token" => "64ir0v_ioQMdWin6Dv9poXGW-SI04yQr2oXE67YqgP5",
|
64
|
+
"scope" => "public",
|
65
|
+
"created_at" => 1610493513
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
The temporary code lasts for 10 minutes and the access token lasts for 2 hours.
|
70
|
+
|
71
|
+
After the access token expires, you'll need to use the `refresh_token` to get a new one:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
GustoApi::Oauth.refresh_token(refresh_token)
|
75
|
+
```
|
76
|
+
|
77
|
+
The hash returned is identical to that returned by `get_token`. It will give a new `access_token` and `refresh_token`. Each `refresh_token` can only be used once.
|
78
|
+
|
79
|
+
### Creating a Company
|
80
|
+
|
81
|
+
This requires configuring the API token above with the token provided by Gusto.
|
82
|
+
|
83
|
+
Example with the minimum set of attributes:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
GustoApi::Company.create(
|
87
|
+
user: {
|
88
|
+
first_name: 'George',
|
89
|
+
last_name: 'Hampton,'
|
90
|
+
email: 'george@example.com'
|
91
|
+
},
|
92
|
+
company: {
|
93
|
+
name: 'Hampton LLC'
|
94
|
+
}
|
95
|
+
)
|
96
|
+
```
|
97
|
+
|
98
|
+
Returns:
|
99
|
+
|
100
|
+
```
|
101
|
+
{
|
102
|
+
"account_claim_url": "https://app.gusto.com/claim_account/3456789"
|
103
|
+
}
|
104
|
+
```
|
105
|
+
|
106
|
+
Documentation for full list of attributes and possible errors: https://docs.gusto.com/v1/examples/creating-a-company
|
107
|
+
|
108
|
+
### Getting the Current User
|
109
|
+
|
110
|
+
To get the authenticated user:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
GustoApi::CurrentUser.fetch(access_token)
|
114
|
+
```
|
115
|
+
|
116
|
+
This will return a hash:
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
{
|
120
|
+
"id" => 7757869449967110,
|
121
|
+
"email" => "bonusly+demo@gusto.com",
|
122
|
+
"roles" => {
|
123
|
+
"payroll_admin" => {
|
124
|
+
"companies" => [
|
125
|
+
{
|
126
|
+
"id" => 7756341740967741,
|
127
|
+
"name" => "Bonusly Demo",
|
128
|
+
"trade_name" => "",
|
129
|
+
"locations" => [
|
130
|
+
{
|
131
|
+
"id" => 7757727716494058,
|
132
|
+
"street_1" => "912 Silver St.",
|
133
|
+
"street_2" => "Suite 1966",
|
134
|
+
"city" => "San Francisco",
|
135
|
+
"state" => "CA",
|
136
|
+
"zip" => "94107",
|
137
|
+
"country" => "USA",
|
138
|
+
"active" => true
|
139
|
+
}
|
140
|
+
]
|
141
|
+
}
|
142
|
+
]
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
### Getting a Company's Employees
|
150
|
+
|
151
|
+
This and most other endpoints require getting an `access_token` via OAuth.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
GustoApi::Company.new(id, access_token).employees
|
155
|
+
```
|
156
|
+
|
157
|
+
Documentation for response: https://docs.gusto.com/v1/employees
|
158
|
+
|
159
|
+
### Want to interact with a different API endpoint?
|
160
|
+
|
161
|
+
GustoApi provides two generic `Request` classes for interacting with the API.
|
162
|
+
|
163
|
+
For API endpoints where you use the API key provided by Gusto, there's `GustoApi::TokenRequest` class with the following initialize signature:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
def initialize(endpoint:, method:, params: {})
|
167
|
+
```
|
168
|
+
|
169
|
+
`method` must be `:get` or `:post`, and `endpoint` is the URI for the API endpoint starting with "v1/".
|
170
|
+
|
171
|
+
`params` is a hash that will be sent as query params for a GET request or the response's body for a POST.
|
172
|
+
|
173
|
+
For API endpoints where you use the `access_token` fetched via OAuth, there's `GustoApi::BearerRequest` with the following initialize signature:
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
def initialize(endpoint:, method:, params: {}, auth_token:)
|
177
|
+
```
|
178
|
+
|
179
|
+
The arguments are the same except that it requires passing in the `access_token` as the `auth_token` argument.
|
180
|
+
|
181
|
+
Calling `submit` on the request instance will use HTTParty to send the request and return the response.
|
182
|
+
|
183
|
+
|
184
|
+
## Development
|
185
|
+
|
186
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
187
|
+
|
188
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
189
|
+
|
190
|
+
## Contributing
|
191
|
+
|
192
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bonusly/gusto_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bonusly/gusto_api/blob/master/CODE_OF_CONDUCT.md).
|
193
|
+
|
194
|
+
|
195
|
+
## License
|
196
|
+
|
197
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
198
|
+
|
199
|
+
## Code of Conduct
|
200
|
+
|
201
|
+
Everyone interacting in the Gusto::Api project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bonusly/gusto_api/blob/master/CODE_OF_CONDUCT.md).
|
202
|
+
|
203
|
+
## About Bonusly
|
204
|
+
|
205
|
+
![Bonusly Logo](https://bonusly-files.s3.amazonaws.com/bonusly-logo.png?small)
|
206
|
+
|
207
|
+
Bonusly is the fun and easy way to engage all of your employees and improve retention and productivity at every level of your organization.
|
208
|
+
|
209
|
+
Check out [our product](https://bonus.ly) or [our engineering blog](https://engineering.bonus.ly).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gusto_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gusto_api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/gusto_api/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "gusto_api"
|
5
|
+
spec.version = GustoApi::VERSION
|
6
|
+
spec.authors = ["Jon Evans"]
|
7
|
+
spec.email = ["jon@bonus.ly"]
|
8
|
+
|
9
|
+
spec.summary = %q{A small wrapper around the Gusto API}
|
10
|
+
spec.homepage = "https://github.com/bonusly/gusto_api"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/bonusly/gusto_api"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/bonusly/gusto_api/blob/master/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_dependency("httparty")
|
28
|
+
end
|
data/lib/gusto_api.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "gusto_api/version"
|
2
|
+
require "gusto_api/configuration"
|
3
|
+
require "gusto_api/request"
|
4
|
+
require "gusto_api/token_request"
|
5
|
+
require "gusto_api/bearer_request"
|
6
|
+
require "gusto_api/oauth_request"
|
7
|
+
require "gusto_api/company"
|
8
|
+
require "gusto_api/oauth"
|
9
|
+
require "gusto_api/current_user"
|
10
|
+
|
11
|
+
module GustoApi
|
12
|
+
class Error < StandardError; end
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_writer :configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configure
|
23
|
+
yield(configuration)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GustoApi
|
2
|
+
class Company
|
3
|
+
def self.create(user:, company:)
|
4
|
+
raise Error.new("Missing a required attribute") unless user[:first_name] && user[:last_name] && user[:email] && company[:name]
|
5
|
+
|
6
|
+
TokenRequest.new(
|
7
|
+
endpoint: 'v1/provision',
|
8
|
+
method: :post,
|
9
|
+
params: { user: user, company: company }
|
10
|
+
).submit
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(id, access_token)
|
14
|
+
self.id = id
|
15
|
+
self.access_token = access_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def employees(include_terminated: false)
|
19
|
+
params = include_terminated ? {} : { terminated: false }
|
20
|
+
BearerRequest.new(
|
21
|
+
endpoint: "v1/companies/#{id}/employees",
|
22
|
+
method: :get,
|
23
|
+
params: params,
|
24
|
+
auth_token: access_token
|
25
|
+
).submit
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_accessor :id, :access_token
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GustoApi
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_token, :client_id, :client_secret, :redirect_url, :testing
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.testing = true
|
7
|
+
end
|
8
|
+
|
9
|
+
def base_uri
|
10
|
+
testing ? 'https://api.gusto-demo.com/' : 'https://api.gusto.com/'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module GustoApi
|
2
|
+
class Oauth
|
3
|
+
def self.auth_url
|
4
|
+
URI(GustoApi.configuration.base_uri + "oauth/authorize").tap do |uri|
|
5
|
+
uri.query = URI.encode_www_form(
|
6
|
+
client_id: GustoApi.configuration.client_id,
|
7
|
+
redirect_uri: GustoApi.configuration.redirect_url,
|
8
|
+
response_type: 'code'
|
9
|
+
)
|
10
|
+
end.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_token(code)
|
14
|
+
OauthRequest.new(
|
15
|
+
method: :post,
|
16
|
+
params: {
|
17
|
+
client_id: GustoApi.configuration.client_id,
|
18
|
+
client_secret: GustoApi.configuration.client_secret,
|
19
|
+
redirect_uri: GustoApi.configuration.redirect_url,
|
20
|
+
code: code,
|
21
|
+
grant_type: 'authorization_code'
|
22
|
+
}
|
23
|
+
).submit
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.refresh_token(refresh_token)
|
27
|
+
OauthRequest.new(
|
28
|
+
method: :post,
|
29
|
+
params: {
|
30
|
+
client_id: GustoApi.configuration.client_id,
|
31
|
+
client_secret: GustoApi.configuration.client_secret,
|
32
|
+
redirect_uri: GustoApi.configuration.redirect_url,
|
33
|
+
refresh_token: refresh_token,
|
34
|
+
grant_type: 'refresh_token'
|
35
|
+
}
|
36
|
+
).submit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module GustoApi
|
4
|
+
class Request
|
5
|
+
def initialize(endpoint:, method:, params: {}, auth_token:, auth_type: 'Token')
|
6
|
+
raise Error.new("Invalid method: #{method}. Must be :get or :post") unless %i[get post].include?(method)
|
7
|
+
|
8
|
+
self.endpoint = endpoint
|
9
|
+
self.method = method
|
10
|
+
self.params = params
|
11
|
+
self.auth_token = auth_token
|
12
|
+
self.auth_type = auth_type
|
13
|
+
end
|
14
|
+
|
15
|
+
def submit
|
16
|
+
HTTParty.send(method, url, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_accessor :endpoint, :method, :params, :auth_token, :auth_type
|
22
|
+
|
23
|
+
def options
|
24
|
+
{
|
25
|
+
headers: headers
|
26
|
+
}.merge(param_options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def headers
|
30
|
+
return {} if auth_token.nil?
|
31
|
+
|
32
|
+
{
|
33
|
+
"Authorization" => "#{auth_type} #{auth_token}"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def param_options
|
38
|
+
return {} unless params.any?
|
39
|
+
|
40
|
+
{
|
41
|
+
params_key => params
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def url
|
46
|
+
URI.join(GustoApi.configuration.base_uri, endpoint).to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
def params_key
|
50
|
+
method == :get ? :query : :body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gusto_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- jon@bonus.ly
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- gusto_api.gemspec
|
47
|
+
- lib/gusto_api.rb
|
48
|
+
- lib/gusto_api/bearer_request.rb
|
49
|
+
- lib/gusto_api/company.rb
|
50
|
+
- lib/gusto_api/configuration.rb
|
51
|
+
- lib/gusto_api/current_user.rb
|
52
|
+
- lib/gusto_api/oauth.rb
|
53
|
+
- lib/gusto_api/oauth_request.rb
|
54
|
+
- lib/gusto_api/request.rb
|
55
|
+
- lib/gusto_api/token_request.rb
|
56
|
+
- lib/gusto_api/version.rb
|
57
|
+
homepage: https://github.com/bonusly/gusto_api
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata:
|
61
|
+
homepage_uri: https://github.com/bonusly/gusto_api
|
62
|
+
source_code_uri: https://github.com/bonusly/gusto_api
|
63
|
+
changelog_uri: https://github.com/bonusly/gusto_api/blob/master/CHANGELOG.md
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.3.0
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.1.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: A small wrapper around the Gusto API
|
83
|
+
test_files: []
|