Skip to content

Commit

Permalink
Updated API
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dlesk committed Jan 3, 2012
1 parent 31560b0 commit 4122028
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
15 changes: 13 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<hr />
**API Documentation**

The below documentation will use http://localhost:8085/ as the base URL for Gamez
The below documentation will use http://127.0.0.1:8085/ as the base URL for Gamez and the api_key of "ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw"
<hr />
*General*

Expand All @@ -19,5 +19,16 @@ Currently, no API actions are implemented.
*Parameters*

API_KEY - The Gamez API Key (Can be retrieved from Settings page)

MODE - The type of request. Valid values: ["search"]
TERM - Used with search and should be part of the game name
SYSTEM - The name of the system corresponding with the action
</hr>
*Modes*

**SEARCH**
This mode searches for a game. A json response will be returned containing all games matching the search term. The term parameter should be supplied. If it is blank or not supplied, all games will be returned

Examples:
Get list of all games: http://127.0.0.1:8085/api?api_key=ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw&mode=search
Search for games that contain "Super" and are only for the Wii: http://127.0.0.1:8085/api?api_key=ikzFRzA1Y8I1UajNJAOQ803TbTYk1vLB64A9SxrAxAw&mode=search&term=super&system=wii
</hr>
Binary file modified Gamez.db
Binary file not shown.
23 changes: 22 additions & 1 deletion lib/DBFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,25 @@ def AddXbox360GamesIfMissing():
cursor.execute(sql)
connection.commit()
cursor.close()
return
return

def ApiGetGamesFromTerm(term,system):
db_path = os.path.join(os.path.abspath(""),"Gamez.db")
sql = "SELECT GAME_NAME,SYSTEM FROM GAMES where game_name like '%" + term.replace("'","''") + "%' AND SYSTEM LIKE '%" + system + "%' ORDER BY GAME_NAME ASC"
data = ""
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute(sql)
result = cursor.fetchall()
for record in result:
try:
game_name = str(record[0])
system = str(record[1])
rowdata = '{"GameTitle":"' + game_name + '","System":"' + system + '"},'
data = data + rowdata
except:
continue
cursor.close()
data = data[:-1]
data = "[" + data + "]"
return data
Binary file modified lib/DBFunctions.pyc
Binary file not shown.
18 changes: 15 additions & 3 deletions lib/WebRoot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cherrypy
import json
import os
from DBFunctions import GetGamesFromTerm, GetGameDataFromTerm, AddGameToDb, GetRequestedGames, RemoveGameFromDb, UpdateStatus, GetLog, ClearDBLog,AddWiiGamesIfMissing,AddXbox360GamesIfMissing
from DBFunctions import GetGamesFromTerm, GetGameDataFromTerm, AddGameToDb, GetRequestedGames, RemoveGameFromDb, UpdateStatus, GetLog, ClearDBLog,AddWiiGamesIfMissing,AddXbox360GamesIfMissing,ApiGetGamesFromTerm
from UpgradeFunctions import CheckForNewVersion,IgnoreVersion,UpdateToLatestVersion
import ConfigParser
from time import sleep
Expand Down Expand Up @@ -548,7 +548,7 @@ def clearlog(self):
raise cherrypy.InternalRedirect('/')

@cherrypy.expose
def api(self,api_key=''):
def api(self,api_key='',mode='',term='',system=''):
config = ConfigParser.RawConfigParser()
configFilePath = os.path.join(WebRoot.appPath,'Gamez.ini')
config.read(configFilePath)
Expand All @@ -558,7 +558,19 @@ def api(self,api_key=''):
elif(api_key <> systemApiKey):
return json.dumps({"Error" : "Invalid API Key"})
else:
response = {"Error" : "API Not Yet Implemented"}
if(mode == 'search'):
return ApiGetGamesFromTerm(term,system)
else:
response = {"Error" : mode + " Mode Not Implemented"}

#TODO: Get List of requested games

#TODO: Add Game to requested list

#TODO: Remove game from requested list

#TODO: Update game list from gamezapp.org web service

return json.dumps(response)
return json.dumps({"Error" : "Unkown Error"})

Expand Down
Binary file modified lib/WebRoot.pyc
Binary file not shown.

0 comments on commit 4122028

Please sign in to comment.