wotc 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 +8 -0
- data/.rakeTasks +7 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/faraday/raise_http_exception.rb +34 -0
- data/lib/wotc.rb +25 -0
- data/lib/wotc/api.rb +28 -0
- data/lib/wotc/client.rb +20 -0
- data/lib/wotc/client/applicants.rb +32 -0
- data/lib/wotc/client/companies.rb +25 -0
- data/lib/wotc/client/documents.rb +22 -0
- data/lib/wotc/client/employees.rb +50 -0
- data/lib/wotc/client/locations.rb +23 -0
- data/lib/wotc/client/payrolls.rb +28 -0
- data/lib/wotc/client/registers.rb +11 -0
- data/lib/wotc/client/users.rb +12 -0
- data/lib/wotc/client/webhooks.rb +26 -0
- data/lib/wotc/client/wotcs.rb +8 -0
- data/lib/wotc/configuration.rb +88 -0
- data/lib/wotc/connection.rb +30 -0
- data/lib/wotc/error.rb +25 -0
- data/lib/wotc/request.rb +64 -0
- data/lib/wotc/version.rb +3 -0
- data/wotc.gemspec +45 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c55912e173441fafde565727cfea98101a699ee28b0f3b949a9949f7730cab2b
|
4
|
+
data.tar.gz: 69abcb3adee7d97d0832c4a4b6b26d5d316b1940f4bd26bb8b4bfe87c8761664
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a72f369eb59c4deeeecaf6b6cc5a69cb2420d685745a8edf2a7e2dd38c1710d29b219754c329c445585d4d93052cd5fc4bf530a9ee06060a6a7302e729fd86db
|
7
|
+
data.tar.gz: a428af1f1dd944dbe1509b86e19c45dd51a0439131e02f13bb8184ca8078884935e2ede71956a26379ca4297183d7cada0a72efe205cf7347e7558233b87fc41
|
data/.gitignore
ADDED
data/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build wotc-ruby-gem-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated file" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install wotc-ruby-gem-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install wotc-ruby-gem-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push wotc-ruby-gem-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
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 xiaorong.ruby@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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ryan Lv
|
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,83 @@
|
|
1
|
+
![WOTC_logo_header-02](https://user-images.githubusercontent.com/1224077/79107910-d97bc880-7da7-11ea-95a3-40be03be614c.png)
|
2
|
+
|
3
|
+
# wotc-ruby-gem
|
4
|
+
|
5
|
+
Ruby toolkit for wotc.com API
|
6
|
+
|
7
|
+
## wotc.com REST APIs and documentation
|
8
|
+
|
9
|
+
1. Go to the [developer site](https://sandbox.wotc.com/portal/api/documentation) of wotc.com and create an sandbox account.
|
10
|
+
2. create an access token in the [integration console](https://sandbox.wotc.com/portal/client/account/integrations#show-access-token).
|
11
|
+
|
12
|
+
## quick start
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'wotc-ruby-gem'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install wotc-ruby-gem
|
27
|
+
|
28
|
+
## Usage Examples
|
29
|
+
|
30
|
+
```
|
31
|
+
# Provide authentication credential
|
32
|
+
client = WOTC::Client.new(access_token: 'your access token')
|
33
|
+
|
34
|
+
# Fetch the employees of current commpany
|
35
|
+
client.employees
|
36
|
+
|
37
|
+
# fetch the settings of a company
|
38
|
+
client.get_company_settings
|
39
|
+
|
40
|
+
# list all webhooks of a company
|
41
|
+
client.webhooks
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
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).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/helloworld1812/wotc-ruby-gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
53
|
+
|
54
|
+
Here are some ways you can contribute:
|
55
|
+
|
56
|
+
- by reporting bugs
|
57
|
+
- by suggesting new features
|
58
|
+
- by writing or editing documentation
|
59
|
+
- by writing test case
|
60
|
+
- by writing code (no patch is too small: fix typos, add comments, clean up inconsistent whitespace)
|
61
|
+
- by refactoring code
|
62
|
+
- by closing issues
|
63
|
+
- by reviewing patches
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
68
|
+
|
69
|
+
## Code of Conduct
|
70
|
+
|
71
|
+
Everyone interacting in the Wotc::Ruby::Gem project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/wotc-ruby-gem/blob/master/CODE_OF_CONDUCT.md).
|
72
|
+
|
73
|
+
## Reference
|
74
|
+
|
75
|
+
**Good examples of API Wrapper**
|
76
|
+
|
77
|
+
- [Octokit](https://github.com/octokit/octokit.rb/blob/master/lib/octokit/client.rb)
|
78
|
+
- [Instagram](https://github.com/Instagram/instagram-ruby-gem/blob/master/lib/instagram/client.rb)
|
79
|
+
- [Twitter](https://github.com/sferik/twitter/blob/master/lib/twitter/rest/api.rb)
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wotc"
|
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
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module FaradayMiddleWare
|
4
|
+
class RaiseHttpException < Faraday::Middleware
|
5
|
+
def initialize(app)
|
6
|
+
super(app)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@app.call(env).on_complete do |response|
|
11
|
+
case response.status.to_i
|
12
|
+
when 400
|
13
|
+
raise WOTC::BadRequest, error_message(env)
|
14
|
+
when 404
|
15
|
+
raise WOTC::NotFound, error_message(env)
|
16
|
+
when 500
|
17
|
+
raise WOTC::InternalServerError, error_message(env)
|
18
|
+
when 502
|
19
|
+
raise WOTC::BadGateway, error_message(env)
|
20
|
+
when 503
|
21
|
+
raise WOTC::ServiceUnavailable, error_message(env)
|
22
|
+
when 504
|
23
|
+
raise WOTC::GatewayTimeout, error_message(env)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def error_message(env)
|
31
|
+
"\nURL: #{env.url}\nmethod: #{env.method} \nstatus: #{env.status}\nerrors: #{env.response.body}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/wotc.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../wotc/error', __FILE__)
|
2
|
+
require File.expand_path('../wotc/api', __FILE__)
|
3
|
+
require File.expand_path('../wotc/client', __FILE__)
|
4
|
+
|
5
|
+
module WOTC
|
6
|
+
extend Configuration
|
7
|
+
|
8
|
+
# Alias for WOTC::Client.new
|
9
|
+
#
|
10
|
+
# @return [WOTC::Client]
|
11
|
+
def self.client(options={})
|
12
|
+
::WOTC::Client.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Delegate to WOTC::Client
|
16
|
+
def self.method_missing(method, *args, &block)
|
17
|
+
return super unless client.respond_to?(method)
|
18
|
+
client.send(method, *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Delegate to WOTC::Client
|
22
|
+
def self.respond_to?(method, include_all=false)
|
23
|
+
return client.respond_to?(method, include_all) || super
|
24
|
+
end
|
25
|
+
end
|
data/lib/wotc/api.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
require File.expand_path('../configuration', __FILE__)
|
4
|
+
|
5
|
+
module WOTC
|
6
|
+
class API
|
7
|
+
include Connection
|
8
|
+
include Request
|
9
|
+
|
10
|
+
attr_accessor *WOTC::Configuration::VALID_OPTIONS_KEYS
|
11
|
+
|
12
|
+
# Creates a new API
|
13
|
+
def initialize(options={})
|
14
|
+
options = WOTC.options.merge(options)
|
15
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
16
|
+
send("#{key}=", options[key])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def config
|
21
|
+
conf = {}
|
22
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
23
|
+
conf[key] = send key
|
24
|
+
end
|
25
|
+
conf
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/wotc/client.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module WOTC
|
2
|
+
# Wrapper for the WOTC REST API
|
3
|
+
#
|
4
|
+
# @note All methods have been separated into modules and follow the same grouping used in https://sandbox.wotc.com/portal/api/documentation
|
5
|
+
# @see https://sandbox.wotc.com/portal/api/documentation
|
6
|
+
class Client < API
|
7
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each{ |f| require f }
|
8
|
+
|
9
|
+
include WOTC::Client::Employees
|
10
|
+
include WOTC::Client::Applicants
|
11
|
+
include WOTC::Client::Companies
|
12
|
+
include WOTC::Client::Documents
|
13
|
+
include WOTC::Client::Payrolls
|
14
|
+
include WOTC::Client::Locations
|
15
|
+
include WOTC::Client::Webhooks
|
16
|
+
include WOTC::Client::Users
|
17
|
+
include WOTC::Client::Registers
|
18
|
+
include WOTC::Client::Wotcs
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to applicants.
|
4
|
+
module Applicants
|
5
|
+
# Get as list of applicants
|
6
|
+
def applicants(options={})
|
7
|
+
paginate("applicants", options)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Create an applicant
|
11
|
+
def create_applicant(options)
|
12
|
+
post('applicants', options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Update an applicant
|
16
|
+
def update_applicant(applicant_id, options={})
|
17
|
+
put("applicants/#{applicant_id}", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: boolean response
|
21
|
+
# Delete an applicant
|
22
|
+
def delete_applicant(applicant_id)
|
23
|
+
delete("applicants/#{applicant_id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get as of applicants whose WOTC status has changed in the last 24 hours.
|
27
|
+
# def recent_status_changed_applicants
|
28
|
+
# get("applicants/changes/wotc/status")
|
29
|
+
# end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to companies
|
4
|
+
module Companies
|
5
|
+
|
6
|
+
# Get company settings, if there are no settings saved, anempty response if given.
|
7
|
+
def get_company_settings(company_id=nil)
|
8
|
+
if company_id.nil?
|
9
|
+
get("company/settings")
|
10
|
+
else
|
11
|
+
get("company/settings/?company_id=#{company_id}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Update company settings
|
16
|
+
def update_company_settings(company_id=nil, options={})
|
17
|
+
if company_id.nil?
|
18
|
+
put("company/settings", options)
|
19
|
+
else
|
20
|
+
put("company/settings?company_id=#{company_id}", options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to documents
|
4
|
+
module Documents
|
5
|
+
|
6
|
+
# Upload a document
|
7
|
+
# def upload_document
|
8
|
+
#
|
9
|
+
# end
|
10
|
+
|
11
|
+
# Update a document
|
12
|
+
# def update_document
|
13
|
+
#
|
14
|
+
# end
|
15
|
+
|
16
|
+
# List documents
|
17
|
+
def all_documents(options={})
|
18
|
+
paginate("documents", options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to employees.
|
4
|
+
module Employees
|
5
|
+
# Fetch all employees
|
6
|
+
def employees(options={})
|
7
|
+
paginate("employees", options)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Get a single employee
|
11
|
+
def employee(employee_id)
|
12
|
+
get("employees/#{employee_id}")
|
13
|
+
end
|
14
|
+
|
15
|
+
# Update an employee
|
16
|
+
def update_employee(employee_id, options={})
|
17
|
+
put("employees/#{employee_id}", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create an employee
|
21
|
+
def create_employee(options={})
|
22
|
+
post("employees", options)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get employee's WOTC status
|
26
|
+
def employee_wotc_status(employee_id)
|
27
|
+
get("employees#{employee_id}/wotc/status")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get wotc info for specific employee
|
31
|
+
def employee_wotc_info(employee_id)
|
32
|
+
get("employees/#{employee_id}/wotc")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Generate an auto fill WOTC url
|
36
|
+
def employee_auto_fill_wotc_url(employee_id)
|
37
|
+
get("employees/#{employee_id}/wotc/url")
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get employees with certified WOTC status
|
41
|
+
def certified_employees(company_id=nil)
|
42
|
+
if company_id.nil?
|
43
|
+
get("employees/wotc/certified")
|
44
|
+
else
|
45
|
+
get("employees/wotc/certified?company_id=#{company_id}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to locations
|
4
|
+
module Locations
|
5
|
+
# Get all locations
|
6
|
+
def all_locations
|
7
|
+
get("locations")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_location(options={})
|
11
|
+
post("locations", options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def update_location(options={})
|
15
|
+
put("locations", options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_location(location_id)
|
19
|
+
delete("locations/#{location_id}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to payrolls.
|
4
|
+
module Payrolls
|
5
|
+
# Get as list of hours and wages
|
6
|
+
def all_payrolls(options={})
|
7
|
+
paginate("hours-wages")
|
8
|
+
end
|
9
|
+
|
10
|
+
# Create a payroll record
|
11
|
+
def create_payroll(options={})
|
12
|
+
post("hours-wages", options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# THIS API IS UNSTABLE!
|
16
|
+
# Get as list of hours and wages by employee record
|
17
|
+
# def employee_payrolls(employee_id, options={})
|
18
|
+
# get("employees/#{employee_id}/hours-wages")
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Update a payroll record
|
22
|
+
def update_payroll(payroll_id, options={})
|
23
|
+
put("hours-wages/#{payroll_id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to webhooks.
|
4
|
+
module Webhooks
|
5
|
+
# List company webhooks
|
6
|
+
def webhooks(options={})
|
7
|
+
paginate('webhooks')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Create a webhook
|
11
|
+
def create_webhook(options = {})
|
12
|
+
post('webhooks', options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Update a webhook
|
16
|
+
def update_webhook(webhook_id, options = {})
|
17
|
+
put("webhooks/#{webhook_id}", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delete a webhook
|
21
|
+
def delete_webhook(webhook_id)
|
22
|
+
delete("webhooks/#{webhook_id}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module WOTC
|
4
|
+
# Defines constants and methods related to configuration
|
5
|
+
module Configuration
|
6
|
+
# An array of valid keys in the options hash when configuring a {WOTC::API}
|
7
|
+
VALID_OPTIONS_KEYS = [
|
8
|
+
:access_token,
|
9
|
+
:adapter,
|
10
|
+
:connection_options,
|
11
|
+
:endpoint,
|
12
|
+
:format,
|
13
|
+
:proxy,
|
14
|
+
:user_agent,
|
15
|
+
:auto_paginate,
|
16
|
+
:per_page,
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
# By default, don't set an access token
|
20
|
+
DEFAULT_ACCESS_TOKEN = nil
|
21
|
+
|
22
|
+
# By default, enable auto-paginate
|
23
|
+
DEFAULT_AUTO_PAGINATE = true
|
24
|
+
|
25
|
+
# By default, return 20 resources per page when there is an pagination.
|
26
|
+
DEFAULT_PER_PAGE = 20
|
27
|
+
|
28
|
+
# The adapter that will be used to connect if none is set
|
29
|
+
#
|
30
|
+
# @note The default faraday adapter is Net::HTTP.
|
31
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
32
|
+
|
33
|
+
# By default, don't set any connection options
|
34
|
+
DEFAULT_CONNECTION_OPTIONS = {}
|
35
|
+
|
36
|
+
# The endpoint that will be used to connect if none is set
|
37
|
+
#
|
38
|
+
# @note There is no reason to use any other endpoint at this time
|
39
|
+
DEFAULT_ENDPOINT = 'https://sandbox.wotc.com/portal/api/v1/'.freeze
|
40
|
+
|
41
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
42
|
+
#
|
43
|
+
# @note JSON is the only available format at this time
|
44
|
+
DEFAULT_FORMAT = :json
|
45
|
+
|
46
|
+
# By default, don't use a proxy server
|
47
|
+
DEFAULT_PROXY = nil
|
48
|
+
|
49
|
+
# The user agent that will be sent to the API endpoint if none is set
|
50
|
+
DEFAULT_USER_AGENT = "WOTC Ruby Gem #{WOTC::VERSION}".freeze
|
51
|
+
|
52
|
+
# An array of valid request/response formats
|
53
|
+
VALID_FORMATS = [:json].freeze
|
54
|
+
|
55
|
+
# @private
|
56
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
57
|
+
|
58
|
+
# When this module is extended, set all configuration options to their default values
|
59
|
+
def self.extended(base)
|
60
|
+
base.reset
|
61
|
+
end
|
62
|
+
|
63
|
+
# Convenience method to allow configuration options to be set in a block
|
64
|
+
def configure
|
65
|
+
yield self
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create a hash of options and their values
|
69
|
+
def options
|
70
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
71
|
+
option.merge!(key => send(key))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Reset all configuration options to defaults
|
76
|
+
def reset
|
77
|
+
self.access_token = DEFAULT_ACCESS_TOKEN
|
78
|
+
self.adapter = DEFAULT_ADAPTER
|
79
|
+
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
80
|
+
self.endpoint = DEFAULT_ENDPOINT
|
81
|
+
self.format = DEFAULT_FORMAT
|
82
|
+
self.proxy = DEFAULT_PROXY
|
83
|
+
self.user_agent = DEFAULT_USER_AGENT
|
84
|
+
self.auto_paginate = DEFAULT_AUTO_PAGINATE
|
85
|
+
self.per_page = DEFAULT_PER_PAGE
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
3
|
+
|
4
|
+
module WOTC
|
5
|
+
module Connection
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection
|
10
|
+
options = {
|
11
|
+
headers: {
|
12
|
+
"Accept" => "application/#{format}; charset=utf-8",
|
13
|
+
"User-Agent" => user_agent,
|
14
|
+
},
|
15
|
+
proxy: proxy,
|
16
|
+
url: endpoint
|
17
|
+
}.merge(connection_options)
|
18
|
+
|
19
|
+
Faraday::Connection.new(options) do |conn|
|
20
|
+
conn.authorization :Bearer, access_token
|
21
|
+
conn.request :json
|
22
|
+
|
23
|
+
conn.use FaradayMiddleWare::RaiseHttpException
|
24
|
+
conn.response :json, content_type: /\bjson$/
|
25
|
+
conn.adapter Faraday.default_adapter
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/lib/wotc/error.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module WOTC
|
2
|
+
# Custom error class for rescuing from all wotc.com errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when wotc.com returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when wotc.com returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when wotc.com returns the HTTP status code 500
|
12
|
+
class InternalServerError < Error; end
|
13
|
+
|
14
|
+
# Raised when wotc.com returns the HTTP status code 502
|
15
|
+
class BadGateway < Error; end
|
16
|
+
|
17
|
+
# Raised when wotc.com returns the HTTP status code 503
|
18
|
+
class ServiceUnavailable < Error; end
|
19
|
+
|
20
|
+
# Raised when wotc.com returns the HTTP status code 504
|
21
|
+
class GatewayTimeout < Error; end
|
22
|
+
|
23
|
+
# Raised when client fails to provide required parameters.
|
24
|
+
class MissingRequiredArgument < Error; end
|
25
|
+
end
|
data/lib/wotc/request.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module WOTC
|
4
|
+
# Defines HTTP request methods
|
5
|
+
module Request
|
6
|
+
# HTTP GET request
|
7
|
+
def get(path, options={})
|
8
|
+
request(:get, path, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# HTTP POST request
|
12
|
+
def post(path, options={})
|
13
|
+
request(:post, path, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# HTTP PUT request
|
17
|
+
def put(path, options={})
|
18
|
+
request(:put, path, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# HTTP DELETE request
|
22
|
+
def delete(path, options={})
|
23
|
+
request(:delete, path, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# Auto-pagination for HTTP get.
|
29
|
+
# return all resources when auto_paginate is set true.
|
30
|
+
# return just one page when auto_paginate is set false.
|
31
|
+
def paginate(path, options={})
|
32
|
+
per_page = options[:per_page] || options["per_page"] || @per_page
|
33
|
+
page = options[:page] || options["page"]
|
34
|
+
response = get(path+"?page=1&per_page=#{per_page}")
|
35
|
+
|
36
|
+
# return one page results without pagination.
|
37
|
+
return response if !@auto_paginate
|
38
|
+
|
39
|
+
# return all results when enabled auto paginate
|
40
|
+
last_response = response.dup
|
41
|
+
data = response["data"]
|
42
|
+
while last_response["next_page_url"]
|
43
|
+
last_response = get(last_response["next_page_url"] + "&per_page=#{per_page}")
|
44
|
+
data.concat(last_response["data"]) if last_response["data"].is_a?(Array)
|
45
|
+
end
|
46
|
+
|
47
|
+
return data
|
48
|
+
end
|
49
|
+
|
50
|
+
def request(method, path, options)
|
51
|
+
response = connection.send(method) do |request|
|
52
|
+
case method
|
53
|
+
when :get, :delete
|
54
|
+
request.url(URI.encode(path), options)
|
55
|
+
when :post, :put
|
56
|
+
request.path = URI.encode(path)
|
57
|
+
request.body = options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
return response.body
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/wotc/version.rb
ADDED
data/wotc.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "wotc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "wotc"
|
7
|
+
spec.version = WOTC::VERSION
|
8
|
+
spec.authors = ["workstream.us"]
|
9
|
+
spec.email = ["ryan@workstream.is"]
|
10
|
+
|
11
|
+
spec.summary = %q{Ruby wrapper for wotc.com APIs}
|
12
|
+
spec.description = %q{An Ruby wrapper for wotc.com REST APIs}
|
13
|
+
spec.homepage = "https://github.com/helloworld1812/wotc-ruby-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["source_code_uri"] = "https://github.com/helloworld1812/wotc-ruby-gem"
|
23
|
+
spec.metadata["changelog_uri"] = "https://github.com/helloworld1812/wotc-ruby-gem/CHANGELOG.md"
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
"public gem pushes."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.9.0"
|
41
|
+
spec.add_development_dependency "pry"
|
42
|
+
spec.add_development_dependency "webmock"
|
43
|
+
spec.add_runtime_dependency 'faraday'
|
44
|
+
spec.add_runtime_dependency 'faraday_middleware'
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wotc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- workstream.us
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.9.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.9.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: An Ruby wrapper for wotc.com REST APIs
|
112
|
+
email:
|
113
|
+
- ryan@workstream.is
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rakeTasks"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CHANGELOG.md
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- lib/faraday/raise_http_exception.rb
|
130
|
+
- lib/wotc.rb
|
131
|
+
- lib/wotc/api.rb
|
132
|
+
- lib/wotc/client.rb
|
133
|
+
- lib/wotc/client/applicants.rb
|
134
|
+
- lib/wotc/client/companies.rb
|
135
|
+
- lib/wotc/client/documents.rb
|
136
|
+
- lib/wotc/client/employees.rb
|
137
|
+
- lib/wotc/client/locations.rb
|
138
|
+
- lib/wotc/client/payrolls.rb
|
139
|
+
- lib/wotc/client/registers.rb
|
140
|
+
- lib/wotc/client/users.rb
|
141
|
+
- lib/wotc/client/webhooks.rb
|
142
|
+
- lib/wotc/client/wotcs.rb
|
143
|
+
- lib/wotc/configuration.rb
|
144
|
+
- lib/wotc/connection.rb
|
145
|
+
- lib/wotc/error.rb
|
146
|
+
- lib/wotc/request.rb
|
147
|
+
- lib/wotc/version.rb
|
148
|
+
- wotc.gemspec
|
149
|
+
homepage: https://github.com/helloworld1812/wotc-ruby-gem
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata:
|
153
|
+
homepage_uri: https://github.com/helloworld1812/wotc-ruby-gem
|
154
|
+
source_code_uri: https://github.com/helloworld1812/wotc-ruby-gem
|
155
|
+
changelog_uri: https://github.com/helloworld1812/wotc-ruby-gem/CHANGELOG.md
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubygems_version: 3.0.6
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Ruby wrapper for wotc.com APIs
|
175
|
+
test_files: []
|