Skip to content

Commit

Permalink
Feat: update FloatParameter to avoid unrecognized values
Browse files Browse the repository at this point in the history
  • Loading branch information
Oni-zerone committed Mar 2, 2019
1 parent b9b2843 commit a79841f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

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

2 changes: 1 addition & 1 deletion Example/PunkAPI/ViewController.swift
Expand Up @@ -21,7 +21,7 @@ class ViewController: UIViewController {

@IBAction func loadBeerAction(_ sender: Any) {

let request = BeersRequest(filter: [.abv(condition: .more, value: 1.2)])
let request = BeersRequest(filter: [.abv(condition: .more, value: 3)])

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

Expand Down
10 changes: 5 additions & 5 deletions PunkAPI/Classes/Request/BeersRequest.swift
Expand Up @@ -26,11 +26,11 @@ extension BeersRequest: Request {

public var parameters: [String: Any]? {

if var filter = filterParameters {
filter["page"] = page
return filter
}
return ["page": page]
guard page > 0 else { return filterParameters }

var parameters = filterParameters ?? [:]
parameters["page"] = page
return parameters
}
}

Expand Down
12 changes: 6 additions & 6 deletions PunkAPI/Classes/Request/Parameter/BeersRequestParameter.swift
Expand Up @@ -11,9 +11,9 @@ extension BeersRequest {

public enum Parameter {

case abv(condition: Condition, value: Float)
case ibu(condition: Condition, value: Float)
case ebc(condition: Condition, value: Float)
case abv(condition: Condition, value: Int)
case ibu(condition: Condition, value: Int)
case ebc(condition: Condition, value: Int)

case beerName(value: String)
case yeast(value: String)
Expand All @@ -34,11 +34,11 @@ extension BeersRequest.Parameter {
internal var parameter: RequestParameter {
switch self {
case let .abv(condition, value):
return FloatParameter(key: "abv", condition: condition, value: value)
return IntParameter(key: "abv", condition: condition, value: value)
case let .ibu(condition, value):
return FloatParameter(key: "ibu", condition: condition, value: value)
return IntParameter(key: "ibu", condition: condition, value: value)
case let .ebc(condition, value):
return FloatParameter(key: "ebc", condition: condition, value: value)
return IntParameter(key: "ebc", condition: condition, value: value)

case let .beerName(value):
return StringParameter(key: "beer_name", value: value)
Expand Down
@@ -1,24 +1,23 @@
//
// FloatParameter.swift
// IntParameter.swift
// PunkAPI
//
// Created by Andrea Altea on 02/03/2019.
//

import Foundation

struct FloatParameter: RequestParameter {
struct IntParameter: RequestParameter {

var type: String
var condition: Condition
var value: Any
init(key: String, condition: Condition, value: Float) {
init(key: String, condition: Condition, value: Int) {
self.type = key
self.condition = condition
self.value = value
}
var key: String {
return "\(type)_\(condition.dimension)"
}

}

0 comments on commit a79841f

Please sign in to comment.