Skip to content

Commit

Permalink
Clean merging operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed Jul 25, 2019
1 parent 4ed6276 commit 7549911
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
2 changes: 1 addition & 1 deletion SwiftyInsta/API/Constants/URLs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ struct URLs {
fatalError("Invalid url.")
}

static func getStoryArchiveUrl() throws -> URL {
static func getStoryArchiveUrl() -> URL {
if let url = URL(string: String(format: "%@%@", baseInstagramApiUrl, storyArchive)) {
return url
}
Expand Down
25 changes: 5 additions & 20 deletions SwiftyInsta/API/Services/StoryHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,10 @@ public class StoryHandler: Handler {
completionHandler: completionHandler)
}

func getStoryArchive(completion: @escaping (Result<StoryArchiveFeedModel>) -> ()) throws {
HandlerSettings.shared.httpHelper!.sendAsync(method: .get, url: try URLs.getStoryArchiveUrl(), body: [:], header: [:]) { (data, response, error) in
if let error = error {
completion(Return.fail(error: error, response: .fail, value: nil))
} else {
if let data = data {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
do {
let value = try decoder.decode(StoryArchiveFeedModel.self, from: data)
completion(Return.success(value: value))
} catch {
completion(Return.fail(error: error, response: .ok, value: nil))
}
} else {
let error = CustomErrors.unExpected("The data couldn’t be read because it is missing error when decoding JSON.")
completion(Return.fail(error: error, response: .ok, value: nil))
}
}
}
func archive(completionHandler: @escaping (Result<StoryArchiveFeedModel, Error>) -> Void) {
requests.decodeAsync(StoryArchiveFeedModel.self,
method: .get,
url: URLs.getStoryArchiveUrl(),
completionHandler: completionHandler)
}
}
4 changes: 2 additions & 2 deletions SwiftyInsta/Classes/Models/StoryModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct StoryArchiveFeedModel: Codable, BaseStatusResponseProtocol {
public var numResults: Int?
public var items: [StoryArchiveModel]?
public var status: String?

public init(moreAvailable: Bool?, numResults: Int?, items: [StoryArchiveModel]?) {
self.moreAvailable = moreAvailable
self.numResults = numResults
Expand All @@ -82,7 +82,7 @@ public struct StoryArchiveFeedModel: Codable, BaseStatusResponseProtocol {
public struct StoryArchiveModel: Codable {
public var id: String?
public var mediaCount: Int?

public init(id: String?, mediaCount: Int?) {
self.id = id
self.mediaCount = mediaCount
Expand Down

0 comments on commit 7549911

Please sign in to comment.