TMTumblrSDK


## Introduction


The TMTumblrSDK is a library that allows developers to integrate Tumblr functionality into their iOS applications. With this SDK, you can easily authenticate users, fetch blog data, create and edit posts, manage likes and followers, and much more. This documentation will guide you through the process of installing and using the TMTumblrSDK in your iOS project.


## Installation


To install the TMTumblrSDK, follow these steps:


### Step 1: CocoaPods


The recommended way to install the TMTumblrSDK is by using CocoaPods. If you haven’t already, install CocoaPods by running the following command in your terminal:

“`bash
$ gem install cocoapods
“`


Once CocoaPods is installed, navigate to your project directory and create a new file called `Podfile` using the following command:

“`bash
$ pod init
“`


Open the `Podfile` and add the following lines:

“`ruby
# Podfile
platform :ios, ‘9.0’
target ‘YourTargetName’ do
use_frameworks!

pod ‘TMTumblrSDK’
end
“`


Save the `Podfile` and run the following command:

“`bash
$ pod install
“`


### Step 2: Manual Installation


Alternatively, if you prefer not to use CocoaPods, you can manually install the TMTumblrSDK:

1. Download the latest version of the TMTumblrSDK from the official GitHub repository: [TMTumblrSDK on GitHub](https://github.com/tumblr/TMTumblrSDK)
2. Unzip the downloaded file.
3. Open your Xcode project and select the Project Navigator.
4. Right-click on your project’s folder and select “Add Files to [Your Project Name]”.
5. Navigate to the unzipped TMTumblrSDK folder and select the `TMTumblrSDK.xcodeproj`.
6. In the project settings, select your target and go to the “General” tab.
7. Scroll down to the “Embedded Binaries” section and click the “+” button.
8. Select the `TMTumblrSDK.framework` from the list and click “Add”.


With the TMTumblrSDK successfully installed in your project, you can now start integrating Tumblr functionality into your iOS app.


## Getting Started


Before you can start using the TMTumblrSDK, make sure you have registered your application with Tumblr. Obtain your OAuth consumer key and secret, as they will be required for authentication.


### Authentication


To authenticate a user, use the `TMAPIClient` class. Below is a quick example of how to authenticate a user using OAuth:

“`swift
import TMTumblrSDK

// Create an instance of TMAPIClient with your OAuth consumer key and secret
let client = TMAPIClient.sharedInstance()

// Authenticate using OAuth
client.authenticate(with: .OAuth, presentingViewController: self) { (error, success) in
if success {
// Authentication successful, perform further actions
} else {
// Authentication failed, handle the error
}
}
“`


Make sure to replace `YOUR_CONSUMER_KEY` and `YOUR_CONSUMER_SECRET` with your actual OAuth consumer key and secret.


Upon successful authentication, you will receive an OAuth token and OAuth token secret, which you can use for subsequent API calls.


### Fetching Blog Data


To fetch data from a Tumblr blog, use the `TMAPIClient` class. Below is an example of how to fetch the latest posts from a blog:

“`swift
import TMTumblrSDK

// Create an instance of TMAPIClient with your OAuth consumer key and secret (already authenticated)
let client = TMAPIClient.sharedInstance()

// Fetch the latest posts from a blog
client.posts(“blogname.tumblr.com”, type: .text, parameters: [:]) { (response, error) in
if let response = response as? [String: Any] {
// Process the response data
} else {
// Handle the error
}
}
“`


Replace `”blogname.tumblr.com”` with the actual name of the blog you want to fetch data from.


### Creating a Post


To create a new post on Tumblr, use the `TMAPIClient` class. Below is an example of how to create a text post:

“`swift
import TMTumblrSDK

// Create an instance of TMAPIClient with your OAuth consumer key and secret (already authenticated)
let client = TMAPIClient.sharedInstance()

// Create a new text post
let post = TMAPIClient.newPost(“blogname.tumblr.com”, type: .text)
post.title = “My First Post”
post.body = “Hello, Tumblr!”

// Publish the post
client.create(post) { (response, error) in
if let response = response as? [String: Any] {
// Post creation successful
} else {
// Handle the error
}
}
“`


Replace `”blogname.tumblr.com”` with the actual name of the blog you want to create the post on.


## Additional Functionality


In addition to the basic functionality covered above, the TMTumblrSDK provides various methods for managing likes, followers, drafts, tags, and more. For detailed information on each available function, refer to the official TMTumblrSDK documentation: [TMTumblrSDK Documentation](https://github.com/tumblr/TMTumblrSDK/wiki)


## Conclusion


The TMTumblrSDK is a powerful tool for integrating Tumblr functionality into your iOS applications. By following the installation steps and familiarizing yourself with the provided functionality, you can create compelling Tumblr-powered experiences for your users. Happy coding!