Class: BlockchainNode::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/blockchain-node/request.rb

Constant Summary collapse

DEFAULT_BASE_URL =
"https://api.blockchainnode.io"

Instance Method Summary collapse

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(options)
  @host = options[:host] || DEFAULT_BASE_URL
  @read_timeout = options[:read_timeout] || 45
  @open_timeout = options[: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