diff --git a/Sources/IndieWebKit/Micropub/MicropubSession.swift b/Sources/IndieWebKit/Micropub/MicropubSession.swift index 867ef60..187f015 100644 --- a/Sources/IndieWebKit/Micropub/MicropubSession.swift +++ b/Sources/IndieWebKit/Micropub/MicropubSession.swift @@ -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) diff --git a/Sources/IndieWebKit/Micropub/models/MicropubConfig.swift b/Sources/IndieWebKit/Micropub/models/MicropubConfig.swift new file mode 100644 index 0000000..1d6a2ff --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/MicropubConfig.swift @@ -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 + } +} diff --git a/Sources/IndieWebKit/Micropub/models/MicropubError.swift b/Sources/IndieWebKit/Micropub/models/MicropubError.swift new file mode 100644 index 0000000..5fe03d9 --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/MicropubError.swift @@ -0,0 +1,11 @@ +// +// MicropubError.swift +// +// +// Created by ehinkle-ad on 6/13/19. +// + +import Foundation +enum MicropubError: Error { + case generalError(String) +} diff --git a/Sources/IndieWebKit/Micropub/models/MicropubQueryType.swift b/Sources/IndieWebKit/Micropub/models/MicropubQueryType.swift new file mode 100644 index 0000000..4a6c17e --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/MicropubQueryType.swift @@ -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 +} diff --git a/Sources/IndieWebKit/Micropub/models/PostType.swift b/Sources/IndieWebKit/Micropub/models/PostType.swift new file mode 100644 index 0000000..54bfed4 --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/PostType.swift @@ -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) +} diff --git a/Sources/IndieWebKit/Micropub/models/SupportedPostType.swift b/Sources/IndieWebKit/Micropub/models/SupportedPostType.swift new file mode 100644 index 0000000..d8161ff --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/SupportedPostType.swift @@ -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 +} diff --git a/Sources/IndieWebKit/Micropub/models/SyndicationTarget.swift b/Sources/IndieWebKit/Micropub/models/SyndicationTarget.swift new file mode 100644 index 0000000..dd3486e --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/SyndicationTarget.swift @@ -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 +} diff --git a/Sources/IndieWebKit/Micropub/models/SyndicationTargetCard.swift b/Sources/IndieWebKit/Micropub/models/SyndicationTargetCard.swift new file mode 100644 index 0000000..7b1016d --- /dev/null +++ b/Sources/IndieWebKit/Micropub/models/SyndicationTargetCard.swift @@ -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? +}