uphold 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +13 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +335 -0
- data/Rakefile +14 -0
- data/lib/uphold/api/auth_token.rb +17 -0
- data/lib/uphold/api/card.rb +36 -0
- data/lib/uphold/api/contact.rb +34 -0
- data/lib/uphold/api/endpoints.rb +26 -0
- data/lib/uphold/api/private_transaction.rb +58 -0
- data/lib/uphold/api/public_transaction.rb +23 -0
- data/lib/uphold/api/ticker.rb +23 -0
- data/lib/uphold/api/transparency.rb +15 -0
- data/lib/uphold/api/user.rb +23 -0
- data/lib/uphold/api.rb +22 -0
- data/lib/uphold/client.rb +14 -0
- data/lib/uphold/entities/asset.rb +9 -0
- data/lib/uphold/entities/auth_token.rb +9 -0
- data/lib/uphold/entities/base_entity.rb +27 -0
- data/lib/uphold/entities/card.rb +15 -0
- data/lib/uphold/entities/contact.rb +13 -0
- data/lib/uphold/entities/error.rb +8 -0
- data/lib/uphold/entities/ledger_entry.rb +10 -0
- data/lib/uphold/entities/oauth_error.rb +9 -0
- data/lib/uphold/entities/phone.rb +12 -0
- data/lib/uphold/entities/ticker.rb +10 -0
- data/lib/uphold/entities/transaction.rb +17 -0
- data/lib/uphold/entities/user.rb +18 -0
- data/lib/uphold/helpers.rb +23 -0
- data/lib/uphold/options.rb +39 -0
- data/lib/uphold/pagination.rb +9 -0
- data/lib/uphold/request.rb +70 -0
- data/lib/uphold/request_data.rb +7 -0
- data/lib/uphold/version.rb +3 -0
- data/lib/uphold.rb +46 -0
- data/spec/fixtures/vcr_cassettes/ledger.yml +56 -0
- data/spec/fixtures/vcr_cassettes/me/card.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/cards.yml +67 -0
- data/spec/fixtures/vcr_cassettes/me/contact.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/contacts.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/created_card.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/created_contact.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/phones.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/transactions/cancel.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/transactions/commit.yml +62 -0
- data/spec/fixtures/vcr_cassettes/me/transactions/create.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me/transactions/create_waiting_cancel.yml +118 -0
- data/spec/fixtures/vcr_cassettes/me/transactions/create_waiting_resend.yml +118 -0
- data/spec/fixtures/vcr_cassettes/me/transactions/resend.yml +61 -0
- data/spec/fixtures/vcr_cassettes/me.yml +185 -0
- data/spec/fixtures/vcr_cassettes/pats.yml +61 -0
- data/spec/fixtures/vcr_cassettes/reserve/transaction.yml +60 -0
- data/spec/fixtures/vcr_cassettes/reserve/transactions.yml +60 -0
- data/spec/fixtures/vcr_cassettes/tickers.yml +60 -0
- data/spec/fixtures/vcr_cassettes/transparency.yml +60 -0
- data/spec/integration/api/auth_token_spec.rb +20 -0
- data/spec/integration/api/card_spec.rb +47 -0
- data/spec/integration/api/contact_spec.rb +53 -0
- data/spec/integration/api/private_transactions_spec.rb +74 -0
- data/spec/integration/api/public_transaction_spec.rb +35 -0
- data/spec/integration/api/ticker_spec.rb +21 -0
- data/spec/integration/api/transparency_spec.rb +33 -0
- data/spec/integration/api/user_spec.rb +32 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/vcr.rb +8 -0
- data/spec/support/webmock.rb +11 -0
- data/spec/unit/api/auth_spec.rb +21 -0
- data/spec/unit/api/card_spec.rb +47 -0
- data/spec/unit/api/contact_spec.rb +53 -0
- data/spec/unit/api/private_transaction_spec.rb +114 -0
- data/spec/unit/api/public_transaction_spec.rb +34 -0
- data/spec/unit/api/ticker_spec.rb +34 -0
- data/spec/unit/api/transparency_spec.rb +33 -0
- data/spec/unit/api/user_spec.rb +33 -0
- data/spec/unit/client_spec.rb +33 -0
- data/spec/unit/entities/base_entity_spec.rb +36 -0
- data/spec/unit/helper_spec.rb +37 -0
- data/spec/unit/request_spec.rb +94 -0
- data/uphold.gemspec +30 -0
- metadata +296 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fcbac48fdf6ca84355f80032f2405c44635195a0
|
4
|
+
data.tar.gz: bec84be91e397bee706526eb50fdc3282e45ba68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2afa7286c1b900357966625ed1f273344d616f9374bba8b8909e4936ec7ece0527a3d129963ef2bc5a802290f272458075c1e870c231a1576f026d1617a0c3f5
|
7
|
+
data.tar.gz: 4451d2528a39b13e61ac18704afecd1e7ad8730efb3ed508fa62f7e0db246b9acfc2f35be19a6bf9c91cc9db9e37c56a2a7594d7092df3c6035d14f7590b1b6f
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- '**/Rakefile'
|
4
|
+
- '**/config.ru'
|
5
|
+
Exclude:
|
6
|
+
- 'path/**/*'
|
7
|
+
- 'bin/**/*'
|
8
|
+
- 'vendor/**/*'
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/AlignParameters:
|
14
|
+
EnforcedStyle: with_fixed_indentation
|
15
|
+
|
16
|
+
Style/ClassAndModuleChildren:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/DotPosition:
|
23
|
+
EnforcedStyle: trailing
|
24
|
+
|
25
|
+
Style/IfUnlessModifier:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/MultilineOperationIndentation:
|
29
|
+
EnforcedStyle: indented
|
30
|
+
|
31
|
+
Style/RegexpLiteral:
|
32
|
+
MaxSlashes: 0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Group Buddies
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,335 @@
|
|
1
|
+
# Uphold
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/uphold-ruby.svg)](http://badge.fury.io/rb/uphold)
|
4
|
+
[![Build Status](https://travis-ci.org/subvisual/uphold-ruby.svg?branch=master)](https://travis-ci.org/subvisual/uphold-ruby)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/subvisual/uphold-ruby/badges/gpa.svg)](https://codeclimate.com/github/subvisual/uphold-ruby)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/subvisual/uphold-ruby/badges/coverage.svg)](https://codeclimate.com/github/subvisual/uphold-ruby)
|
7
|
+
|
8
|
+
A ruby client for the [Uphold](https://uphold.com/) API.
|
9
|
+
|
10
|
+
# Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'uphold'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install uphold
|
25
|
+
|
26
|
+
# Contents
|
27
|
+
|
28
|
+
* [Usage](#usage)
|
29
|
+
* [Options](#options)
|
30
|
+
* [Creating an authenticated client](#creating-an-authenticated-client)
|
31
|
+
* [Personal Access Token](#personal-access-token)
|
32
|
+
* [Via argument](#via-argument)
|
33
|
+
* [Via environment variable](#via-environment-variable)
|
34
|
+
* [Endpoints](#endpoints)
|
35
|
+
* [Authentication](#authentication)
|
36
|
+
* [OAuth2](#oauth2)
|
37
|
+
* [Basic Authentication](#basic-authentication)
|
38
|
+
* [Tickers](#tickers)
|
39
|
+
* [Entities](#entities)
|
40
|
+
* [Cards](#cards)
|
41
|
+
* [Transactions](#transactions)
|
42
|
+
* [Public Transactions](#public-transactions)
|
43
|
+
* [Private Transactions](#private-transactions)
|
44
|
+
* [Contacts](#contacts)
|
45
|
+
* [Users](#users)
|
46
|
+
* [Transparency](#transparency)
|
47
|
+
* [Pagination](#pagination)
|
48
|
+
* [Contributing](#contributing)
|
49
|
+
|
50
|
+
# Usage
|
51
|
+
|
52
|
+
To use the gem, you have to instantiate a client. All API calls are made from there. Here's a minimal working example:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'uphold'
|
56
|
+
|
57
|
+
client = Uphold::Client.new
|
58
|
+
puts client.all_tickers
|
59
|
+
```
|
60
|
+
|
61
|
+
## Sandbox mode
|
62
|
+
|
63
|
+
Uphold has a sandbox version for testing purposes:
|
64
|
+
|
65
|
+
* Sandbox site: https://sandbox.uphold.com
|
66
|
+
* Sandbox API: https://api-sandbox.uphold.com
|
67
|
+
|
68
|
+
You can set `Uphold.sandbox = true` to enable sandboxing mode to set the global base URL to point to the sandbox API instead of the production one.
|
69
|
+
|
70
|
+
# Options
|
71
|
+
|
72
|
+
This is a summary of the supported options when instantiating a new client, and their default values:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
Uphold::Client.new(
|
76
|
+
# bearer_token for OAuth authentication
|
77
|
+
token: ENV['UPHOLD_AUTH_TOKEN']
|
78
|
+
)
|
79
|
+
```
|
80
|
+
|
81
|
+
# Creating an authenticated client
|
82
|
+
|
83
|
+
In order to make most of the API calls, you will need to authenticate your
|
84
|
+
client. Here's how you can do that.
|
85
|
+
|
86
|
+
## Personal Access Token
|
87
|
+
|
88
|
+
If you don't have a PAT, learn how to generate one
|
89
|
+
[here](#basic-authentication).
|
90
|
+
|
91
|
+
If you already have a token, you can use it by setting an environment variable,
|
92
|
+
or by passing it when instantiating the client.
|
93
|
+
|
94
|
+
### Via argument
|
95
|
+
|
96
|
+
Pass the token to the constructor:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
Uphold::Client.new(token: 'your-access-token')
|
100
|
+
```
|
101
|
+
|
102
|
+
### Via environment variable
|
103
|
+
|
104
|
+
Set the environment variable using [dotenv](https://github.com/bkeepers/dotenv), or by exporting it in your shell:
|
105
|
+
|
106
|
+
```bash
|
107
|
+
$ export UPHOLD_AUTH_TOKEN="your-access-token"
|
108
|
+
```
|
109
|
+
|
110
|
+
Then instantiate the client:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
Uphold::Client.new
|
114
|
+
```
|
115
|
+
|
116
|
+
# Endpoints
|
117
|
+
|
118
|
+
This is a comprehensive list of all the mappings between this wrapper and the
|
119
|
+
Uphold's API.
|
120
|
+
|
121
|
+
## Authentication
|
122
|
+
|
123
|
+
[*Uphold documentation on authentication*](https://developer.uphold.com/api/v0/#authentication)
|
124
|
+
|
125
|
+
### OAuth2
|
126
|
+
|
127
|
+
**NOT SUPPORTED BY UPHOLD YET**
|
128
|
+
|
129
|
+
### Basic Authentication
|
130
|
+
|
131
|
+
[*Bireserve documentation on basic authentication*](https://developer.uphold.com/api/v0/#basic-authentication)
|
132
|
+
|
133
|
+
The only thing you need, in order to use basic authentication is a Personal
|
134
|
+
Access Token, everything else is transparent to you. If you already have a
|
135
|
+
token, see how to use it [here](#personal-access-token).
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
client.generate_access_token(username: 'your-uphold-username', password:
|
139
|
+
'your-uphold-password', otp: 'a-valid-uphold-otp')
|
140
|
+
```
|
141
|
+
|
142
|
+
To generate a valid OTP you can install [Authy](https://www.authy.com/), follow
|
143
|
+
it's set up process and choose uphold. You should be prompted with a set of
|
144
|
+
numbers, which is your OTP (it only lasts 30 seconds, so you have to be quick).
|
145
|
+
|
146
|
+
## Tickers
|
147
|
+
|
148
|
+
[*Uphold documentation on tickers*](https://developer.uphold.com/api/v0/#tickers)
|
149
|
+
|
150
|
+
**Return the current rates on Uphold for all currency pairs:**
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
client.all_tickers
|
154
|
+
```
|
155
|
+
|
156
|
+
**Return the current rates on Uphold for a specific currency:**
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
client.find_ticker(currency: 'EUR')
|
160
|
+
```
|
161
|
+
|
162
|
+
## Cards
|
163
|
+
|
164
|
+
[*Uphold documentation on cards*](https://developer.uphold.com/api/v0/#cards)
|
165
|
+
|
166
|
+
**Return all the user's cards:**
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
client.all_cards
|
170
|
+
```
|
171
|
+
|
172
|
+
**Return the details for a specific card associated with the user:**
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
client.find_card(id: '37e002a7-8508-4268-a18c-7335a6ddf24b')
|
176
|
+
```
|
177
|
+
|
178
|
+
**Create a card for the user:**
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
client.create_card(label: 'My label', currency: 'BTC')
|
182
|
+
```
|
183
|
+
|
184
|
+
## Transactions
|
185
|
+
|
186
|
+
[*Uphold documentation on transactions*](https://developer.uphold.com/api/v0/#transactions)
|
187
|
+
|
188
|
+
You can interact with both the authenticated user's and public transactions.
|
189
|
+
|
190
|
+
### Public Transactions
|
191
|
+
|
192
|
+
**Return the public view of all transactions in the reserve (supports
|
193
|
+
[Pagination](#pagination)):**
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
client.all_public_transactions
|
197
|
+
```
|
198
|
+
|
199
|
+
**Return the public view of a specific transaction (supports
|
200
|
+
[Pagination](#pagination)):**
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
client.find_public_transactions(id: 'a97bb994-6e24-4a89-b653-e0a6d0bcf634')
|
204
|
+
```
|
205
|
+
|
206
|
+
### Private Transactions
|
207
|
+
|
208
|
+
**Create a transaction:**
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
client.create_transaction(card_id: 'a6d35fcd-xxxx-9c9d1dda6d57', currency:
|
212
|
+
'BTC', amount: 0.1, destination: 'foo@bar.com')
|
213
|
+
```
|
214
|
+
|
215
|
+
**Commit a transaction:**
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
client.commit_transaction(card_id: 'a6d35fcd-xxxx-9c9d1dda6d57', transaction_id:
|
219
|
+
'd51b4e4e-9827-40fb-8763-e0ea2880085b')
|
220
|
+
```
|
221
|
+
|
222
|
+
**Cancel a transaction:**
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
client.cancel_transaction(card_id: 'a6d35fcd-xxxx-9c9d1dda6d57', transaction_id:
|
226
|
+
'd51b4e4e-9827-40fb-8763-e0ea2880085b')
|
227
|
+
```
|
228
|
+
|
229
|
+
**Resend a transaction:**
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
client.resend_transaction(card_id: 'a6d35fcd-xxxx-9c9d1dda6d57', transaction_id:
|
233
|
+
'd51b4e4e-9827-40fb-8763-e0ea2880085b')
|
234
|
+
```
|
235
|
+
|
236
|
+
**Return all transactions associated with the user (supports
|
237
|
+
[Pagination](#pagination)):**
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
client.all_user_transactions
|
241
|
+
```
|
242
|
+
|
243
|
+
**Return all transactions associated with a card:**
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
client.all_card_transactions
|
247
|
+
```
|
248
|
+
|
249
|
+
## Contacts
|
250
|
+
|
251
|
+
[*Uphold documentation on contacts*](https://developer.uphold.com/api/v0/#contacts)
|
252
|
+
|
253
|
+
**Return all the user's contacts:**
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
client.all_contacts
|
257
|
+
```
|
258
|
+
|
259
|
+
**Return the details for a specific contact associated with the user:**
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
client.find_contact(id: '9fae84eb-712d-4b6a-9b2c-764bdde4c079')
|
263
|
+
```
|
264
|
+
|
265
|
+
**Create a contact for the user:**
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
client.create_contact(first_name: 'Luke', last_name: 'Skywalker', company: 'Lars
|
269
|
+
Moisture Farm Inc', emails: ['support@larsmoisturefarm.com')
|
270
|
+
```
|
271
|
+
|
272
|
+
## Users
|
273
|
+
|
274
|
+
[*Uphold documentation on users*](https://developer.uphold.com/api/v0/#users)
|
275
|
+
|
276
|
+
**Return the details of the user:**
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
client.me
|
280
|
+
```
|
281
|
+
|
282
|
+
**Return the list of phone numbers associated with the user:**
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
client.phones
|
286
|
+
```
|
287
|
+
|
288
|
+
## Transparency
|
289
|
+
|
290
|
+
[*Uphold documentation on the reserve status*](https://developer.uphold.com/api/v0/#reserve-status)
|
291
|
+
|
292
|
+
**Return a summary of all obligations and assets:**
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
client.statistics
|
296
|
+
```
|
297
|
+
|
298
|
+
[*Uphold documentation on the reserve ledger*](https://developer.uphold.com/api/v0/#the-reserveledger)
|
299
|
+
|
300
|
+
**Return a detailed record of all obligations and assets flowing into the
|
301
|
+
network:**
|
302
|
+
|
303
|
+
```ruby
|
304
|
+
client.ledger
|
305
|
+
```
|
306
|
+
|
307
|
+
## Pagination
|
308
|
+
|
309
|
+
[*Uphold documentation on pagination*](https://developer.uphold.com/api/v0/#pagination)
|
310
|
+
|
311
|
+
All endpoints that support pagination take a `range` attribute, in which you can
|
312
|
+
specify the first and last indexes for the items you wish to retrieve.
|
313
|
+
|
314
|
+
The response will look exactly like an `Array`, but with a method called
|
315
|
+
`total_items`, that returns the total number of items of that type that
|
316
|
+
Uphold knows of.
|
317
|
+
|
318
|
+
```ruby
|
319
|
+
client = Uphold::Client.new token: 'XXX'
|
320
|
+
client.all_public_transactions.size # 5
|
321
|
+
client.all_public_transactions.total_size # 21110
|
322
|
+
client.all_public_transactions(range: (5..20)).size # 16
|
323
|
+
```
|
324
|
+
|
325
|
+
# Contributing
|
326
|
+
|
327
|
+
1. Fork it ( https://github.com/subvisual/uphold-ruby/fork )
|
328
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
329
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
330
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
331
|
+
5. Create a new Pull Request
|
332
|
+
|
333
|
+
# Copyright
|
334
|
+
|
335
|
+
Copyright (c) 2015 Group Buddies. See [LICENSE.txt](LICENSE.txt) for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RuboCop::RakeTask.new
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :console do
|
8
|
+
require 'pry'
|
9
|
+
require 'uphold'
|
10
|
+
ARGV.clear
|
11
|
+
Pry.start
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: [:rubocop, :spec]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Uphold
|
4
|
+
module API
|
5
|
+
module AuthToken
|
6
|
+
def generate_access_token(username: '', password: '', otp: '')
|
7
|
+
request_data = Uphold::RequestData.new(
|
8
|
+
Endpoints::AUTH,
|
9
|
+
Entities::AuthToken,
|
10
|
+
{ 'X-Uphold-OTP' => otp, 'Authorization' => 'Basic ' + Base64.encode64("#{username}:#{password}") },
|
11
|
+
description: 'Uphold ruby'
|
12
|
+
)
|
13
|
+
Request.perform_with_object(:post, request_data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Uphold
|
2
|
+
module API
|
3
|
+
module Card
|
4
|
+
def all_cards
|
5
|
+
Request.perform_with_objects(:get, cards_request_data)
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_card(id: nil)
|
9
|
+
Request.perform_with_object(:get, card_request_data(id))
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_card(label: nil, currency: nil)
|
13
|
+
Request.perform_with_object(:post, cards_request_data(label: label, currency: currency))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def cards_request_data(payload = nil)
|
19
|
+
RequestData.new(
|
20
|
+
Endpoints::CARD,
|
21
|
+
Entities::Card,
|
22
|
+
authorization_header,
|
23
|
+
payload
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def card_request_data(id)
|
28
|
+
RequestData.new(
|
29
|
+
Endpoints::CARD + "/#{id}",
|
30
|
+
Entities::Card,
|
31
|
+
authorization_header
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Uphold
|
2
|
+
module API
|
3
|
+
module Contact
|
4
|
+
def all_contacts
|
5
|
+
request_data = RequestData.new(
|
6
|
+
Endpoints::USER_CONTACTS,
|
7
|
+
Entities::Contact,
|
8
|
+
authorization_header
|
9
|
+
)
|
10
|
+
Request.perform_with_objects(:get, request_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_contact(id: nil)
|
14
|
+
request_data = RequestData.new(
|
15
|
+
Endpoints::USER_CONTACTS + "/#{id}",
|
16
|
+
Entities::Contact,
|
17
|
+
authorization_header
|
18
|
+
)
|
19
|
+
Request.perform_with_object(:get, request_data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_contact(**args)
|
23
|
+
request_data = RequestData.new(
|
24
|
+
Endpoints::USER_CONTACTS,
|
25
|
+
Entities::Contact,
|
26
|
+
authorization_header,
|
27
|
+
Uphold::Helpers.camelized_hash(args)
|
28
|
+
)
|
29
|
+
|
30
|
+
Request.perform_with_object(:post, request_data)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Uphold
|
2
|
+
module Endpoints
|
3
|
+
AUTH = '/me/tokens'
|
4
|
+
CARD = '/me/cards'
|
5
|
+
CARD_PRIVATE_TRANSACTIONS = CARD + '/:card/transactions'
|
6
|
+
COMMIT_TRANSACTION = CARD_PRIVATE_TRANSACTIONS + '/:id/commit'
|
7
|
+
CANCEL_TRANSACTION = CARD_PRIVATE_TRANSACTIONS + '/:id/cancel'
|
8
|
+
RESEND_TRANSACTION = CARD_PRIVATE_TRANSACTIONS + '/:id/resend'
|
9
|
+
USER_PRIVATE_TRANSACTIONS = '/me/transactions'
|
10
|
+
PUBLIC_TRANSACTIONS = '/reserve/transactions'
|
11
|
+
LEDGER = '/reserve/ledger'
|
12
|
+
STATS = '/reserve/statistics'
|
13
|
+
TICKER = '/ticker'
|
14
|
+
USER = '/me'
|
15
|
+
USER_CONTACTS = '/me/contacts'
|
16
|
+
USER_PHONES = '/me/phones'
|
17
|
+
|
18
|
+
def self.with_placeholders(endpoint, substitutions = {})
|
19
|
+
new_endpoint = endpoint.dup
|
20
|
+
substitutions.each_pair do |placeholder, substitute|
|
21
|
+
new_endpoint.gsub!(placeholder, substitute)
|
22
|
+
end
|
23
|
+
new_endpoint
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Uphold
|
2
|
+
module API
|
3
|
+
module PrivateTransaction
|
4
|
+
def create_transaction(card_id: nil, currency: nil, amount: 0, destination: nil)
|
5
|
+
request_data = RequestData.new(
|
6
|
+
Endpoints.with_placeholders(Endpoints::CARD_PRIVATE_TRANSACTIONS, ':card' => card_id),
|
7
|
+
Entities::Transaction,
|
8
|
+
authorization_header,
|
9
|
+
card_id: card_id, denomination: { currency: currency, amount: amount }, destination: destination
|
10
|
+
)
|
11
|
+
Request.perform_with_object(:post, request_data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def commit_transaction(card_id: nil, transaction_id: nil)
|
15
|
+
request_data = transaction_request_data(Endpoints::COMMIT_TRANSACTION, card_id, transaction_id)
|
16
|
+
Request.perform_with_object(:post, request_data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def cancel_transaction(card_id: nil, transaction_id: nil)
|
20
|
+
request_data = transaction_request_data(Endpoints::CANCEL_TRANSACTION, card_id, transaction_id)
|
21
|
+
Request.perform_with_object(:post, request_data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def resend_transaction(card_id: nil, transaction_id: nil)
|
25
|
+
request_data = transaction_request_data(Endpoints::RESEND_TRANSACTION, card_id, transaction_id)
|
26
|
+
Request.perform_with_object(:post, request_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
def all_user_transactions(range: (0..4))
|
30
|
+
request_data = RequestData.new(
|
31
|
+
Endpoints::USER_PRIVATE_TRANSACTIONS,
|
32
|
+
Entities::Transaction,
|
33
|
+
authorization_header.merge(pagination_header_for_range(range))
|
34
|
+
)
|
35
|
+
Request.perform_with_objects(:get, request_data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_card_transactions(card_id: nil, range: (0..4))
|
39
|
+
request_data = RequestData.new(
|
40
|
+
Endpoints.with_placeholders(Endpoints::CARD_PRIVATE_TRANSACTIONS, ':card' => card_id),
|
41
|
+
Entities::Transaction,
|
42
|
+
authorization_header.merge(pagination_header_for_range(range))
|
43
|
+
)
|
44
|
+
Request.perform_with_objects(:get, request_data)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def transaction_request_data(endpoint, card_id, transaction_id)
|
50
|
+
RequestData.new(
|
51
|
+
Endpoints.with_placeholders(endpoint, ':card' => card_id, ':id' => transaction_id),
|
52
|
+
Entities::Transaction,
|
53
|
+
authorization_header
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Uphold
|
2
|
+
module API
|
3
|
+
module PublicTransaction
|
4
|
+
def all_public_transactions(range: (0..4))
|
5
|
+
request_data = RequestData.new(
|
6
|
+
Endpoints::PUBLIC_TRANSACTIONS,
|
7
|
+
Entities::Transaction,
|
8
|
+
authorization_header.merge(pagination_header_for_range(range))
|
9
|
+
)
|
10
|
+
Request.perform_with_objects(:get, request_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_public_transaction(id: '')
|
14
|
+
request_data = RequestData.new(
|
15
|
+
Endpoints::PUBLIC_TRANSACTIONS + "/#{id}",
|
16
|
+
Entities::Transaction,
|
17
|
+
authorization_header
|
18
|
+
)
|
19
|
+
Request.perform_with_object(:get, request_data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Uphold
|
2
|
+
module API
|
3
|
+
module Ticker
|
4
|
+
def all_tickers
|
5
|
+
request_data = RequestData.new(
|
6
|
+
Endpoints::TICKER,
|
7
|
+
Entities::Ticker,
|
8
|
+
authorization_header
|
9
|
+
)
|
10
|
+
Request.perform_with_objects(:get, request_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_ticker(currency: nil)
|
14
|
+
request_data = RequestData.new(
|
15
|
+
Endpoints::TICKER + "/#{currency}",
|
16
|
+
Entities::Ticker,
|
17
|
+
authorization_header
|
18
|
+
)
|
19
|
+
Request.perform_with_objects(:get, request_data)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Uphold
|
2
|
+
module API
|
3
|
+
module Transparency
|
4
|
+
def statistics
|
5
|
+
request_data = RequestData.new(Endpoints::STATS, Entities::Asset, authorization_header)
|
6
|
+
Request.perform_with_objects(:get, request_data)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ledger
|
10
|
+
request_data = RequestData.new(Endpoints::LEDGER, Entities::LedgerEntry, authorization_header)
|
11
|
+
Request.perform_with_objects(:get, request_data)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|