Cocoapods. Network layer. Fetching repos.
This commit is contained in:
parent
e348ad1eb1
commit
3dafdbc09c
143 changed files with 12470 additions and 47 deletions
|
@ -12,7 +12,7 @@
|
|||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="70" id="KGk-i7-Jjw" customClass="RepoCell" customModule="Repo_browser" customModuleProvider="target">
|
||||
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="70" id="KGk-i7-Jjw" customClass="RepoCell" customModule="repo_browser" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="70"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
|
||||
|
@ -37,8 +37,8 @@
|
|||
<constraints>
|
||||
<constraint firstAttribute="height" constant="37" id="Uc6-wd-Nrg"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" weight="light" pointSize="15"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="15"/>
|
||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Ico" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ly3-fA-QfR">
|
||||
|
@ -59,9 +59,9 @@
|
|||
<constraint firstAttribute="trailing" secondItem="ly3-fA-QfR" secondAttribute="trailing" constant="8" id="B0N-aW-w9S"/>
|
||||
<constraint firstItem="mh9-2s-zEa" firstAttribute="leading" secondItem="WX8-nW-2o2" secondAttribute="leading" id="LX0-SQ-HAa"/>
|
||||
<constraint firstItem="ly3-fA-QfR" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="aAd-Au-MFh"/>
|
||||
<constraint firstItem="WX8-nW-2o2" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="4" id="gM7-ky-GhI"/>
|
||||
<constraint firstAttribute="bottom" secondItem="ly3-fA-QfR" secondAttribute="bottom" constant="8" id="imh-MH-B7N"/>
|
||||
<constraint firstItem="ly3-fA-QfR" firstAttribute="leading" secondItem="mh9-2s-zEa" secondAttribute="trailing" constant="8" id="qPj-9W-xT6"/>
|
||||
<constraint firstItem="WX8-nW-2o2" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="-51" id="s56-f9-Tvk"/>
|
||||
<constraint firstItem="WX8-nW-2o2" firstAttribute="leading" secondItem="cQ8-2c-3gy" secondAttribute="trailing" constant="8" symbolic="YES" id="uH7-F4-5V8"/>
|
||||
<constraint firstItem="cQ8-2c-3gy" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="uzC-xx-wG1"/>
|
||||
<constraint firstItem="mh9-2s-zEa" firstAttribute="bottom" secondItem="cQ8-2c-3gy" secondAttribute="bottom" id="vC3-do-ri7"/>
|
||||
|
@ -78,4 +78,3 @@
|
|||
</tableViewCell>
|
||||
</objects>
|
||||
</document>
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import GithubAPI
|
||||
|
||||
protocol RBRNetworkControllerDelegate: class {
|
||||
func messageServerDown()
|
||||
|
@ -33,28 +34,15 @@ class RBRNetworkController: NSObject {
|
|||
|
||||
// MARKL - Network calls
|
||||
|
||||
func getRepos(owner: String, completion: @escaping (_ data: Data?, _ HTTPStatusCode: Int, _ error: NSError?) -> Void) {
|
||||
let urlString: String = api + owner
|
||||
let targetURL = URL(string: urlString)
|
||||
var request = URLRequest(url: targetURL!)
|
||||
request.addValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept")
|
||||
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
|
||||
func getRepos(owner: String, completion: @escaping (_ data: [RepositoryResponse]) -> Void) {
|
||||
let authentication = AccessTokenAuthentication(access_token: token)
|
||||
|
||||
request.httpMethod = "GET"
|
||||
request.timeoutInterval = timeOut
|
||||
let session = URLSession.shared
|
||||
|
||||
session.dataTask(with: request) {
|
||||
data, response, err in DispatchQueue.main.async(execute: {
|
||||
() -> Void in
|
||||
if (response as? HTTPURLResponse) != nil {
|
||||
completion(data, (response as! HTTPURLResponse).statusCode, err as NSError?)
|
||||
}
|
||||
else {
|
||||
print("No response: \(String(describing: err))")
|
||||
self.delegate?.messageServerDown()
|
||||
}
|
||||
})
|
||||
}.resume()
|
||||
RepositoriesAPI(authentication: authentication).repositories(user: owner) { (response, error) in
|
||||
if let response = response {
|
||||
completion (response)
|
||||
} else {
|
||||
print(error ?? "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import GithubAPI
|
||||
import FontAwesome_swift
|
||||
|
||||
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, RBRNetworkControllerDelegate {
|
||||
|
||||
|
@ -14,7 +16,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
@IBOutlet var tblRepoTable: UITableView!
|
||||
|
||||
let cellIdentifier = "RepoCell"
|
||||
var dataSource: Array<Dictionary<String, String>> = []
|
||||
var dataSource: [RepositoryResponse] = [RepositoryResponse]()
|
||||
var selectedIndex: Int!
|
||||
let netController = RBRNetworkController()
|
||||
|
||||
|
@ -49,9 +51,11 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell: RepoCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! RepoCell
|
||||
|
||||
// cell.imgThumbnail.image = dataSource[indexPath.row][]
|
||||
// cell.lblTitle.text = dataSource[indexPath.row][]
|
||||
cell.lblDescription.text = dataSource[indexPath.row]["Description_RPA"]
|
||||
cell.imgThumbnail.image = UIImage(named: "Octocat")
|
||||
cell.lblTitle.text = dataSource[indexPath.row].name
|
||||
cell.lblDescription.text = dataSource[indexPath.row].descriptionField
|
||||
cell.lblRepoType.font = UIFont.fontAwesome(ofSize: 12, style: .solid)
|
||||
cell.lblRepoType.text = String.fontAwesomeIcon(name: .codeBranch)
|
||||
// cell.lblRepoType.text = dataSource[indexPath.row][]
|
||||
|
||||
return cell
|
||||
|
@ -69,26 +73,16 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
// MARK: - Network calls
|
||||
|
||||
/**
|
||||
Get all repositories of a user
|
||||
*/
|
||||
Get all repositories of a user
|
||||
*/
|
||||
func getRepos() {
|
||||
if let owner = txfRepoOwner.text {
|
||||
weak var weakSelf = self
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
weakSelf?.netController.getRepos(owner: owner, completion: { (data, HTTPStatusCode, error) in
|
||||
if HTTPStatusCode == 200 && error == nil {
|
||||
do {
|
||||
let result = try JSONSerialization.jsonObject(with: data!, options: []) as! Array<Dictionary<String, AnyObject>>
|
||||
print(result)
|
||||
// weakSelf?.btnConfigUsers.isHidden = self.appChildren.count > 0 ? false : true
|
||||
// weakSelf?.cltChildrenCollection.reloadData()
|
||||
}
|
||||
catch {
|
||||
print("Post request try/catch error: \(error)")
|
||||
}
|
||||
}
|
||||
else {
|
||||
print("Error retrieving repo")
|
||||
weakSelf?.netController.getRepos(owner: owner, completion: { (data) in
|
||||
weakSelf?.dataSource = data
|
||||
DispatchQueue.main.async {
|
||||
weakSelf?.tblRepoTable.reloadData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -98,6 +92,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Action
|
||||
|
||||
@IBAction func loadRepo(_ sender: UIButton) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue