wotc 0.1.0 → 0.1.4
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 +15 -0
- data/lib/wotc/client.rb +1 -0
- data/lib/wotc/configuration.rb +6 -2
- data/lib/wotc/error.rb +34 -1
- data/lib/wotc/request.rb +1 -1
- data/lib/wotc/version.rb +1 -1
- data/wotc.gemspec +3 -3
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: accd9be4b389756d480254cc2b33a24e5d70248fc692e27e303b5d90cf7f2faa
|
4
|
+
data.tar.gz: f79045caefeb7c2d57f67bf1d44fdf05fc208046bfc8fa9a31518bf8bb048dd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98217e59a0fca0f3a151a27f38d6b46a3049855674bcfb65ddf7a8ddf90e2e90f3a082b819a1c70c253be888a349e2a503e50ca727a3b7a84b2c3ee0312d4629
|
7
|
+
data.tar.gz: 1cf741e92df0776083fe83f60bc2cec407f0fd01a9085139da1ef98519ed0a29c7167af0930c99f1c958a40e0c1aa86c4ac3844f9b4135143485a0f2681f3bb7
|
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,15 @@
|
|
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
|
+
end
|
14
|
+
end
|
15
|
+
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,6 +9,7 @@ module WOTC
|
|
8
9
|
:access_token,
|
9
10
|
:adapter,
|
10
11
|
:connection_options,
|
12
|
+
:host,
|
11
13
|
:endpoint,
|
12
14
|
:format,
|
13
15
|
:proxy,
|
@@ -33,9 +35,10 @@ module WOTC
|
|
33
35
|
# By default, don't set any connection options
|
34
36
|
DEFAULT_CONNECTION_OPTIONS = {}
|
35
37
|
|
38
|
+
# By default, use sandbox environment
|
39
|
+
DEFAULT_HOST = 'https://sandbox.wotc.com'.freeze
|
40
|
+
|
36
41
|
# 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
42
|
DEFAULT_ENDPOINT = 'https://sandbox.wotc.com/portal/api/v1/'.freeze
|
40
43
|
|
41
44
|
# The response format appended to the path and sent in the 'Accept' header if none is set
|
@@ -77,6 +80,7 @@ module WOTC
|
|
77
80
|
self.access_token = DEFAULT_ACCESS_TOKEN
|
78
81
|
self.adapter = DEFAULT_ADAPTER
|
79
82
|
self.connection_options = DEFAULT_CONNECTION_OPTIONS
|
83
|
+
self.host = DEFAULT_HOST
|
80
84
|
self.endpoint = DEFAULT_ENDPOINT
|
81
85
|
self.format = DEFAULT_FORMAT
|
82
86
|
self.proxy = DEFAULT_PROXY
|
data/lib/wotc/error.rb
CHANGED
@@ -1,10 +1,43 @@
|
|
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
|
+
# Ryan's TODO
|
30
|
+
def error_sentence
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
4
34
|
|
5
35
|
# Raised when wotc.com returns the HTTP status code 400
|
6
36
|
class BadRequest < Error; end
|
7
37
|
|
38
|
+
# Raised when wotc.com returns the HTTP status code 401
|
39
|
+
class Unauthorized < Error; end
|
40
|
+
|
8
41
|
# Raised when wotc.com returns the HTTP status code 404
|
9
42
|
class NotFound < Error; end
|
10
43
|
|
data/lib/wotc/request.rb
CHANGED
data/lib/wotc/version.rb
CHANGED
data/wotc.gemspec
CHANGED
@@ -35,9 +35,9 @@ 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'
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- workstream.us
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-28 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
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/wotc/client/payrolls.rb
|
139
139
|
- lib/wotc/client/registers.rb
|
140
140
|
- lib/wotc/client/users.rb
|
141
|
+
- lib/wotc/client/utils.rb
|
141
142
|
- lib/wotc/client/webhooks.rb
|
142
143
|
- lib/wotc/client/wotcs.rb
|
143
144
|
- lib/wotc/configuration.rb
|