motion-yapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (348) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +63 -0
  6. data/README.md +16 -0
  7. data/Rakefile +20 -0
  8. data/app/app_delegate.rb +5 -0
  9. data/lib/yapper.rb +30 -0
  10. data/lib/yapper/attachment.rb +48 -0
  11. data/lib/yapper/bson.rb +20 -0
  12. data/lib/yapper/config.rb +18 -0
  13. data/lib/yapper/db.rb +151 -0
  14. data/lib/yapper/document.rb +54 -0
  15. data/lib/yapper/document/attachment.rb +26 -0
  16. data/lib/yapper/document/callbacks.rb +86 -0
  17. data/lib/yapper/document/persistance.rb +171 -0
  18. data/lib/yapper/document/relation.rb +84 -0
  19. data/lib/yapper/document/selection.rb +100 -0
  20. data/lib/yapper/extensions.rb +80 -0
  21. data/lib/yapper/log.rb +5 -0
  22. data/lib/yapper/sync.rb +134 -0
  23. data/lib/yapper/sync/data.rb +12 -0
  24. data/lib/yapper/sync/event.rb +194 -0
  25. data/lib/yapper/sync/queue.rb +164 -0
  26. data/lib/yapper/timestamps.rb +16 -0
  27. data/lib/yapper/version.rb +3 -0
  28. data/lib/yapper/yapper.rb +2 -0
  29. data/spec/helpers/time_helper.rb +3 -0
  30. data/spec/integration/all_spec.rb +40 -0
  31. data/spec/integration/callback_spec.rb +87 -0
  32. data/spec/integration/db_spec.rb +40 -0
  33. data/spec/integration/find_spec.rb +51 -0
  34. data/spec/integration/persistance_spec.rb +118 -0
  35. data/spec/integration/relation_spec.rb +174 -0
  36. data/spec/integration/sync_spec.rb +42 -0
  37. data/spec/integration/timestamps_spec.rb +34 -0
  38. data/spec/integration/types_spec.rb +23 -0
  39. data/spec/integration/when_spec.rb +29 -0
  40. data/spec/integration/where_spec.rb +132 -0
  41. data/vendor/Podfile.lock +24 -0
  42. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +641 -0
  43. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1396 -0
  44. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
  45. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +327 -0
  46. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +113 -0
  47. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +321 -0
  48. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
  49. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +150 -0
  50. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  51. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +157 -0
  52. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +43 -0
  53. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  54. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +143 -0
  55. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +370 -0
  56. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +848 -0
  57. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
  58. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +167 -0
  59. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
  60. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +191 -0
  61. data/vendor/Pods/AFNetworking/LICENSE +19 -0
  62. data/vendor/Pods/AFNetworking/README.md +208 -0
  63. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +641 -0
  64. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
  65. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +113 -0
  66. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
  67. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  68. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +43 -0
  69. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  70. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +370 -0
  71. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
  72. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
  73. data/vendor/Pods/BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
  74. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +41 -0
  75. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  76. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +334 -0
  77. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +601 -0
  78. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +167 -0
  79. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
  80. data/vendor/Pods/BuildHeaders/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  81. data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +109 -0
  82. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +90 -0
  83. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +20 -0
  84. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +547 -0
  85. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +447 -0
  86. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnectionState.h +29 -0
  87. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +37 -0
  88. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtension.h +15 -0
  89. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
  90. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
  91. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
  92. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +108 -0
  93. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
  94. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
  95. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
  96. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
  97. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
  98. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
  99. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  100. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
  101. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseLogging.h +158 -0
  102. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseManager.h +17 -0
  103. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +424 -0
  104. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseQuery.h +42 -0
  105. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
  106. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
  107. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
  108. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
  109. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
  110. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseStatement.h +13 -0
  111. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseString.h +121 -0
  112. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +541 -0
  113. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +186 -0
  114. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +272 -0
  115. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
  116. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +115 -0
  117. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +825 -0
  118. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
  119. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +56 -0
  120. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPage.h +36 -0
  121. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
  122. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +153 -0
  123. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
  124. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  125. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +447 -0
  126. data/vendor/Pods/BuildHeaders/YapDatabase/YapMemoryTable.h +74 -0
  127. data/vendor/Pods/BuildHeaders/YapDatabase/YapNull.h +17 -0
  128. data/vendor/Pods/BuildHeaders/YapDatabase/YapSet.h +41 -0
  129. data/vendor/Pods/BuildHeaders/YapDatabase/YapTouch.h +15 -0
  130. data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
  131. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
  132. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
  133. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  134. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
  135. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
  136. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1353 -0
  137. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +601 -0
  138. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +1083 -0
  139. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +167 -0
  140. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1479 -0
  141. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
  142. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
  143. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
  144. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
  145. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +7 -0
  146. data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
  147. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +641 -0
  148. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
  149. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +113 -0
  150. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
  151. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  152. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +43 -0
  153. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  154. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +370 -0
  155. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
  156. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
  157. data/vendor/Pods/Headers/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
  158. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
  159. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  160. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
  161. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +601 -0
  162. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +167 -0
  163. data/vendor/Pods/Headers/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
  164. data/vendor/Pods/Headers/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  165. data/vendor/Pods/Headers/Reachability/Reachability.h +109 -0
  166. data/vendor/Pods/Headers/YapDatabase/YapCache.h +90 -0
  167. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +20 -0
  168. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +547 -0
  169. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +447 -0
  170. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +29 -0
  171. data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +37 -0
  172. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtension.h +15 -0
  173. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
  174. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
  175. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
  176. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +108 -0
  177. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
  178. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
  179. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
  180. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
  181. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
  182. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
  183. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  184. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
  185. data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +158 -0
  186. data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +17 -0
  187. data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +424 -0
  188. data/vendor/Pods/Headers/YapDatabase/YapDatabaseQuery.h +42 -0
  189. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
  190. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
  191. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
  192. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
  193. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
  194. data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +13 -0
  195. data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +121 -0
  196. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +541 -0
  197. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +186 -0
  198. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +272 -0
  199. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
  200. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +115 -0
  201. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +825 -0
  202. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
  203. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +56 -0
  204. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +36 -0
  205. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
  206. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +153 -0
  207. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
  208. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  209. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +447 -0
  210. data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +74 -0
  211. data/vendor/Pods/Headers/YapDatabase/YapNull.h +17 -0
  212. data/vendor/Pods/Headers/YapDatabase/YapSet.h +41 -0
  213. data/vendor/Pods/Headers/YapDatabase/YapTouch.h +15 -0
  214. data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +17 -0
  215. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +5 -0
  216. data/vendor/Pods/Headers/____Pods-NSData+MD5Digest-prefix.h +5 -0
  217. data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +5 -0
  218. data/vendor/Pods/Headers/____Pods-YapDatabase-prefix.h +5 -0
  219. data/vendor/Pods/Headers/____Pods-environment.h +38 -0
  220. data/vendor/Pods/Manifest.lock +24 -0
  221. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  222. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.m +39 -0
  223. data/vendor/Pods/NSData+MD5Digest/README.md +11 -0
  224. data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +5 -0
  225. data/vendor/Pods/Pods-AFNetworking-dummy.m +5 -0
  226. data/vendor/Pods/Pods-AFNetworking-prefix.pch +17 -0
  227. data/vendor/Pods/Pods-AFNetworking.xcconfig +1 -0
  228. data/vendor/Pods/Pods-Acknowledgements.markdown +96 -0
  229. data/vendor/Pods/Pods-Acknowledgements.plist +142 -0
  230. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +5 -0
  231. data/vendor/Pods/Pods-CocoaLumberjack-dummy.m +5 -0
  232. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +5 -0
  233. data/vendor/Pods/Pods-CocoaLumberjack.xcconfig +0 -0
  234. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +5 -0
  235. data/vendor/Pods/Pods-NSData+MD5Digest-dummy.m +5 -0
  236. data/vendor/Pods/Pods-NSData+MD5Digest-prefix.pch +5 -0
  237. data/vendor/Pods/Pods-NSData+MD5Digest.xcconfig +0 -0
  238. data/vendor/Pods/Pods-Reachability-Private.xcconfig +5 -0
  239. data/vendor/Pods/Pods-Reachability-dummy.m +5 -0
  240. data/vendor/Pods/Pods-Reachability-prefix.pch +5 -0
  241. data/vendor/Pods/Pods-Reachability.xcconfig +1 -0
  242. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +5 -0
  243. data/vendor/Pods/Pods-YapDatabase-dummy.m +5 -0
  244. data/vendor/Pods/Pods-YapDatabase-prefix.pch +5 -0
  245. data/vendor/Pods/Pods-YapDatabase.xcconfig +1 -0
  246. data/vendor/Pods/Pods-dummy.m +5 -0
  247. data/vendor/Pods/Pods-environment.h +38 -0
  248. data/vendor/Pods/Pods-resources.sh +68 -0
  249. data/vendor/Pods/Pods.bridgesupport +5096 -0
  250. data/vendor/Pods/Pods.xcconfig +5 -0
  251. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +5536 -0
  252. data/vendor/Pods/Reachability/LICENCE.txt +24 -0
  253. data/vendor/Pods/Reachability/README.md +65 -0
  254. data/vendor/Pods/Reachability/Reachability.h +109 -0
  255. data/vendor/Pods/Reachability/Reachability.m +527 -0
  256. data/vendor/Pods/YapDatabase/LICENSE.txt +18 -0
  257. data/vendor/Pods/YapDatabase/README.md +30 -0
  258. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +19 -0
  259. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +108 -0
  260. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +175 -0
  261. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.h +12 -0
  262. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.m +41 -0
  263. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +39 -0
  264. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +966 -0
  265. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +69 -0
  266. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.h +89 -0
  267. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.m +146 -0
  268. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.h +32 -0
  269. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +298 -0
  270. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  271. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.m +95 -0
  272. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.h +68 -0
  273. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +1352 -0
  274. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +440 -0
  275. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.h +15 -0
  276. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +58 -0
  277. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.h +11 -0
  278. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +46 -0
  279. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.h +11 -0
  280. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +180 -0
  281. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +73 -0
  282. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +100 -0
  283. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +149 -0
  284. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.h +33 -0
  285. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +330 -0
  286. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.h +33 -0
  287. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +184 -0
  288. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.h +58 -0
  289. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +1166 -0
  290. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewChangePrivate.h +94 -0
  291. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewMappingsPrivate.h +72 -0
  292. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.h +36 -0
  293. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.mm +296 -0
  294. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.h +27 -0
  295. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.m +28 -0
  296. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +153 -0
  297. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  298. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +272 -0
  299. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +2494 -0
  300. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +825 -0
  301. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +1567 -0
  302. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.h +330 -0
  303. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.m +141 -0
  304. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +186 -0
  305. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +191 -0
  306. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +115 -0
  307. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +897 -0
  308. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +56 -0
  309. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.m +27 -0
  310. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +447 -0
  311. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +4505 -0
  312. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +90 -0
  313. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +453 -0
  314. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.h +29 -0
  315. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.m +48 -0
  316. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +37 -0
  317. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +83 -0
  318. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.h +158 -0
  319. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.m +73 -0
  320. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.h +17 -0
  321. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.m +56 -0
  322. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +424 -0
  323. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.h +13 -0
  324. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.m +26 -0
  325. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseString.h +121 -0
  326. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.h +74 -0
  327. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.m +603 -0
  328. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.h +17 -0
  329. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +31 -0
  330. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.h +15 -0
  331. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.m +31 -0
  332. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +20 -0
  333. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +194 -0
  334. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.h +42 -0
  335. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.m +96 -0
  336. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.h +41 -0
  337. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.m +82 -0
  338. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +547 -0
  339. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +2022 -0
  340. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +447 -0
  341. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +3874 -0
  342. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +541 -0
  343. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +5282 -0
  344. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +16 -0
  345. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +13 -0
  346. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +20 -0
  347. data/yapper.gemspec +24 -0
  348. metadata +458 -0
@@ -0,0 +1,1396 @@
1
+ // AFHTTPClient.m
2
+ //
3
+ // Copyright (c) 2011 Gowalla (http://gowalla.com/)
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included in
13
+ // all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ // THE SOFTWARE.
22
+
23
+ #import <Foundation/Foundation.h>
24
+
25
+ #import "AFHTTPClient.h"
26
+ #import "AFHTTPRequestOperation.h"
27
+
28
+ #import <Availability.h>
29
+
30
+ #ifdef _SYSTEMCONFIGURATION_H
31
+ #import <netinet/in.h>
32
+ #import <netinet6/in6.h>
33
+ #import <arpa/inet.h>
34
+ #import <ifaddrs.h>
35
+ #import <netdb.h>
36
+ #endif
37
+
38
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
39
+ #import <UIKit/UIKit.h>
40
+ #endif
41
+
42
+ #ifdef _SYSTEMCONFIGURATION_H
43
+ NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
44
+ NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
45
+
46
+ typedef SCNetworkReachabilityRef AFNetworkReachabilityRef;
47
+ typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
48
+ #else
49
+ typedef id AFNetworkReachabilityRef;
50
+ #endif
51
+
52
+ typedef void (^AFCompletionBlock)(void);
53
+
54
+ static NSString * AFBase64EncodedStringFromString(NSString *string) {
55
+ NSData *data = [NSData dataWithBytes:[string UTF8String] length:[string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
56
+ NSUInteger length = [data length];
57
+ NSMutableData *mutableData = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
58
+
59
+ uint8_t *input = (uint8_t *)[data bytes];
60
+ uint8_t *output = (uint8_t *)[mutableData mutableBytes];
61
+
62
+ for (NSUInteger i = 0; i < length; i += 3) {
63
+ NSUInteger value = 0;
64
+ for (NSUInteger j = i; j < (i + 3); j++) {
65
+ value <<= 8;
66
+ if (j < length) {
67
+ value |= (0xFF & input[j]);
68
+ }
69
+ }
70
+
71
+ static uint8_t const kAFBase64EncodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
72
+
73
+ NSUInteger idx = (i / 3) * 4;
74
+ output[idx + 0] = kAFBase64EncodingTable[(value >> 18) & 0x3F];
75
+ output[idx + 1] = kAFBase64EncodingTable[(value >> 12) & 0x3F];
76
+ output[idx + 2] = (i + 1) < length ? kAFBase64EncodingTable[(value >> 6) & 0x3F] : '=';
77
+ output[idx + 3] = (i + 2) < length ? kAFBase64EncodingTable[(value >> 0) & 0x3F] : '=';
78
+ }
79
+
80
+ return [[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding];
81
+ }
82
+
83
+ static NSString * const kAFCharactersToBeEscapedInQueryString = @":/?&=;+!@#$()',*";
84
+
85
+ static NSString * AFPercentEscapedQueryStringKeyFromStringWithEncoding(NSString *string, NSStringEncoding encoding) {
86
+ static NSString * const kAFCharactersToLeaveUnescapedInQueryStringPairKey = @"[].";
87
+
88
+ return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, (__bridge CFStringRef)kAFCharactersToLeaveUnescapedInQueryStringPairKey, (__bridge CFStringRef)kAFCharactersToBeEscapedInQueryString, CFStringConvertNSStringEncodingToEncoding(encoding));
89
+ }
90
+
91
+ static NSString * AFPercentEscapedQueryStringValueFromStringWithEncoding(NSString *string, NSStringEncoding encoding) {
92
+ return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, (__bridge CFStringRef)kAFCharactersToBeEscapedInQueryString, CFStringConvertNSStringEncodingToEncoding(encoding));
93
+ }
94
+
95
+ #pragma mark -
96
+
97
+ @interface AFQueryStringPair : NSObject
98
+ @property (readwrite, nonatomic, strong) id field;
99
+ @property (readwrite, nonatomic, strong) id value;
100
+
101
+ - (id)initWithField:(id)field value:(id)value;
102
+
103
+ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding;
104
+ @end
105
+
106
+ @implementation AFQueryStringPair
107
+ @synthesize field = _field;
108
+ @synthesize value = _value;
109
+
110
+ - (id)initWithField:(id)field value:(id)value {
111
+ self = [super init];
112
+ if (!self) {
113
+ return nil;
114
+ }
115
+
116
+ self.field = field;
117
+ self.value = value;
118
+
119
+ return self;
120
+ }
121
+
122
+ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding {
123
+ if (!self.value || [self.value isEqual:[NSNull null]]) {
124
+ return AFPercentEscapedQueryStringKeyFromStringWithEncoding([self.field description], stringEncoding);
125
+ } else {
126
+ return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedQueryStringKeyFromStringWithEncoding([self.field description], stringEncoding), AFPercentEscapedQueryStringValueFromStringWithEncoding([self.value description], stringEncoding)];
127
+ }
128
+ }
129
+
130
+ @end
131
+
132
+ #pragma mark -
133
+
134
+ extern NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary);
135
+ extern NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value);
136
+
137
+ NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding stringEncoding) {
138
+ NSMutableArray *mutablePairs = [NSMutableArray array];
139
+ for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
140
+ [mutablePairs addObject:[pair URLEncodedStringValueWithEncoding:stringEncoding]];
141
+ }
142
+
143
+ return [mutablePairs componentsJoinedByString:@"&"];
144
+ }
145
+
146
+ NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary) {
147
+ return AFQueryStringPairsFromKeyAndValue(nil, dictionary);
148
+ }
149
+
150
+ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
151
+ NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
152
+
153
+ if ([value isKindOfClass:[NSDictionary class]]) {
154
+ NSDictionary *dictionary = value;
155
+ // Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
156
+ NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveCompare:)];
157
+ for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
158
+ id nestedValue = [dictionary objectForKey:nestedKey];
159
+ if (nestedValue) {
160
+ [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
161
+ }
162
+ }
163
+ } else if ([value isKindOfClass:[NSArray class]]) {
164
+ NSArray *array = value;
165
+ for (id nestedValue in array) {
166
+ [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
167
+ }
168
+ } else if ([value isKindOfClass:[NSSet class]]) {
169
+ NSSet *set = value;
170
+ for (id obj in set) {
171
+ [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)];
172
+ }
173
+ } else {
174
+ [mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
175
+ }
176
+
177
+ return mutableQueryStringComponents;
178
+ }
179
+
180
+ @interface AFStreamingMultipartFormData : NSObject <AFMultipartFormData>
181
+ - (id)initWithURLRequest:(NSMutableURLRequest *)urlRequest
182
+ stringEncoding:(NSStringEncoding)encoding;
183
+
184
+ - (NSMutableURLRequest *)requestByFinalizingMultipartFormData;
185
+ @end
186
+
187
+ #pragma mark -
188
+
189
+ @interface AFHTTPClient ()
190
+ @property (readwrite, nonatomic, strong) NSURL *baseURL;
191
+ @property (readwrite, nonatomic, strong) NSMutableArray *registeredHTTPOperationClassNames;
192
+ @property (readwrite, nonatomic, strong) NSMutableDictionary *defaultHeaders;
193
+ @property (readwrite, nonatomic, strong) NSURLCredential *defaultCredential;
194
+ @property (readwrite, nonatomic, strong) NSOperationQueue *operationQueue;
195
+ #ifdef _SYSTEMCONFIGURATION_H
196
+ @property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability;
197
+ @property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
198
+ @property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
199
+ #endif
200
+
201
+ #ifdef _SYSTEMCONFIGURATION_H
202
+ - (void)startMonitoringNetworkReachability;
203
+ - (void)stopMonitoringNetworkReachability;
204
+ #endif
205
+ @end
206
+
207
+ @implementation AFHTTPClient
208
+ @synthesize baseURL = _baseURL;
209
+ @synthesize stringEncoding = _stringEncoding;
210
+ @synthesize parameterEncoding = _parameterEncoding;
211
+ @synthesize registeredHTTPOperationClassNames = _registeredHTTPOperationClassNames;
212
+ @synthesize defaultHeaders = _defaultHeaders;
213
+ @synthesize defaultCredential = _defaultCredential;
214
+ @synthesize operationQueue = _operationQueue;
215
+ #ifdef _SYSTEMCONFIGURATION_H
216
+ @synthesize networkReachability = _networkReachability;
217
+ @synthesize networkReachabilityStatus = _networkReachabilityStatus;
218
+ @synthesize networkReachabilityStatusBlock = _networkReachabilityStatusBlock;
219
+ #endif
220
+ @synthesize defaultSSLPinningMode = _defaultSSLPinningMode;
221
+ @synthesize allowsInvalidSSLCertificate = _allowsInvalidSSLCertificate;
222
+
223
+ + (instancetype)clientWithBaseURL:(NSURL *)url {
224
+ return [[self alloc] initWithBaseURL:url];
225
+ }
226
+
227
+ - (id)init {
228
+ @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"%@ Failed to call designated initializer. Invoke `initWithBaseURL:` instead.", NSStringFromClass([self class])] userInfo:nil];
229
+ }
230
+
231
+ - (id)initWithBaseURL:(NSURL *)url {
232
+ NSParameterAssert(url);
233
+
234
+ self = [super init];
235
+ if (!self) {
236
+ return nil;
237
+ }
238
+
239
+ // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected
240
+ if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) {
241
+ url = [url URLByAppendingPathComponent:@""];
242
+ }
243
+
244
+ self.baseURL = url;
245
+
246
+ self.stringEncoding = NSUTF8StringEncoding;
247
+ self.parameterEncoding = AFFormURLParameterEncoding;
248
+
249
+ self.registeredHTTPOperationClassNames = [NSMutableArray array];
250
+
251
+ self.defaultHeaders = [NSMutableDictionary dictionary];
252
+
253
+ // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
254
+ NSMutableArray *acceptLanguagesComponents = [NSMutableArray array];
255
+ [[NSLocale preferredLanguages] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
256
+ float q = 1.0f - (idx * 0.1f);
257
+ [acceptLanguagesComponents addObject:[NSString stringWithFormat:@"%@;q=%0.1g", obj, q]];
258
+ *stop = q <= 0.5f;
259
+ }];
260
+ [self setDefaultHeader:@"Accept-Language" value:[acceptLanguagesComponents componentsJoinedByString:@", "]];
261
+
262
+ NSString *userAgent = nil;
263
+ #pragma clang diagnostic push
264
+ #pragma clang diagnostic ignored "-Wgnu"
265
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
266
+ // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
267
+ userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)];
268
+ #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
269
+ userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
270
+ #endif
271
+ #pragma clang diagnostic pop
272
+ if (userAgent) {
273
+ if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
274
+ NSMutableString *mutableUserAgent = [userAgent mutableCopy];
275
+ CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, kCFStringTransformToLatin, false);
276
+ userAgent = mutableUserAgent;
277
+ }
278
+ [self setDefaultHeader:@"User-Agent" value:userAgent];
279
+ }
280
+
281
+ #ifdef _SYSTEMCONFIGURATION_H
282
+ self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
283
+ [self startMonitoringNetworkReachability];
284
+ #endif
285
+
286
+ self.operationQueue = [[NSOperationQueue alloc] init];
287
+ [self.operationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
288
+
289
+ // #ifdef included for backwards-compatibility
290
+ #ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
291
+ self.allowsInvalidSSLCertificate = YES;
292
+ #endif
293
+
294
+ return self;
295
+ }
296
+
297
+ - (void)dealloc {
298
+ #ifdef _SYSTEMCONFIGURATION_H
299
+ [self stopMonitoringNetworkReachability];
300
+ #endif
301
+ }
302
+
303
+ - (NSString *)description {
304
+ return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, defaultHeaders: %@, registeredOperationClasses: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.defaultHeaders, self.registeredHTTPOperationClassNames, self.operationQueue];
305
+ }
306
+
307
+ #pragma mark -
308
+
309
+ #ifdef _SYSTEMCONFIGURATION_H
310
+ static BOOL AFURLHostIsIPAddress(NSURL *url) {
311
+ struct sockaddr_in sa_in;
312
+ struct sockaddr_in6 sa_in6;
313
+
314
+ return [url host] && (inet_pton(AF_INET, [[url host] UTF8String], &sa_in) == 1 || inet_pton(AF_INET6, [[url host] UTF8String], &sa_in6) == 1);
315
+ }
316
+
317
+ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetworkReachabilityFlags flags) {
318
+ BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
319
+ BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
320
+ BOOL canConnectionAutomatically = (((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0));
321
+ BOOL canConnectWithoutUserInteraction = (canConnectionAutomatically && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0);
322
+ BOOL isNetworkReachable = (isReachable && (!needsConnection || canConnectWithoutUserInteraction));
323
+
324
+ AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
325
+ if (isNetworkReachable == NO) {
326
+ status = AFNetworkReachabilityStatusNotReachable;
327
+ }
328
+ #if TARGET_OS_IPHONE
329
+ else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
330
+ status = AFNetworkReachabilityStatusReachableViaWWAN;
331
+ }
332
+ #endif
333
+ else {
334
+ status = AFNetworkReachabilityStatusReachableViaWiFi;
335
+ }
336
+
337
+ return status;
338
+ }
339
+
340
+ static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
341
+ AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
342
+ AFNetworkReachabilityStatusBlock block = (__bridge AFNetworkReachabilityStatusBlock)info;
343
+ if (block) {
344
+ block(status);
345
+ }
346
+
347
+ dispatch_async(dispatch_get_main_queue(), ^{
348
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
349
+ [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:status] forKey:AFNetworkingReachabilityNotificationStatusItem]];
350
+ });
351
+ }
352
+
353
+ static const void * AFNetworkReachabilityRetainCallback(const void *info) {
354
+ return Block_copy(info);
355
+ }
356
+
357
+ static void AFNetworkReachabilityReleaseCallback(const void *info) {
358
+ if (info) {
359
+ Block_release(info);
360
+ }
361
+ }
362
+
363
+ - (void)startMonitoringNetworkReachability {
364
+ [self stopMonitoringNetworkReachability];
365
+
366
+ if (!self.baseURL) {
367
+ return;
368
+ }
369
+
370
+ self.networkReachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [[self.baseURL host] UTF8String]);
371
+
372
+ if (!self.networkReachability) {
373
+ return;
374
+ }
375
+
376
+ __weak __typeof(&*self)weakSelf = self;
377
+ AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
378
+ __strong __typeof(&*weakSelf)strongSelf = weakSelf;
379
+ if (!strongSelf) {
380
+ return;
381
+ }
382
+
383
+ strongSelf.networkReachabilityStatus = status;
384
+ if (strongSelf.networkReachabilityStatusBlock) {
385
+ strongSelf.networkReachabilityStatusBlock(status);
386
+ }
387
+ };
388
+
389
+ SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
390
+ SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
391
+
392
+ /* Network reachability monitoring does not establish a baseline for IP addresses as it does for hostnames, so if the base URL host is an IP address, the initial reachability callback is manually triggered.
393
+ */
394
+ if (AFURLHostIsIPAddress(self.baseURL)) {
395
+ SCNetworkReachabilityFlags flags;
396
+ SCNetworkReachabilityGetFlags(self.networkReachability, &flags);
397
+ dispatch_async(dispatch_get_main_queue(), ^{
398
+ AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
399
+ callback(status);
400
+ });
401
+ }
402
+
403
+ SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
404
+ }
405
+
406
+ - (void)stopMonitoringNetworkReachability {
407
+ if (self.networkReachability) {
408
+ SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
409
+
410
+ CFRelease(_networkReachability);
411
+ _networkReachability = NULL;
412
+ }
413
+ }
414
+
415
+ - (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block {
416
+ self.networkReachabilityStatusBlock = block;
417
+ }
418
+ #endif
419
+
420
+ #pragma mark -
421
+
422
+ - (BOOL)registerHTTPOperationClass:(Class)operationClass {
423
+ if (![operationClass isSubclassOfClass:[AFHTTPRequestOperation class]]) {
424
+ return NO;
425
+ }
426
+
427
+ NSString *className = NSStringFromClass(operationClass);
428
+ [self.registeredHTTPOperationClassNames removeObject:className];
429
+ [self.registeredHTTPOperationClassNames insertObject:className atIndex:0];
430
+
431
+ return YES;
432
+ }
433
+
434
+ - (void)unregisterHTTPOperationClass:(Class)operationClass {
435
+ NSString *className = NSStringFromClass(operationClass);
436
+ [self.registeredHTTPOperationClassNames removeObject:className];
437
+ }
438
+
439
+ #pragma mark -
440
+
441
+ - (NSString *)defaultValueForHeader:(NSString *)header {
442
+ return [self.defaultHeaders valueForKey:header];
443
+ }
444
+
445
+ - (void)setDefaultHeader:(NSString *)header value:(NSString *)value {
446
+ [self.defaultHeaders setValue:value forKey:header];
447
+ }
448
+
449
+ - (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password {
450
+ NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];
451
+ [self setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@", AFBase64EncodedStringFromString(basicAuthCredentials)]];
452
+ }
453
+
454
+ - (void)setAuthorizationHeaderWithToken:(NSString *)token {
455
+ [self setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Token token=\"%@\"", token]];
456
+ }
457
+
458
+ - (void)clearAuthorizationHeader {
459
+ [self.defaultHeaders removeObjectForKey:@"Authorization"];
460
+ }
461
+
462
+ #pragma mark -
463
+
464
+ - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
465
+ path:(NSString *)path
466
+ parameters:(NSDictionary *)parameters
467
+ {
468
+ NSParameterAssert(method);
469
+
470
+ if (!path) {
471
+ path = @"";
472
+ }
473
+
474
+ NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL];
475
+ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
476
+ [request setHTTPMethod:method];
477
+ [request setAllHTTPHeaderFields:self.defaultHeaders];
478
+
479
+ if (parameters) {
480
+ if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"] || [method isEqualToString:@"DELETE"]) {
481
+ url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]];
482
+ [request setURL:url];
483
+ } else {
484
+ NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding));
485
+ NSError *error = nil;
486
+
487
+ switch (self.parameterEncoding) {
488
+ case AFFormURLParameterEncoding:;
489
+ [request setValue:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
490
+ [request setHTTPBody:[AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding) dataUsingEncoding:self.stringEncoding]];
491
+ break;
492
+ case AFJSONParameterEncoding:;
493
+ [request setValue:[NSString stringWithFormat:@"application/json; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
494
+ [request setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:(NSJSONWritingOptions)0 error:&error]];
495
+ break;
496
+ case AFPropertyListParameterEncoding:;
497
+ [request setValue:[NSString stringWithFormat:@"application/x-plist; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
498
+ [request setHTTPBody:[NSPropertyListSerialization dataWithPropertyList:parameters format:NSPropertyListXMLFormat_v1_0 options:0 error:&error]];
499
+ break;
500
+ }
501
+
502
+ if (error) {
503
+ NSLog(@"%@ %@: %@", [self class], NSStringFromSelector(_cmd), error);
504
+ }
505
+ }
506
+ }
507
+
508
+ return request;
509
+ }
510
+
511
+ - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
512
+ path:(NSString *)path
513
+ parameters:(NSDictionary *)parameters
514
+ constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
515
+ {
516
+ NSParameterAssert(method);
517
+ NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
518
+
519
+ NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
520
+
521
+ __block AFStreamingMultipartFormData *formData = [[AFStreamingMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding];
522
+
523
+ if (parameters) {
524
+ for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
525
+ NSData *data = nil;
526
+ if ([pair.value isKindOfClass:[NSData class]]) {
527
+ data = pair.value;
528
+ } else if ([pair.value isEqual:[NSNull null]]) {
529
+ data = [NSData data];
530
+ } else {
531
+ data = [[pair.value description] dataUsingEncoding:self.stringEncoding];
532
+ }
533
+
534
+ if (data) {
535
+ [formData appendPartWithFormData:data name:[pair.field description]];
536
+ }
537
+ }
538
+ }
539
+
540
+ if (block) {
541
+ block(formData);
542
+ }
543
+
544
+ return [formData requestByFinalizingMultipartFormData];
545
+ }
546
+
547
+ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
548
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
549
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
550
+ {
551
+ AFHTTPRequestOperation *operation = nil;
552
+
553
+ for (NSString *className in self.registeredHTTPOperationClassNames) {
554
+ Class operationClass = NSClassFromString(className);
555
+ if (operationClass && [operationClass canProcessRequest:urlRequest]) {
556
+ operation = [(AFHTTPRequestOperation *)[operationClass alloc] initWithRequest:urlRequest];
557
+ break;
558
+ }
559
+ }
560
+
561
+ if (!operation) {
562
+ operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
563
+ }
564
+
565
+ [operation setCompletionBlockWithSuccess:success failure:failure];
566
+
567
+ operation.credential = self.defaultCredential;
568
+ operation.SSLPinningMode = self.defaultSSLPinningMode;
569
+ operation.allowsInvalidSSLCertificate = self.allowsInvalidSSLCertificate;
570
+
571
+ return operation;
572
+ }
573
+
574
+ #pragma mark -
575
+
576
+ - (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation {
577
+ [self.operationQueue addOperation:operation];
578
+ }
579
+
580
+ - (void)cancelAllHTTPOperationsWithMethod:(NSString *)method
581
+ path:(NSString *)path
582
+ {
583
+ #pragma clang diagnostic push
584
+ #pragma clang diagnostic ignored "-Wgnu"
585
+ NSString *pathToBeMatched = [[[self requestWithMethod:(method ?: @"GET") path:path parameters:nil] URL] path];
586
+ #pragma clang diagnostic pop
587
+
588
+ for (NSOperation *operation in [self.operationQueue operations]) {
589
+ if (![operation isKindOfClass:[AFHTTPRequestOperation class]]) {
590
+ continue;
591
+ }
592
+
593
+ BOOL hasMatchingMethod = !method || [method isEqualToString:[[(AFHTTPRequestOperation *)operation request] HTTPMethod]];
594
+ BOOL hasMatchingPath = [[[[(AFHTTPRequestOperation *)operation request] URL] path] isEqual:pathToBeMatched];
595
+
596
+ if (hasMatchingMethod && hasMatchingPath) {
597
+ [operation cancel];
598
+ }
599
+ }
600
+ }
601
+
602
+ - (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)urlRequests
603
+ progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock
604
+ completionBlock:(void (^)(NSArray *operations))completionBlock
605
+ {
606
+ NSMutableArray *mutableOperations = [NSMutableArray array];
607
+ for (NSURLRequest *request in urlRequests) {
608
+ AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:nil failure:nil];
609
+ [mutableOperations addObject:operation];
610
+ }
611
+
612
+ [self enqueueBatchOfHTTPRequestOperations:mutableOperations progressBlock:progressBlock completionBlock:completionBlock];
613
+ }
614
+
615
+ - (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations
616
+ progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock
617
+ completionBlock:(void (^)(NSArray *operations))completionBlock
618
+ {
619
+ __block dispatch_group_t dispatchGroup = dispatch_group_create();
620
+ NSBlockOperation *batchedOperation = [NSBlockOperation blockOperationWithBlock:^{
621
+ dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{
622
+ if (completionBlock) {
623
+ completionBlock(operations);
624
+ }
625
+ });
626
+ #if !OS_OBJECT_USE_OBJC
627
+ dispatch_release(dispatchGroup);
628
+ #endif
629
+ }];
630
+
631
+ for (AFHTTPRequestOperation *operation in operations) {
632
+ AFCompletionBlock originalCompletionBlock = [operation.completionBlock copy];
633
+ __weak __typeof(&*operation)weakOperation = operation;
634
+ operation.completionBlock = ^{
635
+ __strong __typeof(&*weakOperation)strongOperation = weakOperation;
636
+ #pragma clang diagnostic push
637
+ #pragma clang diagnostic ignored "-Wgnu"
638
+ dispatch_queue_t queue = strongOperation.successCallbackQueue ?: dispatch_get_main_queue();
639
+ #pragma clang diagnostic pop
640
+ dispatch_group_async(dispatchGroup, queue, ^{
641
+ if (originalCompletionBlock) {
642
+ originalCompletionBlock();
643
+ }
644
+
645
+ NSUInteger numberOfFinishedOperations = [[operations indexesOfObjectsPassingTest:^BOOL(id op, NSUInteger __unused idx, BOOL __unused *stop) {
646
+ return [op isFinished];
647
+ }] count];
648
+
649
+ if (progressBlock) {
650
+ progressBlock(numberOfFinishedOperations, [operations count]);
651
+ }
652
+
653
+ dispatch_group_leave(dispatchGroup);
654
+ });
655
+ };
656
+
657
+ dispatch_group_enter(dispatchGroup);
658
+ [batchedOperation addDependency:operation];
659
+ }
660
+ [self.operationQueue addOperations:operations waitUntilFinished:NO];
661
+ [self.operationQueue addOperation:batchedOperation];
662
+ }
663
+
664
+ #pragma mark -
665
+
666
+ - (void)getPath:(NSString *)path
667
+ parameters:(NSDictionary *)parameters
668
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
669
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
670
+ {
671
+ NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters];
672
+ AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
673
+ [self enqueueHTTPRequestOperation:operation];
674
+ }
675
+
676
+ - (void)postPath:(NSString *)path
677
+ parameters:(NSDictionary *)parameters
678
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
679
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
680
+ {
681
+ NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:parameters];
682
+ AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
683
+ [self enqueueHTTPRequestOperation:operation];
684
+ }
685
+
686
+ - (void)putPath:(NSString *)path
687
+ parameters:(NSDictionary *)parameters
688
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
689
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
690
+ {
691
+ NSURLRequest *request = [self requestWithMethod:@"PUT" path:path parameters:parameters];
692
+ AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
693
+ [self enqueueHTTPRequestOperation:operation];
694
+ }
695
+
696
+ - (void)deletePath:(NSString *)path
697
+ parameters:(NSDictionary *)parameters
698
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
699
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
700
+ {
701
+ NSURLRequest *request = [self requestWithMethod:@"DELETE" path:path parameters:parameters];
702
+ AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
703
+ [self enqueueHTTPRequestOperation:operation];
704
+ }
705
+
706
+ - (void)patchPath:(NSString *)path
707
+ parameters:(NSDictionary *)parameters
708
+ success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
709
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
710
+ {
711
+ NSURLRequest *request = [self requestWithMethod:@"PATCH" path:path parameters:parameters];
712
+ AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
713
+ [self enqueueHTTPRequestOperation:operation];
714
+ }
715
+
716
+ #pragma mark - NSCoding
717
+
718
+ - (id)initWithCoder:(NSCoder *)aDecoder {
719
+ NSURL *baseURL = [aDecoder decodeObjectForKey:@"baseURL"];
720
+
721
+ self = [self initWithBaseURL:baseURL];
722
+ if (!self) {
723
+ return nil;
724
+ }
725
+
726
+ self.stringEncoding = [aDecoder decodeIntegerForKey:@"stringEncoding"];
727
+ self.parameterEncoding = (AFHTTPClientParameterEncoding) [aDecoder decodeIntegerForKey:@"parameterEncoding"];
728
+ self.registeredHTTPOperationClassNames = [aDecoder decodeObjectForKey:@"registeredHTTPOperationClassNames"];
729
+ self.defaultHeaders = [aDecoder decodeObjectForKey:@"defaultHeaders"];
730
+
731
+ return self;
732
+ }
733
+
734
+ - (void)encodeWithCoder:(NSCoder *)aCoder {
735
+ [aCoder encodeObject:self.baseURL forKey:@"baseURL"];
736
+ [aCoder encodeInteger:(NSInteger)self.stringEncoding forKey:@"stringEncoding"];
737
+ [aCoder encodeInteger:self.parameterEncoding forKey:@"parameterEncoding"];
738
+ [aCoder encodeObject:self.registeredHTTPOperationClassNames forKey:@"registeredHTTPOperationClassNames"];
739
+ [aCoder encodeObject:self.defaultHeaders forKey:@"defaultHeaders"];
740
+ }
741
+
742
+ #pragma mark - NSCopying
743
+
744
+ - (id)copyWithZone:(NSZone *)zone {
745
+ AFHTTPClient *HTTPClient = [[[self class] allocWithZone:zone] initWithBaseURL:self.baseURL];
746
+
747
+ HTTPClient.stringEncoding = self.stringEncoding;
748
+ HTTPClient.parameterEncoding = self.parameterEncoding;
749
+ HTTPClient.registeredHTTPOperationClassNames = [self.registeredHTTPOperationClassNames mutableCopyWithZone:zone];
750
+ HTTPClient.defaultHeaders = [self.defaultHeaders mutableCopyWithZone:zone];
751
+ #ifdef _SYSTEMCONFIGURATION_H
752
+ HTTPClient.networkReachabilityStatusBlock = self.networkReachabilityStatusBlock;
753
+ #endif
754
+ return HTTPClient;
755
+ }
756
+
757
+ @end
758
+
759
+ #pragma mark -
760
+
761
+ static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
762
+
763
+ static NSString * const kAFMultipartFormCRLF = @"\r\n";
764
+
765
+ static NSInteger const kAFStreamToStreamBufferSize = 1024 * 1024; //1 meg default
766
+
767
+ static inline NSString * AFMultipartFormInitialBoundary() {
768
+ return [NSString stringWithFormat:@"--%@%@", kAFMultipartFormBoundary, kAFMultipartFormCRLF];
769
+ }
770
+
771
+ static inline NSString * AFMultipartFormEncapsulationBoundary() {
772
+ return [NSString stringWithFormat:@"%@--%@%@", kAFMultipartFormCRLF, kAFMultipartFormBoundary, kAFMultipartFormCRLF];
773
+ }
774
+
775
+ static inline NSString * AFMultipartFormFinalBoundary() {
776
+ return [NSString stringWithFormat:@"%@--%@--%@", kAFMultipartFormCRLF, kAFMultipartFormBoundary, kAFMultipartFormCRLF];
777
+ }
778
+
779
+ static inline NSString * AFContentTypeForPathExtension(NSString *extension) {
780
+ #ifdef __UTTYPE__
781
+ NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
782
+ NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType);
783
+ if (!contentType) {
784
+ return @"application/octet-stream";
785
+ } else {
786
+ return contentType;
787
+ }
788
+ #else
789
+ return @"application/octet-stream";
790
+ #endif
791
+ }
792
+
793
+ NSUInteger const kAFUploadStream3GSuggestedPacketSize = 1024 * 16;
794
+ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
795
+
796
+ @interface AFHTTPBodyPart : NSObject
797
+ @property (nonatomic, assign) NSStringEncoding stringEncoding;
798
+ @property (nonatomic, strong) NSDictionary *headers;
799
+ @property (nonatomic, strong) id body;
800
+ @property (nonatomic, assign) unsigned long long bodyContentLength;
801
+ @property (nonatomic, strong) NSInputStream *inputStream;
802
+
803
+ @property (nonatomic, assign) BOOL hasInitialBoundary;
804
+ @property (nonatomic, assign) BOOL hasFinalBoundary;
805
+
806
+ @property (nonatomic, readonly, getter = hasBytesAvailable) BOOL bytesAvailable;
807
+ @property (nonatomic, readonly) unsigned long long contentLength;
808
+
809
+ - (NSInteger)read:(uint8_t *)buffer
810
+ maxLength:(NSUInteger)length;
811
+ @end
812
+
813
+ @interface AFMultipartBodyStream : NSInputStream <NSStreamDelegate>
814
+ @property (nonatomic, assign) NSUInteger numberOfBytesInPacket;
815
+ @property (nonatomic, assign) NSTimeInterval delay;
816
+ @property (nonatomic, strong) NSInputStream *inputStream;
817
+ @property (nonatomic, readonly) unsigned long long contentLength;
818
+ @property (nonatomic, readonly, getter = isEmpty) BOOL empty;
819
+
820
+ - (id)initWithStringEncoding:(NSStringEncoding)encoding;
821
+ - (void)setInitialAndFinalBoundaries;
822
+ - (void)appendHTTPBodyPart:(AFHTTPBodyPart *)bodyPart;
823
+ @end
824
+
825
+ #pragma mark -
826
+
827
+ @interface AFStreamingMultipartFormData ()
828
+ @property (readwrite, nonatomic, copy) NSMutableURLRequest *request;
829
+ @property (readwrite, nonatomic, strong) AFMultipartBodyStream *bodyStream;
830
+ @property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding;
831
+ @end
832
+
833
+ @implementation AFStreamingMultipartFormData
834
+ @synthesize request = _request;
835
+ @synthesize bodyStream = _bodyStream;
836
+ @synthesize stringEncoding = _stringEncoding;
837
+
838
+ - (id)initWithURLRequest:(NSMutableURLRequest *)urlRequest
839
+ stringEncoding:(NSStringEncoding)encoding
840
+ {
841
+ self = [super init];
842
+ if (!self) {
843
+ return nil;
844
+ }
845
+
846
+ self.request = urlRequest;
847
+ self.stringEncoding = encoding;
848
+ self.bodyStream = [[AFMultipartBodyStream alloc] initWithStringEncoding:encoding];
849
+
850
+ return self;
851
+ }
852
+
853
+ - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
854
+ name:(NSString *)name
855
+ error:(NSError * __autoreleasing *)error
856
+ {
857
+ NSParameterAssert(fileURL);
858
+ NSParameterAssert(name);
859
+
860
+ NSString *fileName = [fileURL lastPathComponent];
861
+ NSString *mimeType = AFContentTypeForPathExtension([fileURL pathExtension]);
862
+
863
+ return [self appendPartWithFileURL:fileURL name:name fileName:fileName mimeType:mimeType error:error];
864
+ }
865
+
866
+ - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
867
+ name:(NSString *)name
868
+ fileName:(NSString *)fileName
869
+ mimeType:(NSString *)mimeType
870
+ error:(NSError * __autoreleasing *)error
871
+ {
872
+ NSParameterAssert(fileURL);
873
+ NSParameterAssert(name);
874
+ NSParameterAssert(fileName);
875
+ NSParameterAssert(mimeType);
876
+
877
+ if (![fileURL isFileURL]) {
878
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedStringFromTable(@"Expected URL to be a file URL", @"AFNetworking", nil) forKey:NSLocalizedFailureReasonErrorKey];
879
+ if (error != NULL) {
880
+ *error = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
881
+ }
882
+
883
+ return NO;
884
+ } else if ([fileURL checkResourceIsReachableAndReturnError:error] == NO) {
885
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedStringFromTable(@"File URL not reachable.", @"AFNetworking", nil) forKey:NSLocalizedFailureReasonErrorKey];
886
+ if (error != NULL) {
887
+ *error = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
888
+ }
889
+
890
+ return NO;
891
+ }
892
+
893
+ NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
894
+ [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
895
+ [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
896
+
897
+ AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
898
+ bodyPart.stringEncoding = self.stringEncoding;
899
+ bodyPart.headers = mutableHeaders;
900
+ bodyPart.body = fileURL;
901
+
902
+ NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:nil];
903
+ bodyPart.bodyContentLength = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];
904
+
905
+ [self.bodyStream appendHTTPBodyPart:bodyPart];
906
+
907
+ return YES;
908
+ }
909
+
910
+
911
+ - (void)appendPartWithInputStream:(NSInputStream *)inputStream
912
+ name:(NSString *)name
913
+ fileName:(NSString *)fileName
914
+ length:(unsigned long long)length
915
+ mimeType:(NSString *)mimeType
916
+ {
917
+ NSParameterAssert(name);
918
+ NSParameterAssert(fileName);
919
+ NSParameterAssert(mimeType);
920
+
921
+ NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
922
+ [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
923
+ [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
924
+
925
+
926
+ AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
927
+ bodyPart.stringEncoding = self.stringEncoding;
928
+ bodyPart.headers = mutableHeaders;
929
+ bodyPart.body = inputStream;
930
+
931
+ bodyPart.bodyContentLength = length;
932
+
933
+ [self.bodyStream appendHTTPBodyPart:bodyPart];
934
+ }
935
+
936
+ - (void)appendPartWithFileData:(NSData *)data
937
+ name:(NSString *)name
938
+ fileName:(NSString *)fileName
939
+ mimeType:(NSString *)mimeType
940
+ {
941
+ NSParameterAssert(name);
942
+ NSParameterAssert(fileName);
943
+ NSParameterAssert(mimeType);
944
+
945
+ NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
946
+ [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
947
+ [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
948
+
949
+ [self appendPartWithHeaders:mutableHeaders body:data];
950
+ }
951
+
952
+ - (void)appendPartWithFormData:(NSData *)data
953
+ name:(NSString *)name
954
+ {
955
+ NSParameterAssert(name);
956
+
957
+ NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
958
+ [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
959
+
960
+ [self appendPartWithHeaders:mutableHeaders body:data];
961
+ }
962
+
963
+ - (void)appendPartWithHeaders:(NSDictionary *)headers
964
+ body:(NSData *)body
965
+ {
966
+ NSParameterAssert(body);
967
+
968
+ AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
969
+ bodyPart.stringEncoding = self.stringEncoding;
970
+ bodyPart.headers = headers;
971
+ bodyPart.bodyContentLength = [body length];
972
+ bodyPart.body = body;
973
+
974
+ [self.bodyStream appendHTTPBodyPart:bodyPart];
975
+ }
976
+
977
+ - (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes
978
+ delay:(NSTimeInterval)delay
979
+ {
980
+ self.bodyStream.numberOfBytesInPacket = numberOfBytes;
981
+ self.bodyStream.delay = delay;
982
+ }
983
+
984
+ - (NSMutableURLRequest *)requestByFinalizingMultipartFormData {
985
+ if ([self.bodyStream isEmpty]) {
986
+ return self.request;
987
+ }
988
+
989
+ // Reset the initial and final boundaries to ensure correct Content-Length
990
+ [self.bodyStream setInitialAndFinalBoundaries];
991
+
992
+ [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", kAFMultipartFormBoundary] forHTTPHeaderField:@"Content-Type"];
993
+ [self.request setValue:[NSString stringWithFormat:@"%llu", [self.bodyStream contentLength]] forHTTPHeaderField:@"Content-Length"];
994
+ [self.request setHTTPBodyStream:self.bodyStream];
995
+
996
+ return self.request;
997
+ }
998
+
999
+ @end
1000
+
1001
+ #pragma mark -
1002
+
1003
+ @interface AFMultipartBodyStream () <NSCopying>
1004
+ @property (nonatomic, assign) NSStreamStatus streamStatus;
1005
+ @property (nonatomic, strong) NSError *streamError;
1006
+ @property (nonatomic, assign) NSStringEncoding stringEncoding;
1007
+ @property (nonatomic, strong) NSMutableArray *HTTPBodyParts;
1008
+ @property (nonatomic, strong) NSEnumerator *HTTPBodyPartEnumerator;
1009
+ @property (nonatomic, strong) AFHTTPBodyPart *currentHTTPBodyPart;
1010
+ @property (nonatomic, strong) NSOutputStream *outputStream;
1011
+ @property (nonatomic, strong) NSMutableData *buffer;
1012
+ @end
1013
+
1014
+ @implementation AFMultipartBodyStream
1015
+ @synthesize streamStatus = _streamStatus;
1016
+ @synthesize streamError = _streamError;
1017
+ @synthesize stringEncoding = _stringEncoding;
1018
+ @synthesize HTTPBodyParts = _HTTPBodyParts;
1019
+ @synthesize HTTPBodyPartEnumerator = _HTTPBodyPartEnumerator;
1020
+ @synthesize currentHTTPBodyPart = _currentHTTPBodyPart;
1021
+ @synthesize inputStream = _inputStream;
1022
+ @synthesize outputStream = _outputStream;
1023
+ @synthesize buffer = _buffer;
1024
+ @synthesize numberOfBytesInPacket = _numberOfBytesInPacket;
1025
+ @synthesize delay = _delay;
1026
+
1027
+ - (id)initWithStringEncoding:(NSStringEncoding)encoding {
1028
+ self = [super init];
1029
+ if (!self) {
1030
+ return nil;
1031
+ }
1032
+
1033
+ self.stringEncoding = encoding;
1034
+ self.HTTPBodyParts = [NSMutableArray array];
1035
+ self.numberOfBytesInPacket = NSIntegerMax;
1036
+
1037
+ return self;
1038
+ }
1039
+
1040
+ - (void)setInitialAndFinalBoundaries {
1041
+ if ([self.HTTPBodyParts count] > 0) {
1042
+ for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
1043
+ bodyPart.hasInitialBoundary = NO;
1044
+ bodyPart.hasFinalBoundary = NO;
1045
+ }
1046
+
1047
+ [[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
1048
+ [[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
1049
+ }
1050
+ }
1051
+
1052
+ - (void)appendHTTPBodyPart:(AFHTTPBodyPart *)bodyPart {
1053
+ [self.HTTPBodyParts addObject:bodyPart];
1054
+ }
1055
+
1056
+ - (BOOL)isEmpty {
1057
+ return [self.HTTPBodyParts count] == 0;
1058
+ }
1059
+
1060
+ #pragma mark - NSInputStream
1061
+
1062
+ - (NSInteger)read:(uint8_t *)buffer
1063
+ maxLength:(NSUInteger)length
1064
+ {
1065
+ if ([self streamStatus] == NSStreamStatusClosed) {
1066
+ return 0;
1067
+ }
1068
+
1069
+ NSInteger totalNumberOfBytesRead = 0;
1070
+
1071
+ while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) {
1072
+ if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) {
1073
+ if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) {
1074
+ break;
1075
+ }
1076
+ } else {
1077
+ NSUInteger maxLength = length - (NSUInteger)totalNumberOfBytesRead;
1078
+ NSInteger numberOfBytesRead = [self.currentHTTPBodyPart read:&buffer[totalNumberOfBytesRead] maxLength:maxLength];
1079
+ if (numberOfBytesRead == -1) {
1080
+ self.streamError = self.currentHTTPBodyPart.inputStream.streamError;
1081
+ break;
1082
+ } else {
1083
+ totalNumberOfBytesRead += numberOfBytesRead;
1084
+
1085
+ if (self.delay > 0.0f) {
1086
+ [NSThread sleepForTimeInterval:self.delay];
1087
+ }
1088
+ }
1089
+ }
1090
+ }
1091
+
1092
+ return totalNumberOfBytesRead;
1093
+ }
1094
+
1095
+ - (BOOL)getBuffer:(__unused uint8_t **)buffer
1096
+ length:(__unused NSUInteger *)len
1097
+ {
1098
+ return NO;
1099
+ }
1100
+
1101
+ - (BOOL)hasBytesAvailable {
1102
+ return [self streamStatus] == NSStreamStatusOpen;
1103
+ }
1104
+
1105
+ #pragma mark - NSStream
1106
+
1107
+ - (void)open {
1108
+ if (self.streamStatus == NSStreamStatusOpen) {
1109
+ return;
1110
+ }
1111
+
1112
+ self.streamStatus = NSStreamStatusOpen;
1113
+
1114
+ [self setInitialAndFinalBoundaries];
1115
+ self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
1116
+ }
1117
+
1118
+ - (void)close {
1119
+ self.streamStatus = NSStreamStatusClosed;
1120
+ }
1121
+
1122
+ - (id)propertyForKey:(__unused NSString *)key {
1123
+ return nil;
1124
+ }
1125
+
1126
+ - (BOOL)setProperty:(__unused id)property
1127
+ forKey:(__unused NSString *)key
1128
+ {
1129
+ return NO;
1130
+ }
1131
+
1132
+ - (void)scheduleInRunLoop:(__unused NSRunLoop *)aRunLoop
1133
+ forMode:(__unused NSString *)mode
1134
+ {}
1135
+
1136
+ - (void)removeFromRunLoop:(__unused NSRunLoop *)aRunLoop
1137
+ forMode:(__unused NSString *)mode
1138
+ {}
1139
+
1140
+ - (unsigned long long)contentLength {
1141
+ unsigned long long length = 0;
1142
+ for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
1143
+ length += [bodyPart contentLength];
1144
+ }
1145
+
1146
+ return length;
1147
+ }
1148
+
1149
+ #pragma mark - Undocumented CFReadStream Bridged Methods
1150
+
1151
+ - (void)_scheduleInCFRunLoop:(__unused CFRunLoopRef)aRunLoop
1152
+ forMode:(__unused CFStringRef)aMode
1153
+ {}
1154
+
1155
+ - (void)_unscheduleFromCFRunLoop:(__unused CFRunLoopRef)aRunLoop
1156
+ forMode:(__unused CFStringRef)aMode
1157
+ {}
1158
+
1159
+ - (BOOL)_setCFClientFlags:(__unused CFOptionFlags)inFlags
1160
+ callback:(__unused CFReadStreamClientCallBack)inCallback
1161
+ context:(__unused CFStreamClientContext *)inContext {
1162
+ return NO;
1163
+ }
1164
+
1165
+ #pragma mark - NSCopying
1166
+
1167
+ -(id)copyWithZone:(NSZone *)zone {
1168
+ AFMultipartBodyStream *bodyStreamCopy = [[[self class] allocWithZone:zone] initWithStringEncoding:self.stringEncoding];
1169
+
1170
+ for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
1171
+ [bodyStreamCopy appendHTTPBodyPart:[bodyPart copy]];
1172
+ }
1173
+
1174
+ [bodyStreamCopy setInitialAndFinalBoundaries];
1175
+
1176
+ return bodyStreamCopy;
1177
+ }
1178
+
1179
+ @end
1180
+
1181
+ #pragma mark -
1182
+
1183
+ typedef enum {
1184
+ AFEncapsulationBoundaryPhase = 1,
1185
+ AFHeaderPhase = 2,
1186
+ AFBodyPhase = 3,
1187
+ AFFinalBoundaryPhase = 4,
1188
+ } AFHTTPBodyPartReadPhase;
1189
+
1190
+ @interface AFHTTPBodyPart () <NSCopying> {
1191
+ AFHTTPBodyPartReadPhase _phase;
1192
+ NSInputStream *_inputStream;
1193
+ unsigned long long _phaseReadOffset;
1194
+ }
1195
+
1196
+ - (BOOL)transitionToNextPhase;
1197
+ - (NSInteger)readData:(NSData *)data
1198
+ intoBuffer:(uint8_t *)buffer
1199
+ maxLength:(NSUInteger)length;
1200
+ @end
1201
+
1202
+ @implementation AFHTTPBodyPart
1203
+ @synthesize stringEncoding = _stringEncoding;
1204
+ @synthesize headers = _headers;
1205
+ @synthesize body = _body;
1206
+ @synthesize bodyContentLength = _bodyContentLength;
1207
+ @synthesize inputStream = _inputStream;
1208
+ @synthesize hasInitialBoundary = _hasInitialBoundary;
1209
+ @synthesize hasFinalBoundary = _hasFinalBoundary;
1210
+
1211
+ - (id)init {
1212
+ self = [super init];
1213
+ if (!self) {
1214
+ return nil;
1215
+ }
1216
+
1217
+ [self transitionToNextPhase];
1218
+
1219
+ return self;
1220
+ }
1221
+
1222
+ - (void)dealloc {
1223
+ if (_inputStream) {
1224
+ [_inputStream close];
1225
+ _inputStream = nil;
1226
+ }
1227
+ }
1228
+
1229
+ - (NSInputStream *)inputStream {
1230
+ if (!_inputStream) {
1231
+ if ([self.body isKindOfClass:[NSData class]]) {
1232
+ _inputStream = [NSInputStream inputStreamWithData:self.body];
1233
+ } else if ([self.body isKindOfClass:[NSURL class]]) {
1234
+ _inputStream = [NSInputStream inputStreamWithURL:self.body];
1235
+ } else if ([self.body isKindOfClass:[NSInputStream class]]) {
1236
+ _inputStream = self.body;
1237
+ }
1238
+ }
1239
+
1240
+ return _inputStream;
1241
+ }
1242
+
1243
+ - (NSString *)stringForHeaders {
1244
+ NSMutableString *headerString = [NSMutableString string];
1245
+ for (NSString *field in [self.headers allKeys]) {
1246
+ [headerString appendString:[NSString stringWithFormat:@"%@: %@%@", field, [self.headers valueForKey:field], kAFMultipartFormCRLF]];
1247
+ }
1248
+ [headerString appendString:kAFMultipartFormCRLF];
1249
+
1250
+ return [NSString stringWithString:headerString];
1251
+ }
1252
+
1253
+ - (unsigned long long)contentLength {
1254
+ unsigned long long length = 0;
1255
+
1256
+ NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary() : AFMultipartFormEncapsulationBoundary()) dataUsingEncoding:self.stringEncoding];
1257
+ length += [encapsulationBoundaryData length];
1258
+
1259
+ NSData *headersData = [[self stringForHeaders] dataUsingEncoding:self.stringEncoding];
1260
+ length += [headersData length];
1261
+
1262
+ length += _bodyContentLength;
1263
+
1264
+ NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
1265
+ length += [closingBoundaryData length];
1266
+
1267
+ return length;
1268
+ }
1269
+
1270
+ - (BOOL)hasBytesAvailable {
1271
+ // Allows `read:maxLength:` to be called again if `AFMultipartFormFinalBoundary` doesn't fit into the available buffer
1272
+ if (_phase == AFFinalBoundaryPhase) {
1273
+ return YES;
1274
+ }
1275
+
1276
+ #pragma clang diagnostic push
1277
+ #pragma clang diagnostic ignored "-Wcovered-switch-default"
1278
+ switch (self.inputStream.streamStatus) {
1279
+ case NSStreamStatusNotOpen:
1280
+ case NSStreamStatusOpening:
1281
+ case NSStreamStatusOpen:
1282
+ case NSStreamStatusReading:
1283
+ case NSStreamStatusWriting:
1284
+ return YES;
1285
+ case NSStreamStatusAtEnd:
1286
+ case NSStreamStatusClosed:
1287
+ case NSStreamStatusError:
1288
+ default:
1289
+ return NO;
1290
+ }
1291
+ #pragma clang diagnostic pop
1292
+ }
1293
+
1294
+ - (NSInteger)read:(uint8_t *)buffer
1295
+ maxLength:(NSUInteger)length
1296
+ {
1297
+ NSUInteger totalNumberOfBytesRead = 0;
1298
+
1299
+ if (_phase == AFEncapsulationBoundaryPhase) {
1300
+ NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary() : AFMultipartFormEncapsulationBoundary()) dataUsingEncoding:self.stringEncoding];
1301
+ totalNumberOfBytesRead += [self readData:encapsulationBoundaryData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1302
+ }
1303
+
1304
+ if (_phase == AFHeaderPhase) {
1305
+ NSData *headersData = [[self stringForHeaders] dataUsingEncoding:self.stringEncoding];
1306
+ totalNumberOfBytesRead += [self readData:headersData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1307
+ }
1308
+
1309
+ if (_phase == AFBodyPhase) {
1310
+ NSInteger numberOfBytesRead = 0;
1311
+
1312
+ numberOfBytesRead = [self.inputStream read:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1313
+ if (numberOfBytesRead == -1) {
1314
+ return -1;
1315
+ } else {
1316
+ totalNumberOfBytesRead += numberOfBytesRead;
1317
+
1318
+ if ([self.inputStream streamStatus] >= NSStreamStatusAtEnd) {
1319
+ [self transitionToNextPhase];
1320
+ }
1321
+ }
1322
+ }
1323
+
1324
+ if (_phase == AFFinalBoundaryPhase) {
1325
+ NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
1326
+ totalNumberOfBytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1327
+ }
1328
+
1329
+ return totalNumberOfBytesRead;
1330
+ }
1331
+
1332
+ - (NSInteger)readData:(NSData *)data
1333
+ intoBuffer:(uint8_t *)buffer
1334
+ maxLength:(NSUInteger)length
1335
+ {
1336
+ #pragma clang diagnostic push
1337
+ #pragma clang diagnostic ignored "-Wgnu"
1338
+ NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length));
1339
+ [data getBytes:buffer range:range];
1340
+ #pragma clang diagnostic pop
1341
+
1342
+ _phaseReadOffset += range.length;
1343
+
1344
+ if (((NSUInteger)_phaseReadOffset) >= [data length]) {
1345
+ [self transitionToNextPhase];
1346
+ }
1347
+
1348
+ return (NSInteger)range.length;
1349
+ }
1350
+
1351
+ - (BOOL)transitionToNextPhase {
1352
+ if (![[NSThread currentThread] isMainThread]) {
1353
+ [self performSelectorOnMainThread:@selector(transitionToNextPhase) withObject:nil waitUntilDone:YES];
1354
+ return YES;
1355
+ }
1356
+
1357
+ #pragma clang diagnostic push
1358
+ #pragma clang diagnostic ignored "-Wcovered-switch-default"
1359
+ switch (_phase) {
1360
+ case AFEncapsulationBoundaryPhase:
1361
+ _phase = AFHeaderPhase;
1362
+ break;
1363
+ case AFHeaderPhase:
1364
+ [self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
1365
+ [self.inputStream open];
1366
+ _phase = AFBodyPhase;
1367
+ break;
1368
+ case AFBodyPhase:
1369
+ [self.inputStream close];
1370
+ _phase = AFFinalBoundaryPhase;
1371
+ break;
1372
+ case AFFinalBoundaryPhase:
1373
+ default:
1374
+ _phase = AFEncapsulationBoundaryPhase;
1375
+ break;
1376
+ }
1377
+ _phaseReadOffset = 0;
1378
+ #pragma clang diagnostic pop
1379
+
1380
+ return YES;
1381
+ }
1382
+
1383
+ #pragma mark - NSCopying
1384
+
1385
+ - (id)copyWithZone:(NSZone *)zone {
1386
+ AFHTTPBodyPart *bodyPart = [[[self class] allocWithZone:zone] init];
1387
+
1388
+ bodyPart.stringEncoding = self.stringEncoding;
1389
+ bodyPart.headers = self.headers;
1390
+ bodyPart.bodyContentLength = self.bodyContentLength;
1391
+ bodyPart.body = self.body;
1392
+
1393
+ return bodyPart;
1394
+ }
1395
+
1396
+ @end