aboutsummaryrefslogtreecommitdiff
path: root/src/guff/api/util.cr
blob: 72e7e5cdffd9145d66db4a188579a3ca3556e781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "json"

module Guff
  module API
    module Util
      private def get_site(context : HTTP::Server::Context) : Int?
        @models.site.to_site(context.request.headers["host"]?)
      end

      private def get_tags(
        s : String?
      ) : Array(String)
        if s && s.size > 0
          Array(String).from_json(s)
        else
          [] of String
        end
      end

      private def get_posts_tags(
        s : String?
      ) : Array(Array(String))
        if s && s.size > 0
          Array(Array(String)).from_json(s)
        else
          [] of Array(String)
        end
      end

      private def get_posts_sort(
        s : String?
      ) : Array(Hash(String, String))?
        if s && s.size > 0
          Array(Hash(String, String)).from_json(s)
        end
      end
    end
  end
end