-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.rb
More file actions
49 lines (47 loc) · 1017 Bytes
/
app.rb
File metadata and controls
49 lines (47 loc) · 1017 Bytes
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
require 'sinatra'
require 'unirest'
require 'pry'
require 'json'
get "/" do
@annonces = array_d_annonce
erb :index
end
def array_d_annonce
array_d_annonce = []
Annonce.fetch_annonces.each do |annonce|
array_d_annonce << Annonce.new(annonce)
end
array_d_annonce
end
class Annonce
def initialize(annonce)
@photo = annonce["photos"][0]["large"]
@ville = annonce["location"]["city"]
@prix = (annonce["price"]["nightly"] * 0.88).to_i
@url = annonce["provider"]["url"]
@capacite = annonce["attr"]["occupancy"]
end
def self.fetch_annonces
response = Unirest.get "https://zilyo.p.mashape.com/search?isinstantbook=true&nelatitude=45.23&nelongitude=4.66&provider=airbnb&swlatitude=44.43&swlongitude=4.00",
headers:{
"X-Mashape-Key" => "dtFSGSEqxtmshQloyQuNPHBymLNSp1aN6M1jsnE1XxVJqxvxKE",
"Accept" => "application/json"
}
response.body["result"]
end
def photo
@photo
end
def ville
@ville
end
def prix
@prix
end
def url
@url
end
def capacite
@capacite
end
end