Skip to content

Commit

Permalink
#12 #19 Begin setting up initial support for Micropub Sessions as wel…
Browse files Browse the repository at this point in the history
…l as initial models for a Micropub Config request
  • Loading branch information
Edward Hinkle committed Jun 13, 2019
1 parent c4ea08f commit 408cbf1
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Sources/IndieWebKit/Micropub/MicropubSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,41 @@ public class MicropubSession {
with accessToken: String) {

self.micropubEndpoint = micropubEndpoint
self.accessToken = accessToken
}

func start(completion: @escaping ((URL?) -> ())) {
guard url != nil else {
// TODO: Throw some type of error
return
func getConfigQuery() throws {
let request = try getConfigurationRequest()
URLSession.shared.dataTask(with: request) { body, response, error in



}

}

// func start(completion: @escaping (() -> Void)) {
// guard url != nil else {
// // TODO: Throw some type of error
// return
// }
//
// }

func getConfigurationRequest() throws -> URLRequest {
guard var configRequestUrl = URLComponents(url: micropubEndpoint, resolvingAgainstBaseURL: false) else {
throw MicropubError.generalError("Config Query Url Malformed")
}

configRequestUrl.queryItems = [
URLQueryItem(name: "q", value: "config")
]

var request = URLRequest(url: configRequestUrl.url!)
request.httpMethod = "GET"
request.addValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Accept")
return request
}

// func getVerificationRequest(with code: String) throws -> URLRequest {
// var request = URLRequest(url: authorizationEndpoint)
Expand Down
24 changes: 24 additions & 0 deletions Sources/IndieWebKit/Micropub/models/MicropubConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// MicropubConfig.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation

// This is the value returned from the Micropub configuration query endpoint.
// See https://micropub.net/draft/#configuration for more information
public struct MicropubConfig: Codable {
let mediaEndpoint: URL?
let syndicateTo: [SyndicationTarget]?
let postTypes: [PostType]? // This supports the Supported Vocabulary extension. See https://github.com/indieweb/micropub-extensions/issues/1
let q: [MicropubQueryType]? // This supports the Supported Queries extension. See https://github.com/indieweb/micropub-extensions/issues/7

enum CodingKeys: String, CodingKey {
case mediaEndpoint = "media_endpoint"
case syndicateTo = "syndicate_to"
case postTypes = "post_types"
case q
}
}
11 changes: 11 additions & 0 deletions Sources/IndieWebKit/Micropub/models/MicropubError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// MicropubError.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation
enum MicropubError: Error {
case generalError(String)
}
17 changes: 17 additions & 0 deletions Sources/IndieWebKit/Micropub/models/MicropubQueryType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MicropubQueryType.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation

// This defines the types of Micropub queries that this framework knows about..
// For more information, see: https://indieweb.org/Micropub-extensions
public enum MicropubQueryType: String {
case source
case syndicateTo = "syndicate-to"
case category
case contact
}
21 changes: 21 additions & 0 deletions Sources/IndieWebKit/Micropub/models/PostType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// PostType.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation

// The enum value becomes the "type" of supported post type, and the associated String is the name used by the server
public enum PostType: String {
case note(String)
case article(String)
case photo(String)
case video(String)
case reply(String)
case like(String)
case repost(String)
case rsvp(String)
case bookmark(String)
}
12 changes: 12 additions & 0 deletions Sources/IndieWebKit/Micropub/models/SupportedPostType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// SupportedPostType.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation
public struct SupportedPostType {
let type: PostType
let name: String
}
14 changes: 14 additions & 0 deletions Sources/IndieWebKit/Micropub/models/SyndicationTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SyndicationTarget.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation
public struct SyndicationTarget {
let uid: String
let name: String
let service: SyndicationTargetCard
let user: SyndicationTargetCard
}
13 changes: 13 additions & 0 deletions Sources/IndieWebKit/Micropub/models/SyndicationTargetCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SyndicationTargetCard.swift
//
//
// Created by ehinkle-ad on 6/13/19.
//

import Foundation
public struct SyndicationTargetCard {
let name: String
let url: URL?
let photo: URL?
}

0 comments on commit 408cbf1

Please sign in to comment.