optimum 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Optimum
4
+ class Decision
5
+ def self.create(params)
6
+ params = params.merge(introducerId: Optimum.configuration.introducer_id)
7
+
8
+ Optimum.connection.post('/decide', params)
9
+ end
10
+
11
+ def self.update(opportunity_id)
12
+ params = { id: opportunity_id, introducerId: Optimum.configuration.introducer_id }
13
+
14
+ Optimum.connection.get('/update', params)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Optimum
4
+ class PathSanitizer
5
+ # Removes any leading '/'
6
+ def self.sanitize(path)
7
+ parts = path.split('/').reject(&:empty?)
8
+ parts.join('/')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Optimum
6
+ class Response
7
+ extend Forwardable
8
+
9
+ def_delegators :@http_response, :body, :status, :success?
10
+
11
+ def initialize(http_response)
12
+ @http_response = http_response
13
+ end
14
+
15
+ def error
16
+ return body.dig(:message) if body.respond_to?(:dig)
17
+
18
+ body.empty? ? '' : body
19
+ end
20
+
21
+ def data
22
+ body || {}
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Optimum
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'optimum/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'optimum'
10
+ spec.version = Optimum::VERSION
11
+ spec.authors = ['Nenad Petronijevic']
12
+ spec.email = ['nenad@finpoint.co.uk']
13
+
14
+ spec.summary = 'Optimum API wrapper'
15
+ spec.description = spec.summary
16
+ spec.homepage = 'https://www.optimumfinance.co.uk'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'addressable'
30
+ spec.add_dependency 'faraday'
31
+ spec.add_dependency 'faraday_middleware'
32
+ spec.add_dependency 'multi_json'
33
+ spec.add_dependency 'rainbow'
34
+
35
+ spec.add_development_dependency 'bundler'
36
+ spec.add_development_dependency 'dotenv'
37
+ spec.add_development_dependency 'faker'
38
+ spec.add_development_dependency 'pry-byebug'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rubocop'
42
+ spec.add_development_dependency 'rubocop-rspec'
43
+ spec.add_development_dependency 'simplecov'
44
+ spec.add_development_dependency 'vcr'
45
+ spec.add_development_dependency 'webmock'
46
+ end
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/decide
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"companyNumber":"08228603","sector":"Beer / Wine Merchant","turnover":3000000,"homeowners":true,"yearsTrading":4,"expectedCustomers":41,"contactName":"dummy
9
+ test","contactNumber":"07123456789","contactEmail":null,"introducerId":"<TOKEN>"}'
10
+ headers:
11
+ Content-Type:
12
+ - application/json
13
+ User-Agent:
14
+ - ruby-optimum-1.0.0
15
+ Accept-Encoding:
16
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
17
+ Accept:
18
+ - "*/*"
19
+ response:
20
+ status:
21
+ code: 400
22
+ message: Bad Request
23
+ headers:
24
+ Server:
25
+ - Cowboy
26
+ Connection:
27
+ - keep-alive
28
+ X-Powered-By:
29
+ - Express
30
+ Access-Control-Allow-Origin:
31
+ - undefined
32
+ Access-Control-Allow-Headers:
33
+ - Content-Type
34
+ Access-Control-Allow-Methods:
35
+ - GET, POST, OPTIONS, PUT, DELETE
36
+ Access-Control-Allow-Credentials:
37
+ - 'true'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ Content-Length:
41
+ - '71'
42
+ Etag:
43
+ - W/"47-pC6I/ZvdDPhlJbKYIPtqjCNjD+E"
44
+ Date:
45
+ - Sun, 06 Sep 2020 14:07:54 GMT
46
+ Via:
47
+ - 1.1 vegur
48
+ body:
49
+ encoding: UTF-8
50
+ string: '{"message":["contact email is required if not in quotation only mode"]}'
51
+ http_version:
52
+ recorded_at: Sun, 06 Sep 2020 14:07:54 GMT
53
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/decide
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"introducerId":"NOT VALID"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - ruby-optimum-1.0.0
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 403
21
+ message: Forbidden
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - Express
29
+ Access-Control-Allow-Origin:
30
+ - undefined
31
+ Access-Control-Allow-Headers:
32
+ - Content-Type
33
+ Access-Control-Allow-Methods:
34
+ - GET, POST, OPTIONS, PUT, DELETE
35
+ Access-Control-Allow-Credentials:
36
+ - 'true'
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Content-Length:
40
+ - '28'
41
+ Etag:
42
+ - W/"1c-vBByhD3CmKOpNrvcwWb9yibQQR8"
43
+ Date:
44
+ - Sun, 06 Sep 2020 14:07:47 GMT
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"message":"not authorised"}'
50
+ http_version:
51
+ recorded_at: Sun, 06 Sep 2020 14:07:47 GMT
52
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/decide
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"companyNumber":"08228603","sector":"Beer / Wine Merchant","turnover":3000000,"homeowners":true,"yearsTrading":4,"expectedCustomers":41,"contactName":"dummy
9
+ test","contactNumber":"07123456789","contactEmail":"dummy@example.com","introducerId":"<TOKEN>"}'
10
+ headers:
11
+ Content-Type:
12
+ - application/json
13
+ User-Agent:
14
+ - ruby-optimum-1.0.0
15
+ Accept-Encoding:
16
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
17
+ Accept:
18
+ - "*/*"
19
+ response:
20
+ status:
21
+ code: 200
22
+ message: OK
23
+ headers:
24
+ Server:
25
+ - Cowboy
26
+ Connection:
27
+ - keep-alive
28
+ X-Powered-By:
29
+ - Express
30
+ Access-Control-Allow-Origin:
31
+ - undefined
32
+ Access-Control-Allow-Headers:
33
+ - Content-Type
34
+ Access-Control-Allow-Methods:
35
+ - GET, POST, OPTIONS, PUT, DELETE
36
+ Access-Control-Allow-Credentials:
37
+ - 'true'
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ Content-Length:
41
+ - '303'
42
+ Etag:
43
+ - W/"12f-2sL25lSvQFDkfKvetydULJKJPHk"
44
+ Date:
45
+ - Sun, 06 Sep 2020 14:07:54 GMT
46
+ Via:
47
+ - 1.1 vegur
48
+ body:
49
+ encoding: UTF-8
50
+ string: '{"decision":{"decision":"approved","trialPeriodMonths":3,"fundingLimit":495000,"annualRenewalFee":0,"badDebtProtection":0.85,"cashAvailableWithinHours":48,"discountFee":3.35,"facility":"Factoring","prepayment":80,"serviceFee":1.53},"opportunityId":"00Q2600000BCAb6EAH","companyName":"FINPOINT
51
+ (UK) LTD"}'
52
+ http_version:
53
+ recorded_at: Sun, 06 Sep 2020 14:07:54 GMT
54
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/update
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"00Q2600000BC6fGEAT","introducerId":"<TOKEN>"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - ruby-optimum-1.0.0
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - Express
29
+ Access-Control-Allow-Origin:
30
+ - undefined
31
+ Access-Control-Allow-Headers:
32
+ - Content-Type
33
+ Access-Control-Allow-Methods:
34
+ - GET, POST, OPTIONS, PUT, DELETE
35
+ Access-Control-Allow-Credentials:
36
+ - 'true'
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Content-Length:
40
+ - '460'
41
+ Etag:
42
+ - W/"1cc-68dsi2WwGJ291KFJB0VKUbf4h9c"
43
+ Date:
44
+ - Sun, 06 Sep 2020 14:15:06 GMT
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"status":"In Progress","closeChance":0,"closeDate":"","owner":"currently
50
+ assigning","originalDecision":{"decision":"approved","trialPeriodMonths":4,"fundingLimit":495000,"annualRenewalFee":0,"badDebtProtection":0.85,"cashAvailableWithinHours":48,"discountFee":3.35,"facility":"Factoring","prepayment":80,"serviceFee":1.53},"latestOffer":{"trialPeriodMonths":4,"facility":"Factoring","fundingLimit":495000,"serviceFee":1.53,"prepayment":80,"discountFee":3.35}}'
51
+ http_version:
52
+ recorded_at: Sun, 06 Sep 2020 14:15:06 GMT
53
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/update
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"00Q2600000BCAbBEAX","introducerId":"<TOKEN>"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - ruby-optimum-1.0.0
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - Express
29
+ Access-Control-Allow-Origin:
30
+ - undefined
31
+ Access-Control-Allow-Headers:
32
+ - Content-Type
33
+ Access-Control-Allow-Methods:
34
+ - GET, POST, OPTIONS, PUT, DELETE
35
+ Access-Control-Allow-Credentials:
36
+ - 'true'
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Content-Length:
40
+ - '302'
41
+ Etag:
42
+ - W/"12e-lvZ5rjr5q+oXEc5pP/O41DcTc1M"
43
+ Date:
44
+ - Sun, 06 Sep 2020 14:18:44 GMT
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: ASCII-8BIT
49
+ string: !binary |-
50
+ eyJzdGF0dXMiOiJJbiBQcm9ncmVzcyIsImNsb3NlQ2hhbmNlIjowLCJjbG9zZURhdGUiOiIiLCJvd25lciI6ImN1cnJlbnRseSBhc3NpZ25pbmciLCJvcmlnaW5hbERlY2lzaW9uIjp7ImRlY2lzaW9uIjoicmVmZXJyZWQiLCJyZWFzb25zIjpbIlR1cm5vdmVyIGlzIGJlbG93IMKjMjUwLDAwMCJdfSwibGF0ZXN0T2ZmZXIiOnsidHJpYWxQZXJpb2RNb250aHMiOm51bGwsImZhY2lsaXR5IjpudWxsLCJmdW5kaW5nTGltaXQiOm51bGwsInNlcnZpY2VGZWUiOm51bGwsInByZXBheW1lbnQiOm51bGwsImRpc2NvdW50RmVlIjpudWxsfX0=
51
+ http_version:
52
+ recorded_at: Sun, 06 Sep 2020 14:18:45 GMT
53
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/update
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"INVALID","introducerId":"<TOKEN>"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - ruby-optimum-1.0.0
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 500
21
+ message: Internal Server Error
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - Express
29
+ Access-Control-Allow-Origin:
30
+ - undefined
31
+ Access-Control-Allow-Headers:
32
+ - Content-Type
33
+ Access-Control-Allow-Methods:
34
+ - GET, POST, OPTIONS, PUT, DELETE
35
+ Access-Control-Allow-Credentials:
36
+ - 'true'
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Content-Length:
40
+ - '115'
41
+ Etag:
42
+ - W/"73-oUxvvSshdcnD0U8cymjXIUVvqHU"
43
+ Date:
44
+ - Sun, 06 Sep 2020 14:08:27 GMT
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"message":"Server error - the server has encounted and unknown error.
50
+ If the problem persists, please report it."}'
51
+ http_version:
52
+ recorded_at: Sun, 06 Sep 2020 14:08:27 GMT
53
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://optimum-core-staging.herokuapp.com/api/v1/instant-decision/update
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"id":"","introducerId":"NOT VALID"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - ruby-optimum-1.0.0
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 403
21
+ message: Forbidden
22
+ headers:
23
+ Server:
24
+ - Cowboy
25
+ Connection:
26
+ - keep-alive
27
+ X-Powered-By:
28
+ - Express
29
+ Access-Control-Allow-Origin:
30
+ - undefined
31
+ Access-Control-Allow-Headers:
32
+ - Content-Type
33
+ Access-Control-Allow-Methods:
34
+ - GET, POST, OPTIONS, PUT, DELETE
35
+ Access-Control-Allow-Credentials:
36
+ - 'true'
37
+ Content-Type:
38
+ - text/plain; charset=utf-8
39
+ Content-Length:
40
+ - '9'
41
+ Etag:
42
+ - W/"9-PatfYBLj4Um1qTm5zrukoLhNyPU"
43
+ Date:
44
+ - Sun, 06 Sep 2020 14:07:47 GMT
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: UTF-8
49
+ string: Forbidden
50
+ http_version:
51
+ recorded_at: Sun, 06 Sep 2020 14:07:47 GMT
52
+ recorded_with: VCR 5.0.0