Skip to content

google-books/swift-api-client

Repository files navigation

Google Books API Client Library for Swift

CocoaPods Version License Swift Version

The Google Books API Client Library for Swift

Installation

The supported options:

CocoaPods

Add this to Podfile

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'GoogleBooksApiClient'
end
$ pod install

Carthage

Add this to Cartfile

github "google-books/swift-api-client"
$ carthage update

How to use

The library makes it simple to call Google Books APIs.

import GoogleBooksApiClient

let session = URLSession.shared
let client = GoogleBooksApiClient(session: session)

Volume

list

let req = GoogleBooksApi.VolumeRequest.List(query: "Google")
let task: URLSessionDataTask = client.invoke(
    req,
    onSuccess: { volumes in NSLog("\(volumes)") },
    onError: { error in NSLog("\(error)") }
)
task.resume()

Mylibraly.Bookshlves

addVolume

let authInfo = GoogleBooksApiAuthInfo(apiKey: nil, authToken: "YOUR_AUTH_TOKEN")
let req = GoogleBooksApi.MyLibraryBookshelvesRequest.AddVolume(
    shelf: BookshelfId.haveRead,
    volumeId: Id("VOLUME_ID"),
    authInfo: authInfo
)
let task: URLSessionDataTask = client.invoke(
    req,
    onSuccess: { volumes in NSLog("\(volumes)" },
    onError: { error in NSLog("\(error)") }
)
task.resume()

License

MIT