GitXplorerGitXplorer
N

SwiftChatty

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
972cd5256014ecb597c364daee6b7616986f6fad

Update README.md

aandrebocchini committed 8 years ago
Unverified
daaa110f00555eaba556a2b523964c914de7bca8

Updated Genome and Alamofire

committed 8 years ago
Unverified
ecad1c8a559d30fb3b0ac3896d46238e48f1b990

Merge remote-tracking branch 'andrebocchini/master'

NNuclearMonster committed 8 years ago
Unverified
754271a9257aefc557c03ae538f0f923bcd1ec0e

Merge pull request #1 from TimeDoctor/master

aandrebocchini committed 8 years ago
Unverified
e8e79496604de5113304a39553639aec2b18f4f8

Updated CocoaPods

NNuclearMonster committed 8 years ago
Unverified
50452a4a7376cc15eda69afb601ebd047db3c60c

Update .travis.yml

aandrebocchini committed 9 years ago

README

The README file for this repository.

Build Status

What is SwiftChatty?

SwiftChatty is an iOS/OSX/tvOS/WatchOS framework written in Swift that models the WinChatty v2 API.

It currently models all requests and data types listed on the WinChatty v2 documentation page, and aims to make using the API as easy as possible for developers wanting to build applications that interact with the Chatty.

How do I use it?

First, create your project in XCode and make sure you have CocoaPods installed. Then create the following Podfile for your project:

use_frameworks!

pod 'SwiftChatty', :git => 'https://github.com/andrebocchini/swiftchatty.git'

After creating the Podfile, run:

pod install

The SwiftChatty framework tries to model the WinChatty v2 API as closely as possible. And the best way to illustrate how it works, is to show an example.

First, add the following line to the top of your source file:

import SwiftChatty

If you look at the documentation for the getChattyRootPosts request, you'll find that it takes the following parameters:

  • offset: Number of threads to skip (for paging)
  • limit: Maximum number of threads to return (for paging)
  • username: If provided, this allows the isParticipant flag to be returned for each thread indicating whether the user posted that thread or replied to it.
  • date: If provided, posts from this day will be returned rather than the currently active chatty posts.

Using SwiftChatty, you'd create a request for that API call like this:

let request = GetChattyRootPostsRequest(withOffset: 0, limit: 100, username: "electroly", date: nil)

And now that you have the request ready to go, you can just feed it to the SwiftChatty client like this:

Client.request(request, completion: { (response: ClientRequestResult<GetChattyRootPostsResponse>) in
    switch response {
    case .Success(let response):
        print("Number of threads: \(response.totalThreadCount)")
        for post in response.rootPosts {
            print("Post ID: \(post.id) - Author: \(post.author)")
        }
    case .Failure(let error):
        print(error)
    }
})

The response object, in this case GetChattyRootPostsResponse, will have two properties that match the properties of the response received from the WinChatty server:

  • totalThreadCount: an integer indicating how many threads it found.
  • rootPosts: An array of RootPost objects. One for each thread.

All documented requests were modeled in the same fashion. So if you want to retrieve posts using the getPost API call, you would build a request using the GetPostRequest model, and would get a GetPostResponse model in return.

WatchOS (or any mixed target) projects

If you are making a WatchOS app (or some other mixed target project), and you try to use SwiftChatty in more than one target, you will probably have to build a Podfile that looks a little like this:

use_frameworks!

def shared_pods
    pod 'SwiftChatty', :git => 'https://github.com/andrebocchini/swiftchatty.git'
end

target 'SwiftChatty WatchOS Demo' do
    platform :ios, '9.0'
    shared_pods
end

target 'SwiftChatty WatchOS Demo WatchKit Extension' do
    platform :watchos, '2.0'
    shared_pods
end

When you run pod install, you will also see CocoaPods print a lot of warnings about duplicate UUIDs and such, and that's normal. Things should still work ok. If you want to disable all those warnings, you can run this in your terminal:

export COCOAPODS_DISABLE_DETERMINISTIC_UUIDS=YES

Dependencies