transfer_wise 0.1.4
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/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +149 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/transfer_wise.rb +36 -0
- data/lib/transfer_wise/account.rb +4 -0
- data/lib/transfer_wise/api_resource.rb +35 -0
- data/lib/transfer_wise/oauth.rb +37 -0
- data/lib/transfer_wise/profile.rb +4 -0
- data/lib/transfer_wise/quote.rb +4 -0
- data/lib/transfer_wise/request.rb +105 -0
- data/lib/transfer_wise/transfer.rb +4 -0
- data/lib/transfer_wise/transfer_wise_error.rb +39 -0
- data/lib/transfer_wise/transfer_wise_object.rb +46 -0
- data/lib/transfer_wise/util.rb +9 -0
- data/lib/transfer_wise/version.rb +3 -0
- data/transfer_wise.gemspec +35 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00dd356c60aab939c84676b5c09dc62f3074bb2a
|
4
|
+
data.tar.gz: 9b0241e4ae8748f10beac8fea6b4d6e18008ff89
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 496f12b334a344cd1ec8da01fcc4fdba520b64792e9d664bb567a93fecdc4c14e4c1ad8a90bd8888b8ce7eaf59372a9c053173e54ae558a535fb7d85a3371da5
|
7
|
+
data.tar.gz: c0022e7b1e2a5e878ecea47886446364ca99b7546739e2f94ac88d502c8f0c0699646c48cb8e28af9c35d5ee71f1bcce0bc03571a45009a32fc136f435c15c6b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
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,149 @@
|
|
1
|
+
# TransferWise
|
2
|
+
|
3
|
+
Welcome to transfer_wise ruby gem! The transfer_wise 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 'transfer_wise'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install transfer_wise
|
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
|
+
}
|
105
|
+
quote = TransferWise::Quote.create(quote_request, {access_token: access_token})
|
106
|
+
```
|
107
|
+
## Account
|
108
|
+
|
109
|
+
Next step is to create the account where you want to transfer the money.
|
110
|
+
If you already have the account you can use that account id and skip this account creation part.
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
account_request = {
|
114
|
+
"profile" => profile.id,
|
115
|
+
"accountHolderName" => "Account Holder Name",
|
116
|
+
"currency" => "INR", # target currency name
|
117
|
+
"country" => "IN", # target country code
|
118
|
+
"type" => "", # get from account requirements
|
119
|
+
"details" => {
|
120
|
+
"legalType" => "PRIVATE",
|
121
|
+
"accountNumber" => "", # target account number
|
122
|
+
"ifscCode" => "", # ifsc code or any other field. Get field name finformation from account requirements api. This could be different for other country except india.
|
123
|
+
"address" => { # get address details also from account requirement based on country.
|
124
|
+
"city" => "City name", # city name
|
125
|
+
"country" => "IN", # country code
|
126
|
+
"firstLine" => "", # address first line
|
127
|
+
"postCode" => "" # post code
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
account = TransferWise::Account.create(account_request, {access_token: access_token})
|
132
|
+
```
|
133
|
+
|
134
|
+
## Transfer
|
135
|
+
|
136
|
+
Create a transfer
|
137
|
+
```ruby
|
138
|
+
transfer_request = {
|
139
|
+
"targetAccount" => account.id,
|
140
|
+
"quote" => quote.id,
|
141
|
+
"details" => {
|
142
|
+
"reference" => "Any Comment" # get the field detail, from transfer requirements api before creating the transfer object.
|
143
|
+
}
|
144
|
+
}
|
145
|
+
transfer = TransferWise::Transfer.create(transfer_request, {access_token: access_token})
|
146
|
+
|
147
|
+
```
|
148
|
+
|
149
|
+
Transfer object is created in transfer wise website. You can go there and make payments to complete the transfer.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "transfer_wise"
|
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,36 @@
|
|
1
|
+
# TransferWise Ruby bindings
|
2
|
+
require 'open-uri'
|
3
|
+
require 'oauth2'
|
4
|
+
require 'rest-client'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
# Version
|
8
|
+
require "transfer_wise/version"
|
9
|
+
|
10
|
+
# Oauth2 Authentication
|
11
|
+
require "transfer_wise/oauth"
|
12
|
+
|
13
|
+
# Resources
|
14
|
+
require 'transfer_wise/transfer_wise_object'
|
15
|
+
require 'transfer_wise/api_resource'
|
16
|
+
require 'transfer_wise/profile'
|
17
|
+
require 'transfer_wise/quote'
|
18
|
+
require 'transfer_wise/account'
|
19
|
+
require 'transfer_wise/transfer'
|
20
|
+
require 'transfer_wise/util'
|
21
|
+
require 'transfer_wise/request'
|
22
|
+
|
23
|
+
# Errors
|
24
|
+
require 'transfer_wise/transfer_wise_error'
|
25
|
+
|
26
|
+
module TransferWise
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_accessor :mode
|
30
|
+
attr_accessor :access_token
|
31
|
+
|
32
|
+
def api_base
|
33
|
+
@api_base ||= "https://#{mode == 'live' ? 'api' : 'test-restgw'}.transferwise.com"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module TransferWise
|
2
|
+
class APIResource
|
3
|
+
include TransferWise::TransferWiseObject
|
4
|
+
|
5
|
+
def self.class_name
|
6
|
+
self.name.split('::')[-1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.resource_url(resource_id)
|
10
|
+
"#{collection_url}/#{resource_id}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.collection_url
|
14
|
+
if self == APIResource
|
15
|
+
raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Account, Transfer, etc.)')
|
16
|
+
end
|
17
|
+
"/v1/#{CGI.escape(class_name.downcase)}s"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create(params={}, opts={})
|
21
|
+
response = TransferWise::Request.request(:post, collection_url, params, opts)
|
22
|
+
convert_to_transfer_wise_object(response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.list(filters = {}, headers = {})
|
26
|
+
response = TransferWise::Request.request(:get, collection_url, filters, headers)
|
27
|
+
convert_to_transfer_wise_object(response)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get(resource_id, headers = {})
|
31
|
+
response = TransferWise::Request.request(:get, resource_url(resource_id), {}, headers)
|
32
|
+
convert_to_transfer_wise_object(response)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
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,105 @@
|
|
1
|
+
module TransferWise
|
2
|
+
class Request
|
3
|
+
|
4
|
+
def self.api_url(url = '')
|
5
|
+
TransferWise.api_base + url
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.request(method, url, params={}, headers={})
|
9
|
+
url = api_url(url)
|
10
|
+
access_token = headers.delete(:access_token) || TransferWise.access_token
|
11
|
+
request_opts = {
|
12
|
+
url: url,
|
13
|
+
method: method,
|
14
|
+
payload: params.to_json,
|
15
|
+
headers: request_headers(access_token).update(headers)
|
16
|
+
}
|
17
|
+
response = execute_request(request_opts)
|
18
|
+
parse(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.request_headers(access_token)
|
24
|
+
{
|
25
|
+
'Authorization' => "Bearer #{access_token}",
|
26
|
+
'Content-Type' => 'application/json'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.execute_request(request_opts)
|
31
|
+
begin
|
32
|
+
response = RestClient::Request.execute(request_opts)
|
33
|
+
rescue => e
|
34
|
+
if e.is_a?(RestClient::Exception)
|
35
|
+
response = handle_error(e, request_opts)
|
36
|
+
else
|
37
|
+
raise
|
38
|
+
end
|
39
|
+
end
|
40
|
+
response
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.parse(response)
|
44
|
+
begin
|
45
|
+
response = JSON.parse(response.body)
|
46
|
+
rescue JSON::ParserError
|
47
|
+
raise handle_parse_error(response.code, response.body)
|
48
|
+
end
|
49
|
+
response
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.handle_error(e, request_opts)
|
53
|
+
if e.is_a?(RestClient::ExceptionWithResponse) && e.response
|
54
|
+
handle_api_error(e.response)
|
55
|
+
else
|
56
|
+
handle_restclient_error(e, request_opts)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.handle_api_error(resp)
|
61
|
+
error_obj = parse(resp).with_indifferent_access
|
62
|
+
error_message = error_obj['error'].presence || error_obj['errors'].map{|e| e["message"]}.join(', ')
|
63
|
+
if TransferWise::STATUS_CLASS_MAPPING.include?(resp.code)
|
64
|
+
raise "TransferWise::#{TransferWise::STATUS_CLASS_MAPPING[resp.code]}".constantize.new(error_params(error_message, resp, error_obj))
|
65
|
+
else
|
66
|
+
raise TransferWise::TransferWiseError.new(error_params(error_message, resp, error_obj))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.handle_restclient_error(e, request_opts)
|
71
|
+
connection_message = "Please check your internet connection and try again. "
|
72
|
+
|
73
|
+
case e
|
74
|
+
when RestClient::RequestTimeout
|
75
|
+
message = "Could not connect to TransferWise (#{request_opts[:url]}). #{connection_message}"
|
76
|
+
when RestClient::ServerBrokeConnection
|
77
|
+
message = "The connection to the server (#{request_opts[:url]}) broke before the " \
|
78
|
+
"request completed. #{connection_message}"
|
79
|
+
else
|
80
|
+
message = "Unexpected error communicating with TransferWise. "
|
81
|
+
end
|
82
|
+
|
83
|
+
raise TransferWise::APIConnectionError.new({message: "#{message} \n\n (Error: #{e.message})"})
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.handle_parse_error(rcode, rbody)
|
87
|
+
TransferWise::ParseError.new({
|
88
|
+
message: "Not able to parse because of invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})",
|
89
|
+
http_status: rcode,
|
90
|
+
http_body: rbody
|
91
|
+
})
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.error_params(error, resp, error_obj)
|
95
|
+
{
|
96
|
+
message: error,
|
97
|
+
http_status: resp.code,
|
98
|
+
http_body: resp.body,
|
99
|
+
json_body: error_obj,
|
100
|
+
http_headers: resp.headers
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
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_transfer_wise_object(resp)
|
34
|
+
case resp
|
35
|
+
when Array
|
36
|
+
resp.map { |i| convert_to_transfer_wise_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,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'transfer_wise/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "transfer_wise"
|
8
|
+
spec.version = TransferWise::VERSION
|
9
|
+
spec.authors = ["Harshvardhan Parihar"]
|
10
|
+
spec.email = ["harsh@milaap.org"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby gem for TransferWise Apis"
|
13
|
+
spec.description = "Ruby gem for TransferWise Apis"
|
14
|
+
spec.homepage = "https://github.com/Milaap/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", ">= 0.5.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,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transfer_wise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harshvardhan Parihar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.4'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.4'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: oauth2
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "<"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.5.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "<"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.5.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.11'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.11'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '10.0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '10.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rspec
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '3.0'
|
95
|
+
description: Ruby gem for TransferWise Apis
|
96
|
+
email:
|
97
|
+
- harsh@milaap.org
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- ".gitignore"
|
103
|
+
- ".rspec"
|
104
|
+
- ".travis.yml"
|
105
|
+
- CODE_OF_CONDUCT.md
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/transfer_wise.rb
|
113
|
+
- lib/transfer_wise/account.rb
|
114
|
+
- lib/transfer_wise/api_resource.rb
|
115
|
+
- lib/transfer_wise/oauth.rb
|
116
|
+
- lib/transfer_wise/profile.rb
|
117
|
+
- lib/transfer_wise/quote.rb
|
118
|
+
- lib/transfer_wise/request.rb
|
119
|
+
- lib/transfer_wise/transfer.rb
|
120
|
+
- lib/transfer_wise/transfer_wise_error.rb
|
121
|
+
- lib/transfer_wise/transfer_wise_object.rb
|
122
|
+
- lib/transfer_wise/util.rb
|
123
|
+
- lib/transfer_wise/version.rb
|
124
|
+
- transfer_wise.gemspec
|
125
|
+
homepage: https://github.com/Milaap/transferwise-rb
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata:
|
129
|
+
allowed_push_host: https://rubygems.org
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.5.1
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Ruby gem for TransferWise Apis
|
150
|
+
test_files: []
|
151
|
+
has_rdoc:
|