Module: Rdwu::Read

Included in:
Api
Defined in:
lib/rdwu/read.rb

Instance Method Summary collapse

Instance Method Details

#find(url) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rdwu/read.rb', line 10

def find(url)
  http = get_request("/api/v1/web_redirects/find?url=#{url}")

  if http.status == 200
    body = JSON.parse(http.body)
    return body['data']
  end

  nil
end

#listObject



4
5
6
7
8
# File 'lib/rdwu/read.rb', line 4

def list
  http = get_request('/api/v1/web_redirects')
  body = JSON.parse(http.body)
  body['data']
end

#qrcode(uuid: nil, url: nil) ⇒ Object



32
33
34
35
36
37
# File 'lib/rdwu/read.rb', line 32

def qrcode(uuid: nil, url: nil)
  return raise('Missing uuid and url') if uuid.nil? && url.nil?

  return qrcode_by_uuid(uuid) unless uuid.nil?
  qrcode_by_url(url) unless url.nil?
end

#qrcode_by_url(url) ⇒ Object



59
60
61
62
63
64
# File 'lib/rdwu/read.rb', line 59

def qrcode_by_url(url)
  data = find(url)
  return if data.nil?

  qrcode_by_uuid(data['id'])
end

#qrcode_by_uuid(uuid) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rdwu/read.rb', line 39

def qrcode_by_uuid(uuid)
  http = get_request("/api/v1/web_redirects/#{uuid}/qrcode_svg")

  if http.status == 200
    svg_base64 = http.body.to_s
    svg_base64 = Base64.decode64(svg_base64)

    return svg_base64
  end

  nil
end

#qrcode_to_png(uuid) ⇒ Object



52
53
54
55
56
57
# File 'lib/rdwu/read.rb', line 52

def qrcode_to_png(uuid)
  http = get_request("/api/v1/web_redirects/#{uuid}/qrcode_png")
  return nil unless http.status == 200

  http.body.to_s
end

#retrieve(uuid) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/rdwu/read.rb', line 21

def retrieve(uuid)
  http = get_request("/api/v1/web_redirects/#{uuid}")

  if http.status == 200
    body = JSON.parse(http.body)
    return body['data']
  end

  nil
end