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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c55912e173441fafde565727cfea98101a699ee28b0f3b949a9949f7730cab2b
4
- data.tar.gz: 69abcb3adee7d97d0832c4a4b6b26d5d316b1940f4bd26bb8b4bfe87c8761664
3
+ metadata.gz: accd9be4b389756d480254cc2b33a24e5d70248fc692e27e303b5d90cf7f2faa
4
+ data.tar.gz: f79045caefeb7c2d57f67bf1d44fdf05fc208046bfc8fa9a31518bf8bb048dd0
5
5
  SHA512:
6
- metadata.gz: a72f369eb59c4deeeecaf6b6cc5a69cb2420d685745a8edf2a7e2dd38c1710d29b219754c329c445585d4d93052cd5fc4bf530a9ee06060a6a7302e729fd86db
7
- data.tar.gz: a428af1f1dd944dbe1509b86e19c45dd51a0439131e02f13bb8184ca8078884935e2ede71956a26379ca4297183d7cada0a72efe205cf7347e7558233b87fc41
6
+ metadata.gz: 98217e59a0fca0f3a151a27f38d6b46a3049855674bcfb65ddf7a8ddf90e2e90f3a082b819a1c70c253be888a349e2a503e50ca727a3b7a84b2c3ee0312d4629
7
+ data.tar.gz: 1cf741e92df0776083fe83f60bc2cec407f0fd01a9085139da1ef98519ed0a29c7167af0930c99f1c958a40e0c1aa86c4ac3844f9b4135143485a0f2681f3bb7
data/.travis.yml CHANGED
@@ -4,4 +4,4 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.5.3
7
- before_install: gem install bundler -v 1.17.3
7
+ before_install: gem install bundler
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 "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
3
3
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
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 :default => :test
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, error_message(env)
13
+ raise WOTC::BadRequest.new(response)
14
+ when 401
15
+ raise WOTC::Unauthorized.new(response)
14
16
  when 404
15
- raise WOTC::NotFound, error_message(env)
17
+ raise WOTC::NotFound.new(response)
16
18
  when 500
17
- raise WOTC::InternalServerError, error_message(env)
19
+ raise WOTC::InternalServerError.new(response)
18
20
  when 502
19
- raise WOTC::BadGateway, error_message(env)
21
+ raise WOTC::BadGateway.new(response)
20
22
  when 503
21
- raise WOTC::ServiceUnavailable, error_message(env)
23
+ raise WOTC::ServiceUnavailable.new(response)
22
24
  when 504
23
- raise WOTC::GatewayTimeout, error_message(env)
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
@@ -20,6 +20,12 @@ module WOTC
20
20
  put("company/settings?company_id=#{company_id}", options)
21
21
  end
22
22
  end
23
+
24
+ # Get the info of company
25
+ def current_company
26
+ result = get('user').body
27
+ result["company"]
28
+ end
23
29
  end
24
30
  end
25
31
  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
- get("employees/#{employee_id}/wotc/url")
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
@@ -16,5 +16,6 @@ module WOTC
16
16
  include WOTC::Client::Users
17
17
  include WOTC::Client::Registers
18
18
  include WOTC::Client::Wotcs
19
+ include WOTC::Client::Utils
19
20
  end
20
21
  end
@@ -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; end
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
@@ -58,7 +58,7 @@ module WOTC
58
58
  end
59
59
  end
60
60
 
61
- return response.body
61
+ response
62
62
  end
63
63
  end
64
64
  end
data/lib/wotc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module WOTC
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.4"
3
3
  end
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", "~> 1.17"
39
- spec.add_development_dependency "rake", "~> 10.0"
40
- spec.add_development_dependency "rspec", "~> 3.9.0"
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.0
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-13 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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