husnjak / igdb-swift-api Goto Github PK
View Code? Open in Web Editor NEWA Swift wrapper for the IGDB.com Free Video Game Database API.
License: MIT License
A Swift wrapper for the IGDB.com Free Video Game Database API.
License: MIT License
I just submitted an update to my app with this wrapper and seeing a few crashes, not sure where they're coming from.
This is all I'm getting from the Xcode crash report.
#3 (null) in closure #1 in IGDBWrapper.achievements(apiCalypse:result:errorResponse:) ()
#5 0x0000000104e8ac30 in closure #1 in IGDBWrapper.apiRequest(endpoint:apicalypseQuery:dataResponse:errorResponse:) at /Pods/IGDB-SWIFT-API/IGDB-SWIFT-API/Classes/Wrapper/IGDBWrapper.swift:24
Any ideas?
(I'm not using the achievements endpoint anywhere in my code so not sure why it's mentioning that?)
I am fetching the games list following the provided example
wrapper.apiProtoRequest(endpoint: .GAMES, apicalypseQuery: "fields *;", dataResponse: { bytes in
let games: [Proto_Game] = try! Proto_GameResult(serializedData: bytes) // This converts Binary to a struct
}, errorResponse: { error in
// Do Something
})
Then I want to find the image ids so I can use the imageBuilder function to get the urls but the resulting url is not a valid image url. The website uses cloudinary_id for urls but those ids are missing from the reponse of games endpoint.
Same issue as before.
IGDB_SWIFT_API: closure #1 in IGDBWrapper.ageRatings(apiCalypse:result:errorResponse:) + 376
Now referencing the ageRatings function, though again I don't use this anywhere in my code. Possibly it's just the top function in the file?
this is my code:
let apicalypse = APICalypse()
.fields(fields: "id,name,category") // Specify the fields you want to retrieve
.where(query: "name = \"w\"") // Use the "where" clause to search by name
.limit(value: 50)
// Make the API request to search for the game by name.
wrapper.games(apiCalypse: apicalypse, result: { games in
// Handle the retrieved games here
for game in games {
if game.name.lowercased() == name.lowercased() {
print(game)
}
}
}) { error in
// Handle any errors that occur during the request
print("Error searching for the game: \(error)")
}
whenever a lowercase 'w' is queried the following error is printed:
Error searching for the game: RequestException(statusCode: 400, url: "https://api.igdb.com/v4/games.pb", msg: "[\n {\n \"title\": \"Syntax Error\",\n \"status\": 400\n }\n]")
IGDB_SWIFT_API/ProtoRequest.swift:107: Fatal error: 'try!' expression unexpectedly raised an error: SwiftProtobuf.BinaryDecodingError.truncated
seems to me like the force unwrap being used in that function is the issue
similar to #10
maybe fixed in moritzscholz's fork where he fixes the force unwrap, still crashes for me though
I am trying to use this package with example code, I ahve setup Access Token and ClientID, but this error is raised up everytime
Fatal error: 'try!' expression unexpectedly raised an error: SwiftProtobuf.BinaryDecodingError.truncated: file IGDB_SWIFT_API/ProtoRequest.swift, line 107
I'm trying to build a quick app using Swift 5 and I can't get it working. Do you have any plans of upgrading it to the last version?
Thanks for your work!
Hello,
I couldn't fetch the photos. Is it possible to help me about this?
let apicalypse = APICalypse()
.fields(fields: "*")
.limit(value: 50)
.sort(field: "release_dates.date", order: .DESCENDING)
.where(query: "themes != 42")
wrapper.games(apiCalypse: apicalypse, result: { games in
for game in games {
self.games.append(game)
print(game.artworks.map({$0.url}))
if game.hasCover {
print("GAMEURL \(game.cover)")
}
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}) { error in
print(error.localizedDescription as Any)
}
Please consider the use of the Swift Package manager. It's such a breeze compared to Cocoa Pods.
Hi,
I'm trying to use this wrapper but I'm not sure if I'm in right way ...
let wrapper: IGDBWrapper = IGDBWrapper()
wrapper.userKey = SecretConstants.tokenIGDB
let params: APICalypse = APICalypse()
.search(searchQuery: "Halo")
.fields(fields: "*")
.sort(field: "release_dates.date", order: .DESCENDING)
wrapper.search(apiCalypse: params, result: { searchGames in
let games = searchGames.map { $0.game }
return completionHandler(games, nil)
}) { error in
return completionHandler(nil, "IGDB: Error parsing API")
}
I have a crash here in your code:
public func search(apiCalypse: APICalypse, result: @escaping ([Proto_Search]) -> (Void), errorResponse: @escaping (RequestException) -> (Void)) {
apiRequest(endpoint: .SEARCH, apicalypseQuery: apiCalypse.buildQuery(), dataResponse: { bytes -> (Void) in
let objects = try! Proto_SearchResult(serializedData: bytes).searches
result(objects)
}, errorResponse: errorResponse)
}
In the try! : Thread 13: Fatal error: 'try!' expression unexpectedly raised an error: SwiftProtobuf.BinaryDecodingError.malformedProtobuf
So I can't make a proper search
And if I use games
instead a search
I'm getting some results but I can't have any cover for games or screenshots:
if let hasCover = gameUpdate?.hasCover, hasCover, let cover = gameUpdate?.cover {
let imageURL = imageBuilder(imageID: cover.imageID, size: .HD, imageType: .PNG)
print(imageURL) // "https://images.igdb.com/igdb/image/upload/t_720p/.png"
print(cover.imageID) // ""
}
Do you have any ideas ?
Thank you
I noticed that I can make a call to https://api.igdb.com/v4/games/count
and get the total Number of results.
Is this supported currently? I'm trying to make a pagination using the offset.
Also, thanks for this great wrapper!
It is hard to handle image urls and image sizes.
I should create a function that builds the urls for me
example code:
func fetchImages( for imagePref : ImagePref, doubleSize : Bool , image : UIImageView, _ url : String) {
var urlBase : String = ""
switch imagePref {
case .cover_small :
urlBase = "cover_small"
case .screenshot_med :
urlBase = "screenshot_med"
case .cover_big :
urlBase = "cover_big"
case .logo_med :
urlBase = "logo_med"
case .screenshot_big :
urlBase = "screenshot_big"
case .screenshot_huge :
urlBase = "screenshothuge"
case .thumb :
urlBase = "thumb"
case .micro :
urlBase = "micro"
case .hd :
urlBase = "720p"
case .fullHd :
urlBase = "1080p"
}
if doubleSize {
let url = URL(string: "https://images.igdb.com/igdb/image/upload/t(urlBase)2x/(url).jpg")
gameImage.kf.setImage(with: url)
} else {
let url = URL(string: "https://images.igdb.com/igdb/image/upload/t(urlBase)/(url).jpg")
gameImage.kf.setImage(with: url)
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.