wealthforge-ruby 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -37
  3. data/lib/wealthforge-ruby.rb +6 -8
  4. data/lib/wealthforge/configuration.rb +13 -11
  5. data/lib/wealthforge/connection.rb +76 -39
  6. data/lib/wealthforge/investment.rb +9 -84
  7. data/lib/wealthforge/issuer.rb +3 -31
  8. data/lib/wealthforge/offering.rb +1 -12
  9. data/lib/wealthforge/version.rb +1 -1
  10. metadata +24 -44
  11. data/.gitignore +0 -10
  12. data/.rspec +0 -2
  13. data/.travis.yml +0 -5
  14. data/Gemfile +0 -4
  15. data/Rakefile +0 -6
  16. data/fixtures/vcr_cassettes/all_investors.yml +0 -14242
  17. data/fixtures/vcr_cassettes/create_investor.yml +0 -42
  18. data/fixtures/vcr_cassettes/create_issuer.yml +0 -42
  19. data/fixtures/vcr_cassettes/create_offering.yml +0 -42
  20. data/fixtures/vcr_cassettes/create_subscription_agreement.yml +0 -42
  21. data/fixtures/vcr_cassettes/due_dilegence.yml +0 -42
  22. data/fixtures/vcr_cassettes/due_dilegence_file.yml +0 -275
  23. data/fixtures/vcr_cassettes/get_investment_by_id.yml +0 -127
  24. data/fixtures/vcr_cassettes/get_investments.yml +0 -9137
  25. data/fixtures/vcr_cassettes/get_investor.yml +0 -45
  26. data/fixtures/vcr_cassettes/get_issuer.yml +0 -46
  27. data/fixtures/vcr_cassettes/get_issuers.yml +0 -238
  28. data/fixtures/vcr_cassettes/get_offering_by_id.yml +0 -94
  29. data/fixtures/vcr_cassettes/get_subscription_agreement.yml +0 -40
  30. data/fixtures/vcr_cassettes/investment_account.yml +0 -44
  31. data/fixtures/vcr_cassettes/investment_certificate.yml +0 -77
  32. data/fixtures/vcr_cassettes/investment_status.yml +0 -81
  33. data/fixtures/vcr_cassettes/list_offerings.yml +0 -375
  34. data/fixtures/vcr_cassettes/redirect_url.yml +0 -42
  35. data/fixtures/vcr_cassettes/request_investment_approval.yml +0 -48
  36. data/fixtures/vcr_cassettes/request_subscription_approval.yml +0 -48
  37. data/fixtures/vcr_cassettes/subscription_agreement.yml +0 -153
  38. data/fixtures/vcr_cassettes/term_sheets.yml +0 -183
  39. data/fixtures/vcr_cassettes/update_investment.yml +0 -87
  40. data/fixtures/vcr_cassettes/update_investment_account.yml +0 -44
  41. data/fixtures/vcr_cassettes/update_investor.yml +0 -80
  42. data/fixtures/vcr_cassettes/upload_accreditation_files.yml +0 -78
  43. data/lib/wealthforge/investor.rb +0 -37
  44. data/wealthforge-ruby.gemspec +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2452b6b4e56ac9d499e475bd59da219bda1facd
4
- data.tar.gz: e31f990a5358a09b6e272ad17a1f21ba04092437
3
+ metadata.gz: 2309bce743622e8eb49912b27e80e7ae7026fc02
4
+ data.tar.gz: b0ffddeac60fa25703bd98072ac82e2360005e52
5
5
  SHA512:
6
- metadata.gz: 8a81f4b7d3620bcd391995241565b52c1840dbc3abce0be353e78087d0eb632c9809d0700a179f91af2a6fb6b18972937b8b3a6aa0687e024fd1cac82ad10e2d
7
- data.tar.gz: cbfad38a5a97bf3fb1b4a8e77da92df2192e30a03fd79ede344c247aaae0e28c593620ea2c591f2ce555a88c187e7f75d924217355ec2166b6a9ce71ac07644d
6
+ metadata.gz: ad5a449f13e7e79063c5df328518050872b1846b1c2c7b08acf34783b0b73dec70f9574f3a92d1e3777a4afc2d9067154b3ba0cb2b51452cbdf9fb9db90e59fb
7
+ data.tar.gz: 7f2ac8c50468da962e6b47037ea08d7b286e9529cd5f558633108ca1b4ada6e9debe0377cd7cfb42dab2d419bce40a0cd1c48fdc2b8d52b594a0aca59c75afb5
data/README.md CHANGED
@@ -26,62 +26,32 @@ Before you can use this gem, you'll need to configure it with the key and cert,
26
26
 
27
27
 
28
28
  WealthForge.configure do |config|
29
- config.wf_crt_file = ENV['WF_CRT_FILE']
30
- config.wf_key_file = ENV['WF_KEY_FILE']
29
+ config.client_secret = ENV['WF_CLIENT_SECRET']
30
+ config.client_id = ENV['WF_CLIENT_ID']
31
31
  config.environment = 'development'
32
32
  end
33
33
 
34
- or
35
-
36
- WealthForge.configure do |config|
37
- config.wf_crt = ENV['WF_CRT']
38
- config.wf_key = ENV['WF_KEY']
39
- config.environment = 'development'
40
- end
41
-
42
-
43
34
 
44
35
  ## Usage
45
36
 
46
- Please refer to the official WealthForge API [documentation](https://api.wealthforge.com/) for a full list of API calls. Note that this is currently a partial implementation of the most commonly used functionality.
37
+ Please refer to the official WealthForge API [documentation](https://wealthforge.api-docs.io/) for a full list of API calls. Note that this is currently a partial implementation of the most commonly used functionality.
47
38
 
48
39
 
49
40
  ### Available Calls
50
41
 
51
- #### Investor
52
-
53
- WealthForge::Investor.all
54
- WealthForge::Investor.create params
55
- WealthForge::Investor.get investor_id
56
- WealthForge::Investor.update investor_id, params
57
- WealthForge::Investor.accreditation_evidence investor_id, params
58
-
59
42
  #### Investment
60
43
 
61
- WealthForge::Investment.all
62
44
  WealthForge::Investment.create params
63
45
  WealthForge::Investment.get investment_id
64
- WealthForge::Investment.update investment_id, params
65
- WealthForge::Investment.redirect_url investment_id
66
- WealthForge::Investment.status investment_id
67
- WealthForge::Investment.account investment_id
68
- WealthForge::Investment.update_account investment_id, account
69
- WealthForge::Investment.approve investment_id
70
- WealthForge::Investment.approve_subscription investment_id
71
- WealthForge::Investment.due_diligence investment_id
72
- WealthForge::Investment.create_subscription_agreement investment_id, params
46
+ WealthForge::Investment.file_upload path, mime_type, title, subscription_id
73
47
 
74
48
  #### Issuer
75
49
 
76
- WealthForge::Issuer.all
77
50
  WealthForge::Issuer.create params
78
- WealthForge::Issuer.get id
79
51
 
80
52
  #### Offering
81
53
 
82
54
  WealthForge::Offering.create params
83
- WealthForge::Offering.all
84
- WealthForge::Offering.get id
85
55
 
86
56
 
87
57
  ## Contributing
@@ -93,8 +63,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/dinosi
93
63
 
94
64
  All tests can be run by typing `rspec`. Prior to running tests, you'll need to export your cert and key as such:
95
65
 
96
- export WF_CRT_FILE=/home/you/wealthforge/certs/development.crt
97
- export WF_KEY_FILE=/home/you/wealthforge/certs/development.key
66
+ export WF_CLIENT_SECRET=[secret]
67
+ export WF_CLIENT_ID=[client-id]
98
68
 
99
69
 
100
70
  ## License
@@ -109,4 +79,4 @@ This project and the code therein was not created by and is not supported by Wea
109
79
 
110
80
  ## Author
111
81
 
112
- Dino Simone (dino@simone.is)
82
+ Dino Simone (dino@simone.is) | dinosimone.com
@@ -1,11 +1,9 @@
1
- require "wealthforge/configuration"
2
- require "wealthforge/version"
3
- require "wealthforge/api_exception"
4
- require "wealthforge/connection"
5
- require "wealthforge/investment"
6
- require "wealthforge/investor"
7
- require "wealthforge/issuer"
8
- require "wealthforge/offering"
1
+ require 'wealthforge/configuration'
2
+ require 'wealthforge/api_exception'
3
+ require 'wealthforge/connection'
4
+ require 'wealthforge/investment'
5
+ require 'wealthforge/issuer'
6
+ require 'wealthforge/offering'
9
7
 
10
8
  module WealthForge
11
9
 
@@ -1,21 +1,23 @@
1
-
2
1
  module WealthForge
2
+
3
3
  class Configuration
4
4
 
5
- attr_accessor :wf_crt
6
- attr_accessor :wf_key
7
- attr_accessor :wf_crt_file
8
- attr_accessor :wf_key_file
5
+ attr_accessor :client_id
6
+ attr_accessor :client_secret
9
7
  attr_accessor :environment
10
-
8
+ attr_accessor :api_url
9
+ attr_accessor :token_url
10
+ attr_accessor :version
11
11
 
12
12
  def initialize
13
- @wf_crt = nil
14
- @wf_key = nil
15
- @wf_crt_file = nil
16
- @wf_crt_key = nil
17
- @environment = "production"
13
+ @client_id = nil
14
+ @client_secret = nil
15
+ @api_url = 'https://api.wealthforge.org/v1/'
16
+ @token_url = 'https://api.wealthforge.org/v1/auth/tokens'
17
+ @environment = 'development'
18
+ @version = 'v2'
18
19
  end
19
20
 
20
21
  end
22
+
21
23
  end
@@ -4,7 +4,7 @@ require 'json'
4
4
  require 'csv'
5
5
  require 'timeout'
6
6
  require 'resolv-replace'
7
-
7
+ require 'jwt'
8
8
 
9
9
  class WealthForge::Connection
10
10
 
@@ -13,81 +13,118 @@ class WealthForge::Connection
13
13
  response = connection.post do |req|
14
14
  req.url endpoint
15
15
  req.headers['Content-Type'] = 'application/json'
16
- req.body = prep_params(params)
17
- end
18
- JSON.parse(response.body, symbolize_names: true)
16
+ req.body = params.to_json
17
+ end
19
18
  rescue => e
20
19
  raise WealthForge::ApiException.new(e)
21
20
  end
21
+ JSON.parse(response.body)
22
22
  end
23
23
 
24
24
 
25
- def self.put(endpoint, params)
25
+ def self.get(endpoint, params)
26
26
  begin
27
- response = connection.put do |req|
27
+ response = connection.get do |req|
28
28
  req.url endpoint
29
29
  req.headers['Content-Type'] = 'application/json'
30
- req.body = prep_params(params)
30
+ req.body = params.to_json
31
31
  end
32
- JSON.parse(response.body, symbolize_names: true)
33
32
  rescue => e
34
33
  raise WealthForge::ApiException.new(e)
35
34
  end
35
+ JSON.parse(response.body)
36
36
  end
37
37
 
38
38
 
39
- def self.get(endpoint, params, raw=false)
39
+ def self.file_upload (endpoint, file, filename, mime_type)
40
+ payload = {:file => Faraday::UploadIO.new(file, mime_type, filename)}
40
41
  begin
41
- response = connection.get do |req|
42
+ response = connection_multipart.post do |req|
42
43
  req.url endpoint
43
- req.headers['Content-Type'] = 'application/json'
44
- req.body = prep_params(params)
44
+ req.body = payload
45
45
  end
46
- raw == false ? JSON.parse(response.body, symbolize_names: true) : response.body
47
46
  rescue => e
48
47
  raise WealthForge::ApiException.new(e)
49
48
  end
49
+ JSON.parse(response.body)
50
50
  end
51
51
 
52
52
 
53
- private
53
+ def self.connection
54
+ set_token
55
+ return Faraday.new(:url => @api_url) do |faraday|
56
+ faraday.request :url_encoded
57
+ faraday.headers['Authorization'] = @wf_token
58
+ faraday.adapter Faraday.default_adapter
59
+ faraday.use CustomErrors
60
+ end
61
+ end
54
62
 
55
63
 
56
- def self.prep_params(params)
57
- return if params.nil?
58
- wf_params = {}
59
- params.each do |key, value|
60
- wf_params[key.to_s.camelize(:lower)] = value
64
+ def self.connection_multipart
65
+ set_token
66
+ return Faraday.new(:url => @api_url) do |faraday|
67
+ faraday.request :multipart
68
+ faraday.headers['Authorization'] = @wf_token
69
+ faraday.adapter Faraday.default_adapter
70
+ faraday.use CustomErrors
61
71
  end
62
- wf_params.to_json
63
72
  end
64
73
 
65
74
 
66
- def self.connection
67
- api_endpoint = (!WealthForge.configuration.environment.nil? and WealthForge.configuration.environment.eql? 'production') ?
68
- 'https://www.capitalforge.com/capitalforge-transaction/api/' :
69
- 'https://sandbox.capitalforge.com/capitalforge-transaction/api/'
70
- return Faraday.new(:url => api_endpoint, :ssl => ssl_options) do |faraday|
71
- faraday.request :url_encoded
72
- faraday.adapter Faraday.default_adapter
75
+ def self.set_token
76
+ if @wf_token == nil
77
+ @wf_client_id = WealthForge.configuration.client_id
78
+ @wf_client_secret = WealthForge.configuration.client_secret
79
+ @api_url = WealthForge.configuration.api_url
80
+ @token_url = WealthForge.configuration.token_url
81
+ @wf_token = retrieve_token
73
82
  end
83
+
84
+ # test to see if token has expired
85
+ t = @wf_token.reverse.chomp("Bearer ".reverse).reverse
86
+ decoded_token = JWT.decode t, nil, false
87
+ token_exp = decoded_token[0]['exp']
88
+ leeway = 60
89
+ now = Time.now.to_i
90
+ token_window = token_exp - leeway
91
+ refresh_token = !(token_window > now)
92
+
93
+ if refresh_token == true
94
+ # makes a call to get a new token
95
+ @wf_token = retrieve_token
96
+ end
97
+ end
98
+
99
+
100
+ def self.retrieve_token
101
+ auth = Faraday.new.post(@token_url) do |faraday|
102
+ faraday.body = {
103
+ data: {
104
+ attributes: {
105
+ clientId: @wf_client_id,
106
+ clientSecret: @wf_client_secret
107
+ },
108
+ type: 'token'
109
+ }
110
+ }.to_json
111
+ end.body
112
+ @wf_token = 'Bearer ' + JSON.parse(auth)['data']['attributes']['accessToken']
74
113
  end
114
+ end
75
115
 
76
116
 
77
- def self.ssl_options
78
- wf_cert = !WealthForge.configuration.wf_crt.nil? ? WealthForge.configuration.wf_crt : File.read(WealthForge.configuration.wf_crt_file)
79
- wf_key = !WealthForge.configuration.wf_key.nil? ? WealthForge.configuration.wf_key : File.read(WealthForge.configuration.wf_key_file)
80
- ssl_options = {
81
- :version => :TLSv1,
82
- :client_cert => OpenSSL::X509::Certificate.new(wf_cert),
83
- :client_key => OpenSSL::PKey::RSA.new(wf_key)
84
- }
85
- if WealthForge.configuration.environment.eql? 'production'
86
- ssl_options[:ca_file] = ENV['CA_FILE']
117
+ class CustomErrors < Faraday::Response::RaiseError
118
+
119
+ def on_complete(env)
120
+ case env[:status]
121
+ when 400...600
122
+ json_body = JSON.parse(env[:body])
123
+ return json_body
87
124
  else
88
- ssl_options[:ca_path] = '/usr/lib/ssl/certs'
125
+ super
89
126
  end
90
- ssl_options
91
127
  end
92
128
 
93
129
  end
130
+
@@ -1,90 +1,15 @@
1
- require 'base64'
2
- require 'mime/types'
3
-
4
1
  class WealthForge::Investment
5
2
 
6
- def self.all
7
- WealthForge::Connection.get "investment", nil
8
- end
9
-
10
-
11
- def self.create(params)
12
- WealthForge::Connection.post "investment", params
13
- end
14
-
15
-
16
- def self.get(investment_id)
17
- WealthForge::Connection.get "investment/#{investment_id}", nil
18
- end
19
-
20
-
21
- def self.update(investment_id, params)
22
- WealthForge::Connection.put "investment/#{investment_id}", params
23
- end
24
-
25
-
26
- def self.redirect_url(investment_id)
27
- WealthForge::Connection.get "investment/#{investment_id}/start", nil
28
- end
29
-
30
-
31
- def self.status(investment_id)
32
- WealthForge::Connection.get "investment/#{investment_id}/status", nil
33
- end
34
-
35
-
36
- def self.account(investment_id)
37
- WealthForge::Connection.get "investment/#{investment_id}/account", nil
38
- end
39
-
40
-
41
- def self.update_account(investment_id, params)
42
- WealthForge::Connection.put "investment/#{investment_id}/account", params
43
- end
44
-
45
-
46
- def self.approve(investment_id)
47
- WealthForge::Connection.put "investment/#{investment_id}/approve", nil
48
- end
49
-
50
-
51
- def self.approve_subscription(investment_id)
52
- WealthForge::Connection.put "investment/#{investment_id}/approveSubscriptionAgreement", nil
53
- end
54
-
55
-
56
- def self.certificate(investment_id)
57
- WealthForge::Connection.get "investment/#{investment_id}/certificate", nil, true
58
- end
59
-
60
-
61
- def self.due_diligence(investment_id)
62
- WealthForge::Connection.get "investment/#{investment_id}/duediligence", nil
63
- end
64
-
65
-
66
- def self.subscription_agreement(investment_id)
67
- WealthForge::Connection.get "investment/#{investment_id}/subscriptionAgreement", nil
68
- end
69
-
70
-
71
- def self.create_subscription_agreement(investment_id, params)
72
- mapped_params = {
73
- status: {code: 'FILE_INPROGRESS', active: true},
74
- mimeType: MIME::Types.type_for(params[:filename]).first.to_s,
75
- folder: {parentFolder: {code: 'DUE_DILIGENCE'}},
76
- fileName: params[:filename],
77
- displayTitle: params[:filename],
78
- content: Base64.strict_encode64(params[:file]),
79
- parent: params[:parent]
80
- }
81
- WealthForge::Connection.put "investment/#{investment_id}/subscriptionAgreement", mapped_params
82
- end
83
-
3
+ def self.create(params = {})
4
+ WealthForge::Connection.post 'subscriptions', params
5
+ end
84
6
 
85
- def self.term_sheets(investment_id)
86
- WealthForge::Connection.get "investment/#{investment_id}/offerDetail", nil, false
87
- end
7
+ def self.get(subscription_id)
8
+ WealthForge::Connection.get "subscriptions/#{subscription_id}", nil
9
+ end
88
10
 
11
+ def self.file_upload(file_path, mime_type, filename, subscription_id)
12
+ WealthForge::Connection.file_upload "files/#{subscription_id}", file_path, filename, mime_type
13
+ end
89
14
 
90
15
  end
@@ -1,35 +1,7 @@
1
-
2
1
  class WealthForge::Issuer
3
2
 
4
- def self.all
5
- WealthForge::Connection.get "issuer", nil
6
- end
7
-
8
- def self.create(params = {})
9
- params[:country] = {code: params[:country]}
10
- params[:state_of_formation] = {code: params[:state_of_formation]}
11
- params[:entity_type] = {code: params[:entity_type]}
12
- WealthForge::Connection.post "issuer", params
13
- end
14
-
15
- def self.get(issuer_id)
16
- WealthForge::Connection.get "issuer/#{issuer_id}", nil
17
- end
18
-
19
- def self.update(params = {}, issuer_id)
20
- WealthForge::Connection.post "issuer/#{issuer_id}", params
21
- end
22
-
23
- def self.accounts(issuer_id)
24
- WealthForge::Connection.get "issuer/#{issuer_id}/accounts", nil
25
- end
26
-
27
- def self.create_account(params = {}, issuer_id)
28
- WealthForge::Connection.post "issuer/#{issuer_id}/accounts", params
29
- end
30
-
31
- def self.update_account(params, issuer_id, account_id)
32
- WealthForge::Connection.put "issuer/#{issuer_id}/accounts/#{account_id}", params
3
+ def self.create(params)
4
+ WealthForge::Connection.post 'issuers', params
33
5
  end
34
6
 
35
- end
7
+ end