Files
MBS/WEBSERVICES/sports/equipos.4gl
T

158 lines
4.1 KiB
Plaintext

IMPORT util
IMPORT com
IMPORT os
IMPORT security
DEFINE metodo VARCHAR(10)
{
PROGRAM : equipos.4gl
}
MAIN
CALL equipos()
END MAIN
FUNCTION equipos()
DEFINE url,result STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
DEFINE team_all_season RECORD
copyRight STRING,
queryResults RECORD
created STRING,
totalSize INT
END RECORD ,
row DYNAMIC ARRAY OF RECORD
phone_number,
venue_name,
franchise_code,
all_star_sw,
sport_code,
address_city,
city,
name_display_full,
spring_league_abbrev,
time_zone_alt STRING,
sport_id,
venue_id,
mlb_org_id INT,
time_zone_generic,
mlb_org STRING,
last_year_of_play INT,
league_full,
home_opener_time,
address_province STRING,
league_id INT,
name_abbrev,
bis_team_code,
league,
spring_league,
base_url,
address_zip,
sport_code_display,
mlb_org_short,
time_zone,
address_line1,
mlb_org_brief,
address_line2 STRING,
season INT,
address_line3,
division_abbrev,
name_display_short STRING,
team_id INT,
active_sw,
address_intl,
state,
address_country,
mlb_org_abbrev,
division,
team_code,
NAME,
website_url,
sport_code_name STRING,
first_year_of_play INT,
league_abbrev,
name_display_long,
store_url,
time_zone_text,
name_short,
home_opener,
address_state,
division_full STRING,
time_zone_num INT,
spring_league_full,
address,
name_display_brief,
file_code STRING,
division_id INT,
spring_league_id INT,
venue_short STRING
END RECORD
END RECORD
LET metodo = 'GET'
LET url = "http://lookup-service-prod.mlb.com/json/named.team_all_season.bam?sport_code=%27mlb%27&all_star_sw=%27N%27&sort_order=name_asc&season=%272021%27"
LET http_req = com.HttpRequest.Create(url)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.doRequest()
LET http_resp=http_req.getResponse()
IF http_resp.getStatusCode() <> 200 THEN
DISPLAY "ERR ",http_resp.getStatusDescription()
ELSE
LET result = http_resp.getTextResponse()
TRY
CALL util.JSON.parse(result,team_all_season)
CATCH
DISPLAY "ERROR ",STATUS," ",SQLCA.SQLERRM
END TRY
DISPLAY "respuesta ",result
END IF
END FUNCTION
FUNCTION sync_send_command(url, cmd)
DEFINE url, cmd STRING
DEFINE result, tmp STRING
DEFINE http_req com.HTTPRequest
DEFINE http_resp com.HTTPResponse
TRY LET http_req = com.HTTPRequest.Create(url)
CALL http_req.setConnectionTimeout(40)
CALL http_req.setTimeout(40)
CALL http_req.setMethod(metodo)
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("DBSync-Client","mbs")
CALL http_req.setHeader("Content-Type","dbsync/json")
CALL http_req.doTextRequest(cmd)
LET http_resp=http_req.getResponse()
IF http_resp.getStatusCode() != 200 THEN
RETURN http_resp.getStatusCode(), http_resp.getStatusDescription()
END IF
LET tmp = http_resp.getStatusDescription()
IF (tmp == "OK" || tmp == "no error" ) THEN
RETURN -1, SFMT("HTTP request status description: %1 ",tmp)
END IF
LET result = http_resp.getTextResponse()
CATCH
RETURN -2, SFMT("HTTP request error: STATUS=%1 (%2)",STATUS,SQLCA.SQLERRM)
END TRY
RETURN 0, result
END FUNCTION
FUNCTION show_sync_err(msg)
DEFINE msg STRING
CALL fgl_winmessage(%"ERROR", msg, "exclamation")
END FUNCTION