-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlineup.rb
37 lines (33 loc) · 861 Bytes
/
lineup.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
class Lineup
def initialize(fixture_id)
@fixture_id = fixture_id
@data = ""
end
def get
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://api-football-v1.p.rapidapi.com/v3/fixtures/lineups?fixture=#{@fixture_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(url)
request["X-RapidAPI-Key"] = '1705cb0e7bmshf870e4322c873dcp1b2908jsnd47fd32dfd79'
request["X-RapidAPI-Host"] = 'api-football-v1.p.rapidapi.com'
response = http.request(request)
@data = response.read_body
end
def to_s
@data.to_s
end
def to_h
JSON::parse(to_s)
end
def home_team
puts to_h
to_h["response"][0]["team"]["name"]
end
def away_team
to_h["response"][1]["team"]["name"]
end
end