Code Monkey home page Code Monkey logo

wordpressswift's Introduction

WordPressSwift

Version License Platform

Description

WordPressSwift allow you to integrate a WordPress blog on your own app. You can retreive the categories of the blog, posts (you can filter by category), and the featured image of one post. In next versions we'll introduce more amazing features.

Usage

Run the example project from the Example directory and check out CategoryViewController.swift and PostViewController.swift.

import WordPressSwift

let wordpress = WordPressSwift()

// Get categories

var myCategories: [WPCategory] = []
wordpress.getCategories(blogURL: "http://myBlog.es") { (categories) in

    self.myCategories = categoriesblogURL
    
    // Write here all that you want to execute after load categories.

}

// Get posts

var myPosts: [WPPost] = []

wordpress.getPosts(blogURL: "http://myBlog.es", page: 1, postPerPage: 5) { (posts) in

    /*
    If you have a blog with many posts, the best way to load it quickly on your app is loading posts by pages. You must enter the page to load (you can use a counter to increment it when you want to load more posts) and postPerPage, which is the number of posts that you want load per each page.
    
    Also you need to provide an integer array to categoryID. You can filter the posts by categories, so you can provide here the IDs of categories to filter (you can access to ID on WPCategory.id). If you want to load all posts, put categoryID to [0].
    */

    self.myPosts = postsblogURL
    
    // Write here all that you want to execute after load categories.

}

// Get featured image of a postafter

var myImage: WPFeaturedImage!

wordpress.featuredImage(blogURL: "http://myBlog.es", post: myPost) { (image) in

    /*
    On post parameter you must provide a post of type: WPPostblogURL
    */

    self.myImage = image
    
    // Write here all that you want to execute after load categories.
    
}

Data types

WordPressSwift uses three data types: WPCategory, WPPost and WPFeaturedImage. The types of data includes multiple values that can be useful in development process.

public struct WPPost: Codable {

    public struct Title: Codable {
        public let text: String
    }

    public struct Content: Codable {
        public let text: String
        public let protected: Bool
    }

    public struct Excerpt: Codable {
        public let text: String
        public let protected: Bool
    }

    public let id: Int
    public let date: String
    public let date_gmt: String
    public let modified: String
    public let modified_gmt: String
    public let slug: String
    public let status: String
    public let type: String
    public let link: String
    public let title: Title
    public let content: Content
    public let excerpt: Excerpt
    public let author: Int
    public let featured_media: Int
    public let comment_status: String
    public let ping_status: String
    public let sticky: Bool
    public let template: String
    public let format: String
    public let categories: [Int]
    public let tags: [Int]

}

public struct WPCategory: Codable {

    public let id: Int
    public let count: Int
    public let description: String
    public let link: String
    public let name: String
    public let slug: String
    public let taxonomy: String
    public let parent: Int

}

public struct WPFeaturedImage: Codable {

    public struct MediaDetails: Codable {
        public let width: Int
        public let height: Int
        public let file: String
    }

    public let id: Int
    public let image: String
    public let type: String
    public let media_type: String
    public let media_details: MediaDetails

}

Installation

WordPressSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'WordPressSwift'

You can also copy into your project the file WordPressSwift.framwork

Requirements

iOS 10.0 and Swift 4.0 are required.

Author

I'm Ruben Fernandez Email: [email protected] Twitter: @RubenApps.

License

WordPressSwift is available under the MIT license. See the LICENSE file for more info.

wordpressswift's People

Contributors

rubenfer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.