wotc 0.1.0 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +3 -1
- data/Rakefile +10 -7
- data/lib/faraday/raise_http_exception.rb +8 -12
- data/lib/wotc/client/companies.rb +6 -0
- data/lib/wotc/client/employees.rb +9 -2
- data/lib/wotc/client/registers.rb +8 -2
- data/lib/wotc/client/utils.rb +21 -0
- data/lib/wotc/client.rb +1 -0
- data/lib/wotc/configuration.rb +17 -3
- data/lib/wotc/connection.rb +3 -0
- data/lib/wotc/error.rb +40 -1
- data/lib/wotc/request.rb +8 -8
- data/lib/wotc/version.rb +1 -1
- data/wotc.gemspec +4 -3
- metadata +26 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac8eac181af5b251e56003ba42aacd6e7f8ca376f48178325c0f4349f28a788
|
4
|
+
data.tar.gz: c51990906c2d06401afe3a2733433a4e84b7715f3b19c330916f42ef64cb2218
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f72eb6b6da6b24702f0916776944d4a51977ae11e95ceafade99f9f4a05cb446d3ec4277fad045b0e60374874f06470a26c750edef707d560f7e49d9a14f41fb
|
7
|
+
data.tar.gz: 8d30545f71f13374dcde47fe733815baf9324371418f245550b02be3ec9c883a0c1379de899ab679627b2b0525f42f8aa802e447f7481ffe6724f1ec6736e331
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
![WOTC_logo_header-02](https://user-images.githubusercontent.com/1224077/79107910-d97bc880-7da7-11ea-95a3-40be03be614c.png)
|
2
2
|
|
3
|
+
|
3
4
|
# wotc-ruby-gem
|
4
5
|
|
5
|
-
Ruby toolkit for wotc.com API
|
6
|
+
Ruby toolkit for wotc.com API [![Build Status](https://secure.travis-ci.org/helloworld1812/wotc-ruby-gem.svg)](http://travis-ci.org/helloworld1812/wotc-ruby-gem)
|
7
|
+
|
6
8
|
|
7
9
|
## wotc.com REST APIs and documentation
|
8
10
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
desc 'Run the specs'
|
6
|
+
RSpec::Core::RakeTask.new do |r|
|
7
|
+
r.verbose = false
|
8
8
|
end
|
9
9
|
|
10
|
-
task :
|
10
|
+
task :test => :spec
|
11
|
+
|
12
|
+
# Add rubycop
|
13
|
+
task :default => [:spec]
|
@@ -10,25 +10,21 @@ module FaradayMiddleWare
|
|
10
10
|
@app.call(env).on_complete do |response|
|
11
11
|
case response.status.to_i
|
12
12
|
when 400
|
13
|
-
raise WOTC::BadRequest
|
13
|
+
raise WOTC::BadRequest.new(response)
|
14
|
+
when 401
|
15
|
+
raise WOTC::Unauthorized.new(response)
|
14
16
|
when 404
|
15
|
-
raise WOTC::NotFound
|
17
|
+
raise WOTC::NotFound.new(response)
|
16
18
|
when 500
|
17
|
-
raise WOTC::InternalServerError
|
19
|
+
raise WOTC::InternalServerError.new(response)
|
18
20
|
when 502
|
19
|
-
raise WOTC::BadGateway
|
21
|
+
raise WOTC::BadGateway.new(response)
|
20
22
|
when 503
|
21
|
-
raise WOTC::ServiceUnavailable
|
23
|
+
raise WOTC::ServiceUnavailable.new(response)
|
22
24
|
when 504
|
23
|
-
raise WOTC::GatewayTimeout
|
25
|
+
raise WOTC::GatewayTimeout.new(response)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
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
29
|
end
|
34
30
|
end
|
@@ -33,8 +33,15 @@ module WOTC
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# Generate an auto fill WOTC url
|
36
|
-
def employee_auto_fill_wotc_url(employee_id)
|
37
|
-
|
36
|
+
def employee_auto_fill_wotc_url(employee_id, redirect=nil)
|
37
|
+
uri = URI.parse(redirect) rescue false
|
38
|
+
result = if uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
|
39
|
+
get("employees/#{employee_id}/wotc/url?redirect=#{redirect}")
|
40
|
+
else
|
41
|
+
get("employees/#{employee_id}/wotc/url")
|
42
|
+
end
|
43
|
+
|
44
|
+
return result.body["url"]
|
38
45
|
end
|
39
46
|
|
40
47
|
# Get employees with certified WOTC status
|
@@ -3,8 +3,14 @@ module WOTC
|
|
3
3
|
module Registers
|
4
4
|
|
5
5
|
# Register for an account and get back a life time access token.
|
6
|
-
def register(options)
|
7
|
-
post("register", options)
|
6
|
+
def register(options = {})
|
7
|
+
response = post("register", options)
|
8
|
+
if response.body.is_a?(Hash) && response.body["token"]
|
9
|
+
return response
|
10
|
+
else
|
11
|
+
# raise error when token is missing.
|
12
|
+
raise WOTC::BadRequest.new(response)
|
13
|
+
end
|
8
14
|
end
|
9
15
|
end
|
10
16
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WOTC
|
2
|
+
class Client
|
3
|
+
# Defines methods related to utils
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
# Trigger an api call to verify access_token is valid.
|
7
|
+
def token_valid?
|
8
|
+
user = get('user').body
|
9
|
+
return true if user&.fetch("id")
|
10
|
+
rescue => e
|
11
|
+
return false
|
12
|
+
end
|
13
|
+
|
14
|
+
# Pre-qualify an application of WOTC status
|
15
|
+
def wotc_calculator(options={})
|
16
|
+
result = post('wotc/calculator', options)
|
17
|
+
result.body == true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/wotc/client.rb
CHANGED
data/lib/wotc/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
2
3
|
|
3
4
|
module WOTC
|
4
5
|
# Defines constants and methods related to configuration
|
@@ -8,12 +9,15 @@ module WOTC
|
|
8
9
|
:access_token,
|
9
10
|
:adapter,
|
10
11
|
:connection_options,
|
12
|
+
:host,
|
11
13
|
:endpoint,
|
12
14
|
:format,
|
13
15
|
:proxy,
|
14
16
|
:user_agent,
|
15
17
|
:auto_paginate,
|
16
18
|
:per_page,
|
19
|
+
:timeout,
|
20
|
+
:open_timeout,
|
17
21
|
].freeze
|
18
22
|
|
19
23
|
# By default, don't set an access token
|
@@ -30,12 +34,19 @@ module WOTC
|
|
30
34
|
# @note The default faraday adapter is Net::HTTP.
|
31
35
|
DEFAULT_ADAPTER = Faraday.default_adapter
|
32
36
|
|
33
|
-
# By default, don't set
|
37
|
+
# By default, don't set connection options.
|
34
38
|
DEFAULT_CONNECTION_OPTIONS = {}
|
35
39
|
|
40
|
+
# Default timeout time is 20 seconds
|
41
|
+
DEFAULT_TIMEOUT = 20
|
42
|
+
|
43
|
+
# By default, the open timeout is 20 seconds.
|
44
|
+
DEFAULT_OPEN_TIMEOUT = 20
|
45
|
+
|
46
|
+
# By default, use sandbox environment
|
47
|
+
DEFAULT_HOST = 'https://sandbox.wotc.com'.freeze
|
48
|
+
|
36
49
|
# 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
50
|
DEFAULT_ENDPOINT = 'https://sandbox.wotc.com/portal/api/v1/'.freeze
|
40
51
|
|
41
52
|
# The response format appended to the path and sent in the 'Accept' header if none is set
|
@@ -77,12 +88,15 @@ module WOTC
|
|
77
88
|
self.access_token = DEFAULT_ACCESS_TOKEN
|
78
89
|
self.adapter = DEFAULT_ADAPTER
|
79
90
|
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
91
|
+
self.host = DEFAULT_HOST
|
80
92
|
self.endpoint = DEFAULT_ENDPOINT
|
81
93
|
self.format = DEFAULT_FORMAT
|
82
94
|
self.proxy = DEFAULT_PROXY
|
83
95
|
self.user_agent = DEFAULT_USER_AGENT
|
84
96
|
self.auto_paginate = DEFAULT_AUTO_PAGINATE
|
85
97
|
self.per_page = DEFAULT_PER_PAGE
|
98
|
+
self.timeout = DEFAULT_TIMEOUT
|
99
|
+
self.open_timeout = DEFAULT_OPEN_TIMEOUT
|
86
100
|
end
|
87
101
|
end
|
88
102
|
end
|
data/lib/wotc/connection.rb
CHANGED
@@ -18,6 +18,9 @@ module WOTC
|
|
18
18
|
|
19
19
|
Faraday::Connection.new(options) do |conn|
|
20
20
|
conn.authorization :Bearer, access_token
|
21
|
+
# https://github.com/lostisland/faraday/issues/417#issuecomment-223413386
|
22
|
+
conn.options[:timeout] = timeout
|
23
|
+
conn.options[:open_timeout] = open_timeout
|
21
24
|
conn.request :json
|
22
25
|
|
23
26
|
conn.use FaradayMiddleWare::RaiseHttpException
|
data/lib/wotc/error.rb
CHANGED
@@ -1,10 +1,49 @@
|
|
1
1
|
module WOTC
|
2
2
|
# Custom error class for rescuing from all wotc.com errors
|
3
|
-
class Error < StandardError
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :http_method, :url, :errors
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
super
|
8
|
+
@response = response.dup
|
9
|
+
@http_method = response.method.to_s
|
10
|
+
@url = response.url
|
11
|
+
if response.body.is_a?(Hash) && !response.body.empty? && !response.body.fetch("errors", nil).nil?
|
12
|
+
@raw_errors = response.body.fetch("errors")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
<<-HEREDOC
|
18
|
+
URL: #{@response.url}
|
19
|
+
method: #{@response.method}
|
20
|
+
response status: #{@response.status}
|
21
|
+
response body: #{@response.response.body}
|
22
|
+
HEREDOC
|
23
|
+
end
|
24
|
+
|
25
|
+
def raw_errors
|
26
|
+
@raw_errors
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_sentence
|
30
|
+
return if @raw_errors.nil?
|
31
|
+
|
32
|
+
array = []
|
33
|
+
@raw_errors.each do |_, v|
|
34
|
+
array += v
|
35
|
+
end
|
36
|
+
|
37
|
+
array.join(' ')
|
38
|
+
end
|
39
|
+
end
|
4
40
|
|
5
41
|
# Raised when wotc.com returns the HTTP status code 400
|
6
42
|
class BadRequest < Error; end
|
7
43
|
|
44
|
+
# Raised when wotc.com returns the HTTP status code 401
|
45
|
+
class Unauthorized < Error; end
|
46
|
+
|
8
47
|
# Raised when wotc.com returns the HTTP status code 404
|
9
48
|
class NotFound < Error; end
|
10
49
|
|
data/lib/wotc/request.rb
CHANGED
@@ -38,10 +38,10 @@ module WOTC
|
|
38
38
|
|
39
39
|
# return all results when enabled auto paginate
|
40
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"]
|
44
|
-
data.concat(last_response["data"]) if last_response["data"].is_a?(Array)
|
41
|
+
data = response.body["data"]
|
42
|
+
while last_response.body["next_page_url"]
|
43
|
+
last_response = get(last_response.body["next_page_url"])
|
44
|
+
data.concat(last_response.body["data"]) if last_response.body["data"].is_a?(Array)
|
45
45
|
end
|
46
46
|
|
47
47
|
return data
|
@@ -51,14 +51,14 @@ module WOTC
|
|
51
51
|
response = connection.send(method) do |request|
|
52
52
|
case method
|
53
53
|
when :get, :delete
|
54
|
-
request.url(URI.
|
54
|
+
request.url(Addressable::URI.escape(path), options)
|
55
55
|
when :post, :put
|
56
|
-
request.path = URI.
|
56
|
+
request.path = Addressable::URI.escape(path)
|
57
57
|
request.body = options
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
response
|
62
62
|
end
|
63
63
|
end
|
64
|
-
end
|
64
|
+
end
|
data/lib/wotc/version.rb
CHANGED
data/wotc.gemspec
CHANGED
@@ -35,11 +35,12 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ["lib"]
|
37
37
|
|
38
|
-
spec.add_development_dependency "bundler", "
|
39
|
-
spec.add_development_dependency "rake", "
|
40
|
-
spec.add_development_dependency "rspec", "
|
38
|
+
spec.add_development_dependency "bundler", ">= 1.17"
|
39
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
40
|
+
spec.add_development_dependency "rspec", ">= 3.9.0"
|
41
41
|
spec.add_development_dependency "pry"
|
42
42
|
spec.add_development_dependency "webmock"
|
43
43
|
spec.add_runtime_dependency 'faraday'
|
44
44
|
spec.add_runtime_dependency 'faraday_middleware'
|
45
|
+
spec.add_runtime_dependency 'addressable'
|
45
46
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wotc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- workstream.us
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.17'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.9.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.9.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: addressable
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: An Ruby wrapper for wotc.com REST APIs
|
112
126
|
email:
|
113
127
|
- ryan@workstream.is
|
@@ -138,6 +152,7 @@ files:
|
|
138
152
|
- lib/wotc/client/payrolls.rb
|
139
153
|
- lib/wotc/client/registers.rb
|
140
154
|
- lib/wotc/client/users.rb
|
155
|
+
- lib/wotc/client/utils.rb
|
141
156
|
- lib/wotc/client/webhooks.rb
|
142
157
|
- lib/wotc/client/wotcs.rb
|
143
158
|
- lib/wotc/configuration.rb
|
@@ -168,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
183
|
- !ruby/object:Gem::Version
|
169
184
|
version: '0'
|
170
185
|
requirements: []
|
171
|
-
rubygems_version: 3.
|
186
|
+
rubygems_version: 3.1.6
|
172
187
|
signing_key:
|
173
188
|
specification_version: 4
|
174
189
|
summary: Ruby wrapper for wotc.com APIs
|