Class: CronosExplorer::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/cronos_explorer/request.rb

Class Method Summary collapse

Class Method Details

.connectObject



26
27
28
29
30
31
# File 'lib/cronos_explorer/request.rb', line 26

def connect
  Faraday.new(url: CronosExplorer.domain) do |faraday|
    faraday.request :json
    faraday.adapter Faraday.default_adapter
  end
end

.get(hash) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/cronos_explorer/request.rb', line 7

def get(hash)
  res = connect.get do |req|
    req.url params(hash)
    req.headers['Content-Type'] = 'application/json'
  end.body

  Oj.load(res)
end

.params(hash) ⇒ Object



33
34
35
# File 'lib/cronos_explorer/request.rb', line 33

def params(hash)
  '?' + URI.encode_www_form(hash)
end

.post(hash) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/cronos_explorer/request.rb', line 16

def post(hash)
  res = connect.post do |req, params|
    req.url params(hash)
    req.headers['Content-Type'] = 'application/json'
    req.params params
  end.body

  Oj.load(res)
end