revolut-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ module Revolut
2
+ module Api
3
+ module Response
4
+ class User
5
+ attr_accessor :id
6
+ attr_accessor :created_date
7
+ attr_accessor :address
8
+ attr_accessor :birth_date
9
+ attr_accessor :first_name, :last_name, :phone, :email, :email_verified
10
+ attr_accessor :state, :referral_code, :kyc, :terms_version
11
+ attr_accessor :under_review, :risk_assessed, :locale
12
+ attr_accessor :wallet
13
+
14
+ def initialize(hash = {})
15
+ user_data = hash.fetch("user", {})
16
+ wallet_data = hash.fetch("wallet", {})
17
+
18
+ self.id = user_data.fetch("id", nil)
19
+ self.created_date = user_data.fetch("createdDate", nil)
20
+ self.created_date = ::Revolut::Api::Utilities.epoch_to_utc(self.created_date) unless self.created_date.nil?
21
+ self.address = ::Revolut::Api::Response::Address.new(user_data.fetch("address", {}))
22
+ self.birth_date = user_data.fetch("birthDate", nil)
23
+ self.first_name = user_data.fetch("firstName", nil)
24
+ self.last_name = user_data.fetch("lastName", nil)
25
+ self.phone = user_data.fetch("phone", nil)
26
+ self.email = user_data.fetch("email", nil)
27
+ self.email_verified = user_data.fetch("emailVerified", false)
28
+ self.state = user_data.fetch("state", nil)
29
+ self.referral_code = user_data.fetch("referralCode", nil)
30
+ self.kyc = user_data.fetch("kyc", nil)
31
+ self.terms_version = user_data.fetch("termsVersion", nil)
32
+ self.under_review = user_data.fetch("underReview", false)
33
+ self.risk_assessed = user_data.fetch("riskAssessed", false)
34
+ self.locale = user_data.fetch("locale", nil)
35
+
36
+ self.wallet = ::Revolut::Api::Response::Wallet.new(wallet_data)
37
+ end
38
+
39
+ def active?
40
+ in_state?(:active)
41
+ end
42
+
43
+ def in_state?(state)
44
+ self.state.downcase.strip.to_sym.eql?(state)
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,42 @@
1
+ module Revolut
2
+ module Api
3
+ module Response
4
+ class Wallet
5
+ attr_accessor :id, :ref, :state
6
+ attr_accessor :base_currency
7
+ attr_accessor :total_topup
8
+ attr_accessor :pockets
9
+
10
+ def initialize(hash = {})
11
+ self.id = hash.fetch("id", nil)
12
+ self.ref = hash.fetch("ref", nil)
13
+ self.state = hash.fetch("state", nil)
14
+
15
+ self.base_currency = hash.fetch("baseCurrency", nil)
16
+
17
+ self.total_topup = hash.fetch("totalTopup", nil)
18
+ self.total_topup = ::Revolut::Api::Utilities.convert_from_integer_amount(self.base_currency, self.total_topup) if !self.base_currency.to_s.empty? && !self.total_topup.nil?
19
+
20
+ self.pockets = {}
21
+ hash.fetch("pockets", []).each do |pocket_data|
22
+ pocket = ::Revolut::Api::Response::Pocket.new(pocket_data)
23
+ self.pockets[pocket.currency] = pocket
24
+ end
25
+ end
26
+
27
+ def active?
28
+ in_state?(:active)
29
+ end
30
+
31
+ def in_state?(state)
32
+ self.state.downcase.strip.to_sym.eql?(state)
33
+ end
34
+
35
+ def pocket(currency)
36
+ self.pockets.fetch(currency, nil)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ module Revolut
2
+ module Api
3
+ class Utilities
4
+
5
+ class << self
6
+ def epoch_to_utc(time)
7
+ Time.at(time/::Revolut::Api::Constants::TIME[:epoch_base]).utc
8
+ end
9
+
10
+ def utc_to_epoch(time)
11
+ time.to_i * ::Revolut::Api::Constants::TIME[:epoch_base]
12
+ end
13
+
14
+ # Revolut uses cents, so if you send in $10, multiply by 100 to get Revolut's internal prices
15
+ def convert_to_integer_amount(currency, amount)
16
+ sub_unit = ::Revolut::Api::Constants::CRYPTOS.include?(currency) ? ::Revolut::Api::Constants::BASE_UNITS[:crypto] : ::Revolut::Api::Constants::BASE_UNITS[:fiat]
17
+ (amount.to_f * sub_unit).round(0).to_i
18
+ end
19
+
20
+ def convert_from_integer_amount(currency, amount)
21
+ sub_unit = ::Revolut::Api::Constants::CRYPTOS.include?(currency) ? ::Revolut::Api::Constants::BASE_UNITS[:crypto] : ::Revolut::Api::Constants::BASE_UNITS[:fiat]
22
+ (amount.to_f / sub_unit)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Revolut
2
+ module Api
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "revolut/api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "revolut-api"
8
+ spec.version = Revolut::Api::VERSION
9
+ spec.authors = ["Sebastian Johnsson"]
10
+ spec.email = ["sebastian.johnsson@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby API client for interacting with Revolut's consumer API}
13
+ spec.description = %q{Ruby client for interacting with Revolut's consumer API (user data, transactions, exchange etc.)}
14
+ spec.homepage = "https://github.com/SebastianJ/revolut-api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "faraday", ">= 0.15"
25
+ spec.add_dependency "faraday_middleware", ">= 0.12"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "rdoc", "~> 6.0"
31
+ spec.add_development_dependency "vcr", "~> 4.0"
32
+ spec.add_development_dependency "webmock", "~> 3.1"
33
+
34
+ spec.add_development_dependency "pry", "~> 0.11"
35
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: revolut-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Johnsson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-25 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.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '6.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '6.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: '4.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.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: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.11'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.11'
139
+ description: Ruby client for interacting with Revolut's consumer API (user data, transactions,
140
+ exchange etc.)
141
+ email:
142
+ - sebastian.johnsson@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - credentials.yml.example
159
+ - lib/revolut/api.rb
160
+ - lib/revolut/api/base.rb
161
+ - lib/revolut/api/client.rb
162
+ - lib/revolut/api/configuration.rb
163
+ - lib/revolut/api/constants.rb
164
+ - lib/revolut/api/errors.rb
165
+ - lib/revolut/api/private/auth.rb
166
+ - lib/revolut/api/private/exchange.rb
167
+ - lib/revolut/api/private/transactions.rb
168
+ - lib/revolut/api/private/user.rb
169
+ - lib/revolut/api/public/client.rb
170
+ - lib/revolut/api/railtie.rb
171
+ - lib/revolut/api/response/address.rb
172
+ - lib/revolut/api/response/card.rb
173
+ - lib/revolut/api/response/card_issuer.rb
174
+ - lib/revolut/api/response/merchant.rb
175
+ - lib/revolut/api/response/pocket.rb
176
+ - lib/revolut/api/response/quote.rb
177
+ - lib/revolut/api/response/transaction.rb
178
+ - lib/revolut/api/response/user.rb
179
+ - lib/revolut/api/response/wallet.rb
180
+ - lib/revolut/api/utilities.rb
181
+ - lib/revolut/api/version.rb
182
+ - revolut-api.gemspec
183
+ homepage: https://github.com/SebastianJ/revolut-api
184
+ licenses:
185
+ - MIT
186
+ metadata: {}
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.7.7
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Ruby API client for interacting with Revolut's consumer API
207
+ test_files: []