Module: HelloBlock::Request

Extended by:
Request
Included in:
Request
Defined in:
lib/helloblock/request.rb

Instance Method Summary collapse

Instance Method Details

#baseObject



4
5
6
# File 'lib/helloblock/request.rb', line 4

def base
  "https://#{HelloBlock.network}.helloblock.io/#{HelloBlock.version}"
end

#get(endpoint, query: {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/helloblock/request.rb', line 20

def get(endpoint, query: {})
  response = HTTParty.get("#{base()}#{endpoint}", query: query)

  if response.code != 200
    body = JSON.parse(response.body)
    p body
    raise "#{body["message"]}"
  end
  return response["data"]
end

#post(endpoint, body: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/helloblock/request.rb', line 8

def post(endpoint, body: {})
  # ensure / at end of endpoint
  response = HTTParty.post("#{base()}#{endpoint}", body: body)

  if response.code != 200
    body = JSON.parse(response.body)
    p body
    raise "#{body["message"]}"
  end
  return response["data"]
end