transferwise 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 48da3462cb2196089353e83e8bbbd968eaac85f1
4
+ data.tar.gz: 4857e5d0da3a5c3ce61d001d9e64a79899f2d9e1
5
+ SHA512:
6
+ metadata.gz: a6ccaef13c20aee10f5453f2d74707718ae85dc5165181f38e9bda99d4bd8d67f4637efe0a8021e126f99cac6f92011321b2554485921772fd2f23f8ede8fc24
7
+ data.tar.gz: 88e5a125574d11978a036566c3d1325b5780c1cc15dfb1add368f9a52f9d6900b8a983353002faf1b0a28a52100e02a653402a247b01eae9a9c3eca67f97a043
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /transferwise-*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at harsh@milaap.org. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transferwise.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Harshvardhan Parihar
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # Transferwise
2
+
3
+ Welcome to transferwise ruby gem! The transferwise Ruby gem provide a small SDK for convenient access to the Transferwise API from applications written in the Ruby language. It provides a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which allows the bindings to tolerate a number of different versions of the API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'transferwise'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install transferwise
20
+
21
+ ## Usage
22
+
23
+ The library needs to be configured with environment mode "test" or "live"
24
+ ```ruby
25
+ For live mode
26
+ Transferwise.mode = "live"
27
+
28
+ For test mode
29
+ Transferwise.mode = "test"
30
+ ```
31
+ # Development
32
+ ## Authentication
33
+
34
+ Transferwise uses OAuth 2 for API authentication and authorization. Calls done in behalf of the user require the access token, other calls require Basic Auth. Please keep in mind that tokens are unique to user and should be stored securely.
35
+
36
+ ```ruby
37
+ tw = Transferwise::OAuth.new(client_id, client_secret)
38
+ ```
39
+
40
+ ```ruby
41
+ redirect_url = "www.example.com/callback" # Url where you want user to redirect back after authentication from transferwise
42
+ url = tw.authorize_url(redirect_url)
43
+ ```
44
+
45
+ This will give you the url where you have to redirect the user to authorize and after authorization you will get redirected to redirect_url with authentication_code.
46
+
47
+ ```ruby
48
+ code = "aqw12q" # some authentication_code from response of authentication
49
+ tw.get_access_token(code, redirect_url)
50
+ =begin
51
+ Response:
52
+ {
53
+ "token_type" => "bearer",
54
+ "scope" => "transfers",
55
+ :access_token => "1bceb8d8-4115-4daa-8370-d9bc8de0c732",
56
+ :refresh_token => "6ff3451a-e713-416a-b735-20d8020f6ce2",
57
+ :expires_at => 1487908739
58
+ }
59
+ =end
60
+ ```
61
+
62
+ Store this access token and periodically refresh it before it expires
63
+
64
+ ```ruby
65
+ tw.refresh_token(access_token, opts = {refresh_token: refresh_token, expires_at: expires_at})
66
+ =begin
67
+ Response:
68
+ {
69
+ "token_type" => "bearer",
70
+ "scope" => "transfers",
71
+ :access_token => "59e18a25-c84e-4f06-aee4-416c9211a8c8",
72
+ :refresh_token => "6ff3451a-e713-416a-b735-20d8020f6ce2",
73
+ :expires_at => 1487873072
74
+ }
75
+ =end
76
+ ```
77
+
78
+ # Anatomy of a Transferwise Transfer
79
+ To create the transfers, we need to get profile, quote and target account first.
80
+
81
+ ## Profile
82
+ Create a profile as individual or business.
83
+ ```ruby
84
+ profile_request = {
85
+ type: "personal", # or business
86
+ details: {
87
+ firstName: "First name", # Sender FirstName
88
+ lastName: "Last Name", # Sender LastName
89
+ dateOfBirth: "1980-07-20", # sender DOB
90
+ phoneNumber: "+918147001602" # Sender number in international format
91
+ }
92
+ }
93
+ profile = Transferwise::Profile.create(profile_request, {access_token: access_token})
94
+ ```
95
+ ## Quote
96
+ Create a quote
97
+ ```ruby
98
+ quote_request = {
99
+ profile: profile.id, # got from previous profile response
100
+ source: "USD", # source currency
101
+ target: "INR", # target currency
102
+ sourceAmount: "100", # source amount is amount which sender is going to send. Transferwise will deduct their fees and receipient will receive less money.
103
+ rateType: "FIXED",
104
+ type: 'BALANCE_PAYOUT' # or 'BALANCE_CONVERSION' if using for conversion
105
+ }
106
+ quote = Transferwise::Quote.create(quote_request, {access_token: access_token})
107
+ ```
108
+ ## Account
109
+
110
+ Next step is to create the account where you want to transfer the money.
111
+ If you already have the account you can use that account id and skip this account creation part.
112
+
113
+ ```ruby
114
+ account_request = {
115
+ "profile" => profile.id,
116
+ "accountHolderName" => "Account Holder Name",
117
+ "currency" => "INR", # target currency name
118
+ "country" => "IN", # target country code
119
+ "type" => "", # get from account requirements
120
+ "details" => {
121
+ "legalType" => "PRIVATE",
122
+ "accountNumber" => "", # target account number
123
+ "ifscCode" => "", # ifsc code or any other field. Get field name finformation from account requirements api. This could be different for other country except india.
124
+ "address" => { # get address details also from account requirement based on country.
125
+ "city" => "City name", # city name
126
+ "country" => "IN", # country code
127
+ "firstLine" => "", # address first line
128
+ "postCode" => "" # post code
129
+ }
130
+ }
131
+ }
132
+ account = Transferwise::Account.create(account_request, {access_token: access_token})
133
+ ```
134
+
135
+ ## Transfer
136
+
137
+ Create a transfer
138
+ ```ruby
139
+ transfer_request = {
140
+ "customerTransactionId" => "d57db29d-1060-4ce8-bd5e-800edaf982a9", # some unique uuid format number to identify the transfer.
141
+ "targetAccount" => account.id,
142
+ "quote" => quote.id,
143
+ "details" => {
144
+ "reference" => "Any Comment" # get the field detail, from transfer requirements api before creating the transfer object.
145
+ }
146
+ }
147
+ transfer = Transferwise::Transfer.create(transfer_request, {access_token: access_token})
148
+
149
+ ```
150
+
151
+ The Transfer object is created via the Transferwise website. You can go there and make payments to complete the transfer.
152
+
153
+ Fund a transfer
154
+ ```ruby
155
+ Transferwise::Transfer.fund(transfer_id, { access_token: access_token })
156
+ ```
157
+
158
+ Cancel a transfer
159
+ ```ruby
160
+ Transferwise::Transfer.cancel(transfer_id, { access_token: access_token })
161
+ ```
162
+
163
+ # Transferwise Borderless Account
164
+ A Borderless Account is a "virtual" bank account that you can control via the Transferwise API, to send funds to external bank accounts (across borders), as well as download statements and view the current balance.
165
+
166
+ ## Borderless Accounts
167
+ https://api-docs.transferwise.com/v1/borderless-account/search-account-by-user-profile
168
+
169
+ Get all the borderless accounts given a `profileId`
170
+
171
+ ```ruby
172
+ account_request = { profileId: 1234567 }
173
+ account = Transferwise::BorderlessAccount.list(nil, { 'params' => account_request, access_token: access_token })
174
+ ```
175
+
176
+ ## Borderless Account
177
+ https://api-docs.transferwise.com/v1/borderless-account/get-available-balances
178
+
179
+ Get a borderless account given a `borderless_account_id`
180
+
181
+ ```ruby
182
+ borderless_account_id = 123
183
+ account = Transferwise::BorderlessAccount.get(borderless_account_id, {access_token: access_token})
184
+ ```
185
+
186
+ ## Transactions
187
+ https://api-docs.transferwise.com/v1/borderless-account/get-account-statement
188
+
189
+ Get all the transactions for an account given a `borderless_account_id`
190
+
191
+ ```ruby
192
+ borderless_account_id = 123
193
+ transactions = Transferwise::BorderlessAccount::Transaction.list(nil, { 'params' => { page: '5' }, access_token: access_token }, borderless_account_id)
194
+ ```
195
+
196
+ ## Conversions
197
+ https://api-docs.transferwise.com/v1/borderless-account/convert-between-currencies
198
+
199
+ Move funds between your borderless account currencies.
200
+
201
+ ```ruby
202
+ borderless_account_id = 123
203
+ access_header = { access_token: access_token }
204
+ transactions = Transferwise::BorderlessAccount.convert(borderless_account_id, conversion_quote_id, access_header)
205
+ ```
206
+
207
+ ## Statement
208
+ https://api-docs.transferwise.com/v1/borderless-account/get-statement
209
+
210
+ Get a borderless account statement for a given currency
211
+
212
+ ```ruby
213
+ query_string = {
214
+ profileId: 1234567,
215
+ currency: 'GBP',
216
+ startDate: '2017-12-01',
217
+ endDate: '2017-12-07'
218
+ }
219
+ statement = Transferwise::BorderlessAccount::Statement.list(nil, { 'params' => query_string })
220
+ ```
221
+
222
+ ## Currencies
223
+ https://api-docs.transferwise.com/v1/borderless-account/available-currencies
224
+
225
+ Get a list of available currencies for your balances
226
+
227
+ ```ruby
228
+ Transferwise::BorderlessAccount::BalanceCurrency.list
229
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "transferwise"
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
data/bin/setup ADDED
@@ -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,40 @@
1
+ # Transferwise Ruby bindings
2
+ require 'open-uri'
3
+ require 'oauth2'
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ # Version
8
+ require "transferwise/version"
9
+
10
+ # Oauth2 Authentication
11
+ require "transferwise/oauth"
12
+
13
+ # Resources
14
+ require 'transferwise/transferwise_object'
15
+ require 'transferwise/api_resource'
16
+ require 'transferwise/profile'
17
+ require 'transferwise/quote'
18
+ require 'transferwise/account'
19
+ require 'transferwise/transfer'
20
+ require 'transferwise/util'
21
+ require 'transferwise/request'
22
+ require 'transferwise/borderless_account'
23
+ require 'transferwise/borderless_account/balance_currency'
24
+ require 'transferwise/borderless_account/statement'
25
+ require 'transferwise/borderless_account/transaction'
26
+
27
+ # Errors
28
+ require 'transferwise/transferwise_error'
29
+
30
+ module Transferwise
31
+
32
+ class << self
33
+ attr_accessor :mode
34
+ attr_accessor :access_token
35
+
36
+ def api_base
37
+ @api_base ||= "https://#{mode == 'live' ? 'api' : 'test-api'}.transferwise.com"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module Transferwise
2
+ class Account < APIResource
3
+ end
4
+ end
@@ -0,0 +1,37 @@
1
+ module Transferwise
2
+ class APIResource
3
+ include Transferwise::TransferwiseObject
4
+
5
+ API_VERSION = 'v1'.freeze
6
+
7
+ def self.class_name
8
+ self.name.split('::')[-1]
9
+ end
10
+
11
+ def self.resource_url(resource_id)
12
+ "#{collection_url}/#{resource_id}"
13
+ end
14
+
15
+ def self.collection_url(resource_id = nil)
16
+ if self == APIResource
17
+ raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Account, Transfer, etc.)')
18
+ end
19
+ "/#{API_VERSION}/#{CGI.escape(class_name.downcase)}s"
20
+ end
21
+
22
+ def self.create(params = {}, opts = {})
23
+ response = Transferwise::Request.request(:post, collection_url, params, opts)
24
+ convert_to_transferwise_object(response)
25
+ end
26
+
27
+ def self.list(filters = {}, headers = {}, resource_id = nil)
28
+ response = Transferwise::Request.request(:get, collection_url(resource_id), filters, headers)
29
+ convert_to_transferwise_object(response)
30
+ end
31
+
32
+ def self.get(resource_id, headers = {})
33
+ response = Transferwise::Request.request(:get, resource_url(resource_id), {}, headers)
34
+ convert_to_transferwise_object(response)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ module Transferwise
2
+ class BorderlessAccount < APIResource
3
+ def self.collection_url(resource_id = nil)
4
+ "/#{API_VERSION}/borderless-accounts"
5
+ end
6
+
7
+ def self.convert(borderless_account_id, quote_id, headers)
8
+ url = "/#{resource_url(borderless_account_id)}/conversions"
9
+
10
+ params = { 'quoteId' => quote_id }
11
+ response = Request.request(:post, url, params, headers)
12
+ convert_to_transferwise_object(response)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Transferwise
2
+ class BorderlessAccount::BalanceCurrency < APIResource
3
+ def self.collection_url(resource_id = nil)
4
+ "/#{API_VERSION}/borderless-accounts/balance-currencies"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Transferwise
2
+ class BorderlessAccount::Statement < APIResource
3
+ def self.collection_url(resource_id = nil)
4
+ "/#{API_VERSION}/borderless-accounts/statement"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Transferwise
2
+ class BorderlessAccount::Transaction < APIResource
3
+ def self.collection_url(resource_id = nil)
4
+ "/#{API_VERSION}/borderless-accounts/#{resource_id}/transactions"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ module Transferwise
2
+ class OAuth
3
+ attr_accessor :access_token
4
+
5
+ def initialize(client_id, client_secret)
6
+ @client_id, @client_secret = client_id, client_secret
7
+ end
8
+
9
+ # Get the OAuth 2 client
10
+ def client
11
+ @client ||= ::OAuth2::Client.new(
12
+ @client_id,
13
+ @client_secret,
14
+ { site: Transferwise.api_base,
15
+ auth_scheme: :basic_auth
16
+ }
17
+ )
18
+ end
19
+
20
+ # Get the url to redirect a user to, pass the redirect_url you want the user
21
+ # to be redirected back to.
22
+ def authorize_url(redirect_url)
23
+ client.auth_code.authorize_url({redirect_uri: redirect_url})
24
+ end
25
+
26
+ # Get the access token. You must pass the exact same redirect_url passed
27
+ # to the authorize_url method
28
+ def get_access_token(code, redirect_url)
29
+ @access_token ||= client.auth_code.get_token(code, redirect_uri: redirect_url)
30
+ end
31
+
32
+ # This method is used to refresh the access token before it expires
33
+ def refresh_token(access_token, opts = {})
34
+ OAuth2::AccessToken.new(client, access_token, opts).refresh!
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ module Transferwise
2
+ class Profile < APIResource
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Transferwise
2
+ class Quote < APIResource
3
+ end
4
+ end
@@ -0,0 +1,103 @@
1
+ module Transferwise
2
+ class Request
3
+ def self.api_url(url = '')
4
+ Transferwise.api_base + url
5
+ end
6
+
7
+ def self.request(method, url, params={}, headers={})
8
+ url = api_url(url)
9
+ access_token = headers.delete(:access_token) || Transferwise.access_token
10
+ request_opts = {
11
+ url: url,
12
+ method: method,
13
+ payload: params.to_json,
14
+ headers: request_headers(access_token).update(headers)
15
+ }
16
+ response = execute_request(request_opts)
17
+ parse(response)
18
+ end
19
+
20
+ private
21
+
22
+ def self.request_headers(access_token)
23
+ {
24
+ 'Authorization' => "Bearer #{access_token}",
25
+ 'Content-Type' => 'application/json'
26
+ }
27
+ end
28
+
29
+ def self.execute_request(request_opts)
30
+ begin
31
+ response = RestClient::Request.execute(request_opts)
32
+ rescue => e
33
+ if e.is_a?(RestClient::Exception)
34
+ response = handle_error(e, request_opts)
35
+ else
36
+ raise
37
+ end
38
+ end
39
+ response
40
+ end
41
+
42
+ def self.parse(response)
43
+ begin
44
+ response = JSON.parse(response.body)
45
+ rescue JSON::ParserError
46
+ raise handle_parse_error(response.code, response.body)
47
+ end
48
+ response
49
+ end
50
+
51
+ def self.handle_error(e, request_opts)
52
+ if e.is_a?(RestClient::ExceptionWithResponse) && e.response
53
+ handle_api_error(e.response)
54
+ else
55
+ handle_restclient_error(e, request_opts)
56
+ end
57
+ end
58
+
59
+ def self.handle_api_error(resp)
60
+ error_obj = parse(resp).with_indifferent_access
61
+ error_message = error_obj['error'].presence || error_obj['errors']&.map{|e| e["message"]}&.join(', ') || error_obj.to_s
62
+ if Transferwise::STATUS_CLASS_MAPPING.include?(resp.code)
63
+ raise "Transferwise::#{Transferwise::STATUS_CLASS_MAPPING[resp.code]}".constantize.new(error_params(error_message, resp, error_obj))
64
+ else
65
+ raise Transferwise::TransferwiseError.new(error_params(error_message, resp, error_obj))
66
+ end
67
+ end
68
+
69
+ def self.handle_restclient_error(e, request_opts)
70
+ connection_message = "Please check your internet connection and try again. "
71
+
72
+ case e
73
+ when RestClient::RequestTimeout
74
+ message = "Could not connect to Transferwise (#{request_opts[:url]}). #{connection_message}"
75
+ when RestClient::ServerBrokeConnection
76
+ message = "The connection to the server (#{request_opts[:url]}) broke before the " \
77
+ "request completed. #{connection_message}"
78
+ else
79
+ message = "Unexpected error communicating with Transferwise. "
80
+ end
81
+
82
+ raise Transferwise::APIConnectionError.new({message: "#{message} \n\n (Error: #{e.message})"})
83
+ end
84
+
85
+ def self.handle_parse_error(rcode, rbody)
86
+ Transferwise::ParseError.new({
87
+ message: "Not able to parse because of invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})",
88
+ http_status: rcode,
89
+ http_body: rbody
90
+ })
91
+ end
92
+
93
+ def self.error_params(error, resp, error_obj)
94
+ {
95
+ message: error,
96
+ http_status: resp.code,
97
+ http_body: resp.body,
98
+ json_body: error_obj,
99
+ http_headers: resp.headers
100
+ }
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,19 @@
1
+ module Transferwise
2
+ class Transfer < APIResource
3
+ def self.cancel(transfer_id, headers)
4
+ url = "#{resource_url(transfer_id)}/cancel"
5
+
6
+ params = { 'transferId' => transfer_id }
7
+ response = Request.request(:put, url, params, headers)
8
+ convert_to_transferwise_object(response)
9
+ end
10
+
11
+ def self.fund(transfer_id, headers)
12
+ url = "#{resource_url(transfer_id)}/payments"
13
+
14
+ params = { 'type' => 'BALANCE' }
15
+ response = Request.request(:post, url, params, headers)
16
+ convert_to_transferwise_object(response)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ module Transferwise
2
+
3
+ STATUS_CLASS_MAPPING = {
4
+ 400 => "InvalidRequestError",
5
+ 404 => "InvalidRequestError",
6
+ 401 => "AuthenticationError"
7
+ }
8
+
9
+ class TransferwiseError < StandardError
10
+ attr_reader :message, :http_status, :http_body, :http_headers, :json_body
11
+
12
+ def initialize(params = {})
13
+ params.each do |key, value|
14
+ instance_variable_set("@#{key}", value)
15
+ end
16
+ end
17
+
18
+ def to_s
19
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
20
+ "#{status_string}#{@message}"
21
+ end
22
+ end
23
+
24
+ class APIConnectionError < TransferwiseError
25
+ end
26
+
27
+ class APIError < TransferwiseError
28
+ end
29
+
30
+ class AuthenticationError < TransferwiseError
31
+ end
32
+
33
+ class InvalidRequestError < TransferwiseError
34
+ end
35
+
36
+ class ParseError < TransferwiseError
37
+ end
38
+
39
+ end
@@ -0,0 +1,46 @@
1
+ module Transferwise
2
+ module TransferwiseObject
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def initialize()
9
+ @values = {}
10
+ end
11
+
12
+ def initialize_from(values)
13
+ add_methods(values.keys)
14
+ update_attributes(values)
15
+ self
16
+ end
17
+
18
+ def add_methods(keys)
19
+ self.instance_eval do
20
+ keys.each do |k|
21
+ self.class.send(:define_method, k.underscore) { @values[k] }
22
+ end
23
+ end
24
+ end
25
+
26
+ def update_attributes(values)
27
+ values.each do |k, v|
28
+ @values[k] = v
29
+ end
30
+ end
31
+
32
+ module ClassMethods
33
+ def convert_to_transferwise_object(resp)
34
+ case resp
35
+ when Array
36
+ resp.map { |i| convert_to_transferwise_object(i) }
37
+ when Hash
38
+ self.new.initialize_from(resp)
39
+ else
40
+ resp
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ module Transferwise
2
+ module Util
3
+
4
+ def self.indifferent_access(object)
5
+ object.with_indifferent_access
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Transferwise
2
+ VERSION = "0.1.6"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'transferwise/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "transferwise"
8
+ spec.version = Transferwise::VERSION
9
+ spec.authors = ["Harshvardhan Parihar", "Fernando Gorodscy"]
10
+ spec.email = ["harsh@milaap.org", "fegorodscy@gmail.com"]
11
+
12
+ spec.summary = "Ruby gem for Transferwise Apis"
13
+ spec.description = "Ruby gem for Transferwise Apis"
14
+ spec.homepage = "https://github.com/fegorodscy/transferwise-rb"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency('rest-client', '>= 1.4', '< 4.0')
31
+ spec.add_runtime_dependency("oauth2".freeze, ["< 2.0", ">= 1.4.0"])
32
+ spec.add_development_dependency "bundler", "~> 1.11"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transferwise
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Harshvardhan Parihar
8
+ - Fernando Gorodscy
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2018-01-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '1.4'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '4.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '1.4'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - !ruby/object:Gem::Dependency
35
+ name: oauth2
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '2.0'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.0
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.11'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.11'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ description: Ruby gem for Transferwise Apis
97
+ email:
98
+ - harsh@milaap.org
99
+ - fegorodscy@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/transferwise.rb
115
+ - lib/transferwise/account.rb
116
+ - lib/transferwise/api_resource.rb
117
+ - lib/transferwise/borderless_account.rb
118
+ - lib/transferwise/borderless_account/balance_currency.rb
119
+ - lib/transferwise/borderless_account/statement.rb
120
+ - lib/transferwise/borderless_account/transaction.rb
121
+ - lib/transferwise/oauth.rb
122
+ - lib/transferwise/profile.rb
123
+ - lib/transferwise/quote.rb
124
+ - lib/transferwise/request.rb
125
+ - lib/transferwise/transfer.rb
126
+ - lib/transferwise/transferwise_error.rb
127
+ - lib/transferwise/transferwise_object.rb
128
+ - lib/transferwise/util.rb
129
+ - lib/transferwise/version.rb
130
+ - transferwise.gemspec
131
+ homepage: https://github.com/fegorodscy/transferwise-rb
132
+ licenses:
133
+ - MIT
134
+ metadata:
135
+ allowed_push_host: https://rubygems.org
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.14
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Ruby gem for Transferwise Apis
156
+ test_files: []