Skip to content

Commit

Permalink
Merge pull request #3 from Oni-zerone/feature/beer-parsing
Browse files Browse the repository at this point in the history
Feature/beer parsing
  • Loading branch information
Oni-zerone committed Feb 24, 2019
2 parents e6aedfe + df27f71 commit 53f0128
Show file tree
Hide file tree
Showing 19 changed files with 433 additions and 250 deletions.
13 changes: 7 additions & 6 deletions Example/Pods/Local Podspecs/PunkAPI.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

281 changes: 144 additions & 137 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

22 changes: 17 additions & 5 deletions Example/PunkAPI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
9767CBF7221993F900E684C4 /* BeerParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9767CBF6221993F800E684C4 /* BeerParsingTests.swift */; };
9767CBFA2219958F00E684C4 /* BeerStubs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9767CBF82219958800E684C4 /* BeerStubs.swift */; };
EBB1B4D6901624C6A90359CA /* Pods_PunkAPI_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46341D8F014E1940E53D4F02 /* Pods_PunkAPI_Tests.framework */; };
/* End PBXBuildFile section */

Expand All @@ -29,7 +30,7 @@

/* Begin PBXFileReference section */
00C6BA9ADC6CC9CF141BE6E8 /* Pods_PunkAPI_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PunkAPI_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0CA29904BB7426E73CC31E50 /* PunkAPI.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = PunkAPI.podspec; path = ../PunkAPI.podspec; sourceTree = "<group>"; };
0CA29904BB7426E73CC31E50 /* PunkAPI.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = PunkAPI.podspec; path = ../PunkAPI.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
19516DEBCED4A6F0ADCEC345 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
46341D8F014E1940E53D4F02 /* Pods_PunkAPI_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PunkAPI_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD01AFB9204008FA782 /* PunkAPI_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PunkAPI_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -41,8 +42,9 @@
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
607FACE51AFB9204008FA782 /* PunkAPI_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PunkAPI_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
613B14F018C28CF1557EC3D5 /* Pods-PunkAPI_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PunkAPI_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PunkAPI_Tests/Pods-PunkAPI_Tests.debug.xcconfig"; sourceTree = "<group>"; };
9767CBF6221993F800E684C4 /* BeerParsingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeerParsingTests.swift; sourceTree = "<group>"; };
9767CBF82219958800E684C4 /* BeerStubs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeerStubs.swift; sourceTree = "<group>"; };
9A440A355337DF96D159D208 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
A4CA42C1E1AE14F816574722 /* Pods-PunkAPI_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PunkAPI_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PunkAPI_Example/Pods-PunkAPI_Example.debug.xcconfig"; sourceTree = "<group>"; };
E294694CD6DD5DA5A6B471F1 /* Pods-PunkAPI_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PunkAPI_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-PunkAPI_Example/Pods-PunkAPI_Example.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -124,7 +126,7 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
607FACEB1AFB9204008FA782 /* Tests.swift */,
9767CBF5221993DA00E684C4 /* BeerParsing */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
path = Tests;
Expand Down Expand Up @@ -159,6 +161,15 @@
name = Pods;
sourceTree = "<group>";
};
9767CBF5221993DA00E684C4 /* BeerParsing */ = {
isa = PBXGroup;
children = (
9767CBF6221993F800E684C4 /* BeerParsingTests.swift */,
9767CBF82219958800E684C4 /* BeerStubs.swift */,
);
name = BeerParsing;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -362,7 +373,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */,
9767CBF7221993F900E684C4 /* BeerParsingTests.swift in Sources */,
9767CBFA2219958F00E684C4 /* BeerStubs.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
31 changes: 29 additions & 2 deletions Example/PunkAPI/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -20,11 +20,38 @@
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bXF-hH-fze">
<rect key="frame" x="26" y="173.5" width="323" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wZl-Yl-g7E">
<rect key="frame" x="66" y="244" width="243" height="30"/>
<state key="normal" title="Button"/>
<connections>
<action selector="loadBeerAction:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="tT1-Ms-trY"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="wZl-Yl-g7E" firstAttribute="top" secondItem="bXF-hH-fze" secondAttribute="bottom" constant="50" id="21X-jS-OkY"/>
<constraint firstItem="wZl-Yl-g7E" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="50" id="P1g-cb-Ja9"/>
<constraint firstItem="bXF-hH-fze" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" constant="-150" id="Qba-Fg-tb6"/>
<constraint firstItem="wZl-Yl-g7E" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="cAa-3I-nKq"/>
<constraint firstAttribute="trailingMargin" secondItem="bXF-hH-fze" secondAttribute="trailing" constant="10" id="ca9-Wr-Djz"/>
<constraint firstItem="bXF-hH-fze" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="10" id="qCi-lc-gUJ"/>
</constraints>
</view>
<connections>
<outlet property="label" destination="bXF-hH-fze" id="tgr-2o-TX6"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="140" y="133.5832083958021"/>
</scene>
</scenes>
</document>
22 changes: 19 additions & 3 deletions Example/PunkAPI/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,27 @@ import PunkAPI

class ViewController: UIViewController {

@IBOutlet weak var label: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

PunkAPI().get(BeerRequest(id: 1), completion: { beers in
print(beers)
})
}


@IBAction func loadBeerAction(_ sender: Any) {

PunkAPI().get(BeerRequest(id: 6), queue: .main) { [weak self] beersResult in

guard let strongSelf = self else { return }
switch beersResult {

case .success(let beers):
strongSelf.label.text = beers.first?.name ?? "Not Found"

case .failure(let error):
strongSelf.label.text = error.localizedDescription
}
}
}
}
73 changes: 73 additions & 0 deletions Example/Tests/BeerParsingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// BeerParsingTests.swift
// PunkAPI_Tests
//
// Created by Andrea Altea on 17/02/2019.
// Copyright © 2019 CocoaPods. All rights reserved.
//

import XCTest
@testable import PunkAPI

class BeerParsingTests: XCTestCase {

var parser: JSONDecoder!

override func setUp() {

let parser = JSONDecoder()
parser.keyDecodingStrategy = .convertFromSnakeCase
self.parser = parser
}

override func tearDown() {
self.parser = nil
}

func testFirst() {
self.decodeBeers(BeerStub.first)
}

func testSecond() {
self.decodeBeers(BeerStub.second)
}

func testThird() {
self.decodeBeers(BeerStub.third)
}

func testFourth() {
self.decodeBeers(BeerStub.fourth)
}

func testFifth() {
self.decodeBeers(BeerStub.fifth)
}

func testSixth() {
self.decodeBeers(BeerStub.sixth)
}

func testMultipleFirst() {
self.decodeBeers(BeerStub.multipleFirst)
}

func testMultipleSecond() {
self.decodeBeers(BeerStub.multipleSecond)
}

@discardableResult
func decodeBeers(_ json: String) -> [Beer]? {

do {
guard let data = json.data(using: .utf8) else {
XCTFail("invalid stub")
return nil
}
return try self.parser.decode([Beer].self, from: data)
} catch let error {
XCTFail(error.localizedDescription)
return nil
}
}
}
Loading

0 comments on commit 53f0128

Please sign in to comment.