coinbase-custody-ruby 0.1.0
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/lib/coinbase_custody/address_book.rb +37 -0
- data/lib/coinbase_custody/addresses.rb +25 -0
- data/lib/coinbase_custody/client.rb +45 -0
- data/lib/coinbase_custody/transactions.rb +56 -0
- data/lib/coinbase_custody/util.rb +34 -0
- data/lib/coinbase_custody/wallets.rb +39 -0
- data/lib/coinbase_custody.rb +13 -0
- data/lib/generators/coinbase_custody/initialize_generator.rb +22 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 52668c29e8449e04ca1db45140c9789c3f6c6703a8d22cf81311ac449d5944f6
|
4
|
+
data.tar.gz: 440abb3989668b9324a844a67aebcdd794735c3dc9e2a2ea04f50ea43bb3ea38
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b90fc6dd8f90d57f708063e585054b77129cbb56579c59008605a4058d8ac122a67d615acd08a5de0a614954cbbfcc857752d94ab47b6246d3d09487f7c1f84
|
7
|
+
data.tar.gz: 9889f3ddec10a5679eff629797811c289daf735371b0ff62b3df4e45b68bbb5d8b43948fa3794bfae2282e4c770e083e8cd37c03f5c78c12286bbfb941d4aa18
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinbaseCustody
|
4
|
+
# AddressBook API
|
5
|
+
class AddressBook < Client
|
6
|
+
ADDRESS_BOOK_PATH = '/address_book'
|
7
|
+
|
8
|
+
# Gets a list of address book addresses
|
9
|
+
#
|
10
|
+
# Retrieve a list of addresses in your organization's address book
|
11
|
+
# The response value can be filtered by query parameters.
|
12
|
+
# @params [String] currency optional the currency to filter
|
13
|
+
# @params [String] account_identifier optional the account identifier to
|
14
|
+
# filter by
|
15
|
+
# @params [String] name optional The name to filter by
|
16
|
+
# @params [String] address optional the address to filter
|
17
|
+
# @return [Hash] a hash with status code and organization's address book
|
18
|
+
def list(params = {})
|
19
|
+
format_response(get(ADDRESS_BOOK_PATH, query: params))
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a new address book address
|
23
|
+
#
|
24
|
+
# Request a new address be added to your organization's address book
|
25
|
+
# @params [String] currency required The currency of the new allowed address
|
26
|
+
# @params [String] account_identifier required The name of the
|
27
|
+
# new allowed address
|
28
|
+
# @params [String] name required The crypto address of the
|
29
|
+
# new allowed address
|
30
|
+
# @params [String] address optional The account identifier of the new
|
31
|
+
# allowed address
|
32
|
+
# @return [Hash] a hash with status code and address detail
|
33
|
+
def create(address_book_details)
|
34
|
+
format_response(post(ADDRESS_BOOK_PATH, body: address_book_details))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinbaseCustody
|
4
|
+
# Addresses APIs
|
5
|
+
class Addresses < Client
|
6
|
+
ADDRESSES_PATH = '/addresses'
|
7
|
+
# Get a list of all crypto addresses associated with the account.
|
8
|
+
|
9
|
+
# @params [String] wallet_id
|
10
|
+
# @params [String] currency
|
11
|
+
# @params [String] state e.g cold, restore_in_progress, restored
|
12
|
+
# @return [Hash] list of addresses
|
13
|
+
def list(params = {})
|
14
|
+
format_response(get(ADDRESSES_PATH, query: params))
|
15
|
+
end
|
16
|
+
|
17
|
+
# Gets a single address.
|
18
|
+
|
19
|
+
# @params [String] address
|
20
|
+
# @return [Hash] address details
|
21
|
+
def fetch(address)
|
22
|
+
format_response(get("#{ADDRESSES_PATH}/#{address}"))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
module CoinbaseCustody
|
6
|
+
# Client
|
7
|
+
class Client
|
8
|
+
include Util
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@url = COINBASE_CUSTODY_CONFIG[:url]
|
12
|
+
@access_key = COINBASE_CUSTODY_CONFIG[:api_access_key]
|
13
|
+
@passphrase = COINBASE_CUSTODY_CONFIG[:passphrase]
|
14
|
+
[@url, @access_key, @passphrase].each do |opt|
|
15
|
+
raise 'Missing coinbase custody credentials' if opt.blank?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def headers
|
20
|
+
{
|
21
|
+
'Content-Type' => 'application/json',
|
22
|
+
'Cb-Access-Key' => @access_key,
|
23
|
+
'Cb-Access-Passphrase' => @passphrase
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def http_request(request_params: {}, body: nil)
|
28
|
+
request_params.merge!(headers: headers)
|
29
|
+
request_params.merge!(body: body.to_json) if body.present?
|
30
|
+
yield(request_params) if block_given?
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(path, params = {})
|
34
|
+
http_request(request_params: params) do |request_params|
|
35
|
+
HTTParty.get("#{@url}#{path}", request_params)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def post(path, body: nil)
|
40
|
+
http_request(body: body) do |request_params|
|
41
|
+
HTTParty.post("#{@url}#{path}", request_params)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinbaseCustody
|
4
|
+
# Coinbase Transaction APIs
|
5
|
+
class Transactions < Client
|
6
|
+
TRANSACTIONS_PATH = '/transactions'
|
7
|
+
|
8
|
+
# Retrieve a list of the transactions from organization.
|
9
|
+
# The response is filterable by query parameters.
|
10
|
+
#
|
11
|
+
# @param [Hash] The hash with the following parameters
|
12
|
+
# currency [String] The type of currency to filter.
|
13
|
+
# state [String] The state of transactions to filter.
|
14
|
+
# type [String] The type of transactions to filter.
|
15
|
+
# wallet_id [String] The wallet id to filter.
|
16
|
+
# start_time [String] The start time to filter.
|
17
|
+
# end_time [String] The end time to filter.
|
18
|
+
# human_id [String] The human id to filter.
|
19
|
+
# before [String] Request page before (newer) this
|
20
|
+
# pagination id (optional).
|
21
|
+
# after [String] Request page after (older) this pagination id
|
22
|
+
# (optional).
|
23
|
+
# limit [Integer] Number of results per request.
|
24
|
+
# @return [Hash] a list of transactions records.
|
25
|
+
def list(params = {})
|
26
|
+
format_response(get(TRANSACTIONS_PATH, query: params))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Gets a single transaction by id
|
30
|
+
#
|
31
|
+
# @param id [String] The transaction id to retrieve
|
32
|
+
# @return [Hash] The information about a single transaction
|
33
|
+
# from organization.
|
34
|
+
def fetch(transaction_id)
|
35
|
+
format_response(get("#{TRANSACTIONS_PATH}/#{transaction_id}"))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Creates a new withdrawal transaction
|
39
|
+
#
|
40
|
+
# @param params [Hash] The hash with the following parameters
|
41
|
+
# body [Object] The create transaction payload
|
42
|
+
# source [String] The source wallet id for the transaction
|
43
|
+
# currency [String] A fiat currency symbol such as USD.
|
44
|
+
# If provided Custody will automatically convert the amount value
|
45
|
+
# into crypto units.
|
46
|
+
# whole_amount [String] The amount of the transaction in
|
47
|
+
# whole units (e.g. "1.01")
|
48
|
+
# destination [String] The destination address of the transaction
|
49
|
+
# account_identifier [String] The account identifier of the transaction
|
50
|
+
# (for example destination tag or memo value)
|
51
|
+
# @return [Hash] Created transaction record
|
52
|
+
def create(params = {})
|
53
|
+
format_response(post(TRANSACTIONS_PATH, body: params))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinbaseCustody
|
4
|
+
# Utility file for general methods
|
5
|
+
module Util
|
6
|
+
BASE_API_URL = COINBASE_CUSTODY_CONFIG[:url]
|
7
|
+
|
8
|
+
def send_request(path)
|
9
|
+
headers = {
|
10
|
+
'Content-Type' => 'application/json',
|
11
|
+
'Accept' => 'application/json',
|
12
|
+
'User-Agent' => 'request'
|
13
|
+
}
|
14
|
+
response = HTTParty.get("#{BASE_API_URL}#{path}", headers: headers)
|
15
|
+
format_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def format_response(response)
|
19
|
+
{
|
20
|
+
status: response.code,
|
21
|
+
result: (JSON.parse(response.body) rescue response.body),
|
22
|
+
pagination: pagination_params(response.headers)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def pagination_params(headers = {})
|
27
|
+
if headers['cb-before'].blank? || headers['cb-after'].blank?
|
28
|
+
return {}
|
29
|
+
end
|
30
|
+
|
31
|
+
{ before: headers['cb-before'], after: headers['cb-after'] }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CoinbaseCustody
|
4
|
+
# Wallets API's
|
5
|
+
class Wallets < Client
|
6
|
+
WALLETS_PATH = '/wallets'
|
7
|
+
|
8
|
+
# Gets a list of wallets
|
9
|
+
#
|
10
|
+
# Retrieve a list of your organization's wallets.
|
11
|
+
# The response value can be filtered by query parameters.
|
12
|
+
# @params [String] currency optional the currency to filter
|
13
|
+
# @return [Hash] a hash with status code and organization's wallets
|
14
|
+
def list(params = {})
|
15
|
+
format_response(get(WALLETS_PATH, query: params))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Creates a new wallet
|
19
|
+
#
|
20
|
+
# Request a new wallet be created for your organization
|
21
|
+
# The response value can be filtered by query parameters.
|
22
|
+
# @params [String] currency required the currency
|
23
|
+
# @params [String] name required the name for wallet
|
24
|
+
# @return [Hash] a hash with status code and wallet creation detail such as
|
25
|
+
# apporval_url, currency, name, activity_id
|
26
|
+
def create(wallet_details)
|
27
|
+
format_response(post(WALLETS_PATH, body: wallet_details))
|
28
|
+
end
|
29
|
+
|
30
|
+
# fetch a specific wallet by id
|
31
|
+
#
|
32
|
+
# Retrieve information about an individual wallet for your organization.
|
33
|
+
# @params [String] wallet id
|
34
|
+
# @return [Hash] a hash with status code and wallet details
|
35
|
+
def fetch(wallet_id)
|
36
|
+
format_response(get("#{WALLETS_PATH}/#{wallet_id}"))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'coinbase_custody/util'
|
5
|
+
require 'coinbase_custody/client'
|
6
|
+
require 'coinbase_custody/addresses'
|
7
|
+
require 'coinbase_custody/address_book'
|
8
|
+
require 'coinbase_custody/transactions'
|
9
|
+
require 'coinbase_custody/wallets'
|
10
|
+
|
11
|
+
# Coinbase base module
|
12
|
+
module CoinbaseCustody
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
module CoinbaseCustody
|
5
|
+
module Generators
|
6
|
+
# YML file generator
|
7
|
+
class InitializeGenerator < Rails::Generators::Base
|
8
|
+
def create_initializer_file
|
9
|
+
yaml_file = {
|
10
|
+
development: {
|
11
|
+
url: '',
|
12
|
+
api_access_key: '',
|
13
|
+
passphrase: ''
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
create_file 'config/coinbase_custody.yml', yaml_file.to_yaml
|
18
|
+
create_file 'config/initializers/coinbase_custody.rb', "COINBASE_CUSTODY_CONFIG = YAML.load_file(Rails.root.join('config', 'coinbase_custody.yml'))"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coinbase-custody-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ''
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: vcr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httparty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.13.7
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.13.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-airbnb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.2
|
97
|
+
description: Ruby coinbase custody APIs wrapper
|
98
|
+
email: ''
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- lib/coinbase_custody.rb
|
104
|
+
- lib/coinbase_custody/address_book.rb
|
105
|
+
- lib/coinbase_custody/addresses.rb
|
106
|
+
- lib/coinbase_custody/client.rb
|
107
|
+
- lib/coinbase_custody/transactions.rb
|
108
|
+
- lib/coinbase_custody/util.rb
|
109
|
+
- lib/coinbase_custody/wallets.rb
|
110
|
+
- lib/generators/coinbase_custody/initialize_generator.rb
|
111
|
+
homepage: ''
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.7.8
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Ruby coinbase custody APIs wrapper
|
135
|
+
test_files: []
|