-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
57 lines (45 loc) · 1.29 KB
/
main.rb
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'sinatra'
require 'curb'
require 'json'
LOGO = "/images/logo_hektor.png"
LOGO_VERT = "/images/logo_vert_hektor.png"
class App < Sinatra::Base
def initialize
super()
@logo = LOGO_VERT
end
get '/' do
@image = get_last_img
erb :index
end
get '/info' do
@logo = LOGO
erb :info
end
get '/bio' do
erb :bio
end
get '/oeuvres' do
@oeuvres = get_all_img.to_json
erb :oeuvres
end
get '/paysages/:image' do
original = get_image(params['image'])
@image = original['full']
images = get_all_img.map { |i| {id: i["id"], slug: i["slug"]} }.sort {|a,b| a[:id] <=> b[:id]}
index_image = images.find_index { |e| e[:id] == original['id'] }
@prev = "/paysages/" + images[index_image - 1][:slug] if index_image > 0
@next = "/paysages/" + images[index_image + 1][:slug] if index_image < images.count - 1
erb :images
end
def get_last_img
JSON.parse(Curl.get('https://api.hektor.ca/rest/artworks/?format=json&limit=1').body)["results"].first["full"]
end
def get_all_img
JSON.parse(Curl.get('https://api.hektor.ca/rest/artworks/?format=json&limit=10000').body)["results"]
end
def get_image (image)
JSON.parse(Curl.get('https://api.hektor.ca/rest/artworks/' + image + '/').body)
end
run! if __FILE__ == $0
end