Top Level Namespace

Defined Under Namespace

Modules: Jekyll

Constant Summary collapse

RESULT_LIMIT =
200
FORMAT_STRING_EVENTS =
".data[] |
  {
      title: .title,
      description: .description,
      date: .slots[0].from | split(\"T\")[0],
      time:
      {
          from: .slots[0].from,
          to: .slots[-1].to
      },
      organiser:
      {
          name: .animal.userName,
      },
      place:
      {
          id: .place.id,
          name: .place.title,
          description: .place.description,
          area: .place.city
      },
      imageUrl:.images[0].mediumImageUrl,
      tags:.tags,
      websiteUrl: .websiteUrl
  }
"
FORMAT_STRING_PLACES =
".data[] |
  {
      id: .id,
      title: .title,
      description: .description,
      street: .street,
      cityCode: .cityCode,
      city: .city,
      country: .country,
      imageUrl:.images[0].mediumImageUrl
  }
"
FORMAT_STRING_META =
".config |
  {
      title: .title,
      description: .description,
  }
"
SEARCH_STRINGS =
{
  "events" => FORMAT_STRING_EVENTS,
  "places" => FORMAT_STRING_PLACES,
  "meta" => FORMAT_STRING_META
}.freeze

Instance Method Summary collapse

Instance Method Details

#check_config(config) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/jekyll/hoffnung3000/main.rb', line 75

def check_config(config)
  raise "HOFFNUNG3000 Error: Jekyl _config.yml file must contain a hoffnung3000 block" unless config["hoffnung3000"]
  unless config["hoffnung3000"]["url"]
    raise "HOFFNUNG3000 Error: Jekyl _config.yml file must contain a hoffnung3000 > url value"
  end

  config
end

#fetch_data(url, key) ⇒ Object



88
89
90
# File 'lib/jekyll/hoffnung3000/main.rb', line 88

def fetch_data(url, key)
  HTTP.get(format("%<url>s/api/%<key>s", { url: url, key: key }), { params: { limit: RESULT_LIMIT } }).body
end

#format_data(data, key) ⇒ Object



65
66
67
68
# File 'lib/jekyll/hoffnung3000/main.rb', line 65

def format_data(data, key)
  jq = JQ(data, parse_json: true)
  jq.search(SEARCH_STRINGS[key])
end

#get_hoffnung(config, key) ⇒ Object



92
93
94
95
96
97
# File 'lib/jekyll/hoffnung3000/main.rb', line 92

def get_hoffnung(config, key)
  url = url(config)
  data = fetch_data(url, key)
  formatted_data = format_data(data, key)
  write_data(formatted_data, key)
end

#url(config) ⇒ Object



84
85
86
# File 'lib/jekyll/hoffnung3000/main.rb', line 84

def url(config)
  check_config(config)["hoffnung3000"]["url"]
end

#write_data(data, file_name) ⇒ Object



70
71
72
73
# File 'lib/jekyll/hoffnung3000/main.rb', line 70

def write_data(data, file_name)
  Dir.mkdir("_data") unless Dir.exist?("_data")
  File.write(format("_data/%s.json", file_name), JSON.generate(data))
end