Class: ArkEcosystem::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/arkecosystem/client/connection.rb

Overview

The connection used to communicate with the API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, client = nil) ⇒ ArkEcosystem::Client::Connection

Create a new connection instance.

Parameters:

  • config (Hash)

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/arkecosystem/client/connection.rb', line 28

def initialize(config, client = nil)
  @host = config[:host]
  @version = config[:version]

  raise ArgumentError, 'No API host is provided.' if @host.nil?
  raise ArgumentError, 'No API version is provided.' if @version.nil?

  if client.nil? # rubocop:disable Style/ConditionalAssignment
    @client = ArkEcosystem::Client::HTTP::Client.new(config)
  else
    @client = client.new(config)
  end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



21
22
23
# File 'lib/arkecosystem/client/connection.rb', line 21

def client
  @client
end

Instance Method Details

#accountsObject

Return the Accounts API resource.

Returns:

  • (Object)


45
46
47
48
49
50
51
52
# File 'lib/arkecosystem/client/connection.rb', line 45

def accounts
  case @version
  when 1
    @accounts ||= ArkEcosystem::Client::API::One::Accounts.new(@client)
  else
    raise NotImplementedError
  end
end

#blocksObject

Return the Blocks API resource.

Returns:

  • (Object)


57
58
59
60
61
62
63
64
65
66
# File 'lib/arkecosystem/client/connection.rb', line 57

def blocks
  case @version
  when 1
    @blocks ||= ArkEcosystem::Client::API::One::Blocks.new(@client)
  when 2
    @blocks ||= ArkEcosystem::Client::API::Two::Blocks.new(@client)
  else
    raise NotImplementedError
  end
end

#delegatesObject

Return the Delegates API resource.

Returns:

  • (Object)


71
72
73
74
75
76
77
78
79
80
# File 'lib/arkecosystem/client/connection.rb', line 71

def delegates
  case @version
  when 1
    @delegates ||= ArkEcosystem::Client::API::One::Delegates.new(@client)
  when 2
    @delegates ||= ArkEcosystem::Client::API::Two::Delegates.new(@client)
  else
    raise NotImplementedError
  end
end

#loaderObject

Return the Loader API resource.

Returns:

  • (Object)


85
86
87
88
89
90
91
92
# File 'lib/arkecosystem/client/connection.rb', line 85

def loader
  case @version
  when 1
    @loader ||= ArkEcosystem::Client::API::One::Loader.new(@client)
  else
    raise NotImplementedError
  end
end

#nodeObject

Return the Node API resource.

Returns:

  • (Object)


97
98
99
100
101
102
103
104
# File 'lib/arkecosystem/client/connection.rb', line 97

def node
  case @version
  when 2
    @node ||= ArkEcosystem::Client::API::Two::Node.new(@client)
  else
    raise NotImplementedError
  end
end

#peersObject

Return the Peers API resource.

Returns:

  • (Object)


109
110
111
112
113
114
115
116
117
118
# File 'lib/arkecosystem/client/connection.rb', line 109

def peers
  case @version
  when 1
    @peers ||= ArkEcosystem::Client::API::One::Peers.new(@client)
  when 2
    @peers ||= ArkEcosystem::Client::API::Two::Peers.new(@client)
  else
    raise NotImplementedError
  end
end

#signaturesObject

Return the Signatures API resource.

Returns:

  • (Object)


123
124
125
126
127
128
129
130
# File 'lib/arkecosystem/client/connection.rb', line 123

def signatures
  case @version
  when 1
    @signatures ||= ArkEcosystem::Client::API::One::Signatures.new(@client) # rubocop:disable Metrics/LineLength
  else
    raise NotImplementedError
  end
end

#transactionsObject

Return the Transactions API resource.

Returns:

  • (Object)


135
136
137
138
139
140
141
142
143
144
# File 'lib/arkecosystem/client/connection.rb', line 135

def transactions
  case @version
  when 1
    @transactions ||= ArkEcosystem::Client::API::One::Transactions.new(@client) # rubocop:disable Metrics/LineLength
  when 2
    @transactions ||= ArkEcosystem::Client::API::Two::Transactions.new(@client) # rubocop:disable Metrics/LineLength
  else
    raise NotImplementedError
  end
end

#votesObject

Return the Vptes API resource.

Returns:

  • (Object)


149
150
151
152
153
154
155
156
# File 'lib/arkecosystem/client/connection.rb', line 149

def votes
  case @version
  when 2
    @votes ||= ArkEcosystem::Client::API::Two::Votes.new(@client)
  else
    raise NotImplementedError
  end
end

#walletsObject

Return the Wallets API resource.

Returns:

  • (Object)


161
162
163
164
165
166
167
168
# File 'lib/arkecosystem/client/connection.rb', line 161

def wallets
  case @version
  when 2
    @wallets ||= ArkEcosystem::Client::API::Two::Wallets.new(@client)
  else
    raise NotImplementedError
  end
end