├── LICENSE ├── README.md ├── banner.png ├── redmin.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── xcshareddata │ └── xcschemes │ │ └── redmin.xcscheme └── xcuserdata │ └── gabrieloc.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── redmin ├── Info.plist ├── conveniences ├── Encoding.swift ├── Endpoint.swift ├── HTMLParsing.swift ├── ListingEndpoint.swift ├── NetworkService.swift └── TimeFormatting.swift ├── identity ├── AuthenticationResult.swift ├── Authenticator.swift ├── IdentityEndpoint.swift ├── Listing.swift ├── SubredditsEndpoint.swift ├── SubscribedPostsEndpoint.swift ├── SubscriptionsEndpoint.swift ├── TokenRefreshEndpoint.swift └── User.swift ├── listings ├── Comment.swift ├── Conveniences.swift ├── Conversation.swift ├── ConversationEndpoint.swift ├── Image.swift ├── More.swift ├── MoreChildrenEndpoint.swift ├── Node.swift ├── Post.swift ├── PostsEndpoint.swift ├── RedditVideo.swift └── Subreddit.swift └── redmin.h /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![redmin](banner.png) 2 | 3 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 4 | 5 | Prototyping something and need realistic user generated content? Redmin is a really simple wrapper for accessing the main parts of Reddit which don't require authentication or an API token. For now, only the most basic parts of comments and posts are modelled but more will be added in the future. 6 | 7 | You can choose how granular to get with what's sent and received. For example, to pull down 50 posts from the `r/gifs` subreddit, you can use a convenience defined in `Conveniences.swift`: 8 | 9 | ```swift 10 | 50.postsFromSubreddit("gifs") { posts in 11 | // do something with your posts 12 | } 13 | ``` 14 | 15 | Or, if you want more control over when to make the request, or want it to be cancellable: 16 | ```swift 17 | let endpoint = PostsEndpoint(subreddit: "gifs", category: .top, limit: 50) 18 | let task: URLSessionDataTask = endpoint.request { posts in 19 | // do something with your posts 20 | } 21 | ``` 22 | 23 | `Post` objects can be used to get images and comments. For example, given a `post`: 24 | ```swift 25 | post.bestPreviewImage.request { image in 26 | // send image (UIImage) to an UIImageView 27 | } 28 | 50.comments(from: post) { comments in 29 | // populate a tableView with an array of comment objects 30 | } 31 | ``` 32 | 33 | 34 | For requests or suggestions, you can find me at [@_gabrieloc](https://twitter.com/_gabrieloc). 35 | -------------------------------------------------------------------------------- /banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gabrieloc/redmin/5a54513aca0d7f1fd7b2b79e4dad230c5e1d4877/banner.png -------------------------------------------------------------------------------- /redmin.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B200CAED218FB86900C7BA42 /* SubscribedPostsEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200CAEC218FB86900C7BA42 /* SubscribedPostsEndpoint.swift */; }; 11 | B200CAEF218FB9AC00C7BA42 /* Listing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200CAEE218FB9AC00C7BA42 /* Listing.swift */; }; 12 | B200CAF3218FC17000C7BA42 /* ListingEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200CAF2218FC17000C7BA42 /* ListingEndpoint.swift */; }; 13 | B200E8A5217C745E003A60B0 /* Conveniences.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200E8A4217C745E003A60B0 /* Conveniences.swift */; }; 14 | B200E8BE217CC391003A60B0 /* More.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200E8BD217CC391003A60B0 /* More.swift */; }; 15 | B200E8C0217D8C08003A60B0 /* Conversation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200E8BF217D8C08003A60B0 /* Conversation.swift */; }; 16 | B200E8C8217DA71A003A60B0 /* MoreChildrenEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200E8C7217DA71A003A60B0 /* MoreChildrenEndpoint.swift */; }; 17 | B200E8CC217DBD58003A60B0 /* HTMLParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200E8CB217DBD58003A60B0 /* HTMLParsing.swift */; }; 18 | B200E8CE217DD7E9003A60B0 /* TimeFormatting.swift in Sources */ = {isa = PBXBuildFile; fileRef = B200E8CD217DD7E9003A60B0 /* TimeFormatting.swift */; }; 19 | B203D16D219B6E7100403D3D /* RedditVideo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B203D16C219B6E7100403D3D /* RedditVideo.swift */; }; 20 | B20ECFFF21871F03004BB416 /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ECFFE21871F03004BB416 /* NetworkService.swift */; }; 21 | B20ED00121873224004BB416 /* Encoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED00021873224004BB416 /* Encoding.swift */; }; 22 | B20ED0112188084C004BB416 /* SubredditsEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED00B2188084C004BB416 /* SubredditsEndpoint.swift */; }; 23 | B20ED0122188084C004BB416 /* AuthenticationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED00C2188084C004BB416 /* AuthenticationResult.swift */; }; 24 | B20ED0132188084C004BB416 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED00D2188084C004BB416 /* User.swift */; }; 25 | B20ED0142188084C004BB416 /* TokenRefreshEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED00E2188084C004BB416 /* TokenRefreshEndpoint.swift */; }; 26 | B20ED0152188084C004BB416 /* Authenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED00F2188084C004BB416 /* Authenticator.swift */; }; 27 | B20ED0162188084C004BB416 /* IdentityEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B20ED0102188084C004BB416 /* IdentityEndpoint.swift */; }; 28 | B298EC3F219625E100331CA6 /* SubscriptionsEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B298EC3E219625E100331CA6 /* SubscriptionsEndpoint.swift */; }; 29 | B2E0638021845B430023D473 /* Subreddit.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E0637F21845B430023D473 /* Subreddit.swift */; }; 30 | B2F2FFAC21799D8500DF20D3 /* redmin.h in Headers */ = {isa = PBXBuildFile; fileRef = B2F2FFAA21799D8500DF20D3 /* redmin.h */; settings = {ATTRIBUTES = (Public, ); }; }; 31 | B2F2FFB521799DAF00DF20D3 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F2FFA121799D2200DF20D3 /* Endpoint.swift */; }; 32 | B2F2FFB621799DAF00DF20D3 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F2FF9D21799CBD00DF20D3 /* Post.swift */; }; 33 | B2F2FFB721799DAF00DF20D3 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F2FF9B21799CB900DF20D3 /* Comment.swift */; }; 34 | B2F2FFB821799DAF00DF20D3 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F2FF9F21799CF900DF20D3 /* Node.swift */; }; 35 | B2F2FFD6217A07BC00DF20D3 /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F2FFD5217A07BC00DF20D3 /* Image.swift */; }; 36 | B2F66037217B2CF300B7AABA /* PostsEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F66036217B2CF300B7AABA /* PostsEndpoint.swift */; }; 37 | B2F66039217B2D0300B7AABA /* ConversationEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2F66038217B2D0300B7AABA /* ConversationEndpoint.swift */; }; 38 | /* End PBXBuildFile section */ 39 | 40 | /* Begin PBXFileReference section */ 41 | B200CAEC218FB86900C7BA42 /* SubscribedPostsEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscribedPostsEndpoint.swift; sourceTree = ""; }; 42 | B200CAEE218FB9AC00C7BA42 /* Listing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Listing.swift; sourceTree = ""; }; 43 | B200CAF2218FC17000C7BA42 /* ListingEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListingEndpoint.swift; sourceTree = ""; }; 44 | B200E8A4217C745E003A60B0 /* Conveniences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conveniences.swift; sourceTree = ""; }; 45 | B200E8BD217CC391003A60B0 /* More.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = More.swift; sourceTree = ""; }; 46 | B200E8BF217D8C08003A60B0 /* Conversation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Conversation.swift; sourceTree = ""; }; 47 | B200E8C7217DA71A003A60B0 /* MoreChildrenEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreChildrenEndpoint.swift; sourceTree = ""; }; 48 | B200E8CB217DBD58003A60B0 /* HTMLParsing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLParsing.swift; sourceTree = ""; }; 49 | B200E8CD217DD7E9003A60B0 /* TimeFormatting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeFormatting.swift; sourceTree = ""; }; 50 | B203D16C219B6E7100403D3D /* RedditVideo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedditVideo.swift; sourceTree = ""; }; 51 | B20ECFFE21871F03004BB416 /* NetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkService.swift; sourceTree = ""; }; 52 | B20ED00021873224004BB416 /* Encoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encoding.swift; sourceTree = ""; }; 53 | B20ED00B2188084C004BB416 /* SubredditsEndpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubredditsEndpoint.swift; sourceTree = ""; }; 54 | B20ED00C2188084C004BB416 /* AuthenticationResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticationResult.swift; sourceTree = ""; }; 55 | B20ED00D2188084C004BB416 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 56 | B20ED00E2188084C004BB416 /* TokenRefreshEndpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenRefreshEndpoint.swift; sourceTree = ""; }; 57 | B20ED00F2188084C004BB416 /* Authenticator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Authenticator.swift; sourceTree = ""; }; 58 | B20ED0102188084C004BB416 /* IdentityEndpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentityEndpoint.swift; sourceTree = ""; }; 59 | B298EC3E219625E100331CA6 /* SubscriptionsEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionsEndpoint.swift; sourceTree = ""; }; 60 | B2E0637F21845B430023D473 /* Subreddit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Subreddit.swift; sourceTree = ""; }; 61 | B2F2FF9B21799CB900DF20D3 /* Comment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = ""; }; 62 | B2F2FF9D21799CBD00DF20D3 /* Post.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = ""; }; 63 | B2F2FF9F21799CF900DF20D3 /* Node.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Node.swift; sourceTree = ""; }; 64 | B2F2FFA121799D2200DF20D3 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = ""; }; 65 | B2F2FFA821799D8500DF20D3 /* Redmin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Redmin.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 66 | B2F2FFAA21799D8500DF20D3 /* redmin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = redmin.h; sourceTree = ""; }; 67 | B2F2FFAB21799D8500DF20D3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 68 | B2F2FFD5217A07BC00DF20D3 /* Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = ""; }; 69 | B2F66036217B2CF300B7AABA /* PostsEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostsEndpoint.swift; sourceTree = ""; }; 70 | B2F66038217B2D0300B7AABA /* ConversationEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationEndpoint.swift; sourceTree = ""; }; 71 | /* End PBXFileReference section */ 72 | 73 | /* Begin PBXFrameworksBuildPhase section */ 74 | B2F2FFA521799D8500DF20D3 /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | /* End PBXFrameworksBuildPhase section */ 82 | 83 | /* Begin PBXGroup section */ 84 | B20ECFF821871036004BB416 /* listings */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | B2F2FFD5217A07BC00DF20D3 /* Image.swift */, 88 | B200E8BD217CC391003A60B0 /* More.swift */, 89 | B2F2FF9B21799CB900DF20D3 /* Comment.swift */, 90 | B200E8A4217C745E003A60B0 /* Conveniences.swift */, 91 | B200E8BF217D8C08003A60B0 /* Conversation.swift */, 92 | B2F66038217B2D0300B7AABA /* ConversationEndpoint.swift */, 93 | B200E8C7217DA71A003A60B0 /* MoreChildrenEndpoint.swift */, 94 | B2F2FF9F21799CF900DF20D3 /* Node.swift */, 95 | B2F2FF9D21799CBD00DF20D3 /* Post.swift */, 96 | B203D16C219B6E7100403D3D /* RedditVideo.swift */, 97 | B2F66036217B2CF300B7AABA /* PostsEndpoint.swift */, 98 | B2E0637F21845B430023D473 /* Subreddit.swift */, 99 | ); 100 | path = listings; 101 | sourceTree = ""; 102 | }; 103 | B20ECFF92187104B004BB416 /* conveniences */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | B200E8CB217DBD58003A60B0 /* HTMLParsing.swift */, 107 | B2F2FFA121799D2200DF20D3 /* Endpoint.swift */, 108 | B200CAF2218FC17000C7BA42 /* ListingEndpoint.swift */, 109 | B20ECFFE21871F03004BB416 /* NetworkService.swift */, 110 | B20ED00021873224004BB416 /* Encoding.swift */, 111 | B200E8CD217DD7E9003A60B0 /* TimeFormatting.swift */, 112 | ); 113 | path = conveniences; 114 | sourceTree = ""; 115 | }; 116 | B20ED00A2188084C004BB416 /* identity */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | B20ED0102188084C004BB416 /* IdentityEndpoint.swift */, 120 | B20ED00B2188084C004BB416 /* SubredditsEndpoint.swift */, 121 | B298EC3E219625E100331CA6 /* SubscriptionsEndpoint.swift */, 122 | B200CAEE218FB9AC00C7BA42 /* Listing.swift */, 123 | B200CAEC218FB86900C7BA42 /* SubscribedPostsEndpoint.swift */, 124 | B20ED00C2188084C004BB416 /* AuthenticationResult.swift */, 125 | B20ED00D2188084C004BB416 /* User.swift */, 126 | B20ED00E2188084C004BB416 /* TokenRefreshEndpoint.swift */, 127 | B20ED00F2188084C004BB416 /* Authenticator.swift */, 128 | ); 129 | path = identity; 130 | sourceTree = ""; 131 | }; 132 | B2F2FF7921799B5200DF20D3 = { 133 | isa = PBXGroup; 134 | children = ( 135 | B2F2FFA921799D8500DF20D3 /* redmin */, 136 | B2F2FF8321799B5200DF20D3 /* Products */, 137 | ); 138 | sourceTree = ""; 139 | }; 140 | B2F2FF8321799B5200DF20D3 /* Products */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | B2F2FFA821799D8500DF20D3 /* Redmin.framework */, 144 | ); 145 | name = Products; 146 | sourceTree = ""; 147 | }; 148 | B2F2FFA921799D8500DF20D3 /* redmin */ = { 149 | isa = PBXGroup; 150 | children = ( 151 | B20ECFF821871036004BB416 /* listings */, 152 | B20ECFF92187104B004BB416 /* conveniences */, 153 | B20ED00A2188084C004BB416 /* identity */, 154 | B2F2FFAB21799D8500DF20D3 /* Info.plist */, 155 | B2F2FFAA21799D8500DF20D3 /* redmin.h */, 156 | ); 157 | path = redmin; 158 | sourceTree = ""; 159 | }; 160 | /* End PBXGroup section */ 161 | 162 | /* Begin PBXHeadersBuildPhase section */ 163 | B2F2FFA321799D8500DF20D3 /* Headers */ = { 164 | isa = PBXHeadersBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | B2F2FFAC21799D8500DF20D3 /* redmin.h in Headers */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXHeadersBuildPhase section */ 172 | 173 | /* Begin PBXNativeTarget section */ 174 | B2F2FFA721799D8500DF20D3 /* Redmin */ = { 175 | isa = PBXNativeTarget; 176 | buildConfigurationList = B2F2FFB121799D8500DF20D3 /* Build configuration list for PBXNativeTarget "Redmin" */; 177 | buildPhases = ( 178 | B2F2FFA321799D8500DF20D3 /* Headers */, 179 | B2F2FFA421799D8500DF20D3 /* Sources */, 180 | B2F2FFA521799D8500DF20D3 /* Frameworks */, 181 | B2F2FFA621799D8500DF20D3 /* Resources */, 182 | ); 183 | buildRules = ( 184 | ); 185 | dependencies = ( 186 | ); 187 | name = Redmin; 188 | productName = redmin; 189 | productReference = B2F2FFA821799D8500DF20D3 /* Redmin.framework */; 190 | productType = "com.apple.product-type.framework"; 191 | }; 192 | /* End PBXNativeTarget section */ 193 | 194 | /* Begin PBXProject section */ 195 | B2F2FF7A21799B5200DF20D3 /* Project object */ = { 196 | isa = PBXProject; 197 | attributes = { 198 | LastSwiftUpdateCheck = 1000; 199 | LastUpgradeCheck = 1000; 200 | ORGANIZATIONNAME = gabrieloc; 201 | TargetAttributes = { 202 | B2F2FFA721799D8500DF20D3 = { 203 | CreatedOnToolsVersion = 10.0; 204 | }; 205 | }; 206 | }; 207 | buildConfigurationList = B2F2FF7D21799B5200DF20D3 /* Build configuration list for PBXProject "redmin" */; 208 | compatibilityVersion = "Xcode 9.3"; 209 | developmentRegion = en; 210 | hasScannedForEncodings = 0; 211 | knownRegions = ( 212 | en, 213 | Base, 214 | ); 215 | mainGroup = B2F2FF7921799B5200DF20D3; 216 | productRefGroup = B2F2FF8321799B5200DF20D3 /* Products */; 217 | projectDirPath = ""; 218 | projectRoot = ""; 219 | targets = ( 220 | B2F2FFA721799D8500DF20D3 /* Redmin */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXResourcesBuildPhase section */ 226 | B2F2FFA621799D8500DF20D3 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXResourcesBuildPhase section */ 234 | 235 | /* Begin PBXSourcesBuildPhase section */ 236 | B2F2FFA421799D8500DF20D3 /* Sources */ = { 237 | isa = PBXSourcesBuildPhase; 238 | buildActionMask = 2147483647; 239 | files = ( 240 | B2F66039217B2D0300B7AABA /* ConversationEndpoint.swift in Sources */, 241 | B200CAEF218FB9AC00C7BA42 /* Listing.swift in Sources */, 242 | B200E8BE217CC391003A60B0 /* More.swift in Sources */, 243 | B2F2FFB521799DAF00DF20D3 /* Endpoint.swift in Sources */, 244 | B20ED0112188084C004BB416 /* SubredditsEndpoint.swift in Sources */, 245 | B2F2FFB721799DAF00DF20D3 /* Comment.swift in Sources */, 246 | B200E8C8217DA71A003A60B0 /* MoreChildrenEndpoint.swift in Sources */, 247 | B2F66037217B2CF300B7AABA /* PostsEndpoint.swift in Sources */, 248 | B2F2FFB621799DAF00DF20D3 /* Post.swift in Sources */, 249 | B20ED0152188084C004BB416 /* Authenticator.swift in Sources */, 250 | B200E8CE217DD7E9003A60B0 /* TimeFormatting.swift in Sources */, 251 | B200E8A5217C745E003A60B0 /* Conveniences.swift in Sources */, 252 | B20ED0142188084C004BB416 /* TokenRefreshEndpoint.swift in Sources */, 253 | B20ED0122188084C004BB416 /* AuthenticationResult.swift in Sources */, 254 | B2F2FFB821799DAF00DF20D3 /* Node.swift in Sources */, 255 | B200CAF3218FC17000C7BA42 /* ListingEndpoint.swift in Sources */, 256 | B200E8CC217DBD58003A60B0 /* HTMLParsing.swift in Sources */, 257 | B200CAED218FB86900C7BA42 /* SubscribedPostsEndpoint.swift in Sources */, 258 | B200E8C0217D8C08003A60B0 /* Conversation.swift in Sources */, 259 | B298EC3F219625E100331CA6 /* SubscriptionsEndpoint.swift in Sources */, 260 | B20ECFFF21871F03004BB416 /* NetworkService.swift in Sources */, 261 | B20ED00121873224004BB416 /* Encoding.swift in Sources */, 262 | B2F2FFD6217A07BC00DF20D3 /* Image.swift in Sources */, 263 | B203D16D219B6E7100403D3D /* RedditVideo.swift in Sources */, 264 | B20ED0162188084C004BB416 /* IdentityEndpoint.swift in Sources */, 265 | B2E0638021845B430023D473 /* Subreddit.swift in Sources */, 266 | B20ED0132188084C004BB416 /* User.swift in Sources */, 267 | ); 268 | runOnlyForDeploymentPostprocessing = 0; 269 | }; 270 | /* End PBXSourcesBuildPhase section */ 271 | 272 | /* Begin XCBuildConfiguration section */ 273 | B2F2FF9221799B5300DF20D3 /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ALWAYS_SEARCH_USER_PATHS = NO; 277 | CLANG_ANALYZER_NONNULL = YES; 278 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 279 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 280 | CLANG_CXX_LIBRARY = "libc++"; 281 | CLANG_ENABLE_MODULES = YES; 282 | CLANG_ENABLE_OBJC_ARC = YES; 283 | CLANG_ENABLE_OBJC_WEAK = YES; 284 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 285 | CLANG_WARN_BOOL_CONVERSION = YES; 286 | CLANG_WARN_COMMA = YES; 287 | CLANG_WARN_CONSTANT_CONVERSION = YES; 288 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 289 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 290 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INFINITE_RECURSION = YES; 294 | CLANG_WARN_INT_CONVERSION = YES; 295 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 297 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 298 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 299 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 300 | CLANG_WARN_STRICT_PROTOTYPES = YES; 301 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 302 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 303 | CLANG_WARN_UNREACHABLE_CODE = YES; 304 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 305 | CODE_SIGN_IDENTITY = "iPhone Developer"; 306 | COPY_PHASE_STRIP = NO; 307 | DEBUG_INFORMATION_FORMAT = dwarf; 308 | ENABLE_STRICT_OBJC_MSGSEND = YES; 309 | ENABLE_TESTABILITY = YES; 310 | GCC_C_LANGUAGE_STANDARD = gnu11; 311 | GCC_DYNAMIC_NO_PIC = NO; 312 | GCC_NO_COMMON_BLOCKS = YES; 313 | GCC_OPTIMIZATION_LEVEL = 0; 314 | GCC_PREPROCESSOR_DEFINITIONS = ( 315 | "DEBUG=1", 316 | "$(inherited)", 317 | ); 318 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 319 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 320 | GCC_WARN_UNDECLARED_SELECTOR = YES; 321 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 322 | GCC_WARN_UNUSED_FUNCTION = YES; 323 | GCC_WARN_UNUSED_VARIABLE = YES; 324 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 325 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 326 | MTL_FAST_MATH = YES; 327 | ONLY_ACTIVE_ARCH = YES; 328 | SDKROOT = iphoneos; 329 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 330 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 331 | }; 332 | name = Debug; 333 | }; 334 | B2F2FF9321799B5300DF20D3 /* Release */ = { 335 | isa = XCBuildConfiguration; 336 | buildSettings = { 337 | ALWAYS_SEARCH_USER_PATHS = NO; 338 | CLANG_ANALYZER_NONNULL = YES; 339 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 340 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 341 | CLANG_CXX_LIBRARY = "libc++"; 342 | CLANG_ENABLE_MODULES = YES; 343 | CLANG_ENABLE_OBJC_ARC = YES; 344 | CLANG_ENABLE_OBJC_WEAK = YES; 345 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 346 | CLANG_WARN_BOOL_CONVERSION = YES; 347 | CLANG_WARN_COMMA = YES; 348 | CLANG_WARN_CONSTANT_CONVERSION = YES; 349 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 350 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 351 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 352 | CLANG_WARN_EMPTY_BODY = YES; 353 | CLANG_WARN_ENUM_CONVERSION = YES; 354 | CLANG_WARN_INFINITE_RECURSION = YES; 355 | CLANG_WARN_INT_CONVERSION = YES; 356 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 357 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 358 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 359 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 360 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 361 | CLANG_WARN_STRICT_PROTOTYPES = YES; 362 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 363 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 364 | CLANG_WARN_UNREACHABLE_CODE = YES; 365 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 366 | CODE_SIGN_IDENTITY = "iPhone Developer"; 367 | COPY_PHASE_STRIP = NO; 368 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 369 | ENABLE_NS_ASSERTIONS = NO; 370 | ENABLE_STRICT_OBJC_MSGSEND = YES; 371 | GCC_C_LANGUAGE_STANDARD = gnu11; 372 | GCC_NO_COMMON_BLOCKS = YES; 373 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 374 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 375 | GCC_WARN_UNDECLARED_SELECTOR = YES; 376 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 377 | GCC_WARN_UNUSED_FUNCTION = YES; 378 | GCC_WARN_UNUSED_VARIABLE = YES; 379 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 380 | MTL_ENABLE_DEBUG_INFO = NO; 381 | MTL_FAST_MATH = YES; 382 | SDKROOT = iphoneos; 383 | SWIFT_COMPILATION_MODE = wholemodule; 384 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 385 | VALIDATE_PRODUCT = YES; 386 | }; 387 | name = Release; 388 | }; 389 | B2F2FFB221799D8500DF20D3 /* Debug */ = { 390 | isa = XCBuildConfiguration; 391 | buildSettings = { 392 | CODE_SIGN_IDENTITY = ""; 393 | CODE_SIGN_STYLE = Manual; 394 | CURRENT_PROJECT_VERSION = 1; 395 | DEFINES_MODULE = YES; 396 | DEVELOPMENT_TEAM = ""; 397 | DYLIB_COMPATIBILITY_VERSION = 1; 398 | DYLIB_CURRENT_VERSION = 1; 399 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 400 | INFOPLIST_FILE = redmin/Info.plist; 401 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 402 | LD_RUNPATH_SEARCH_PATHS = ( 403 | "$(inherited)", 404 | "@executable_path/Frameworks", 405 | "@loader_path/Frameworks", 406 | ); 407 | PRODUCT_BUNDLE_IDENTIFIER = com.gabrieloc.redmin; 408 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 409 | PROVISIONING_PROFILE_SPECIFIER = ""; 410 | SKIP_INSTALL = YES; 411 | SWIFT_VERSION = 4.2; 412 | TARGETED_DEVICE_FAMILY = "1,2"; 413 | VERSIONING_SYSTEM = "apple-generic"; 414 | VERSION_INFO_PREFIX = ""; 415 | }; 416 | name = Debug; 417 | }; 418 | B2F2FFB321799D8500DF20D3 /* Release */ = { 419 | isa = XCBuildConfiguration; 420 | buildSettings = { 421 | CODE_SIGN_IDENTITY = ""; 422 | CODE_SIGN_STYLE = Manual; 423 | CURRENT_PROJECT_VERSION = 1; 424 | DEFINES_MODULE = YES; 425 | DEVELOPMENT_TEAM = ""; 426 | DYLIB_COMPATIBILITY_VERSION = 1; 427 | DYLIB_CURRENT_VERSION = 1; 428 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 429 | INFOPLIST_FILE = redmin/Info.plist; 430 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 431 | LD_RUNPATH_SEARCH_PATHS = ( 432 | "$(inherited)", 433 | "@executable_path/Frameworks", 434 | "@loader_path/Frameworks", 435 | ); 436 | PRODUCT_BUNDLE_IDENTIFIER = com.gabrieloc.redmin; 437 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 438 | PROVISIONING_PROFILE_SPECIFIER = ""; 439 | SKIP_INSTALL = YES; 440 | SWIFT_VERSION = 4.2; 441 | TARGETED_DEVICE_FAMILY = "1,2"; 442 | VERSIONING_SYSTEM = "apple-generic"; 443 | VERSION_INFO_PREFIX = ""; 444 | }; 445 | name = Release; 446 | }; 447 | /* End XCBuildConfiguration section */ 448 | 449 | /* Begin XCConfigurationList section */ 450 | B2F2FF7D21799B5200DF20D3 /* Build configuration list for PBXProject "redmin" */ = { 451 | isa = XCConfigurationList; 452 | buildConfigurations = ( 453 | B2F2FF9221799B5300DF20D3 /* Debug */, 454 | B2F2FF9321799B5300DF20D3 /* Release */, 455 | ); 456 | defaultConfigurationIsVisible = 0; 457 | defaultConfigurationName = Release; 458 | }; 459 | B2F2FFB121799D8500DF20D3 /* Build configuration list for PBXNativeTarget "Redmin" */ = { 460 | isa = XCConfigurationList; 461 | buildConfigurations = ( 462 | B2F2FFB221799D8500DF20D3 /* Debug */, 463 | B2F2FFB321799D8500DF20D3 /* Release */, 464 | ); 465 | defaultConfigurationIsVisible = 0; 466 | defaultConfigurationName = Release; 467 | }; 468 | /* End XCConfigurationList section */ 469 | }; 470 | rootObject = B2F2FF7A21799B5200DF20D3 /* Project object */; 471 | } 472 | -------------------------------------------------------------------------------- /redmin.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /redmin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /redmin.xcodeproj/xcshareddata/xcschemes/redmin.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /redmin.xcodeproj/xcuserdata/gabrieloc.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | redmin.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /redmin/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /redmin/conveniences/Encoding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Encoding.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-29. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension Dictionary where Key == String, Value == String { 12 | var formEncoded: Data? { 13 | return self 14 | .reduce(into: [String](), { 15 | let encodedValue = $1.value.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! 16 | $0.append("\($1.key)=\(encodedValue)") 17 | }) 18 | .joined(separator: "&") 19 | .data(using: .utf8) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /redmin/conveniences/Endpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Endpoint.swift 3 | // redditlight 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-19. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum ContentType: String { 12 | case form = "application/x-www-form-urlencoded" 13 | case json = "application/json" 14 | } 15 | 16 | public enum NetworkError: Error { 17 | case invalidResponse(statusCode: Int) 18 | case corruptResponse 19 | 20 | public var isAuthenticationRequired: Bool { 21 | switch self { 22 | case .invalidResponse(let statusCode): 23 | return statusCode == 403 24 | default: 25 | return false 26 | } 27 | } 28 | } 29 | 30 | public enum EndpointResponse { 31 | case success(Response) 32 | case failure(Error) 33 | } 34 | 35 | public enum Method { 36 | case get 37 | case post(body: [String: String]) 38 | 39 | var rawValue: String { 40 | switch self { 41 | case .get: 42 | return "GET" 43 | case .post: 44 | return "POST" 45 | } 46 | } 47 | } 48 | 49 | public protocol Endpoint { 50 | associatedtype R: Decodable 51 | var resourcePath: String { get } 52 | var queryItems: [URLQueryItem]? { get } 53 | var method: Method { get } 54 | var contentType: ContentType { get } 55 | } 56 | 57 | fileprivate let decoder = JSONDecoder() 58 | 59 | extension Endpoint { 60 | public var queryItems: [URLQueryItem]? { 61 | return nil 62 | } 63 | 64 | public var contentType: ContentType { 65 | return .json 66 | } 67 | 68 | public var method: Method { 69 | return .get 70 | } 71 | 72 | var components: URLComponents { 73 | let url = "\(resourcePath)\(contentType == .json ? ".json" : "")" 74 | var components = URLComponents(string: url)! 75 | components.queryItems = [URLQueryItem(name: "raw_json", value: "1")] + (queryItems ?? []) 76 | return components 77 | } 78 | 79 | @discardableResult 80 | public func request(_ completion: @escaping ((EndpointResponse) -> Void)) -> URLSessionDataTask { 81 | print("requesting \(components.url?.absoluteString ?? resourcePath)") 82 | return NetworkService.shared.request( 83 | components, 84 | contentType: contentType, 85 | method: method, 86 | completion: { (data, response, error) in 87 | let response = self.createResponse(data, response, error) 88 | completion(response) 89 | }) 90 | } 91 | 92 | func createResponse(_ data: Data?, _ urlResponse: URLResponse?, _ error: Error?) -> EndpointResponse { 93 | guard 94 | let data = data, 95 | let httpResponse = urlResponse as? HTTPURLResponse 96 | else { 97 | return .failure(error ?? NetworkError.corruptResponse) 98 | } 99 | 100 | guard (200..<300).contains(httpResponse.statusCode) else { 101 | return .failure(NetworkError.invalidResponse(statusCode: httpResponse.statusCode)) 102 | } 103 | 104 | do { 105 | let decoded = try decoder.decode(R.self, from: data) 106 | return .success(decoded) 107 | } catch (let error) { 108 | print(error) 109 | return .failure(error) 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /redmin/conveniences/HTMLParsing.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HTMLParsing.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-22. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension String { 12 | public func htmlAttributedString(font: UIFont) -> NSAttributedString { 13 | let fontFamily = font.familyName == UIFont.systemFont(ofSize: 14).familyName ? "'-apple-system', 'HelveticaNeue', 'sans-serif'" : font.familyName 14 | let format = "%@" 15 | let formatted = String(format: format, trimmingCharacters(in: .whitespacesAndNewlines)) 16 | 17 | guard 18 | let data = formatted.data(using: String.Encoding.utf16, allowLossyConversion: false), 19 | let attributedString = try? NSMutableAttributedString( 20 | data: data, 21 | options: [ 22 | .documentType: NSAttributedString.DocumentType.html, 23 | .characterEncoding: String.Encoding.utf8.rawValue 24 | ], 25 | documentAttributes: nil) 26 | else { 27 | return NSAttributedString(string: self) 28 | } 29 | if let lastCharacter = attributedString.string.last, lastCharacter == "\n" { 30 | attributedString.deleteCharacters(in: NSRange(location: attributedString.length-1, length: 1)) 31 | } 32 | return attributedString 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /redmin/conveniences/ListingEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ListingEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-11-04. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | protocol ListingEndpoint: Endpoint { 12 | var after: Fullname? { get } 13 | var limit: Int { get } 14 | } 15 | 16 | extension ListingEndpoint { 17 | 18 | public var queryItems: [URLQueryItem]? { 19 | var items = [ 20 | URLQueryItem(name: "limit", value: String(limit)), 21 | ] 22 | if let after = self.after { 23 | items.append(URLQueryItem(name: "after", value: after)) 24 | } 25 | 26 | return items 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /redmin/conveniences/NetworkService.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkService.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-29. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public class NetworkService { 12 | let session = URLSession.shared 13 | public static let shared = NetworkService() 14 | 15 | public enum Authentication { 16 | case none 17 | case authorized(clientID: String) 18 | case authenticated(accessToken: String) 19 | } 20 | 21 | public var authentication: Authentication 22 | 23 | public var isAuthenticated: Bool { 24 | if case Authentication.authenticated = authentication { 25 | return true 26 | } 27 | return false 28 | } 29 | 30 | var baseURL: URL { 31 | let path: String = { 32 | switch authentication { 33 | case .authenticated: 34 | return "https://oauth.reddit.com" 35 | default: 36 | return "https://www.reddit.com" 37 | } 38 | }() 39 | return URL(string: path)! 40 | } 41 | 42 | public func headers(contentType: ContentType) -> [String: String] { 43 | var headers = [ 44 | "Content-Type": contentType.rawValue 45 | ] 46 | switch authentication { 47 | case .none: 48 | break 49 | case .authorized(let clientID): 50 | let token = "\(clientID):" 51 | let encoded = token.data(using: String.Encoding.utf8)!.base64EncodedString() 52 | headers["Authorization"] = "Basic \(encoded)" 53 | case .authenticated(let accessToken): 54 | headers["Authorization"] = "bearer \(accessToken)" 55 | } 56 | return headers 57 | } 58 | 59 | internal init() { 60 | authentication = .none 61 | } 62 | 63 | func request(_ components: URLComponents, contentType: ContentType, method: Method, completion: @escaping ((Data?, URLResponse?, Error?) -> Void)) -> URLSessionDataTask { 64 | var request = URLRequest(url: components.url(relativeTo: baseURL)!) 65 | request.allHTTPHeaderFields = headers(contentType: contentType) 66 | request.httpMethod = method.rawValue 67 | if case Method.post(let body) = method { 68 | request.httpBody = body.formEncoded! 69 | } 70 | let task = session.dataTask(with: request, completionHandler: completion) 71 | task.resume() 72 | return task 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /redmin/conveniences/TimeFormatting.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TimeFormatting.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-22. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension TimeInterval { 12 | var minutes: TimeInterval { return Unit.minute.to(self) } 13 | var minute: TimeInterval { return minutes } 14 | var hours: TimeInterval { return Unit.hour.to(self) } 15 | var hour: TimeInterval { return hours } 16 | var days: TimeInterval { return Unit.day.to(self) } 17 | var day: TimeInterval { return days } 18 | 19 | enum Unit: Double { 20 | case second = 1 21 | case minute = 60 22 | case hour = 3600 23 | case day = 86400 24 | 25 | func from(_ time: TimeInterval) -> TimeInterval { 26 | return time / rawValue 27 | } 28 | 29 | func to(_ time: TimeInterval) -> TimeInterval { 30 | return time * rawValue 31 | } 32 | } 33 | 34 | var floori: Int { 35 | return Int(floor(self)) 36 | } 37 | 38 | public var prettyDuration: String { 39 | switch self { 40 | case 0..<1.minute: 41 | return "\(self.floori)s" 42 | case 1.minute..<1.hour: 43 | return "\(Unit.minute.from(self).floori)min" 44 | case 1.hour..<1.day: 45 | return "\(Unit.hour.from(self).floori)hr" 46 | case 1.day.. UIViewController { 50 | return SFSafariViewController(url: url) 51 | } 52 | 53 | public func retrieveAccessToken(with code: String, _ completion: @escaping (EndpointResponse) -> Void) { 54 | let tokenRefresh = TokenRefreshEndpoint( 55 | grantType: .authorizationCode(code: code), 56 | redirectURI: urlScheme, 57 | clientID: clientID 58 | ) 59 | NetworkService.shared.authentication = .authorized(clientID: clientID) 60 | tokenRefresh.request(completion) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /redmin/identity/IdentityEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IdentityEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-30. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct IdentityEndpoint: Endpoint { 12 | public typealias R = User 13 | 14 | public var resourcePath: String { 15 | return "/api/v1/me" 16 | } 17 | 18 | public init() { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /redmin/identity/Listing.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Listing.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-11-04. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Listing: Decodable { 12 | let node: Node> 13 | 14 | public var data: [T] { 15 | return node.data.children.compactMap { $0.data } 16 | } 17 | 18 | public var nextPage: Fullname? { 19 | return node.data.after 20 | } 21 | 22 | public init(from decoder: Decoder) throws { 23 | let container = try decoder.singleValueContainer() 24 | node = try container.decode(Node.self) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /redmin/identity/SubredditsEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SubredditsEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-30. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct SubredditsEndpoint: ListingEndpoint { 12 | public typealias R = Listing 13 | public var resourcePath: String 14 | 15 | public var limit: Int = 100 16 | public var after: Fullname? 17 | 18 | public enum Grouping: String { 19 | case popular, new, gold, `default` 20 | } 21 | 22 | public init(grouping: Grouping) { 23 | self.resourcePath = "subreddits/\(grouping.rawValue)" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /redmin/identity/SubscribedPostsEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SubscribedPostsEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-11-04. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public class SubscribedPostsEndpoint: PostsEndpoint { 12 | public override var resourcePath: String { 13 | return "subreddits/mine/subscriber" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /redmin/identity/SubscriptionsEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SubscriptionsEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-11-09. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct SubscriptionsEndpoint: ListingEndpoint { 12 | public typealias R = Listing 13 | public var limit: Int = 100 14 | public var after: Fullname? 15 | public let resourcePath: String 16 | 17 | public enum `Type`: String { 18 | case subscriber 19 | case contributor 20 | case moderator 21 | case streams 22 | } 23 | 24 | public init(type: Type) { 25 | self.resourcePath = "subreddits/mine/\(type.rawValue)" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /redmin/identity/TokenRefreshEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TokenRefreshEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-29. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct TokenRefreshResponse: Decodable { 12 | public let accessToken: String 13 | public let tokenType: String 14 | public let expiresIn: TimeInterval 15 | public let scope: String 16 | public let refreshToken: String 17 | 18 | enum CodingKeys: String, CodingKey { 19 | case accessToken = "access_token" 20 | case tokenType = "token_type" 21 | case expiresIn = "expires_in" 22 | case scope 23 | case refreshToken = "refresh_token" 24 | } 25 | } 26 | 27 | public struct TokenRefreshEndpoint: Endpoint { 28 | public typealias R = TokenRefreshResponse 29 | 30 | public enum GrantType { 31 | case authorizationCode(code: String) 32 | case refreshToken 33 | 34 | var rawValue: String { 35 | switch self { 36 | case .authorizationCode: 37 | return "authorization_code" 38 | case .refreshToken: 39 | return "refresh_token" 40 | } 41 | } 42 | } 43 | 44 | let grantType: GrantType 45 | let redirectURI: String 46 | let clientID: String 47 | 48 | public init(grantType: GrantType, redirectURI: String, clientID: String) { 49 | self.grantType = grantType 50 | self.redirectURI = redirectURI 51 | self.clientID = clientID 52 | } 53 | 54 | var body: [String: String] { 55 | var body = [ 56 | "grant_type": grantType.rawValue, 57 | "redirect_uri": redirectURI 58 | ] 59 | if case GrantType.authorizationCode(let code) = grantType { 60 | body["code"] = code 61 | } 62 | return body 63 | } 64 | 65 | public var method: Method { 66 | return .post(body: body) 67 | } 68 | 69 | public var resourcePath: String { 70 | return "api/v1/access_token" 71 | } 72 | 73 | public var contentType: ContentType { 74 | return .form 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /redmin/identity/User.swift: -------------------------------------------------------------------------------- 1 | // 2 | // User.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-28. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct User: Decodable, Encodable { 12 | public let name: String 13 | } 14 | -------------------------------------------------------------------------------- /redmin/listings/Comment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Comment.swift 3 | // redditlight 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-19. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Comment: Resource { 12 | internal static let font: UIFont = .systemFont(ofSize: 14) 13 | 14 | public let author: String 15 | public let body: String 16 | public let score: Int 17 | 18 | public let id: String 19 | public let parentID: String 20 | public let depth: Int 21 | 22 | public let createdAt: Date 23 | 24 | var replyNode: Node>? 25 | 26 | public let bodyHTML: NSAttributedString 27 | 28 | enum CodingKeys: String, CodingKey { 29 | case author 30 | case body 31 | case depth 32 | case id 33 | case parentID = "parent_id" 34 | case bodyHTML = "body_html" 35 | case replyNode = "replies" 36 | case score 37 | case createdAt = "created_utc" 38 | } 39 | 40 | public init(from decoder: Decoder) throws { 41 | let container = try decoder.container(keyedBy: CodingKeys.self) 42 | author = try container.decode(String.self, forKey: .author) 43 | body = try container.decode(String.self, forKey: .body) 44 | depth = try container.decode(Int.self, forKey: .depth) 45 | id = try container.decode(String.self, forKey: .id) 46 | parentID = try container.decode(String.self, forKey: .parentID) 47 | score = try container.decode(Int.self, forKey: .score) 48 | replyNode = try? container.decode(Node>.self, forKey: .replyNode) 49 | 50 | let unixCreatedAt = try container.decode(Double.self, forKey: .createdAt) 51 | createdAt = Date(timeIntervalSince1970: unixCreatedAt) 52 | 53 | let rawHTML = try container.decode(String.self, forKey: .bodyHTML) 54 | bodyHTML = rawHTML.htmlAttributedString(font: Comment.font) 55 | } 56 | 57 | static func aggregateDescendants(of comment: Comment, into collection: inout [Comment]) { 58 | let itemNodes = comment.replyNode?.data.children 59 | let comments: [Comment]? = itemNodes?.compactMap { itemNode in 60 | guard case Conversation.Item.comment(let comment) = itemNode.data else { 61 | return nil 62 | } 63 | return comment 64 | } 65 | comments?.forEach { reply in 66 | collection.append(reply) 67 | aggregateDescendants(of: reply, into: &collection) 68 | } 69 | } 70 | 71 | public var durationSinceCreation: String { 72 | let time = -createdAt.timeIntervalSinceNow 73 | return time.prettyDuration 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /redmin/listings/Conveniences.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Conveniences.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-21. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | // NOTE: 12 | // The code in this file is extremely hacky and inefficient and should not be 13 | // used for any sort of production project. 14 | 15 | extension Int { 16 | public func comments(category: PostCategory = .top, _ completion: @escaping (([Comment]) -> Void )){ 17 | commentsFromSubreddit(named: nil, category: category, sort: .top, completion) 18 | } 19 | 20 | public func posts(category: PostCategory = .top, _ completion: @escaping (([Post]) -> Void)) { 21 | postsFromSubreddit(named: nil, category: category, completion) 22 | } 23 | 24 | // TODO this is limited to 100 posts at a time (API constraint). 25 | // To get more posts, pass the nextPage property on PostsResponse to PostsEndpoint 26 | // for each subsequent request 27 | public func postsFromSubreddit(named name: String?, category: PostCategory = .top, _ completion: @escaping (([Post]) -> Void)) { 28 | PostsEndpoint(subreddit: name, category: category, limit: self).request { (response) in 29 | guard case EndpointResponse.success(let postsResponse) = response else { 30 | return 31 | } 32 | completion(postsResponse.posts) 33 | } 34 | } 35 | 36 | public func commentsFromPost(_ post: Post, sort: Sort = .top, _ completion: @escaping (([Comment]) -> Void)) { 37 | let goal = self 38 | var aggregation = [Comment]() 39 | 40 | ConversationEndpoint(post: post, sort: sort, limit: self).request { (response) in 41 | guard 42 | case EndpointResponse.success(let commentsResponse) = response else { 43 | return 44 | } 45 | 46 | func deepAggregateComments(from items: [Conversation.Item], completion: @escaping (() -> Void)) { 47 | guard aggregation.count < goal else { 48 | completion() 49 | return 50 | } 51 | aggregateReplies(of: items.comments) { 52 | if let more = items.more { 53 | aggregatePagedComments(with: more) { 54 | completion() 55 | } 56 | } else { 57 | completion() 58 | } 59 | } 60 | } 61 | 62 | let comments = commentsResponse.items.comments 63 | aggregation += comments 64 | 65 | func aggregateReplies(of comments: [Comment], _ completion: @escaping () -> Void) { 66 | guard aggregation.count < goal, let replyNode = comments.first?.replyNode else { 67 | completion() 68 | return 69 | } 70 | aggregation += comments 71 | let items = replyNode.data.children.compactMap { $0.data } 72 | deepAggregateComments(from: items, completion: completion) 73 | } 74 | 75 | func aggregatePagedComments(with more: More, _ completion: @escaping () -> Void) { 76 | guard aggregation.count < goal else { 77 | completion() 78 | return 79 | } 80 | 81 | MoreChildrenEndpoint(more: more).request { response in 82 | guard 83 | case EndpointResponse.success(let moreResponse) = response else { 84 | completion() 85 | return 86 | } 87 | 88 | aggregation += moreResponse.items.comments 89 | 90 | if let more = moreResponse.items.more { 91 | aggregatePagedComments(with: more, completion) 92 | } else { 93 | completion() 94 | } 95 | } 96 | } 97 | 98 | deepAggregateComments(from: commentsResponse.items) { 99 | completion(aggregation) 100 | } 101 | } 102 | } 103 | 104 | public func commentsFromSubreddit(named name: String?, category: PostCategory = .top, sort: Sort = .top, _ completion: @escaping (([Comment]) -> Void)) { 105 | 106 | let goal = self 107 | var aggregation = [Comment]() 108 | 109 | func aggregateComments(from posts: [Post], completion: @escaping (([Comment]) -> Void)) { 110 | guard let post = posts.first, aggregation.count < goal else { 111 | completion(aggregation) 112 | return 113 | } 114 | 115 | commentsFromPost(post) { comments in 116 | aggregation += comments 117 | print(aggregation.count) 118 | aggregateComments(from: Array(posts[1..>.self) 47 | post = postNode.data.children.compactMap { $0.data }.first! 48 | 49 | let itemsNode = try container.decode(Node>.self) 50 | var items = [Item]() 51 | Conversation.aggregateDescendants(of: itemsNode.data.children.map { $0.data }, into: &items) 52 | self.items = items 53 | } 54 | 55 | 56 | static func aggregateDescendants(of items: [Item], into collection: inout [Item]) { 57 | for item in items { 58 | collection.append(item) 59 | guard 60 | let comment = item.data as? Comment, 61 | let replyNode = comment.replyNode 62 | else { 63 | return 64 | } 65 | let replies = replyNode.data.children.map { $0.data } 66 | aggregateDescendants(of: replies, into: &collection) 67 | } 68 | } 69 | } 70 | 71 | 72 | extension Array where Element == Conversation.Item { 73 | var comments: [Comment] { 74 | return compactMap { $0.data as? Comment } 75 | } 76 | 77 | var more: More? { 78 | return compactMap { $0.data as? More }.first 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /redmin/listings/ConversationEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CommentsEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-20. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public enum Sort: String, CaseIterable { 12 | case confidence, top, new, controversial, old, random, qa, live 13 | } 14 | 15 | public struct ConversationEndpoint: Endpoint { 16 | public typealias R = Conversation 17 | 18 | public static let defaultLimit = 100 19 | public let resourcePath: String 20 | 21 | let sort: Sort 22 | let limit: Int 23 | 24 | public init(post: Post, sort: Sort = .top, limit: Int = ConversationEndpoint.defaultLimit) { 25 | self.resourcePath = post.commentsPath 26 | self.sort = sort 27 | self.limit = limit 28 | } 29 | 30 | public var queryItems: [URLQueryItem]? { 31 | return [ 32 | URLQueryItem(name: "sort", value: sort.rawValue), 33 | URLQueryItem(name: "limit", value: String(limit)) 34 | ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /redmin/listings/Image.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Image.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-19. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension Image: Decodable { 12 | enum CodingKeys: String, CodingKey { 13 | case url, width, height 14 | } 15 | 16 | public init(from decoder: Decoder) throws { 17 | let container = try decoder.container(keyedBy: CodingKeys.self) 18 | url = try container.decode(URL.self, forKey: .url) 19 | 20 | if let width = try? container.decode(CGFloat.self, forKey: .width), 21 | let height = try? container.decode(CGFloat.self, forKey: .height) { 22 | self.size = CGSize(width: width, height: height) 23 | } else { 24 | self.size = nil 25 | } 26 | } 27 | } 28 | 29 | extension CGSize: Hashable { 30 | public func hash(into hasher: inout Hasher) { 31 | hasher.combine(height.hashValue << 32 ^ width.hashValue) 32 | } 33 | } 34 | 35 | public struct Image: Equatable, Hashable { 36 | public let url: URL 37 | public let size: CGSize? 38 | var dataTask: URLSessionDataTask? 39 | 40 | static let session = URLSession(configuration: .default) 41 | 42 | init(url: URL, size: CGSize?) { 43 | self.url = url 44 | self.size = size 45 | } 46 | 47 | static var timeout: TimeInterval = 10 48 | 49 | public var heightRatio: CGFloat? { 50 | guard let size = size else { 51 | return nil 52 | } 53 | return size.height / size.width 54 | } 55 | 56 | public enum ImageError: Error { 57 | case corruptData 58 | } 59 | 60 | var request: URLRequest { 61 | return URLRequest( 62 | url: url, 63 | cachePolicy: .returnCacheDataElseLoad, 64 | timeoutInterval: Image.timeout 65 | ) 66 | } 67 | 68 | // TODO caching not working for some reason 69 | 70 | public mutating func fetch(_ completion: @escaping (EndpointResponse) -> Void) { 71 | dataTask = Image.session.dataTask(with: request) { (data, _, error) in 72 | guard let data = data, let image = UIImage(data: data) else { 73 | completion(.failure(error ?? ImageError.corruptData)) 74 | return 75 | } 76 | completion(.success(image)) 77 | } 78 | dataTask?.resume() 79 | } 80 | 81 | public static func warmCache(with image: Image) { 82 | session.dataTask(with: image.request).resume() 83 | } 84 | 85 | public func cancel() { 86 | dataTask?.cancel() 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /redmin/listings/More.swift: -------------------------------------------------------------------------------- 1 | // 2 | // More.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-21. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct More: Resource, Decodable { 12 | public let count: Int 13 | public let children: [String] 14 | public let depth: Int 15 | public let parentID: String 16 | 17 | enum CodingKeys: String, CodingKey { 18 | case count, children, depth, parentID = "parent_id" 19 | } 20 | 21 | public var title: String { 22 | return "\(count) more \(count == 1 ? "reply" : "replies")" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /redmin/listings/MoreChildrenEndpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MoreChildrenEndpoint.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-22. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct MoreChildrenResponse: Decodable { 12 | struct Body: Decodable { 13 | struct Things: Decodable { 14 | let things: [Node] 15 | } 16 | let errors: [String] 17 | let data: Things 18 | } 19 | let json: Body 20 | 21 | public var errors: [String] { 22 | return json.errors 23 | } 24 | 25 | public var items: [Conversation.Item] { 26 | return json.data.things.compactMap { $0.data } 27 | } 28 | } 29 | 30 | public struct MoreChildrenEndpoint: Endpoint { 31 | public typealias R = MoreChildrenResponse 32 | 33 | let maxChildren = 100 34 | let more: More 35 | public let resourcePath: String 36 | 37 | public init(more: More) { 38 | self.more = more 39 | self.resourcePath = "api/morechildren" 40 | } 41 | 42 | public var queryItems: [URLQueryItem]? { 43 | let childCount = min(more.children.count, maxChildren) 44 | return [ 45 | URLQueryItem(name: "children", value: more.children[0..: Resource, Decodable { 25 | let before: Fullname? 26 | let after: Fullname? 27 | let children: [Node] 28 | } 29 | 30 | struct Node: Decodable, Resource { 31 | let kind: Kind 32 | let data: D 33 | } 34 | -------------------------------------------------------------------------------- /redmin/listings/Post.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Post.swift 3 | // redditlight 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-19. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Media: Decodable, Equatable { 12 | public let redditVideo: RedditVideo 13 | enum CodingKeys: String, CodingKey { 14 | case redditVideo = "reddit_video" 15 | } 16 | } 17 | 18 | public struct Post: Resource, Decodable, Equatable { 19 | public struct Preview: Decodable, Equatable { 20 | public struct PreviewImages: Decodable, Equatable { 21 | public let source: Image 22 | public let resolutions: [Image] 23 | } 24 | public let images: [PreviewImages] 25 | public let enabled: Bool 26 | } 27 | 28 | public let attributedText: NSAttributedString? 29 | public let commentCount: Int 30 | public let id: String 31 | public let media: Media? 32 | public let text: String? 33 | public let title: String 34 | public let preview: Preview? 35 | public let subreddit: String 36 | public let url: URL? 37 | 38 | enum CodingKeys: String, CodingKey { 39 | case commentCount = "num_comments" 40 | case id 41 | case media 42 | case preview 43 | case subreddit = "subreddit_name_prefixed" 44 | case title 45 | case text = "selftext" 46 | case textHTML = "selftext_html" 47 | case url 48 | } 49 | 50 | public init(from decoder: Decoder) throws { 51 | let container = try decoder.container(keyedBy: CodingKeys.self) 52 | commentCount = try container.decode(Int.self, forKey: .commentCount) 53 | id = try container.decode(String.self, forKey: .id) 54 | media = try? container.decode(Media.self, forKey: .media) 55 | preview = try? container.decode(Preview.self, forKey: .preview) 56 | subreddit = try container.decode(String.self, forKey: .subreddit) 57 | text = try? container.decode(String.self, forKey: .text) 58 | title = try container.decode(String.self, forKey: .title) 59 | url = try? container.decode(URL.self, forKey: .url) 60 | 61 | if let rawHTML = try? container.decode(String.self, forKey: .textHTML) { 62 | attributedText = rawHTML.htmlAttributedString( 63 | font: .systemFont(ofSize: 13) 64 | ) 65 | } else { 66 | attributedText = nil 67 | } 68 | } 69 | 70 | var commentsPath: String { 71 | return [subreddit, "comments", id].joined(separator: "/") 72 | } 73 | 74 | public func textPreview(until endIndex: Int = 150) -> String? { 75 | guard let text = self.attributedText?.string else { 76 | return nil 77 | } 78 | 79 | let preview: String = { 80 | if let firstParagraph = text.components(separatedBy: .newlines).first, 81 | firstParagraph.count < endIndex { 82 | return firstParagraph 83 | } 84 | let slice = text[..> 13 | 14 | public let posts: [Post] 15 | 16 | public var nextPage: Fullname? { 17 | return postNode.data.after 18 | } 19 | 20 | public init(from decoder: Decoder) throws { 21 | let container = try decoder.singleValueContainer() 22 | postNode = try container.decode(Node.self) 23 | posts = postNode.data.children.compactMap { $0.data } 24 | } 25 | } 26 | 27 | public enum PostCategory: String, CaseIterable { 28 | case hot, new, rising, top 29 | } 30 | 31 | public class PostsEndpoint: Endpoint { 32 | public typealias R = PostsResponse 33 | 34 | public var subreddit: String? 35 | public var category: PostCategory 36 | public var limit: Int 37 | public var after: Fullname? 38 | 39 | public init(subreddit: String?, category: PostCategory, limit: Int, after: Fullname? = nil) { 40 | self.subreddit = subreddit 41 | self.category = category 42 | self.limit = limit 43 | self.after = after 44 | } 45 | 46 | public var resourcePath: String { 47 | if let subreddit = self.subreddit { 48 | return "\(subreddit)/\(category.rawValue)" 49 | } 50 | return category.rawValue 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /redmin/listings/RedditVideo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RedditVideo.swift 3 | // Redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-11-13. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct RedditVideo: Decodable, Equatable { 12 | public let dashURL: URL 13 | public let duration: Int 14 | public let fallbackURL: URL 15 | public let height: CGFloat 16 | public let width: CGFloat 17 | public let hlsURL: URL 18 | public let isGif: Bool 19 | public let scrubberMediaURL: URL 20 | public let transcodingStatus: String 21 | 22 | enum CodingKeys: String, CodingKey { 23 | case dashURL = "dash_url" 24 | case duration 25 | case fallbackURL = "fallback_url" 26 | case height 27 | case width 28 | case hlsURL = "hls_url" 29 | case isGif = "is_gif" 30 | case scrubberMediaURL = "scrubber_media_url" 31 | case transcodingStatus = "transcoding_status" 32 | } 33 | 34 | public var heightRatio: CGFloat { 35 | return height / width 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /redmin/listings/Subreddit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Subreddit.swift 3 | // redmin-client 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-27. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct Subreddit: Resource, Codable, Equatable { 12 | public var title: String 13 | public var displayName: String 14 | public var advertiserCategory: String? 15 | 16 | private var rawDescription: String? 17 | private var iconURL: URL? 18 | private var iconSize: [Int]? 19 | private var bannerURL: URL? 20 | private var bannerSize: [Int]? 21 | 22 | public var icon: Image? 23 | public var banner: Image? 24 | public var description: NSAttributedString? 25 | 26 | enum CodingKeys: String, CodingKey { 27 | case advertiserCategory = "advertiser_category" 28 | case title 29 | case rawDescription = "public_description_html" 30 | case displayName = "display_name" 31 | case iconURL = "icon_img" 32 | case iconSize = "icon_size" 33 | case bannerURL = "banner_img" 34 | case bannerSize = "banner_size" 35 | } 36 | 37 | public init(from decoder: Decoder) throws { 38 | let container = try decoder.container(keyedBy: CodingKeys.self) 39 | advertiserCategory = try? container.decode(String.self, forKey: .advertiserCategory) 40 | title = try container.decode(String.self, forKey: .title) 41 | displayName = try container.decode(String.self, forKey: .displayName) 42 | 43 | rawDescription = try? container.decode(String.self, forKey: .rawDescription) 44 | description = rawDescription?.htmlAttributedString(font: UIFont.systemFont(ofSize: 14)) 45 | 46 | iconURL = try? container.decode(URL.self, forKey: .iconURL) 47 | iconSize = try? container.decode([Int].self, forKey: .iconSize) 48 | icon = { 49 | guard let url = iconURL, let size = iconSize, size.count == 2 else { 50 | return nil 51 | } 52 | return Image(url: url, size: CGSize(width: size[0], height: size[1])) 53 | }() 54 | 55 | bannerURL = try? container.decode(URL.self, forKey: .bannerURL) 56 | bannerSize = try? container.decode([Int].self, forKey: .bannerSize) 57 | banner = { 58 | guard let url = bannerURL, let size = bannerSize, size.count == 2 else { 59 | return nil 60 | } 61 | return Image(url: url, size: CGSize(width: size[0], height: size[1])) 62 | }() 63 | } 64 | 65 | public func encode(to encoder: Encoder) throws { 66 | var container = encoder.container(keyedBy: CodingKeys.self) 67 | try container.encode(title, forKey: .title) 68 | try container.encode(displayName, forKey: .displayName) 69 | try container.encode(rawDescription, forKey: .rawDescription) 70 | try container.encode(iconURL, forKey: .iconURL) 71 | try container.encode(iconSize, forKey: .iconSize) 72 | try container.encode(bannerURL, forKey: .bannerURL) 73 | try container.encode(bannerSize, forKey: .bannerSize) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /redmin/redmin.h: -------------------------------------------------------------------------------- 1 | // 2 | // redmin.h 3 | // redmin 4 | // 5 | // Created by Gabriel O'Flaherty-Chan on 2018-10-19. 6 | // Copyright © 2018 gabrieloc. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for redmin. 12 | FOUNDATION_EXPORT double redminVersionNumber; 13 | 14 | //! Project version string for redmin. 15 | FOUNDATION_EXPORT const unsigned char redminVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | --------------------------------------------------------------------------------