Class: BlockchainNode::Request
- Inherits:
-
Object
- Object
- BlockchainNode::Request
- Defined in:
- lib/blockchain-node/request.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.blockchainnode.io"
Instance Method Summary collapse
- #get(path:, auth_token:) ⇒ Object
-
#initialize(options) ⇒ Request
constructor
A new instance of Request.
- #post(path:, data: {}, auth_token: nil) ⇒ Object
Constructor Details
#initialize(options) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 |
# File 'lib/blockchain-node/request.rb', line 9 def initialize() @host = [:host] || DEFAULT_BASE_URL @read_timeout = [:read_timeout] || 45 @open_timeout = [:open_timeout] || 3 end |
Instance Method Details
#get(path:, auth_token:) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/blockchain-node/request.rb', line 15 def get(path:, auth_token:) uri = URI(@host + path) request = Net::HTTP::Get.new(uri) request['Content-Type'] = "application/json" request['Authorization'] = "Bearer #{auth_token}" if auth_token process_request(uri, request) end |
#post(path:, data: {}, auth_token: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/blockchain-node/request.rb', line 25 def post(path:, data: {}, auth_token: nil) uri = URI(@host + path) request = Net::HTTP::Post.new(uri) request['Content-Type'] = "application/json" request['Authorization'] = "Bearer #{auth_token}" if auth_token request.body = data.to_json process_request(uri, request) end |