Latest 0.5.0
Homepage https://github.com/mattwyskiel/GoogleAPISwiftClient
License Apache License, Version 2.0
Platforms ios 8.0, osx 10.9, watchos 2.0, requires ARC
Dependencies Alamofire, ObjectMapper
Frameworks Foundation
Authors

Google APIs Swift Client

A lot of us probably use at least one of Google’s public data APIs, and those of us using Cocoa and Cocoa Touch are directed to the open-source Google APIs Objective-C Client for implementation help.

It was good for what it was in 2011, but that was before Swift, modern Objective-C, CocoaPods, and even Automatic Reference Counting! Some things in life age well; that library is not one of them. And Google hasn’t helped by basically ignoring their client library in these ways. They don’t even support it in their new CocoaPods-based library distribution system! (Don’t be fooled: "Google APIs for iOS" is just an aggregation pod for all the other "modern" libraries that Google supports with this distribution flow, obviously not including the aforementioned Data APIs Client)

That’s why I decided I would try something new. Something that would actually utilize current technologies. Something that would be actually nice for developers to use.

I couldn’t find what I was looking for, so I decided to build it myself.

This library is still in its early stages. It contains the base model and fetcher classes and protocols, as well as implementations of the Discovery API, the Blogger API, and the YouTube Data API. More services to come! See Contributing below if you would like to help. Even starring this project helps me know this project is worth working on.

Installation

  pod 'GoogleAPISwiftClient/{API}', '~> 0.5.0'

where API is the name of the API you wish to use. You can use multiple API’s – just use multiple pod declarations! API names are listed in the podspec file under subspecs.

Then import:

  import GoogleAPIs

Authentication

The Google APIs use one of two methods for authentication: an API Key or OAuth 2.0.

Both the API key and OAuth access token are set directly in the GoogleService protocol conformant, before any service fetchers that require authentication by either are called (see the specific service API’s documentation for which authentication method to use for a specific method).

This means that you can use any means necessary to get the OAuth token information and keep it up to date. You can use GTM-OAuth2, the new Google Sign-in SDK, or any other OAuth 2 library to get the job done.

Basic Usage

Simply use a chosen service’s base class (named after itself) to make a request, which then returns the data to a completion handler.

For example, if I wanted to fetch a specific comment for a given Blogger post:

  • First I’d initialize the Blogger service
    let bloggerService = Blogger()
  • Then I’d set the API Key:
    bloggerService.fetcher.apiKey = "abcdefghijklmnop1234567890" // Example
  • Then I’d only need to call this method to get a specific comment for a blog post:
    bloggerService.getCommments(commentId: "abcdef", postId: "ghijkl", blogId: "1234567") {
      comment, error in
      // handle
    }

It really is that simple!

Contributing

  • If you would like to help improve the base classes and protocols (GoogleObject, GoogleService, etc.) then feel free to fork and create a pull request for this repository.
  • If you would like to add new services, please see GoogleServiceGenerator. That repository hosts the code for the app that generates the code for the Google services.

License

Apache License, Version 2.0

See LICENSE file for details.

Latest podspec

{
    "name": "GoogleAPISwiftClient",
    "version": "0.5.0",
    "summary": "A Google API Client for Apple Platforms in 2016",
    "description": "A lot of us probably use at least one of Google's public data APIs, and those of us using Cocoa and Cocoa Touch are directed to the open-source [Google APIs Objective-C Client](https://code.google.com/p/google-api-objectivec-client/) for implementation help.nIt was good for what it was in 2011, but that was before Swift, modern Objective-C, CocoaPods, and even Automatic Reference Counting! Some things in life age well; that library is not one of them. And Google hasn't helped by basically ignoring their client library in these ways.nThat's why I decided I would try something new. Something that would actually utilize current technologies. Something that would be actually nice for developers to use.nI couldn't find what I was looking for, so I decided to build it myself.nThis library is still in its early stages, but I'm excited for what this library could become!",
    "homepage": "https://github.com/mattwyskiel/GoogleAPISwiftClient",
    "license": "Apache License, Version 2.0",
    "authors": {
        "Matthew Wyskiel": "[email protected]"
    },
    "social_media_url": "https://twitter.com/mattwyskiel",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0"
    },
    "source": {
        "git": "https://github.com/mattwyskiel/GoogleAPISwiftClient.git",
        "tag": "0.5.0"
    },
    "frameworks": "Foundation",
    "requires_arc": true,
    "dependencies": {
        "Alamofire": [
            "~> 3.3.0"
        ],
        "ObjectMapper": [
            "~> 1.2.0"
        ]
    },
    "module_name": "GoogleAPIs",
    "default_subspecs": "Common",
    "subspecs": [
        {
            "name": "Common",
            "source_files": "GoogleClient/*.{swift}"
        },
        {
            "name": "Discovery",
            "source_files": "GoogleClient/Discovery/*.{swift}",
            "dependencies": {
                "GoogleAPISwiftClient/Common": []
            }
        },
        {
            "name": "Blogger",
            "source_files": "GoogleClient/Blogger/*.{swift}",
            "dependencies": {
                "GoogleAPISwiftClient/Common": []
            }
        },
        {
            "name": "YouTube",
            "source_files": "GoogleClient/YouTube/*.{swift}",
            "dependencies": {
                "GoogleAPISwiftClient/Common": []
            }
        }
    ]
}

Pin It on Pinterest

Share This