GitXplorerGitXplorer
N

SwiftChatty

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
912958a31883536e408dd3387e268b6b32d6cbec

Merge remote-tracking branch 'andrebocchini/master'

NNuclearMonster committed 8 years ago
Unverified
4c1186bc904fc63a52c0e236458f31c7e1702db5

Update .travis.yml

aandrebocchini committed 8 years ago
Unverified
827d9ab3f8634bc01a858228ee2931d570f07d99

Update SwiftChatty.podspec

aandrebocchini committed 8 years ago
Unverified
7bbc9f8ae277fc14ef8382d79bc25ee9d9a9f14c

Update .travis.yml

aandrebocchini committed 8 years ago
Unverified
9b0c94449eaac133612ca36b7105ad8d59cda511

Update .travis.yml

aandrebocchini committed 8 years ago
Unverified
b6ac93a5bf09add93610e792a1e879a1e39cf160

Update .travis.yml

aandrebocchini committed 8 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