Class: IOSTSdk::Http::Client
- Inherits:
-
Object
- Object
- IOSTSdk::Http::Client
- Defined in:
- lib/iost_sdk/http/client.rb
Constant Summary collapse
- READ_METHODS =
key: method name value: an array of args
{ get_node_info: [], get_chain_info: [], get_gas_ratio: [], get_ram_info: [], get_tx_by_hash: [:hash_value], get_tx_receipt_by_tx_hash: [:hash_value], get_block_by_hash: [:hash_value, :complete], get_block_by_number: [:number, :complete], get_account: [:name, :by_longest_chain], get_token_balance: [:account_name, :token_name, :by_longest_chain], get_contract: [:id, :by_longest_chain], get_contract_storage: [:query], get_contract_storage_fields: [:query] }.freeze
- WRITE_METHODS =
{ send_tx: [:transaction, :account_name, :key_pair] # TODO: exec_tx # TODO: subscribe }.freeze
- METHODS =
READ_METHODS.merge(WRITE_METHODS) .freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base_url:) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(base_url:) ⇒ Client
Returns a new instance of Client.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/iost_sdk/http/client.rb', line 43 def initialize(base_url:) @base_url = base_url METHODS.each do |method_name, method_args| # require the file require "iost_sdk/http/#{method_name}" # define the method self.class.send(:define_method, method_name) do |**args| # extract match args for the call raise ArgumentError.new('Invalid method arguments.') unless Set.new(method_args).subset?(Set.new(args.keys)) valid_args = method_args.reduce({}) do |memo, k| memo[k] = args[k] memo end # init and invoke class_name = IOSTSdk::String.camelize(method_name) clazz = IOSTSdk::String.classify("IOSTSdk::Http::#{class_name}") clazz.new.invoke(valid_args.merge(base_url: @base_url)) end end end |
Class Method Details
.read_apis ⇒ Object
39 40 41 |
# File 'lib/iost_sdk/http/client.rb', line 39 def self.read_apis READ_METHODS end |