Module: HelloBlock::Client::Endpoints
- Included in:
- HelloBlock::Client
- Defined in:
- lib/helloblock/client/endpoints.rb
Constant Summary collapse
- ADDRESSES_PATH =
'/addresses/'- UNSPENTS_PATH =
'/addresses/unspents'- TRANSACTIONS_FOR_ADDRESS_PATH =
'/addresses/transactions'- TRANSACTIONS_PATH =
'/transactions'- LATEST_TRANSACTION_PATH =
'/transactions/latest'- PROPAGATE_PATH =
POST
'/transactions'- BLOCKS_PATH =
'/blocks'- LATEST_BLOCKS_PATH =
'/blocks/latest'- WALLET_PATH =
'/wallet'- FAUCET_PATH =
'/faucet'- WITHDRAWAL_PATH =
POST
'/withdrawal'- POST_REQUESTS =
[:propagate, :withdrawal]
Instance Method Summary collapse
- #base_url ⇒ Object
-
#endpoint_defined?(method) ⇒ Boolean
:unspents => UNSPENTS_PATH.
-
#method_missing(method, *args, &block) ⇒ Object
client.unspents(addresses: …) => method_missing(:unspents, addresses: … ).
-
#navigate_to_path(method, *args) ⇒ Object
get(UNSPENTS_PATH, addresses: …).
- #post_request?(method) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
client.unspents(addresses: …) => method_missing(:unspents, addresses: … )
25 26 27 |
# File 'lib/helloblock/client/endpoints.rb', line 25 def method_missing(method, *args, &block) endpoint_defined?(method) ? navigate_to_path(method, args[0]) : super end |
Instance Method Details
#base_url ⇒ Object
19 20 21 |
# File 'lib/helloblock/client/endpoints.rb', line 19 def base_url "http://#{network}.helloblock.io" end |
#endpoint_defined?(method) ⇒ Boolean
:unspents => UNSPENTS_PATH
31 32 33 |
# File 'lib/helloblock/client/endpoints.rb', line 31 def endpoint_defined?(method) Endpoints.constants.include?("#{method.upcase}_PATH".to_sym) end |
#navigate_to_path(method, *args) ⇒ Object
get(UNSPENTS_PATH, addresses: …)
37 38 39 40 |
# File 'lib/helloblock/client/endpoints.rb', line 37 def navigate_to_path(method, *args) path = Endpoints.const_get("#{method.upcase}_PATH".to_sym) post_request?(method) ? post(path, body: args[0]) : get(path, args[0]) end |
#post_request?(method) ⇒ Boolean
42 43 44 |
# File 'lib/helloblock/client/endpoints.rb', line 42 def post_request?(method) POST_REQUESTS.include?(method) end |