wealthforge-ruby 2.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dcd8122910f6620bbbc235b951d7185c3237c9f1
4
+ data.tar.gz: 21112526fe39abcd43a61fe5fa66a0246995cff8
5
+ SHA512:
6
+ metadata.gz: d57a41dd0c40ae3273dd6e215e500b7f128a9bd320bf06e163a6608af7915ec2081621c30e6f3f3d394539e2f92f141c4c553f050e623655a712c2df05180094
7
+ data.tar.gz: e90c12a26e768203a99f46604a05fa498fb029c888aab048af7f334414870058166a0754aae1898976b9246e174c168bf2036e33ae47522faf2b2103ae5cb25e
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Dino Simone
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,82 @@
1
+ # WealthForge API Client for Ruby
2
+
3
+ The WealthForge API acts as a connection between WealthForge's back-end transaction engine, CapitalForge, and your front-end website. This client seamlessly integrates into your Ruby application to provide an interface to the WealthForge API web service.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'wealth_forge'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install wealthforge-ruby
21
+
22
+
23
+ ## Configuration
24
+
25
+ Before you can use this gem, you'll need to configure it with the key and cert, which you'll have after registering with WealthForge. If using with Rails, put this code in the initializer.
26
+
27
+
28
+ WealthForge.configure do |config|
29
+ config.client_secret = ENV['WF_CLIENT_SECRET']
30
+ config.client_id = ENV['WF_CLIENT_ID']
31
+ config.environment = 'development'
32
+ end
33
+
34
+
35
+ ## Usage
36
+
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.
38
+
39
+
40
+ ### Available Calls
41
+
42
+ #### Investment
43
+
44
+ WealthForge::Investment.create params
45
+ WealthForge::Investment.get investment_id
46
+ WealthForge::Investment.file_upload path, mime_type, title, subscription_id
47
+
48
+ #### Issuer
49
+
50
+ WealthForge::Issuer.create params
51
+
52
+ #### Offering
53
+
54
+ WealthForge::Offering.create params
55
+
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dinosimone/wealthforge-ruby.
60
+
61
+
62
+ ## Tests
63
+
64
+ All tests can be run by typing `rspec`. Prior to running tests, you'll need to export your cert and key as such:
65
+
66
+ export WF_CLIENT_SECRET=[secret]
67
+ export WF_CLIENT_ID=[client-id]
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
73
+
74
+
75
+ ## Disclaimer
76
+
77
+ This project and the code therein was not created by and is not supported by WealthForge.
78
+
79
+
80
+ ## Author
81
+
82
+ Dino Simone (dino@simone.is) | dinosimone.com
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wealthforge-ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
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'
7
+
8
+ module WealthForge
9
+
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def self.reset
19
+ @configuration = Configuration.new
20
+ end
21
+
22
+ def self.configure
23
+ yield(configuration)
24
+ configuration.api_url = configuration.environment == 'production' ? configuration.production_url : configuration.sandbox_url
25
+ configuration.token_url = "#{configuration.api_url}/auth/tokens"
26
+ end
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ class WealthForge::ApiException < StandardError
2
+ def initialize(e = nil)
3
+ puts "API error: #{e.inspect}"
4
+ super e
5
+ set_backtrace e.backtrace if e
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ module WealthForge
2
+
3
+ class Configuration
4
+
5
+ attr_accessor :client_id
6
+ attr_accessor :client_secret
7
+ attr_accessor :environment
8
+ attr_accessor :api_url
9
+ attr_accessor :token_url
10
+ attr_accessor :version
11
+ attr_accessor :production_url
12
+ attr_accessor :sandbox_url
13
+
14
+ def initialize
15
+ @client_id = nil
16
+ @client_secret = nil
17
+ @environment = nil
18
+ @api_url = nil
19
+ @token_url = nil
20
+ @production_url = 'https://api.wealthforge.com/v1'
21
+ @sandbox_url = 'https://api.wealthforge.org/v1'
22
+ @version = 'v1'
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,146 @@
1
+ require 'openssl'
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'csv'
5
+ require 'timeout'
6
+ require 'resolv-replace'
7
+ require 'jwt'
8
+
9
+ class WealthForge::Connection
10
+
11
+ def self.post(endpoint, params)
12
+ begin
13
+ response = connection.post do |req|
14
+ req.url endpoint
15
+ req.headers['Content-Type'] = 'application/json'
16
+ req.body = params.to_json
17
+ end
18
+ rescue => e
19
+ raise WealthForge::ApiException.new(e)
20
+ end
21
+ JSON.parse(response.body)
22
+ end
23
+
24
+
25
+ def self.get(endpoint, params)
26
+ begin
27
+ response = connection.get do |req|
28
+ req.url endpoint
29
+ req.headers['Content-Type'] = 'application/json'
30
+ req.body = params.to_json
31
+ end
32
+ rescue => e
33
+ raise WealthForge::ApiException.new(e)
34
+ end
35
+ JSON.parse(response.body)
36
+ end
37
+
38
+
39
+ def self.patch(endpoint, params)
40
+ begin
41
+ response = connection.patch do |req|
42
+ req.url endpoint
43
+ req.headers['Content-Type'] = 'application/json'
44
+ req.body = params.to_json
45
+ end
46
+ rescue => e
47
+ raise WealthForge::ApiException.new(e)
48
+ end
49
+ response.body
50
+ end
51
+
52
+
53
+ def self.file_upload (endpoint, file, filename, mime_type)
54
+ payload = {:file => Faraday::UploadIO.new(file, mime_type, filename)}
55
+ begin
56
+ response = connection_multipart.post do |req|
57
+ req.url endpoint
58
+ req.body = payload
59
+ end
60
+ rescue => e
61
+ raise WealthForge::ApiException.new(e)
62
+ end
63
+ JSON.parse(response.body)
64
+ end
65
+
66
+
67
+ def self.connection
68
+ set_token
69
+ return Faraday.new(:url => @api_url) do |faraday|
70
+ faraday.request :url_encoded
71
+ faraday.options.timeout = 5
72
+ faraday.options.open_timeout = 5
73
+ faraday.headers['Authorization'] = @wf_token
74
+ faraday.adapter Faraday.default_adapter
75
+ faraday.use CustomErrors
76
+ end
77
+ end
78
+
79
+
80
+ def self.connection_multipart
81
+ set_token
82
+ return Faraday.new(:url => @api_url) do |faraday|
83
+ faraday.request :multipart
84
+ faraday.headers['Authorization'] = @wf_token
85
+ faraday.adapter Faraday.default_adapter
86
+ faraday.use CustomErrors
87
+ end
88
+ end
89
+
90
+
91
+ def self.set_token
92
+ if @wf_token == nil
93
+ @wf_client_id = WealthForge.configuration.client_id
94
+ @wf_client_secret = WealthForge.configuration.client_secret
95
+ @api_url = WealthForge.configuration.api_url
96
+ @token_url = WealthForge.configuration.token_url
97
+ @wf_token = retrieve_token
98
+ end
99
+
100
+ # test to see if token has expired
101
+ t = @wf_token.reverse.chomp("Bearer ".reverse).reverse
102
+ decoded_token = JWT.decode t, nil, false
103
+ token_exp = decoded_token[0]['exp']
104
+ leeway = 60
105
+ now = Time.now.to_i
106
+ token_window = token_exp - leeway
107
+ refresh_token = !(token_window > now)
108
+
109
+ if refresh_token == true
110
+ # makes a call to get a new token
111
+ @wf_token = retrieve_token
112
+ end
113
+ end
114
+
115
+
116
+ def self.retrieve_token
117
+ auth = Faraday.new.post(@token_url) do |faraday|
118
+ faraday.body = {
119
+ data: {
120
+ attributes: {
121
+ clientId: @wf_client_id,
122
+ clientSecret: @wf_client_secret
123
+ },
124
+ type: 'token'
125
+ }
126
+ }.to_json
127
+ end.body
128
+ @wf_token = 'Bearer ' + JSON.parse(auth)['data']['attributes']['accessToken']
129
+ end
130
+ end
131
+
132
+
133
+ class CustomErrors < Faraday::Response::RaiseError
134
+
135
+ def on_complete(env)
136
+ case env[:status]
137
+ when 400...600
138
+ json_body = JSON.parse(env[:body])
139
+ return json_body
140
+ else
141
+ super
142
+ end
143
+ end
144
+
145
+ end
146
+
@@ -0,0 +1,19 @@
1
+ class WealthForge::Investment
2
+
3
+ def self.create(params = {})
4
+ WealthForge::Connection.post 'subscriptions', params
5
+ end
6
+
7
+ def self.get(subscription_id)
8
+ WealthForge::Connection.get "subscriptions/#{subscription_id}", nil
9
+ end
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
14
+
15
+ def self.cancel_subscription(subscription_id)
16
+ WealthForge::Connection.patch "subscriptions/#{subscription_id}/status/SPONSOR_CANCELLED", nil
17
+ end
18
+
19
+ end
@@ -0,0 +1,7 @@
1
+ class WealthForge::Issuer
2
+
3
+ def self.create(params)
4
+ WealthForge::Connection.post 'issuers', params
5
+ end
6
+
7
+ end
@@ -0,0 +1,11 @@
1
+ class WealthForge::Offering
2
+
3
+ def self.create(params)
4
+ WealthForge::Connection.post 'offerings', params
5
+ end
6
+
7
+ def self.get(offering_id)
8
+ WealthForge::Connection.get "offerings/#{offering_id}", nil
9
+ end
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ module WealthForge
2
+ VERSION = '2.2.8'
3
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wealthforge-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.2.8
5
+ platform: ruby
6
+ authors:
7
+ - Dino Simone | dinosimone.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: mime-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jwt
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: factory_girl
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.0'
139
+ description: The WealthForge API acts as a connection between WealthForge's back-end
140
+ transaction engine, CapitalForge, and your front-end website.
141
+ email:
142
+ - dino@simone.is
143
+ executables:
144
+ - console
145
+ - setup
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - LICENSE
150
+ - README.md
151
+ - bin/console
152
+ - bin/setup
153
+ - lib/wealthforge-ruby.rb
154
+ - lib/wealthforge/api_exception.rb
155
+ - lib/wealthforge/configuration.rb
156
+ - lib/wealthforge/connection.rb
157
+ - lib/wealthforge/investment.rb
158
+ - lib/wealthforge/issuer.rb
159
+ - lib/wealthforge/offering.rb
160
+ - lib/wealthforge/version.rb
161
+ homepage: https://github.com/dinosimone/wealthforge-ruby
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.6.13
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: WealthForge API Client
185
+ test_files: []