fasttrack-client 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/common.rb +39 -0
- data/lib/constants.rb +8 -0
- data/lib/exceptions.rb +46 -0
- data/lib/fasttrack.rb +57 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e550af164fd3e9964567dd95ec3bd9d59873d186
|
4
|
+
data.tar.gz: 4907511370c8d19c267e8692e6e63131b8a3a874
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bdcb822a31096835b9e1b3e228ed6f7860959e98af5c0eaaaf4d90aad1b19466d05cf03e813bfae5e1fdc6cbc93f538c8132382c544ab6890ad1f87f600d6f3e
|
7
|
+
data.tar.gz: b064380567856d7eb4f48feb29e7a57f0b1f19140e9a8a46d4824dc6d5d95b0598693c7bc815a2dcc7e52e7f8f0ad5ce372e91ed48a118e34eac426bcfd8c063
|
data/lib/common.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative './exceptions'
|
2
|
+
|
3
|
+
ERRORS_BY_STATUS = {
|
4
|
+
'400' => FastTrack::BadRequestException,
|
5
|
+
'401' => FastTrack::UnauthorizedException,
|
6
|
+
'404' => FastTrack::NotFoundException,
|
7
|
+
'405' => FastTrack::MethodNotAllowedException,
|
8
|
+
'406' => FastTrack::NotAcceptableException,
|
9
|
+
'429' => FastTrack::TooManyRequestsException
|
10
|
+
}
|
11
|
+
|
12
|
+
ERRORS_BY_ERROR_CODE = {
|
13
|
+
'1' => FastTrack::VersionRequiredException,
|
14
|
+
'2' => FastTrack::NoResultException,
|
15
|
+
'3' => FastTrack::BadParametersException,
|
16
|
+
'4' => FastTrack::InvalidVersionException
|
17
|
+
}
|
18
|
+
|
19
|
+
def exceptionForResponse(status, errorCode)
|
20
|
+
fastTrackError = nil
|
21
|
+
|
22
|
+
if errorCode != nil
|
23
|
+
fastTrackError = ERRORS_BY_ERROR_CODE[errorCode]
|
24
|
+
end
|
25
|
+
|
26
|
+
if fastTrackError == nil && status != nil
|
27
|
+
fastTrackError = ERRORS_BY_STATUS[status.to_s]
|
28
|
+
|
29
|
+
if status >= 500 && status < 600
|
30
|
+
fastTrackError = FastTrack::InternalServerException
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if fastTrackError == nil
|
35
|
+
fastTrackError = Exception
|
36
|
+
end
|
37
|
+
|
38
|
+
return fastTrackError
|
39
|
+
end
|
data/lib/constants.rb
ADDED
data/lib/exceptions.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module FastTrack
|
3
|
+
# Bad parameters
|
4
|
+
class BadParametersException < Exception
|
5
|
+
end
|
6
|
+
|
7
|
+
# Bad request
|
8
|
+
class BadRequestException < Exception
|
9
|
+
end
|
10
|
+
|
11
|
+
# Internal server error
|
12
|
+
class InternalServerException < Exception
|
13
|
+
end
|
14
|
+
|
15
|
+
# Invalid version
|
16
|
+
class InvalidVersionException < Exception
|
17
|
+
end
|
18
|
+
|
19
|
+
# Method not allowed
|
20
|
+
class MethodNotAllowedException < Exception
|
21
|
+
end
|
22
|
+
|
23
|
+
# No result
|
24
|
+
class NoResultException < Exception
|
25
|
+
end
|
26
|
+
|
27
|
+
# Not acceptable
|
28
|
+
class NotAcceptableException < Exception
|
29
|
+
end
|
30
|
+
|
31
|
+
# Not found
|
32
|
+
class NotFoundException < Exception
|
33
|
+
end
|
34
|
+
|
35
|
+
# Too many requests
|
36
|
+
class TooManyRequestsException < Exception
|
37
|
+
end
|
38
|
+
|
39
|
+
# Unauthorized
|
40
|
+
class UnauthorizedException < Exception
|
41
|
+
end
|
42
|
+
|
43
|
+
# Version required
|
44
|
+
class VersionRequiredException < Exception
|
45
|
+
end
|
46
|
+
end
|
data/lib/fasttrack.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'JSON'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require_relative './common'
|
5
|
+
require_relative './constants'
|
6
|
+
|
7
|
+
module FastTrack
|
8
|
+
class Client
|
9
|
+
def initialize(token, opts = {})
|
10
|
+
@token = token
|
11
|
+
@opts = opts
|
12
|
+
end
|
13
|
+
|
14
|
+
# Request to the API endpoint
|
15
|
+
def get(path, params)
|
16
|
+
begin
|
17
|
+
headers = {
|
18
|
+
'Authorization' => 'Token ' + @token,
|
19
|
+
'Accept' => ACCEPT + '; version = ' + VERSION.to_s,
|
20
|
+
'params' => params
|
21
|
+
};
|
22
|
+
|
23
|
+
url = 'https://api.fasttrack-intl.com' + path
|
24
|
+
|
25
|
+
response = RestClient.get(url, headers)
|
26
|
+
|
27
|
+
return JSON.parse(response.body)
|
28
|
+
rescue RestClient::ExceptionWithResponse => e
|
29
|
+
body = nil;
|
30
|
+
response = e.response
|
31
|
+
|
32
|
+
begin
|
33
|
+
body = JSON.parse(response.body)
|
34
|
+
rescue
|
35
|
+
body = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
exception = exceptionForResponse(response.code, body['error_code'])
|
39
|
+
raise exception, body['detail']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Retrieve company details with a `domain`
|
44
|
+
def getCompany(domain)
|
45
|
+
return self.get PATHNAME_COMPANY, {
|
46
|
+
'domain' => domain
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
# Retrieve contact details with an `email`
|
51
|
+
def getContact(email)
|
52
|
+
return self.get PATHNAME_CONTACT, {
|
53
|
+
'email' => email
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fasttrack-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fast Track
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webmock
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description: This Fasttrack library enables you to request the Fasttrack API in a
|
42
|
+
convenient way. For more information about the Fasttrack API please see https://api.fasttrack-intl.com
|
43
|
+
email: info@fasttrack-intl.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/common.rb
|
49
|
+
- lib/constants.rb
|
50
|
+
- lib/exceptions.rb
|
51
|
+
- lib/fasttrack.rb
|
52
|
+
homepage: https://github.com/fasttrack/fasttrack-ruby
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.6.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Fast Track client
|
76
|
+
test_files: []
|