coinbase 0.0.1 → 4.0.7

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.

Potentially problematic release.


This version of coinbase might be problematic. Click here for more details.

Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +611 -0
  6. data/Rakefile +7 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +7 -0
  9. data/coinbase.gemspec +27 -0
  10. data/lib/coinbase/wallet/adapters/em_http.rb +78 -0
  11. data/lib/coinbase/wallet/adapters/net_http.rb +68 -0
  12. data/lib/coinbase/wallet/api_client.rb +692 -0
  13. data/lib/coinbase/wallet/api_errors.rb +120 -0
  14. data/lib/coinbase/wallet/api_response.rb +41 -0
  15. data/lib/coinbase/wallet/ca-coinbase.crt +629 -0
  16. data/lib/coinbase/wallet/client.rb +101 -0
  17. data/lib/coinbase/wallet/models/account.rb +187 -0
  18. data/lib/coinbase/wallet/models/address.rb +12 -0
  19. data/lib/coinbase/wallet/models/api_object.rb +46 -0
  20. data/lib/coinbase/wallet/models/checkout.rb +19 -0
  21. data/lib/coinbase/wallet/models/order.rb +12 -0
  22. data/lib/coinbase/wallet/models/transaction.rb +21 -0
  23. data/lib/coinbase/wallet/models/transfer.rb +13 -0
  24. data/lib/coinbase/wallet/models/user.rb +15 -0
  25. data/lib/coinbase/wallet/version.rb +5 -0
  26. data/lib/coinbase/wallet.rb +23 -156
  27. data/spec/account_spec.rb +193 -0
  28. data/spec/clients/client_spec.rb +34 -0
  29. data/spec/clients/oauth_client_spec.rb +56 -0
  30. data/spec/endpoints_spec.rb +352 -0
  31. data/spec/error_spec.rb +137 -0
  32. data/spec/models/address_spec.rb +26 -0
  33. data/spec/models/api_object_spec.rb +63 -0
  34. data/spec/models/checkout_spec.rb +52 -0
  35. data/spec/models/current_user_spec.rb +29 -0
  36. data/spec/models/order_spec.rb +52 -0
  37. data/spec/models/request_spec.rb +47 -0
  38. data/spec/models/transfer_spec.rb +64 -0
  39. data/spec/models/user_spec.rb +24 -0
  40. data/spec/spec_helper.rb +13 -0
  41. metadata +62 -98
  42. data/lib/coinbase/address.rb +0 -127
  43. data/lib/coinbase/asset.rb +0 -20
  44. data/lib/coinbase/balance_map.rb +0 -48
  45. data/lib/coinbase/constants.rb +0 -38
  46. data/lib/coinbase/network.rb +0 -55
  47. data/lib/coinbase/transfer.rb +0 -153
  48. data/lib/coinbase.rb +0 -18
@@ -0,0 +1,692 @@
1
+ module Coinbase
2
+ module Wallet
3
+ class APIClient
4
+ def auth_headers(method, path, body)
5
+ raise NotImplementedError, "APIClient is not intended to be used directly"
6
+ end
7
+
8
+ #
9
+ # Market Data
10
+ #
11
+ def currencies(params = {})
12
+ out = nil
13
+ get("/v2/currencies", params) do |resp|
14
+ out = resp.data.map { |item| APIObject.new(self, item) }
15
+ yield(out, resp) if block_given?
16
+ end
17
+ out
18
+ end
19
+
20
+ def exchange_rates(params = {})
21
+ out = nil
22
+ get("/v2/exchange-rates", params) do |resp|
23
+ out = resp.data.map { |item| APIObject.new(self, item) }
24
+ yield(out, resp) if block_given?
25
+ end
26
+ out
27
+ end
28
+
29
+ def buy_price(params = {})
30
+ out = nil
31
+ get("/v2/prices/buy", params) do |resp|
32
+ out = APIObject.new(self, resp.data)
33
+ yield(out, resp) if block_given?
34
+ end
35
+ out
36
+ end
37
+
38
+ def sell_price(params = {})
39
+ out = nil
40
+ get("/v2/prices/sell", params) do |resp|
41
+ out = APIObject.new(self, resp.data)
42
+ yield(out, resp) if block_given?
43
+ end
44
+ out
45
+ end
46
+ def spot_price(params = {})
47
+ out = nil
48
+ get("/v2/prices/spot", params) do |resp|
49
+ out = APIObject.new(self, resp.data)
50
+ yield(out, resp) if block_given?
51
+ end
52
+ out
53
+ end
54
+
55
+ def time(params = {})
56
+ out = nil
57
+ get("/v2/time", params) do |resp|
58
+ out = APIObject.new(self, resp.data)
59
+ yield(out, resp) if block_given?
60
+ end
61
+ out
62
+ end
63
+
64
+ #
65
+ # Users
66
+ #
67
+ def user(user_id, params = {})
68
+ out = nil
69
+ get("/v2/users/#{user_id}", params) do |resp|
70
+ out = User.new(self, resp.data)
71
+ yield(out, resp) if block_given?
72
+ end
73
+ out
74
+ end
75
+
76
+ def current_user(params = {})
77
+ out = nil
78
+ get("/v2/user", params) do |resp|
79
+ out = CurrentUser.new(self, resp.data)
80
+ yield(out, resp) if block_given?
81
+ end
82
+ out
83
+ end
84
+
85
+ def auth_info(params = {})
86
+ out = nil
87
+ get("/v2/user/auth", params) do |resp|
88
+ out = APIObject.new(self, resp.data)
89
+ yield(out, resp) if block_given?
90
+ end
91
+ out
92
+ end
93
+
94
+ def update_current_user(params = {})
95
+ out = nil
96
+ put("/v2/user", params) do |resp|
97
+ out = CurrentUser.new(self, resp.data)
98
+ yield(out, resp) if block_given?
99
+ end
100
+ out
101
+ end
102
+
103
+ #
104
+ # Accounts
105
+ #
106
+ def accounts(params = {})
107
+ out = nil
108
+ get("/v2/accounts", params) do |resp|
109
+ out = resp.data.map { |item| Account.new(self, item) }
110
+ yield(out, resp) if block_given?
111
+ end
112
+ out
113
+ end
114
+
115
+ def account(account_id, params = {})
116
+ out = nil
117
+ get("/v2/accounts/#{account_id}", params) do |resp|
118
+ out = Account.new(self, resp.data)
119
+ yield(out, resp) if block_given?
120
+ end
121
+ out
122
+ end
123
+
124
+ def primary_account(params = {})
125
+ out = nil
126
+ get("/v2/accounts/primary", params) do |resp|
127
+ out = Account.new(self, resp.data)
128
+ yield(out, resp) if block_given?
129
+ end
130
+ out
131
+ end
132
+
133
+ def set_primary_account(account_id, params = {})
134
+ out = nil
135
+ post("/v2/accounts/#{account_id}/primary", params) do |resp|
136
+ out = Account.new(self, resp.data)
137
+ yield(out, resp) if block_given?
138
+ end
139
+ out
140
+ end
141
+
142
+ def create_account(params = {})
143
+ out = nil
144
+ post("/v2/accounts", params) do |resp|
145
+ out = Account.new(self, resp.data)
146
+ yield(out, resp) if block_given?
147
+ end
148
+ out
149
+ end
150
+
151
+ def update_account(account_id, params = {})
152
+ out = nil
153
+ put("/v2/accounts/#{account_id}", params) do |resp|
154
+ out = Account.new(self, resp.data)
155
+ yield(out, resp) if block_given?
156
+ end
157
+ out
158
+ end
159
+
160
+ def delete_account(account_id, params = {})
161
+ out = nil
162
+ delete("/v2/accounts/#{account_id}", params) do |resp|
163
+ out = APIObject.new(self, resp.data)
164
+ yield(out, resp) if block_given?
165
+ end
166
+ out
167
+ end
168
+
169
+ #
170
+ # Addresses
171
+ #
172
+ def addresses(account_id, params = {})
173
+ out = nil
174
+ get("/v2/accounts/#{account_id}/addresses", params) do |resp|
175
+ out = resp.data.map { |item| Address.new(self, item) }
176
+ yield(out, resp) if block_given?
177
+ end
178
+ out
179
+ end
180
+
181
+ def address(account_id, address_id, params = {})
182
+ out = nil
183
+ get("/v2/accounts/#{account_id}/addresses/#{address_id}", params) do |resp|
184
+ out = Address.new(self, resp.data)
185
+ yield(out, resp) if block_given?
186
+ end
187
+ out
188
+ end
189
+
190
+ def address_transactions(account_id, address_id, params = {})
191
+ out = nil
192
+ get("/v2/accounts/#{account_id}/addresses/#{address_id}/transactions", params) do |resp|
193
+ out = resp.data.map { |item| Transaction.new(self, item) }
194
+ yield(out, resp) if block_given?
195
+ end
196
+ out
197
+ end
198
+
199
+ def create_address(account_id, params = {})
200
+ out = nil
201
+ post("/v2/accounts/#{account_id}/addresses", params) do |resp|
202
+ out = Address.new(self, resp.data)
203
+ yield(out, resp) if block_given?
204
+ end
205
+ out
206
+ end
207
+
208
+ #
209
+ # Transactions
210
+ #
211
+ def transactions(account_id, params = {})
212
+ out = nil
213
+ get("/v2/accounts/#{account_id}/transactions", params) do |resp|
214
+ out = resp.data.map { |item| Transaction.new(self, item) }
215
+ yield(out, resp) if block_given?
216
+ end
217
+ out
218
+ end
219
+
220
+ def transaction(account_id, transaction_id, params = {})
221
+ out = nil
222
+ get("/v2/accounts/#{account_id}/transactions/#{transaction_id}", params) do |resp|
223
+ out = Transaction.new(self, resp.data)
224
+ yield(out, resp) if block_given?
225
+ end
226
+ out
227
+ end
228
+
229
+ def send(account_id, params = {})
230
+ [ :to, :amount ].each do |param|
231
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
232
+ end
233
+ params['type'] = 'send'
234
+
235
+ out = nil
236
+ post("/v2/accounts/#{account_id}/transactions", params) do |resp|
237
+ out = Transaction.new(self, resp.data)
238
+ yield(out, resp) if block_given?
239
+ end
240
+ out
241
+ end
242
+
243
+ def transfer(account_id, params = {})
244
+ [ :to, :amount ].each do |param|
245
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
246
+ end
247
+ params['type'] = 'transfer'
248
+
249
+ out = nil
250
+ post("/v2/accounts/#{account_id}/transactions", params) do |resp|
251
+ out = Transaction.new(self, resp.data)
252
+ yield(out, resp) if block_given?
253
+ end
254
+ out
255
+ end
256
+
257
+ def request(account_id, params = {})
258
+ [ :to, :amount, :currency ].each do |param|
259
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
260
+ end
261
+ params['type'] = 'request'
262
+
263
+ out = nil
264
+ post("/v2/accounts/#{account_id}/transactions", params) do |resp|
265
+ out = Request.new(self, resp.data)
266
+ yield(out, resp) if block_given?
267
+ end
268
+ out
269
+ end
270
+
271
+ def resend_request(account_id, transaction_id, params = {})
272
+ out = nil
273
+ post("/v2/accounts/#{account_id}/transactions/#{transaction_id}/resend", params) do |resp|
274
+ out = APIObject.new(self, resp.data)
275
+ yield(out, resp) if block_given?
276
+ end
277
+ out
278
+ end
279
+
280
+ def cancel_request(account_id, transaction_id, params = {})
281
+ out = nil
282
+ delete("/v2/accounts/#{account_id}/transactions/#{transaction_id}", params) do |resp|
283
+ out = APIObject.new(self, resp.data)
284
+ yield(out, resp) if block_given?
285
+ end
286
+ out
287
+ end
288
+
289
+ def complete_request(account_id, transaction_id, params = {})
290
+ out = nil
291
+ post("/v2/accounts/#{account_id}/transactions/#{transaction_id}/complete", params) do |resp|
292
+ out = APIObject.new(self, resp.data)
293
+ yield(out, resp) if block_given?
294
+ end
295
+ out
296
+ end
297
+
298
+ #
299
+ # Buys
300
+ #
301
+ def list_buys(account_id, params={})
302
+ out = nil
303
+ get("/v2/accounts/#{account_id}/buys", params) do |resp|
304
+ out = resp.data.map { |item| Transfer.new(self, item) }
305
+ yield(out, resp) if block_given?
306
+ end
307
+ out
308
+ end
309
+
310
+ def list_buy(account_id, transaction_id, params = {})
311
+ out = nil
312
+ get("/v2/accounts/#{account_id}/buys/#{transaction_id}", params) do |resp|
313
+ out = Transfer.new(self, resp.data)
314
+ yield(out, resp) if block_given?
315
+ end
316
+ out
317
+ end
318
+
319
+ def buy(account_id, params = {})
320
+ [ :amount ].each do |param|
321
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
322
+ end
323
+
324
+ out = nil
325
+ post("/v2/accounts/#{account_id}/buys", params) do |resp|
326
+ out = Transfer.new(self, resp.data)
327
+ yield(out, resp) if block_given?
328
+ end
329
+ out
330
+ end
331
+
332
+ def commit_buy(account_id, transaction_id, params = {})
333
+ out = nil
334
+ post("/v2/accounts/#{account_id}/buys/#{transaction_id}/commit", params) do |resp|
335
+ out = Transfer.new(self, resp.data)
336
+ yield(out, resp) if block_given?
337
+ end
338
+ out
339
+ end
340
+
341
+ #
342
+ # Sells
343
+ #
344
+ def list_sells(account_id, params = {})
345
+ out = nil
346
+ get("/v2/accounts/#{account_id}/sells", params) do |resp|
347
+ out = resp.data.map { |item| Transfer.new(self, item) }
348
+ yield(out, resp) if block_given?
349
+ end
350
+ out
351
+ end
352
+
353
+ def list_sell(account_id, transaction_id, params = {})
354
+ out = nil
355
+ get("/v2/accounts/#{account_id}/sells/#{transaction_id}", params) do |resp|
356
+ out = Transfer.new(self, resp.data)
357
+ yield(out, resp) if block_given?
358
+ end
359
+ out
360
+ end
361
+
362
+ def sell(account_id, params = {})
363
+ [ :amount ].each do |param|
364
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
365
+ end
366
+
367
+ out = nil
368
+ post("/v2/accounts/#{account_id}/sells", params) do |resp|
369
+ out = Transfer.new(self, resp.data)
370
+ yield(out, resp) if block_given?
371
+ end
372
+ out
373
+ end
374
+
375
+ def commit_sell(account_id, transaction_id, params = {})
376
+ out = nil
377
+ post("/v2/accounts/#{account_id}/sells/#{transaction_id}/commit", params) do |resp|
378
+ out = Transfer.new(self, resp.data)
379
+ yield(out, resp) if block_given?
380
+ end
381
+ out
382
+ end
383
+
384
+ #
385
+ # Deposits
386
+ #
387
+ def list_deposits(account_id, params={})
388
+ out = nil
389
+ get("/v2/accounts/#{account_id}/deposits", params) do |resp|
390
+ out = resp.data.map { |item| Transfer.new(self, item) }
391
+ yield(out, resp) if block_given?
392
+ end
393
+ out
394
+ end
395
+
396
+ def list_deposit(account_id, transaction_id, params = {})
397
+ out = nil
398
+ get("/v2/accounts/#{account_id}/deposits/#{transaction_id}", params) do |resp|
399
+ out = Transfer.new(self, resp.data)
400
+ yield(out, resp) if block_given?
401
+ end
402
+ out
403
+ end
404
+
405
+ def deposit(account_id, params = {})
406
+ [ :amount ].each do |param|
407
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
408
+ end
409
+
410
+ out = nil
411
+ post("/v2/accounts/#{account_id}/deposits", params) do |resp|
412
+ out = Transfer.new(self, resp.data)
413
+ yield(out, resp) if block_given?
414
+ end
415
+ out
416
+ end
417
+
418
+ def commit_deposit(account_id, transaction_id, params = {})
419
+ out = nil
420
+ post("/v2/accounts/#{account_id}/deposits/#{transaction_id}/commit", params) do |resp|
421
+ out = APIObject.new(self, resp.data)
422
+ yield(out, resp) if block_given?
423
+ end
424
+ out
425
+ end
426
+
427
+ #
428
+ # withdrawals
429
+ #
430
+ def list_withdrawals(account_id, params={})
431
+ out = nil
432
+ get("/v2/accounts/#{account_id}/withdrawals", params) do |resp|
433
+ out = resp.data.map { |item| Transfer.new(self, item) }
434
+ yield(out, resp) if block_given?
435
+ end
436
+ out
437
+ end
438
+
439
+ def list_withdrawal(account_id, transaction_id, params = {})
440
+ out = nil
441
+ get("/v2/accounts/#{account_id}/withdrawals/#{transaction_id}", params) do |resp|
442
+ out = Transfer.new(self, resp.data)
443
+ yield(out, resp) if block_given?
444
+ end
445
+ out
446
+ end
447
+
448
+ def withdraw(account_id, params = {})
449
+ [ :amount ].each do |param|
450
+ raise APIError, "Missing parameter: #{param}" unless params.include? param
451
+ end
452
+
453
+ out = nil
454
+ post("/v2/accounts/#{account_id}/withdrawals", params) do |resp|
455
+ out = Transfer.new(self, resp.data)
456
+ yield(out, resp) if block_given?
457
+ end
458
+ out
459
+ end
460
+
461
+ def commit_withdrawal(account_id, transaction_id, params = {})
462
+ out = nil
463
+ post("/v2/accounts/#{account_id}/withdrawals/#{transaction_id}/commit", params) do |resp|
464
+ out = APIObject.new(self, resp.data)
465
+ yield(out, resp) if block_given?
466
+ end
467
+ out
468
+ end
469
+
470
+ #
471
+ # Payment Methods
472
+ #
473
+ def payment_methods(params = {})
474
+ out = nil
475
+ get("/v2/payment-methods", params) do |resp|
476
+ out = resp.data.map { |item| APIObject.new(self, item) }
477
+ yield(out, resp) if block_given?
478
+ end
479
+ out
480
+ end
481
+
482
+ def payment_method(payment_method_id, params = {})
483
+ out = nil
484
+ get("/v2/payment-methods/#{payment_method_id}", params) do |resp|
485
+ out = APIObject.new(self, resp.data)
486
+ yield(out, resp) if block_given?
487
+ end
488
+ out
489
+ end
490
+
491
+ #
492
+ # Merchants
493
+ #
494
+ def merchant(merchant_id, params = {})
495
+ out = nil
496
+ get("/v2/merchants/#{merchant_id}", params) do |resp|
497
+ out = APIObject.new(self, resp.data)
498
+ yield(out, resp) if block_given?
499
+ end
500
+ out
501
+ end
502
+
503
+ #
504
+ # Orders
505
+ #
506
+ def orders(params = {})
507
+ out = nil
508
+ get("/v2/orders", params) do |resp|
509
+ out = resp.data.map { |item| Order.new(self, item) }
510
+ yield(out, resp) if block_given?
511
+ end
512
+ out
513
+ end
514
+
515
+ def order(order_id, params = {})
516
+ out = nil
517
+ get("/v2/orders/#{order_id}", params) do |resp|
518
+ out = Order.new(self, resp.data)
519
+ yield(out, resp) if block_given?
520
+ end
521
+ out
522
+ end
523
+
524
+ def create_order(params = {})
525
+ [ :amount, :currency, :name ].each do |param|
526
+ fail APIError, "Missing parameter: #{param}" unless params.include? param
527
+ end
528
+
529
+ out = nil
530
+ post("/v2/orders", params) do |resp|
531
+ out = Order.new(self, resp.data)
532
+ yield(out, resp) if block_given?
533
+ end
534
+ out
535
+ end
536
+
537
+ def refund_order(order_id, params={})
538
+ [ :currency ].each do |param|
539
+ fail APIError, "Missing parameter: #{param}" unless params.include? param
540
+ end
541
+
542
+ out = nil
543
+ post("/v2/orders/#{order_id}/refund", params) do |resp|
544
+ out = Order.new(self, resp.data)
545
+ yield(out, resp) if block_given?
546
+ end
547
+ out
548
+ end
549
+
550
+ #
551
+ # Checkouts
552
+ #
553
+ def checkouts(params = {})
554
+ out = nil
555
+ get("/v2/checkouts", params) do |resp|
556
+ out = resp.data.map { |item| Checkout.new(self, item) }
557
+ yield(out, resp) if block_given?
558
+ end
559
+ out
560
+ end
561
+
562
+ def checkout(checkout_id, params = {})
563
+ out = nil
564
+ get("/v2/checkouts/#{checkout_id}", params) do |resp|
565
+ out = Checkout.new(self, resp.data)
566
+ yield(out, resp) if block_given?
567
+ end
568
+ out
569
+ end
570
+
571
+ def create_checkout(params = {})
572
+ [ :amount, :currency, :name ].each do |param|
573
+ fail APIError, "Missing parameter: #{param}" unless params.include? param
574
+ end
575
+
576
+ out = nil
577
+ post("/v2/checkouts", params) do |resp|
578
+ out = Checkout.new(self, resp.data)
579
+ yield(out, resp) if block_given?
580
+ end
581
+ out
582
+ end
583
+
584
+ def checkout_orders(checkout_id, params = {})
585
+ out = nil
586
+ get("/v2/checkouts/#{checkout_id}/orders", params) do |resp|
587
+ out = resp.data.map { |item| Order.new(self, item) }
588
+ yield(out, resp) if block_given?
589
+ end
590
+ out
591
+ end
592
+
593
+ def create_checkout_order(checkout_id, params={})
594
+ out = nil
595
+ post("/v2/checkouts/#{checkout_id}/orders", params) do |resp|
596
+ out = Order.new(self, resp.data)
597
+ yield(out, resp) if block_given?
598
+ end
599
+ out
600
+ end
601
+
602
+ #
603
+ # HTTP Stuff
604
+ #
605
+ def get(path, params)
606
+ uri = path
607
+ if params.count > 0
608
+ uri += "?#{URI.encode_www_form(params)}"
609
+ end
610
+
611
+ headers = {}
612
+ if params.has_key? :two_factor_token
613
+ headers['CB-2FA-TOKEN'] = params[:two_factor_token]
614
+ params.delete(:two_factor_token)
615
+ end
616
+
617
+ http_verb('GET', uri, nil, headers) do |resp|
618
+ if params[:fetch_all] == true &&
619
+ resp.body.has_key?('pagination') &&
620
+ resp.body['pagination']['next_uri'] != nil
621
+ params[:starting_after] = resp.body['data'].last['id']
622
+ get(path, params) do |page|
623
+ body = resp.body
624
+ body['data'] += page.data
625
+ resp.body = body
626
+ yield(resp)
627
+ end
628
+ else
629
+ yield(resp)
630
+ end
631
+ end
632
+ end
633
+
634
+ def put(path, params)
635
+ headers = {}
636
+ if params.has_key? :two_factor_token
637
+ headers['CB-2FA-TOKEN'] = params[:two_factor_token]
638
+ params.delete(:two_factor_token)
639
+ end
640
+
641
+ http_verb('PUT', path, params.to_json, headers) do |resp|
642
+ yield(resp)
643
+ end
644
+ end
645
+
646
+ def post(path, params)
647
+ headers = {}
648
+ if params.has_key? :two_factor_token
649
+ headers['CB-2FA-TOKEN'] = params[:two_factor_token]
650
+ params.delete(:two_factor_token)
651
+ end
652
+
653
+ http_verb('POST', path, params.to_json, headers) do |resp|
654
+ yield(resp)
655
+ end
656
+ end
657
+
658
+ def delete(path, params)
659
+ headers = {}
660
+ if params.has_key? :two_factor_token
661
+ headers['CB-2FA-TOKEN'] = params[:two_factor_token]
662
+ params.delete(:two_factor_token)
663
+ end
664
+
665
+ http_verb('DELETE', path, nil, headers) do |resp|
666
+ yield(resp)
667
+ end
668
+ end
669
+
670
+ def self.whitelisted_certificates
671
+ path = File.expand_path(File.join(File.dirname(__FILE__), 'ca-coinbase.crt'))
672
+
673
+ certs = [ [] ]
674
+ File.readlines(path).each do |line|
675
+ next if ["\n","#"].include?(line[0])
676
+ certs.last << line
677
+ certs << [] if line == "-----END CERTIFICATE-----\n"
678
+ end
679
+
680
+ result = OpenSSL::X509::Store.new
681
+
682
+ certs.each do |lines|
683
+ next if lines.empty?
684
+ cert = OpenSSL::X509::Certificate.new(lines.join)
685
+ result.add_cert(cert)
686
+ end
687
+
688
+ result
689
+ end
690
+ end
691
+ end
692
+ end