Skip to content

Commit

Permalink
Merge pull request #2 from amarofashion/new-model-reviews-question
Browse files Browse the repository at this point in the history
New model reviews question
  • Loading branch information
lilianeblima authored Dec 4, 2017
2 parents 70745d2 + a68339c commit ca9e7c4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Alamofire/Alamofire" "4.5.0"
github "Alamofire/Alamofire" "4.6.0"
43 changes: 33 additions & 10 deletions yotpoKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,13 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = "Liliane Lima";
TargetAttributes = {
FB7575DE1E9D08CC00D1E844 = {
CreatedOnToolsVersion = 8.3;
DevelopmentTeam = PFQ8633X58;
LastSwiftMigration = 0830;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
FB7575E71E9D08CC00D1E844 = {
Expand All @@ -446,17 +446,20 @@
FB92FB941E9E646A00D9B127 = {
CreatedOnToolsVersion = 8.3;
DevelopmentTeam = PFQ8633X58;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
};
FB92FBA71E9E646A00D9B127 = {
CreatedOnToolsVersion = 8.3;
DevelopmentTeam = PFQ8633X58;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
TestTargetID = FB92FB941E9E646A00D9B127;
};
FB92FBB21E9E646A00D9B127 = {
CreatedOnToolsVersion = 8.3;
DevelopmentTeam = PFQ8633X58;
LastSwiftMigration = 0910;
ProvisioningStyle = Automatic;
TestTargetID = FB92FB941E9E646A00D9B127;
};
Expand Down Expand Up @@ -654,15 +657,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -709,15 +718,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -770,7 +785,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -796,7 +812,8 @@
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoKit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down Expand Up @@ -839,7 +856,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -856,7 +874,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -870,7 +889,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/yotpoUsageExample.app/yotpoUsageExample";
};
name = Debug;
Expand All @@ -885,7 +905,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/yotpoUsageExample.app/yotpoUsageExample";
};
name = Release;
Expand All @@ -899,7 +920,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = yotpoUsageExample;
};
name = Debug;
Expand All @@ -913,7 +935,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = amaro.yotpoUsageExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = yotpoUsageExample;
};
name = Release;
Expand Down
4 changes: 3 additions & 1 deletion yotpoKit.xcodeproj/xcshareddata/xcschemes/yotpoKit.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
86 changes: 29 additions & 57 deletions yotpoKit/MyQuestion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,29 @@ open class MyQuestion: RequestYotpo {
//Aliases to custom closures
public typealias CompletionWithProductQuestions = (_ code: Int, _ msg: String, _ productQuestion: ProductQuestion?) -> Void
public typealias CompletionWithQuestions = (_ code: Int, _ msg: String, _ questions: [Question]) -> Void
public typealias CompletionWithQuestionsAndExhibition = (_ code: Int, _ msg: String,
_ productQuestion: ProductQuestion, _ questionsExhibition: [QuestionExhibition]) -> Void
public typealias CompletionDefault = (_ code: Int, _ msg: String) -> Void
public typealias CompletionQuestion = (_ code: Int, _ title: String, _ msg: String) -> Void
public typealias CompleteNextPageQuestions = (_ msg: String, _ newQuestions: [Question], _ productQuestio: ProductQuestion) -> Void

open func getQuestions(productId: String, completion: @escaping CompletionWithProductQuestions) {
let endPoint = Endpoint.MyQuestion().getQuestions(productId: productId, appKey: appKey)

Alamofire.request(endPoint.URI, method: endPoint.method).responseJSON { (response) in
switch response.result {
case .success:
guard let JSON = response.result.value as? [String: AnyObject],
let code = JSON["status"]?["code"] as? Int,
let message = JSON["status"]?["message"] as? String else {
guard let JSON = response.result.value as? [String: AnyObject] else {
completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, nil)
return
}

if code == 200 {
guard let questionDict = JSON["response"] as? [String: AnyObject] else {
completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, nil)
return
}

let productQ = ProductQuestion(dic: questionDict)
completion(code, message, productQ)

} else {
completion(code, message, nil)
guard let questionDict = JSON["response"] as? [String: AnyObject] else {
completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, nil)
return
}

let productQ = ProductQuestion(dic: questionDict)
completion(0, "OK", productQ)

case .failure:
completion(GetMessage.InternetError.code, GetMessage.InternetError.msg, nil)
}
Expand All @@ -57,24 +50,19 @@ open class MyQuestion: RequestYotpo {
switch response.result {
case .success:
guard let JSON = response.result.value as? [String: AnyObject],
let code = JSON["status"]?["code"] as? Int,
let message = JSON["status"]?["message"] as? String else {
completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, [])
return
}

if code == 200 {
guard let questionDict = JSON["response"] as? [String: AnyObject] else {
completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, [])
return
}

let productQ = ProductQuestion(dic: questionDict)
completion(code, message, productQ.questions)

} else {
completion(code, message, [])

guard let questionDict = JSON["response"] as? [String: AnyObject] else {
completion(GetMessage.ParsingError.code, GetMessage.ParsingError.msg, [])
return
}

let productQ = ProductQuestion(dic: questionDict)
completion(200, message, productQ.questions)

case .failure:
completion(GetMessage.InternetError.code, GetMessage.InternetError.msg, [])
}
Expand Down Expand Up @@ -175,41 +163,25 @@ open class MyQuestion: RequestYotpo {

}
}

open func getNextQuestions(productQuestion: ProductQuestion,
oldQuestionsExhibition: [QuestionExhibition], productId: String,
completion: @escaping CompletionWithQuestionsAndExhibition) {
let myOldProductQuestion = productQuestion.questions.filter { (question) -> Bool in

open func getNextQuestion(currentQuestion: ProductQuestion, productId: String, completion: @escaping CompleteNextPageQuestions) {
let questions = currentQuestion.questions.filter { (question) -> Bool in
return question.id != 0
}
var newProductQuestion = productQuestion

if productQuestion.totalQuestions > myOldProductQuestion.count {
let currentPage = myOldProductQuestion.count/5
var questionsExhibition = [QuestionExhibition]()
getQuestionPerPage(productId: productId, page: currentPage+1, completion: { (code, msg, result) in
newProductQuestion.questions += result
var newProductQuestion = currentQuestion

if currentQuestion.totalQuestions > questions.count {
let currentPage = questions.count/5

getQuestionPerPage(productId: productId, page: currentPage+1, completion: { (_, _, newQuestions) in

for question in result {
let questExhibition = QuestionExhibition(withQuestion: question)

let isContain = oldQuestionsExhibition.contains(where: { (questionEx) -> Bool in
return questionEx.idQuestion == questExhibition.idQuestion && questionEx.idAnswer == questExhibition.idAnswer &&
questionEx.typeQuestion == questExhibition.typeQuestion
})
if !isContain {
questionsExhibition.append(questExhibition)
for answer in question.answers {
let answerExhibition = QuestionExhibition(withAnswer: answer, idQuest: question.id)
questionsExhibition.append(answerExhibition)
}
}
}
newProductQuestion.questions += newQuestions

completion(code, msg, newProductQuestion, questionsExhibition)
completion("Sucess", newQuestions, newProductQuestion)
})
} else {
completion(2, "There aren't questions to download", newProductQuestion, [])
completion("There aren't questions to download", [], currentQuestion)
}
}

Expand Down
5 changes: 3 additions & 2 deletions yotpoUsageExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import UIKit
import yotpoKit
class ViewController: UIViewController {

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
_ = APIYotpo(appK: "appKey", clientS: "clientSecret").yotpo
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
Expand Down

0 comments on commit ca9e7c4

Please sign in to comment.