-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hamad Fuad
committed
Apr 13, 2022
1 parent
d6aa57a
commit 84b2608
Showing
13 changed files
with
332 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
![swift workflow](https://github.com/ihamadfuad/AppStoreReviewsAPI/actions/workflows/swift.yml/badge.svg) [![codecov](https://codecov.io/gh/ihamadfuad/AppStoreReviewsAPI/branch/main/graph/badge.svg?token=W9KO1BG8S0)](https://codecov.io/gh/ihamadfuad/AppStoreReviewsAPI) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![Issues](https://img.shields.io/github/issues/ihamadfuad/AppStoreReviewsAPI) ![Releases](https://img.shields.io/github/v/release/ihamadfuad/AppStoreReviewsAPI) | ||
|
||
# AppStoreReviewsAPI | ||
|
||
A description of this package. | ||
A Swift 5.6 implementation of iTunes customer reviews. Retrieve customer reviews for your app and display most helpful | ||
reviews. | ||
|
||
## Installation | ||
### Swift Package Manager (SPM) | ||
|
||
You can use The Swift Package Manager to install SwiftEmailValidator by adding it to your Package.swift file: | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "MyApp", | ||
targets: [], | ||
dependencies: [ | ||
.Package(url: "https://github.com/ekscrypto/SwiftEmailValidator.git", .upToNextMajor(from: "1.0.0")) | ||
] | ||
) | ||
|
||
### Usage | ||
|
||
```swift | ||
let appStore = AppStoreReviewsAPI(appID: "310633997") // This app id belongs to WhatsApp | ||
let reviews = try await appStore.reviews() | ||
|
||
reviews.feed.entry.forEach { | ||
|
||
print("Rating: ", $0.imRating.label) | ||
print($0.title.label) | ||
print($0.content.label) | ||
print(" +---------------------------------------------------+ ") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
import Foundation | ||
|
||
extension String: Error { } | ||
|
||
public struct AppStoreReviewsAPI { | ||
public private(set) var text = "Hello, World!" | ||
|
||
public init() { | ||
public enum Sortby: String, Decodable { | ||
|
||
case mostHelpful = "mosthelpful" | ||
case mostRecent = "mostrecent" | ||
} | ||
|
||
var appID = String() | ||
var page: String = "1" | ||
var sortBy: Sortby = .mostHelpful | ||
|
||
private var url: String? | ||
|
||
public init(appID: String, page: String = "1", sortBy: Sortby = .mostHelpful) { | ||
|
||
self.appID = appID | ||
self.page = page | ||
self.sortBy = sortBy | ||
|
||
url = "https://itunes.apple.com/rss/customerreviews/page=" + page + "/id=" + appID + "/sortby=" + sortBy.rawValue + "/json?l=en&cc=gb" | ||
} | ||
|
||
func reviews() async throws -> ReviewsFeed { | ||
|
||
guard let urlString = url, | ||
let url = URL(string: urlString) | ||
else { | ||
throw "\(#function) Line: \(#line) - URL is nil" | ||
} | ||
|
||
let (data, _) = try await URLSession.shared.data(for: URLRequest(url: url), delegate: nil) | ||
|
||
let decoder = JSONDecoder() | ||
decoder.dateDecodingStrategy = .iso8601 | ||
|
||
return try decoder.decode(ReviewsFeed.self, from: data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Author.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Author: Decodable { | ||
|
||
let name, uri: URI | ||
} | ||
|
||
struct URI: Decodable { | ||
|
||
let label: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// Entry.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Entry: Decodable { | ||
|
||
let author: EntryAuthor | ||
let updated: Updated | ||
let imRating, imVersion, id: ID | ||
let title: Title | ||
let content: Content | ||
let link: EntryLink | ||
let imVoteSum: Vote | ||
let imContentType: IMContentType | ||
let imVoteCount: Vote | ||
|
||
enum CodingKeys: String, CodingKey { | ||
|
||
case author, updated | ||
case imRating = "im:rating" | ||
case imVersion = "im:version" | ||
case id, title, content, link | ||
case imVoteSum = "im:voteSum" | ||
case imContentType = "im:contentType" | ||
case imVoteCount = "im:voteCount" | ||
} | ||
} | ||
|
||
// MARK: - Author | ||
struct EntryAuthor: Decodable { | ||
|
||
let uri, name: ID | ||
let label: String | ||
} | ||
|
||
// MARK: - Content | ||
struct Content: Decodable { | ||
|
||
let label: String | ||
let attributes: ContentAttributes | ||
} | ||
|
||
// MARK: - ContentAttributes | ||
struct ContentAttributes: Decodable { | ||
|
||
let type: TypeEnum | ||
} | ||
|
||
enum TypeEnum: String, Decodable { | ||
|
||
case text = "text" | ||
} | ||
|
||
// MARK: - Vote | ||
struct Vote: Decodable { | ||
|
||
let label: String | ||
} | ||
|
||
// MARK: - IMContentType | ||
struct IMContentType: Decodable { | ||
|
||
let attributes: IMContentTypeAttributes | ||
} | ||
|
||
// MARK: - IMContentTypeAttributes | ||
struct IMContentTypeAttributes: Decodable { | ||
|
||
let term, label: Label | ||
} | ||
|
||
enum Label: String, Decodable { | ||
|
||
case application = "Application" | ||
} | ||
|
||
// MARK: - EntryLink | ||
struct EntryLink: Decodable { | ||
|
||
let attributes: LinkAttributes | ||
} | ||
|
||
// MARK: - LinkAttributes | ||
struct LinkAttributes: Decodable { | ||
|
||
let rel: String | ||
let href: String | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// ID.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ID: Decodable { | ||
|
||
let label: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Icon.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Icon: Decodable { | ||
|
||
let label: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Link.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Link: Decodable { | ||
|
||
let attributes: Attributes | ||
} | ||
|
||
struct Attributes: Decodable { | ||
|
||
let rel: String | ||
let type: String? | ||
let href: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ReviewsFeed.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ReviewsFeed: Decodable { | ||
|
||
let feed: Feed | ||
} | ||
|
||
struct Feed: Decodable { | ||
|
||
let id: ID | ||
let author: Author | ||
let entry: [Entry] | ||
let updated: Updated | ||
let rights: Rights | ||
let title: Title | ||
let icon: Icon | ||
let link: [Link] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Rights.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Rights: Decodable { | ||
|
||
let label: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Title.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Title: Decodable { | ||
|
||
let label: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Updated.swift | ||
// | ||
// | ||
// Created by Hamad Ali on 13/04/2022. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Updated: Decodable { | ||
|
||
let label: Date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters