A library wrapping the Pastebin.com API.
Xcode 8 or greater
- Clone the repository
- Copy
Pastr.swift
into your project
Pastr is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Pastr"
import Pastr
(if using CocoaPods)
Configure Pastr with your Pastebin api key. Read more about it and how you obtain one here
Pastr.pasteBinApiKey = "<API key>"
If you're accessing apis that requires an authenticated user, you have to set the user key:
Pastr.pastebinUserKey = "<User key>"
Pastr.post(text: "Hey I'm posting this to Pastebin!") { result in
switch result {
case .failure(let error): fatalError() // Handle
case .success(let key): print("Posted paste with key \(key)")
}
}
This function accepts the following parameters:
name
- To give the paste a namescope
- Private, public or unlisted (enumPastrScope
)format
- Pastebin supports syntax highlighting. A list of supported types are available inPastr.Format
expiration
- Sets when the post should expire (default is never) (enumPastrExpiration
).
Pastr.get(paste: "<a paste key>") { result in
switch result {
case .failure(let error): fatalError() // Handle
case .success(let content): print("Retrieved: \(content)")
}
}
This function will authenticate a user with pastebin and return a "user key" to be used for functions that require this token.
Pastr.delete(paste: "<a paste key>") { result in
…
}
Pastr.delete(paste: "<a paste key>") { result in
…
}
Pastr.getUserPastes { result in
…
}
Will return a raw string containing XML.
Retrieves the 18 currently trending pastes.
Pastr.getTrendingPastes { result in
…
}
Will return a raw string containing XML.
Pastr.getUserInfo { result in
…
}
Will return a raw string containing XML.
If you find a bug or have some ideas for improvements, create a new issue or open a pull request.
Pastr is available under the MIT license. See the LICENSE file for more info.