arkecosystem-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 958be54c0939a1111806b826bb21b532e07a41e9707c36cef424128a00b1d319
4
+ data.tar.gz: dbf364ac0a812da66ec70269d4d63c4241dea8704aa2d21dbede58c9bc941cfe
5
+ SHA512:
6
+ metadata.gz: 16ead079fddf532ea8643a0e3bab41c193772848e429dfe7b2f6fb405603bf5581924f89dd52d1ffbb42be884babfdf2f7bfd43ac6cfb8a75c713914eed828e4
7
+ data.tar.gz: d0cde8bda58261812840860ee16b4b02599f2a0f6241873e350196f14fd827da8b33ec38ca3d25ecd35bd0662b13b651a2f1b5d5b48be872c211b6ee7a8f4e40
@@ -0,0 +1,2 @@
1
+ require 'arkecosystem/client/connection'
2
+ require 'arkecosystem/client/connection_manager'
@@ -0,0 +1,17 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # The base for any API resources.
7
+ class Base
8
+ # Create a new resource instance.
9
+ #
10
+ # @param client [Object]
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-accounts
9
+ module One
10
+ # Methods for the Accounts API
11
+ class Accounts < Base
12
+ # Get the balance for the given address.
13
+ #
14
+ # @param address [String]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def balance(address)
18
+ @client.get('accounts/getBalance', address: address)
19
+ end
20
+
21
+ # Get the public key for the given address.
22
+ #
23
+ # @param address [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def public_key(address)
27
+ @client.get('accounts/getPublickey', address: address)
28
+ end
29
+
30
+ # Get the delegate by the given address.
31
+ #
32
+ # @param address [String]
33
+ #
34
+ # @return [Faraday::Response]
35
+ def delegate(address)
36
+ @client.get('accounts/delegates', address: address)
37
+ end
38
+
39
+ # Get the delegate registration fee.
40
+ #
41
+ # @return [Faraday::Response]
42
+ def delegates_fee
43
+ @client.get('accounts/delegates/fee')
44
+ end
45
+
46
+ # Get the account by the given address.
47
+ #
48
+ # @param address [String]
49
+ #
50
+ # @return [Faraday::Response]
51
+ def account(address)
52
+ @client.get('accounts', address: address)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,96 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-blocks
9
+ module One
10
+ # Methods for the Blocks API
11
+ class Blocks < Base
12
+ # Get all blocks.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('blocks', parameters)
19
+ end
20
+
21
+ # Get the delegate by the given id.
22
+ #
23
+ # @param id [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(id)
27
+ @client.get('blocks/get', id: id)
28
+ end
29
+
30
+ # Get the blockchain epoch.
31
+ #
32
+ # @return [Faraday::Response]
33
+ def epoch
34
+ @client.get('blocks/getEpoch')
35
+ end
36
+
37
+ # Get the blockchain height.
38
+ #
39
+ # @return [Faraday::Response]
40
+ def height
41
+ @client.get('blocks/getHeight')
42
+ end
43
+
44
+ # Get the blockchain nethash.
45
+ #
46
+ # @return [Faraday::Response]
47
+ def nethash
48
+ @client.get('blocks/getNethash')
49
+ end
50
+
51
+ # Get the blockchain fee.
52
+ #
53
+ # @return [Faraday::Response]
54
+ def fee
55
+ @client.get('blocks/getFee')
56
+ end
57
+
58
+ # Get the blockchain fees.
59
+ #
60
+ # @return [Faraday::Response]
61
+ def fees
62
+ @client.get('blocks/getFees')
63
+ end
64
+
65
+ # Get the blockchain milestone.
66
+ #
67
+ # @return [Faraday::Response]
68
+ def milestone
69
+ @client.get('blocks/getMilestone')
70
+ end
71
+
72
+ # Get the blockchain reward.
73
+ #
74
+ # @return [Faraday::Response]
75
+ def reward
76
+ @client.get('blocks/getReward')
77
+ end
78
+
79
+ # Get the blockchain supply.
80
+ #
81
+ # @return [Faraday::Response]
82
+ def supply
83
+ @client.get('blocks/getSupply')
84
+ end
85
+
86
+ # Get the blockchain status.
87
+ #
88
+ # @return [Faraday::Response]
89
+ def status
90
+ @client.get('blocks/getStatus')
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,102 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-delegates
9
+ module One
10
+ # Methods for the Delegates API
11
+ class Delegates < Base
12
+ # Get all delegates.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('delegates', parameters)
19
+ end
20
+
21
+ # Get the delegate by the given id.
22
+ #
23
+ # @param parameters [Hash]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(parameters = {})
27
+ @client.get('delegates/get', parameters)
28
+ end
29
+
30
+ # Count all delegates.
31
+ #
32
+ # @return [Faraday::Response]
33
+ def count
34
+ @client.get('delegates/count')
35
+ end
36
+
37
+ # Search all delegates.
38
+ #
39
+ # @param query [String]
40
+ # @param parameters [Hash]
41
+ #
42
+ # @return [Faraday::Response]
43
+ def search(query, parameters = {})
44
+ @client.get('delegates/search', { q: query }.merge(parameters))
45
+ end
46
+
47
+ # Get the voters for the given delegate.
48
+ #
49
+ # @param address [String]
50
+ # @param parameters [Hash]
51
+ #
52
+ # @return [Faraday::Response]
53
+ def voters(public_key, parameters = {})
54
+ mandatory = { publicKey: public_key }
55
+
56
+ @client.get('delegates/voters', mandatory.merge(parameters))
57
+ end
58
+
59
+ # Get the delegate registration fee.
60
+ #
61
+ # @param address [String]
62
+ #
63
+ # @return [Faraday::Response]
64
+ def fee
65
+ @client.get('delegates/fee')
66
+ end
67
+
68
+ # Get the total forged for the given delegate.
69
+ #
70
+ # @param generator_public_key [String]
71
+ #
72
+ # @return [Faraday::Response]
73
+ def forged_by_account(generator_public_key)
74
+ parameters = { generatorPublicKey: generator_public_key }
75
+ @client.get('delegates/forging/getForgedByAccount', parameters)
76
+ end
77
+
78
+ # Get a list of the next forgers.
79
+ #
80
+ # @param address [String]
81
+ #
82
+ # @return [Faraday::Response]
83
+ def next_forgers
84
+ @client.get('delegates/getNextForgers')
85
+ end
86
+
87
+ # Get the forging status for the given delegate.
88
+ #
89
+ # @param public_key [String]
90
+ # @param parameters [Hash]
91
+ #
92
+ # @return [Faraday::Response]
93
+ def forging_status(public_key, parameters = {})
94
+ mandatory = { publicKey: public_key }
95
+
96
+ @client.get('delegates/forging/status', mandatory.merge(parameters))
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,36 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-loader
9
+ module One
10
+ # Methods for the Loader API
11
+ class Loader < Base
12
+ # Get the loader status.
13
+ #
14
+ # @return [Faraday::Response]
15
+ def status
16
+ @client.get('loader/status')
17
+ end
18
+
19
+ # Get the loader syncing status.
20
+ #
21
+ # @return [Faraday::Response]
22
+ def sync
23
+ @client.get('loader/status/sync')
24
+ end
25
+
26
+ # Get the loader configuration.
27
+ #
28
+ # @return [Faraday::Response]
29
+ def autoconfigure
30
+ @client.get('loader/autoconfigure')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-peers
9
+ module One
10
+ # Methods for the Peers API
11
+ class Peers < Base
12
+ # Get all peers.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('peers', parameters)
19
+ end
20
+
21
+ # Get the peer by the given ip and port.
22
+ #
23
+ # @param ip_addr [String]
24
+ # @param port [Integer]
25
+ #
26
+ # @return [Faraday::Response]
27
+ def show(ip_addr, port)
28
+ @client.get('peers/get', ip: ip_addr, port: port)
29
+ end
30
+
31
+ # Get the node version of the peer.
32
+ #
33
+ # @return [Faraday::Response]
34
+ def version
35
+ @client.get('peers/version')
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-signatures
9
+ module One
10
+ # Methods for the Signatures API
11
+ class Signatures < Base
12
+ # Get the signatures fee.
13
+ #
14
+ # @return [Faraday::Response]
15
+ def fee
16
+ @client.get('signatures/fee')
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 1 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v1-transactions
9
+ module One
10
+ # Methods for the Transactions API
11
+ class Transactions < Base
12
+ # Get all transactions.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('transactions', parameters)
19
+ end
20
+
21
+ # Get the transaction by the given id.
22
+ #
23
+ # @param id [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(id)
27
+ @client.get('transactions/get', id: id)
28
+ end
29
+
30
+ # Get all unconfirmed transactions.
31
+ #
32
+ # @param parameters [Hash]
33
+ #
34
+ # @return [Faraday::Response]
35
+ def all_unconfirmed(parameters = {})
36
+ @client.get('transactions/unconfirmed', parameters)
37
+ end
38
+
39
+ # Get the unconfirmed transaction by the given id.
40
+ #
41
+ # @param id [String]
42
+ #
43
+ # @return [Faraday::Response]
44
+ def show_unconfirmed(id)
45
+ @client.get('transactions/unconfirmed/get', id: id)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,52 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-blocks
9
+ module Two
10
+ # Methods for the Blocks API
11
+ class Blocks < Base
12
+ # Get all blocks.
13
+ #
14
+ # @param parameters [String]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('blocks', parameters)
19
+ end
20
+
21
+ # Get the block by the given id.
22
+ #
23
+ # @param id [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(id)
27
+ @client.get("blocks/#{id}")
28
+ end
29
+
30
+ # Get the transaction for the given block.
31
+ #
32
+ # @param id [String]
33
+ # @param parameters [Hash]
34
+ #
35
+ # @return [Faraday::Response]
36
+ def transactions(id, parameters = {})
37
+ @client.get("blocks/#{id}/transactions", parameters)
38
+ end
39
+
40
+ # Search all blocks.
41
+ #
42
+ # @param parameters [Hash]
43
+ #
44
+ # @return [Faraday::Response]
45
+ def search(parameters)
46
+ @client.post('blocks/search', parameters)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,53 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-delegates
9
+ module Two
10
+ # Methods for the Delegates API
11
+ class Delegates < Base
12
+ # Get all delegates.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('delegates', parameters)
19
+ end
20
+
21
+ # Get the delegate by the given id.
22
+ #
23
+ # @param id [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(id)
27
+ @client.get("delegates/#{id}")
28
+ end
29
+
30
+ # Get the blocks for the given delegate.
31
+ #
32
+ # @param id [String]
33
+ # @param parameters [Hash]
34
+ #
35
+ # @return [Faraday::Response]
36
+ def blocks(id, parameters = {})
37
+ @client.get("delegates/#{id}/blocks", parameters)
38
+ end
39
+
40
+ # Get the votes for the given delegate.
41
+ #
42
+ # @param id [String]
43
+ # @param parameters [Hash]
44
+ #
45
+ # @return [Faraday::Response]
46
+ def voters(id, parameters = {})
47
+ @client.get("delegates/#{id}/voters", parameters)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,36 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-node
9
+ module Two
10
+ # Methods for the Node API
11
+ class Node < Base
12
+ # Get the loader status.
13
+ #
14
+ # @return [Faraday::Response]
15
+ def status
16
+ @client.get('node/status')
17
+ end
18
+
19
+ # Get the loader syncing status.
20
+ #
21
+ # @return [Faraday::Response]
22
+ def syncing
23
+ @client.get('node/syncing')
24
+ end
25
+
26
+ # Get the loader configuration.
27
+ #
28
+ # @return [Faraday::Response]
29
+ def configuration
30
+ @client.get('node/configuration')
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-peers
9
+ module Two
10
+ # Methods for the Peers API
11
+ class Peers < Base
12
+ # Get all peers.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('peers', parameters)
19
+ end
20
+
21
+ # Get the peer by the given ip.
22
+ #
23
+ # @param ip_addr [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(ip_addr)
27
+ @client.get("peers/#{ip_addr}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,76 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-transactions
9
+ module Two
10
+ # Methods for the Transactions API
11
+ class Transactions < Base
12
+ # Get all transactions.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('transactions', parameters)
19
+ end
20
+
21
+ # Create new transactions.
22
+ #
23
+ # @param parameters [Hash]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def create(parameters)
27
+ @client.post('transactions', parameters)
28
+ end
29
+
30
+ # Get the transaction by the given id.
31
+ #
32
+ # @param id [String]
33
+ #
34
+ # @return [Faraday::Response]
35
+ def show(id)
36
+ @client.get("transactions/#{id}")
37
+ end
38
+
39
+ # Get all unconfirmed transactions.
40
+ #
41
+ # @param parameters [Hash]
42
+ #
43
+ # @return [Faraday::Response]
44
+ def all_unconfirmed(parameters = {})
45
+ @client.get('transactions/unconfirmed', parameters)
46
+ end
47
+
48
+ # Get the unconfirmed transaction by the given id.
49
+ #
50
+ # @param id [String]
51
+ #
52
+ # @return [Faraday::Response]
53
+ def show_unconfirmed(id)
54
+ @client.get("transactions/unconfirmed/#{id}")
55
+ end
56
+
57
+ # Search all transactions.
58
+ #
59
+ # @param parameters [Hash]
60
+ #
61
+ # @return [Faraday::Response]
62
+ def search(parameters)
63
+ @client.post('transactions/search', parameters)
64
+ end
65
+
66
+ # Get a list of all transaction types.
67
+ #
68
+ # @return [Faraday::Response]
69
+ def types
70
+ @client.get('transactions/types')
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,33 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-votes
9
+ module Two
10
+ # Methods for the Votes API
11
+ class Votes < Base
12
+ # Get all votes.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('votes', parameters)
19
+ end
20
+
21
+ # Get the vote by the given id.
22
+ #
23
+ # @param id [String]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def show(id)
27
+ @client.get("votes/#{id}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,90 @@
1
+ require 'arkecosystem/client/api/base'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module API
6
+ # Methods for Version 2 of the API
7
+ #
8
+ # @see https://docs.ark.io/v1.0/reference#api-v2-wallets
9
+ module Two
10
+ # Methods for the Wallets API
11
+ class Wallets < Base
12
+ # Get all wallets.
13
+ #
14
+ # @param parameters [Hash]
15
+ #
16
+ # @return [Faraday::Response]
17
+ def all(parameters = {})
18
+ @client.get('wallets', parameters)
19
+ end
20
+
21
+ # Get all wallets sorted by balance.
22
+ #
23
+ # @param parameters [Hash]
24
+ #
25
+ # @return [Faraday::Response]
26
+ def top(parameters = {})
27
+ @client.get('wallets/top', parameters)
28
+ end
29
+
30
+ # Get the wallet by the given id.
31
+ #
32
+ # @param id [String]
33
+ #
34
+ # @return [Faraday::Response]
35
+ def show(id)
36
+ @client.get("wallets/#{id}")
37
+ end
38
+
39
+ # Get the transactions for the given wallet.
40
+ #
41
+ # @param id [String]
42
+ # @param parameters [Hash]
43
+ #
44
+ # @return [Faraday::Response]
45
+ def transactions(id, parameters = {})
46
+ @client.get("wallets/#{id}/transactions", parameters)
47
+ end
48
+
49
+ # Get the sent transactions for the given wallet.
50
+ #
51
+ # @param id [String]
52
+ # @param parameters [Hash]
53
+ #
54
+ # @return [Faraday::Response]
55
+ def sent_transactions(id, parameters = {})
56
+ @client.get("wallets/#{id}/transactions/sent", parameters)
57
+ end
58
+
59
+ # Get the received transactions for the given wallet.
60
+ #
61
+ # @param id [String]
62
+ # @param parameters [Hash]
63
+ #
64
+ # @return [Faraday::Response]
65
+ def received_transaction(id, parameters = {})
66
+ @client.get("wallets/#{id}/transactions/received", parameters)
67
+ end
68
+
69
+ # Get the votes for the given wallet.
70
+ #
71
+ # @param if [String]
72
+ #
73
+ # @return [Faraday::Response]
74
+ def votes(id)
75
+ @client.get("wallets/#{id}/votes")
76
+ end
77
+
78
+ # Search all wallets.
79
+ #
80
+ # @param parameters [Hash]
81
+ #
82
+ # @return [Faraday::Response]
83
+ def search(parameters)
84
+ @client.post('wallets/search', parameters)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,171 @@
1
+ require 'arkecosystem/client/http/client'
2
+ require 'arkecosystem/client/api/one/accounts'
3
+ require 'arkecosystem/client/api/one/blocks'
4
+ require 'arkecosystem/client/api/one/delegates'
5
+ require 'arkecosystem/client/api/one/loader'
6
+ require 'arkecosystem/client/api/one/peers'
7
+ require 'arkecosystem/client/api/one/signatures'
8
+ require 'arkecosystem/client/api/one/transactions'
9
+ require 'arkecosystem/client/api/two/blocks'
10
+ require 'arkecosystem/client/api/two/delegates'
11
+ require 'arkecosystem/client/api/two/node'
12
+ require 'arkecosystem/client/api/two/peers'
13
+ require 'arkecosystem/client/api/two/transactions'
14
+ require 'arkecosystem/client/api/two/votes'
15
+ require 'arkecosystem/client/api/two/wallets'
16
+
17
+ module ArkEcosystem
18
+ module Client
19
+ # The connection used to communicate with the API.
20
+ class Connection
21
+ attr_accessor :client
22
+
23
+ # Create a new connection instance.
24
+ #
25
+ # @param config [Hash]
26
+ #
27
+ # @return [ArkEcosystem::Client::Connection]
28
+ def initialize(config, client = nil)
29
+ @host = config[:host]
30
+ @version = config[:version]
31
+
32
+ raise ArgumentError, 'No API host is provided.' if @host.nil?
33
+ raise ArgumentError, 'No API version is provided.' if @version.nil?
34
+
35
+ if client.nil? # rubocop:disable Style/ConditionalAssignment
36
+ @client = ArkEcosystem::Client::HTTP::Client.new(config)
37
+ else
38
+ @client = client.new(config)
39
+ end
40
+ end
41
+
42
+ # Return the Accounts API resource.
43
+ #
44
+ # @return [Object]
45
+ def accounts
46
+ case @version
47
+ when 1
48
+ @accounts ||= ArkEcosystem::Client::API::One::Accounts.new(@client)
49
+ else
50
+ raise NotImplementedError
51
+ end
52
+ end
53
+
54
+ # Return the Blocks API resource.
55
+ #
56
+ # @return [Object]
57
+ def blocks
58
+ case @version
59
+ when 1
60
+ @blocks ||= ArkEcosystem::Client::API::One::Blocks.new(@client)
61
+ when 2
62
+ @blocks ||= ArkEcosystem::Client::API::Two::Blocks.new(@client)
63
+ else
64
+ raise NotImplementedError
65
+ end
66
+ end
67
+
68
+ # Return the Delegates API resource.
69
+ #
70
+ # @return [Object]
71
+ def delegates
72
+ case @version
73
+ when 1
74
+ @delegates ||= ArkEcosystem::Client::API::One::Delegates.new(@client)
75
+ when 2
76
+ @delegates ||= ArkEcosystem::Client::API::Two::Delegates.new(@client)
77
+ else
78
+ raise NotImplementedError
79
+ end
80
+ end
81
+
82
+ # Return the Loader API resource.
83
+ #
84
+ # @return [Object]
85
+ def loader
86
+ case @version
87
+ when 1
88
+ @loader ||= ArkEcosystem::Client::API::One::Loader.new(@client)
89
+ else
90
+ raise NotImplementedError
91
+ end
92
+ end
93
+
94
+ # Return the Node API resource.
95
+ #
96
+ # @return [Object]
97
+ def node
98
+ case @version
99
+ when 2
100
+ @node ||= ArkEcosystem::Client::API::Two::Node.new(@client)
101
+ else
102
+ raise NotImplementedError
103
+ end
104
+ end
105
+
106
+ # Return the Peers API resource.
107
+ #
108
+ # @return [Object]
109
+ def peers
110
+ case @version
111
+ when 1
112
+ @peers ||= ArkEcosystem::Client::API::One::Peers.new(@client)
113
+ when 2
114
+ @peers ||= ArkEcosystem::Client::API::Two::Peers.new(@client)
115
+ else
116
+ raise NotImplementedError
117
+ end
118
+ end
119
+
120
+ # Return the Signatures API resource.
121
+ #
122
+ # @return [Object]
123
+ def signatures
124
+ case @version
125
+ when 1
126
+ @signatures ||= ArkEcosystem::Client::API::One::Signatures.new(@client) # rubocop:disable Metrics/LineLength
127
+ else
128
+ raise NotImplementedError
129
+ end
130
+ end
131
+
132
+ # Return the Transactions API resource.
133
+ #
134
+ # @return [Object]
135
+ def transactions
136
+ case @version
137
+ when 1
138
+ @transactions ||= ArkEcosystem::Client::API::One::Transactions.new(@client) # rubocop:disable Metrics/LineLength
139
+ when 2
140
+ @transactions ||= ArkEcosystem::Client::API::Two::Transactions.new(@client) # rubocop:disable Metrics/LineLength
141
+ else
142
+ raise NotImplementedError
143
+ end
144
+ end
145
+
146
+ # Return the Vptes API resource.
147
+ #
148
+ # @return [Object]
149
+ def votes
150
+ case @version
151
+ when 2
152
+ @votes ||= ArkEcosystem::Client::API::Two::Votes.new(@client)
153
+ else
154
+ raise NotImplementedError
155
+ end
156
+ end
157
+
158
+ # Return the Wallets API resource.
159
+ #
160
+ # @return [Object]
161
+ def wallets
162
+ case @version
163
+ when 2
164
+ @wallets ||= ArkEcosystem::Client::API::Two::Wallets.new(@client)
165
+ else
166
+ raise NotImplementedError
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,48 @@
1
+ require 'arkecosystem/client/connection'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ # Manager that holds all connections
6
+ #
7
+ # @see https://docs.ark.io/v1.0/reference
8
+ class ConnectionManager
9
+ attr_accessor :default, :connections
10
+
11
+ # Create a new client instance.
12
+ #
13
+ # @return [Faraday::Response]
14
+ def initialize
15
+ @default = 'main'
16
+ @connections = {}
17
+ end
18
+
19
+ # Connection to the given connection.
20
+ #
21
+ # @param connection [ArkEcosystem::Client::Connection]
22
+ # @param name [String]
23
+ #
24
+ # @return [Faraday::Response]
25
+ def connect(connection, name = 'main')
26
+ @connections[name] = connection
27
+ end
28
+
29
+ # Disconnect from the given connection.
30
+ #
31
+ # @param name [String]
32
+ #
33
+ # @return [nil]
34
+ def disconnect(name)
35
+ @connections.delete(name)
36
+ end
37
+
38
+ # Get a connection instance.
39
+ #
40
+ # @param name [String]
41
+ #
42
+ # @return [ArkEcosystem::Client::Connection]
43
+ def connection(name)
44
+ @connections[name]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,100 @@
1
+ require 'faraday_middleware'
2
+ require 'arkecosystem/client/http/response'
3
+
4
+ module ArkEcosystem
5
+ module Client
6
+ module HTTP
7
+ # The HTTP client used for sending requests.
8
+ class Client
9
+ attr_accessor :http_client
10
+
11
+ # Create a new resource instance.
12
+ #
13
+ # @param config [Hash]
14
+ #
15
+ # @return [ArkEcosystem::Client::API::Two::Wallets]
16
+ def initialize(config)
17
+ @host = config[:host]
18
+ @version = config[:version]
19
+ @http_client = nil
20
+ end
21
+
22
+ # Create and send a HTTP "GET" request.
23
+ #
24
+ # @param url [String]
25
+ # @param query [Hash]
26
+ #
27
+ # @return [Faraday::Response]
28
+ def get(url, query = {})
29
+ send_request(:get, url, query)
30
+ end
31
+
32
+ # Create and send a HTTP "POST" request.
33
+ #
34
+ # @param url [String]
35
+ # @param payload [Hash]
36
+ #
37
+ # @return [Faraday::Response]
38
+ def post(url, payload = {})
39
+ send_request(:post, url, payload)
40
+ end
41
+
42
+ # Create and send a HTTP "PUT" request.
43
+ #
44
+ # @param url [String]
45
+ # @param payload [Hash]
46
+ #
47
+ # @return [Faraday::Response]
48
+ def put(url, payload = {})
49
+ send_request(:put, url, payload)
50
+ end
51
+
52
+ # Create and send a HTTP "DELETE" request.
53
+ #
54
+ # @param url [String]
55
+ # @param query [Hash]
56
+ #
57
+ # @return [Faraday::Response]
58
+ def delete(url, query = {})
59
+ send_request(:delete, url, query)
60
+ end
61
+
62
+ private
63
+
64
+ # Create and send a HTTP request.
65
+ #
66
+ # @param method [String]
67
+ # @param path [String]
68
+ # @param data [String]
69
+ #
70
+ # @return [Faraday::Response]
71
+ def send_request(method, path, data)
72
+ response = faraday.send(method, path, data)
73
+
74
+ ArkEcosystem::Client::HTTP::Response.new(response)
75
+ end
76
+
77
+ # Create a new Faraday instance.
78
+ #
79
+ # @return [Faraday]
80
+ def faraday # rubocop:disable Metrics/MethodLength
81
+ if @http_client.nil?
82
+ Faraday.new @host.to_s do |faraday|
83
+ faraday.headers['Content-Type'] = 'application/json'
84
+
85
+ unless @version.nil?
86
+ faraday.headers['API-Version'] = @version.to_s
87
+ end
88
+
89
+ faraday.request :json
90
+
91
+ faraday.adapter Faraday.default_adapter
92
+ end
93
+ else
94
+ @http_client
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ module ArkEcosystem
4
+ module Client
5
+ module HTTP
6
+ # The HTTP response returned by the client.
7
+ class Response
8
+ attr_accessor :response
9
+
10
+ def initialize(response)
11
+ @response = response
12
+ end
13
+
14
+ def body
15
+ JSON.parse(@response.body)
16
+ end
17
+
18
+ def url
19
+ @response.to_hash[:url].to_s
20
+ end
21
+
22
+ def to_hash
23
+ @response.to_hash
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module ArkEcosystem
2
+ module Client
3
+ # Current major release.
4
+ MAJOR = 0
5
+
6
+ # Current minor release.
7
+ MINOR = 1
8
+
9
+ # Current patch level.
10
+ PATCH = 0
11
+
12
+ # Full release version.
13
+ VERSION = [MAJOR, MINOR, PATCH].join('.').freeze
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arkecosystem-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Faust
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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: 3.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.12.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.12.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.12.2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.12.2
97
+ description: A simple Ruby API client for the ARK Blockchain.
98
+ email:
99
+ - brian@ark.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - lib/arkecosystem/client.rb
105
+ - lib/arkecosystem/client/api/base.rb
106
+ - lib/arkecosystem/client/api/one/accounts.rb
107
+ - lib/arkecosystem/client/api/one/blocks.rb
108
+ - lib/arkecosystem/client/api/one/delegates.rb
109
+ - lib/arkecosystem/client/api/one/loader.rb
110
+ - lib/arkecosystem/client/api/one/peers.rb
111
+ - lib/arkecosystem/client/api/one/signatures.rb
112
+ - lib/arkecosystem/client/api/one/transactions.rb
113
+ - lib/arkecosystem/client/api/two/blocks.rb
114
+ - lib/arkecosystem/client/api/two/delegates.rb
115
+ - lib/arkecosystem/client/api/two/node.rb
116
+ - lib/arkecosystem/client/api/two/peers.rb
117
+ - lib/arkecosystem/client/api/two/transactions.rb
118
+ - lib/arkecosystem/client/api/two/votes.rb
119
+ - lib/arkecosystem/client/api/two/wallets.rb
120
+ - lib/arkecosystem/client/connection.rb
121
+ - lib/arkecosystem/client/connection_manager.rb
122
+ - lib/arkecosystem/client/http/client.rb
123
+ - lib/arkecosystem/client/http/response.rb
124
+ - lib/arkecosystem/client/version.rb
125
+ homepage: https://github.com/ArkEcosystem/ruby-client
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.7.6
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: A simple Ruby API client for the ARK Blockchain.
150
+ test_files: []