Skip to content

Commit

Permalink
Merge pull request #159 from mattdonnelly/swift-3
Browse files Browse the repository at this point in the history
Swifter 2.0 with Swift 3
  • Loading branch information
meteochu authored Sep 9, 2016
2 parents 3f716d0 + 23b3cff commit 0cd4ffd
Show file tree
Hide file tree
Showing 47 changed files with 1,616 additions and 2,514 deletions.
101 changes: 54 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,99 @@

## Getting Started

###Installation
### Installation

If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own project and adding either the SwifteriOS or SwifterMac framework as an embedded framework.

### Swift 3
### Usage

For those using Xcode 8 and Swift 3, there is a [swift-3 branch](https://github.com/mattdonnelly/Swifter/tree/swift-3) of Swifter available. It will be merged to master once Swift 3 exits beta later this year.


###Usage

Swifter can be used with the 3 different kinds of authentication protocols Twitter allows. You can specify which protocol to use as show below.
Swifter can be used with the 3 different kinds of authentication protocols Twitter allows. You can specify which protocol to use as show below. For more information on each of the authentication protocols, please check [Twitter OAuth Help](https://dev.twitter.com/oauth).

Instantiation with ACAccount:

```swift
let swifter = Swifter(account: twitterAccount)
```

Instantiation with OAuth:
// Instantiation using ACAccount
var swifter = Swifter(account: twitterAccount)

```swift
let swifter = Swifter(consumerKey: "", consumerSecret: "")
```
// Instantiation using Twitter's OAuth Consumer Key and secret
swifter = Swifter(consumerKey: TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_SECRET)

Instantiation with App Only Auth:
// Instantiation using App-Only authentication
swifter = Swifter(consumerKey: TWITTER_CONSUMER_KEY, consumerSecret: TWITTER_CONSUMER_SECRET, appOnly: true)

```swift
let swifter = Swifter(consumerKey: "", consumerSecret: "", appOnly: true)
```

##Example Requests
## Example Requests

####OAuth Authorization:
#### OAuth Authorization:

```swift
swifter.authorizeWithCallbackURL(callbackURL, success: { accessToken, response in
// ...

}, failure: { error in
swifter.authorize(with: callbackURL, success: { accessToken, response in
// ...
}, failure: { error in
// ...
})
```

// ...
#### Get Home Timeline:

```swift
swifter.getHomeTimeline(count: 50, success: { json in
// ...
}, failure: { error in
// ...
})
```

####Get Home Timeline:
#### Using API that allows for `user_id`/`screenName` or `list_id`/`slug`
Certain Twitter API allows you to use either the `user_id` or `screen_name` to get user related objects (and `list_id`/`slug` for lists). Swifter offers a solution so that the user won't accidentally use the wrong method, and have nothing returned. For more information, check the `SwifterTag.swift` file.

```swift
swifter.getStatusesHomeTimelineWithCount(20, success: { statuses in
// ...

}, failure: { error in
swifter.getUserFollowersIDs(for: .id(userId), success: { json, prev, next in
// alternatively, you can use .screenName(userName)
// ...
}, failure: { error in
// ...

})
```

####Streaming API:
```

```swift
swifter.getStatusesSampleDelimited(progress: { status in
// ...

}, stallWarnings: { code, message, percentFull in
swifter.getListSubscribers(for: .slug(listSlug, owner: .screenName(userName)), success: { json, prev, next in
// alternatively, you can use .id(listId)
// ...

}, failure: { error in
}, failure: { error in
// ...

})

```
Additionally, there is also `.screenName(arrayOfUserNames)` and `.id(arrayOfIds)` for methods that take arrays of screen names, or userIDs

####Status Update:
#### Streaming API:

```swift
swifter.postStatusUpdate("Hello, world", success: { status in
// ...
swifter.streamRandomSampleTweets(progress: { status in
// ...
}, stallWarnings: { code, message, percentFull in
// ...
}, failure: { error in
// ...
})
```

}, failure: { error in
// ...
#### Status Update:

```swift
swifter.postTweet(status: "Hello, world.", success: { status in
// ...
}, failure: { error in
// ...
})
```

##JSON Handling
## JSON Handling

To make accessing data returned by twitter requests, Swifter provides a class for representing JSON which you interact with similarly to a dictionary. The main advantage of using this instead of a Dictionary<String, AnyObject> is that it works better with Swift's strict typing system and doesn't require you to constantly downcast accessed objects. It also removes the need for lots optional chaining, making your code much cleaner and easier to read.

Expand All @@ -101,10 +108,10 @@ if let statusText = statuses[0]["text"].string {
}
```

##OAuth Consumer Tokens
## OAuth Consumer Tokens

In Twitter REST API v1.1, each client application must authenticate itself with consumer key and consumer secret tokens. You can request consumer tokens for your app on Twitter's website: https://dev.twitter.com/apps.
In Twitter REST API v1.1, each client application must authenticate itself with consumer key and consumer secret tokens. You can request consumer tokens for your app on [Twitter's dev website](https://dev.twitter.com/apps)

#License
# License

Swifter is licensed under the MIT License. See the LICENSE file for more information.
Loading

0 comments on commit 0cd4ffd

Please sign in to comment.