Skip to content

Commit

Permalink
Update minimum platform version
Browse files Browse the repository at this point in the history
Closes #255
  • Loading branch information
sbertix committed Aug 31, 2021
1 parent 670b2f5 commit 25cb7d8
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 158 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "SwiftyInsta",
platforms: [
.macOS(.v10_12), .iOS(.v9), .tvOS(.v9)
.macOS(.v10_14), .iOS(.v12), .tvOS(.v12), .watchOS(.v5)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
16 changes: 8 additions & 8 deletions SwiftyInsta.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SwiftyInsta"
s.version = "2.5.0"
s.version = "2.6.0"
s.summary = "Private and Tokenless Instagram RESTful API."

s.homepage = "https://github.com/TheM4hd1/SwiftyInsta"
Expand All @@ -10,18 +10,18 @@ Pod::Spec.new do |s|
s.module_name = "SwiftyInsta"
s.swift_version = "5.0"

s.ios.deployment_target = "10.0"
s.osx.deployment_target = "10.12"
s.watchos.deployment_target = "3.0"
s.tvos.deployment_target = "10.0"
s.ios.deployment_target = "12.0"
s.osx.deployment_target = "10.14"
s.watchos.deployment_target = "5.0"
s.tvos.deployment_target = "12.0"

s.source = { :git => "https://github.com/TheM4hd1/SwiftyInsta.git", :tag => "#{s.version}" }
s.source_files = "SwiftyInsta/**/*.{h,m,swift}"

s.ios.frameworks = 'UIKit', 'WebKit'
s.macos.frameworks = 'AppKit'
s.tvos.frameworks = 'UIKit'
s.watchos.frameworks = 'UIKit'
s.macos.frameworks = 'AppKit', 'WebKit'
s.tvos.frameworks = 'UIKit', 'WebKit'
s.watchos.frameworks = 'UIKit', 'WebKit"
s.dependency "CryptoSwift", "~> 1.3"
s.dependency "KeychainSwift", "~> 19.0"
Expand Down
110 changes: 0 additions & 110 deletions SwiftyInsta/API/Handlers/StoryHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,116 +113,6 @@ public final class StoryHandler: Handler {
}
}

@available(*, unavailable, message: "Instagram changed this endpoint. We're working on making it work again.")
/// Upload photo.
public func upload(photo: Upload.Picture, completionHandler: @escaping (Result<Upload.Response.Picture, Error>) -> Void) {
guard let storage = handler.response?.storage else {
return completionHandler(.failure(GenericError.custom("Invalid `Authentication.Response` in `APIHandler.respone`. Log in again.")))
}
let uploadId = String(Date().millisecondsSince1970 / 1000)
// prepare content.
var content = Data()
content.append(string: "--\(uploadId)\n")
content.append(string: "Content-Type: text/plain; charset=utf-8\n")
content.append(string: "Content-Disposition: form-data; name=\"upload_id\"\n\n")
content.append(string: "\(uploadId)\n")
content.append(string: "--\(uploadId)\n")
content.append(string: "Content-Type: text/plain; charset=utf-8\n")
content.append(string: "Content-Disposition: form-data; name=\"_uuid\"\n\n")
content.append(string: "\(handler!.settings.device.deviceGuid.uuidString)\n")
content.append(string: "--\(uploadId)\n")
content.append(string: "Content-Type: text/plain; charset=utf-8\n")
content.append(string: "Content-Disposition: form-data; name=\"_csrftoken\"\n\n")
content.append(string: "\(storage.csrfToken)\n")
content.append(string: "--\(uploadId)\n")
content.append(string: "Content-Type: text/plain; charset=utf-8\n")
content.append(string: "Content-Disposition: form-data; name=\"image_compression\"\n\n")
content.append(string: "{\"lib_name\":\"jt\",\"lib_version\":\"1.3.0\",\"quality\":\"87\"}\n")
content.append(string: "--\(uploadId)\n")
content.append(string: "Content-Transfer-Encoding: binary\n")
content.append(string: "Content-Type: application/octet-stream\n")
content.append(string: ["Content-Disposition: form-data; name=photo;",
"filename=pending_media_\(uploadId).jpg;",
"filename*=utf-8''pending_media_\(uploadId).jpg\n\n"].joined(separator: " "))

#if os(macOS)
let imageData = photo.image.tiffRepresentation
#else
let imageData = photo.image.jpegData(compressionQuality: 1)
#endif
content.append(imageData!)
content.append(string: "\n--\(uploadId)--\n\n")
let headers = ["Content-Type": "multipart/form-data; boundary=\"\(uploadId)\""]

requests.request(Upload.Response.Picture.self,
method: .post,
endpoint: Endpoint.Upload.photo,
body: .data(content),
headers: headers,
options: .validateResponse) { [weak self] in
guard let me = self, let handler = me.handler else {
return completionHandler(.failure(GenericError.weakObjectReleased))
}
switch $0 {
case .failure(let error):
handler.settings.queues.response.async {
completionHandler(.failure(error))
}
case .success(let decoded):
guard decoded.status == "ok" else {
return handler.settings.queues.response.async {
completionHandler(.failure(GenericError.unknown))
}
}
me.configure(photo: photo,
with: uploadId,
caption: photo.caption,
completionHandler: completionHandler)
}
}
}

// Set up photo.
func configure(photo: Upload.Picture,
with uploadId: String,
caption: String,
completionHandler: @escaping (Result<Upload.Response.Picture, Error>) -> Void) {
guard let storage = handler.response?.storage else {
return completionHandler(.failure(GenericError.custom("Invalid `Authentication.Response` in `APIHandler.respone`. Log in again.")))
}
// prepare body.
let data = ConfigureStoryUploadModel.init(uuid: handler!.settings.device.deviceGuid.uuidString,
uid: storage.dsUserId,
csrfToken: storage.csrfToken,
sourceType: "1",
caption: caption,
uploadId: uploadId,
disableComments: false,
configureMode: 1,
cameraPosition: "unknown")

let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
guard let payload = try? String(data: encoder.encode(data), encoding: .utf8) else {
return completionHandler(.failure(GenericError.custom("Invalid request.")))
}
do {
let hash = try HMAC(key: Constants.igSignatureKey, variant: .sha256).authenticate(payload.bytes).toHexString()

let signature = "\(hash).\(payload)"
let body: [String: Any] = [
Constants.igSignatureKey: signature.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!,
Constants.igSignatureVersionKey: Constants.igSignatureVersionValue
]

requests.request(Upload.Response.Picture.self,
method: .post,
endpoint: Endpoint.Media.configureStory,
body: .parameters(body),
completion: completionHandler)
} catch { completionHandler(.failure(error)) }
}

/// Get story viewers.
public func viewers(forStory storyId: String,
with paginationParameters: PaginationParameters,
Expand Down
8 changes: 0 additions & 8 deletions SwiftyInsta/API/Handlers/UserHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,6 @@ public final class UserHandler: Handler {
completion: completionHandler)
}

@available(*, unavailable, message: "Instagram no longer supports this endpoint.")
/// Get recent following activities.
public func recentFollowingActivities(with paginationParameters: PaginationParameters,
updateHandler: PaginationUpdateHandler<RecentActivity.Story, AnyPaginatedResponse>?,
completionHandler: @escaping PaginationCompletionHandler<RecentActivity.Story>) {
fatalError("Instagram no longer supports this endpoint.")
}

/// Unfollow user.
public func remove(follower user: User.Reference, completionHandler: @escaping (Result<Bool, Error>) -> Void) {
guard let storage = handler.response?.storage else {
Expand Down
6 changes: 0 additions & 6 deletions SwiftyInsta/Helpers/PaginationParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,4 @@ public class PaginationParameters {
self.maxPagesToLoad = paginationParameters.maxPagesToLoad
}
public static let everything = PaginationParameters(startingAt: nil, maxPagesToLoad: .max)

// MARK: Obsolete
@available(*, unavailable, message: "use `init` instead.")
public static func maxPagesToLoad(maxPages: Int) -> PaginationParameters {
fatalError("`maxPagesToLoad(maxPages:)` was removed.")
}
}
1 change: 0 additions & 1 deletion SwiftyInsta/Local/Authentication/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public struct Authentication {
/// Log in with username and password.
case user(Credentials)

@available(iOS 11, OSX 10.13, macCatalyst 13, *)
/// Log in through web view.
case webView(LoginWebView)

Expand Down
2 changes: 1 addition & 1 deletion SwiftyInsta/Local/Requests/Legacy/StoryModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public struct ConfigureStoryUploadModel: Codable {
public var sourceType: String
public var caption: String
public var uploadId: String
//var edits
// var edits
public var disableComments: Bool
public var configureMode: Int
public var cameraPosition: String
Expand Down
16 changes: 0 additions & 16 deletions SwiftyInsta/UI/LoginWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import WebKit

// MARK: Views
@available(iOS 11, OSX 10.13, macCatalyst 13, *)
public class LoginWebView: WKWebView, WKNavigationDelegate {
/// Called when reaching the end of the login flow.
/// You should probably hide the `InstagramLoginWebView` and notify the user with an activity indicator.
Expand All @@ -21,11 +20,6 @@ public class LoginWebView: WKWebView, WKNavigationDelegate {
private var cookieTimer: Timer?

// MARK: Init
@available(*, unavailable, message: "using a custom `userAgent` is no longer supported")
public init(frame: CGRect, userAgent: String?, didReachEndOfLoginFlow: (() -> Void)? = nil) {
fatalError("Unavailable method.")
}

public init(frame: CGRect, didReachEndOfLoginFlow: (() -> Void)? = nil) {
// delete all cookies.
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
Expand All @@ -39,16 +33,6 @@ public class LoginWebView: WKWebView, WKNavigationDelegate {
setCookieTimer()
}

@available(*, unavailable, message: "use `init(frame:didReachEndOfLoginFlow:)` instead.")
public init(frame: CGRect,
improvingReadability shouldImproveReadability: Bool,
didReachEndOfLoginFlow: (() -> Void)? = nil) {
fatalError("init(frame:improvingReadabililty:didReachEndOfLoginFlow:) has been removed")
}
@available(*, unavailable, message: "use `init(frame:configuration:didReachEndOfLoginFlow:didSuccessfullyLogIn:completionHandler:)` instead.")
private override init(frame: CGRect, configuration: WKWebViewConfiguration) {
fatalError("init(frame:, configuration:) has been removed")
}
@available(*, unavailable)
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down
7 changes: 0 additions & 7 deletions SwiftyInsta/UI/LoginWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import UIKit
import WebKit

@available(iOS 11, OSX 10.11, macCatalyst 13, *)
/// A pre-built `UIViewController` displaying a `LoginWebView`.
public class LoginWebViewController: UIViewController {
/// The handler.
Expand Down Expand Up @@ -53,12 +52,6 @@ public class LoginWebViewController: UIViewController {
}

// MARK: Init
@available(*, unavailable, message: "using a custom `userAgent` is no longer supported")
public init(userAgent: String?,
completionHandler: @escaping (LoginWebViewController, Result<(Authentication.Response, APIHandler), Error>) -> Void) {
fatalError("Unavailable method.")
}

public init(completionHandler: @escaping (LoginWebViewController, Result<(Authentication.Response, APIHandler), Error>) -> Void) {
self.completionHandler = completionHandler
super.init(nibName: nil, bundle: nil)
Expand Down

0 comments on commit 25cb7d8

Please sign in to comment.