Module: Blnk::Client

Included in:
Resourceable
Defined in:
lib/blnk/client.rb

Overview

HTTP Client to do the requests to blnk server

Instance Method Summary collapse

Instance Method Details

#base_uri(path:, uri: Blnk.address) ⇒ Object



26
27
28
29
30
# File 'lib/blnk/client.rb', line 26

def base_uri(path:, uri: Blnk.address)
  uri = URI(uri)
  uri.path = path if path
  uri
end

#clientObject



6
7
8
9
10
11
12
# File 'lib/blnk/client.rb', line 6

def client
  ::HTTP.headers(
    'X-Blnk-Key': Blnk.secret_token,
    'Content-Type': 'application/json',
    accept: 'application/json'
  )
end

#get_request(path:, params: nil) ⇒ Object



14
15
16
# File 'lib/blnk/client.rb', line 14

def get_request(path:, params: nil)
  client.get(base_uri(path:), params:)
end

#post_request(path:, body:) ⇒ Object



22
23
24
# File 'lib/blnk/client.rb', line 22

def post_request(path:, body:)
  client.post(base_uri(path:), json: body)
end

#put_request(path:, body:) ⇒ Object



18
19
20
# File 'lib/blnk/client.rb', line 18

def put_request(path:, body:)
  client.put(base_uri(path:), json: body)
end