Skip to content

Commit

Permalink
Refactor and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
enciyo committed Nov 11, 2021
1 parent 8f75c13 commit 2915298
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 32 deletions.
14 changes: 8 additions & 6 deletions FlipperMockPlugin.podspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
folly_compiler_flags = '-DDEBUG=1 -DFLIPPER_OSS=1 -DFB_SONARKIT_ENABLED=1 -DFOLLY_HAVE_BACKTRACE=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_HAVE_LIBGFLAGS=0 -DFOLLY_HAVE_LIBJEMALLOC=0 -DFOLLY_HAVE_PREADV=0 -DFOLLY_HAVE_PWRITEV=0 -DFOLLY_HAVE_TFO=0 -DFOLLY_USE_SYMBOLIZER=0'
header_search_paths = "\"$(PODS_ROOT)/Flipper-Boost-iOSX\" \"$(PODS_ROOT)/Flipper-DoubleConversion\" \"$(PODS_ROOT)/libevent/include\""
Pod::Spec.new do |spec|
#Descriptions
spec.name = "FlipperNetworkMockPlugin"
spec.version = "1.0.1"
spec.name = "FlipperMockPlugin"
spec.version = "1.0.2"
spec.summary = "Flipper Mock"
spec.module_name = 'FlipperMockPlugin'
spec.homepage = "https://github.com/enciyo/"
Expand All @@ -18,11 +19,12 @@ Pod::Spec.new do |spec|
spec.source = { :git => 'file:///Users/mustafa.kilic/Desktop/flipper-mock-ios/FlipperMockPlugin', :tag => "master" }
spec.source_files = '**/*.swift'


spec.dependency 'FlipperKit/Core'
spec.static_framework = true
spec.dependency 'YogaKit'
spec.dependency 'Yoga'
spec.dependency 'Alamofire'

spec.dependency 'FlipperKit/Core'
spec.compiler_flags = folly_compiler_flags
spec.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)\"/Headers/Private/FlipperKit/**" }

end
end
8 changes: 4 additions & 4 deletions FlipperMockPlugin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
3BF660554864DC31287EA824 /* libPods-FlipperMockPlugin.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 53720408B62D428543D7168E /* libPods-FlipperMockPlugin.a */; };
BE3311F7266D1CA600992F70 /* FlipMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE3311F6266D1C8E00992F70 /* FlipMock.swift */; };
BE3311F8266D1CA600992F70 /* MockManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE3311E4266D1C8E00992F70 /* MockManagement.swift */; };
BE3311F9266D1CA600992F70 /* FlipSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE3311E3266D1C8E00992F70 /* FlipSession.swift */; };
Expand All @@ -25,6 +24,7 @@
BEEE8B342658E90800057CE4 /* MockRequestMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEEE8B332658E90800057CE4 /* MockRequestMethods.swift */; };
BEEE8B362658E94400057CE4 /* MockContentTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEEE8B352658E94400057CE4 /* MockContentTypes.swift */; };
BEEE8B482659323200057CE4 /* Exceptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEEE8B472659323200057CE4 /* Exceptions.swift */; };
CC10DCBD1FA90DDDA7473774 /* Pods_FlipperMockPlugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0CC60420BF298F79E7D2D11B /* Pods_FlipperMockPlugin.framework */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -41,7 +41,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
53720408B62D428543D7168E /* libPods-FlipperMockPlugin.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FlipperMockPlugin.a"; sourceTree = BUILT_PRODUCTS_DIR; };
0CC60420BF298F79E7D2D11B /* Pods_FlipperMockPlugin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlipperMockPlugin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9CB142F6EDE8BD549445A294 /* Pods-FlipperMockPlugin.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlipperMockPlugin.release.xcconfig"; path = "Target Support Files/Pods-FlipperMockPlugin/Pods-FlipperMockPlugin.release.xcconfig"; sourceTree = "<group>"; };
BE3311E3266D1C8E00992F70 /* FlipSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlipSession.swift; sourceTree = "<group>"; };
BE3311E4266D1C8E00992F70 /* MockManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockManagement.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -70,7 +70,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3BF660554864DC31287EA824 /* libPods-FlipperMockPlugin.a in Frameworks */,
CC10DCBD1FA90DDDA7473774 /* Pods_FlipperMockPlugin.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -80,7 +80,7 @@
8F49FBE9698AE8E1B300135C /* Frameworks */ = {
isa = PBXGroup;
children = (
53720408B62D428543D7168E /* libPods-FlipperMockPlugin.a */,
0CC60420BF298F79E7D2D11B /* Pods_FlipperMockPlugin.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down
6 changes: 3 additions & 3 deletions FlipperMockPlugin/src/FlipSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Alamofire

public class FlipSession {

public static let `default` : Session = {
public static let `default` : SessionManager = {
let configuration: URLSessionConfiguration = {
let configuration = URLSessionConfiguration.af.default
let configuration = URLSessionConfiguration.default
let safeProtocolClasses = [FlipMockUrlProtocol.self] + (configuration.protocolClasses ?? [])
configuration.protocolClasses = safeProtocolClasses
return configuration}()
return Session(configuration:configuration)}()
return SessionManager(configuration:configuration)}()

/**
# Warning: #
Expand Down
6 changes: 3 additions & 3 deletions FlipperMockPlugin/src/Mapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ internal extension Dictionary where Key == AnyHashable {
dummyJsonData: try parseMap("dummyJsonData", transform: {item -> String in item.description }),
uniqueId: try parseMap("uniqueId", transform: {item -> String in item }),
queryParams: try parseMap("queryParams", transform: {item -> String in item }),
httpCode: try parseMap("statusCode", transform: {item -> Int in item }),
httpCode: Int(try parseMap("statusCode", transform: {item -> String in item }) as String) ?? 200,
requestType: MockRequestMethods.safeValueOf(value: (try parseMap("httpMethod", transform: {item -> String in item }))),
isMockEnable: try parseMap("isMockEnable", transform: {item -> Bool in item})
)
}

func mapConfig() throws -> Config {
return Config(
isLoggable: try parseMap("isLogable", transform: {item -> Bool in item }),
isLoggable: true,
isMockEnable: try parseMap("isMockEnable", transform: {item -> Bool in item })
)
}
Expand All @@ -35,7 +35,7 @@ internal extension Dictionary where Key == AnyHashable {
throw Exceptions.SerializeException(message: "Expected \(param) nil")
}
if (obje as? T == nil) {
throw Exceptions.SerializeException(message: "\(param) expected type: '\(type(of: T.self))")
throw Exceptions.SerializeException(message: "\(param) expected type: '\(type(of: T.self)) but is '\(type(of: obje.self))")
}
return obje as! T
}
Expand Down
15 changes: 6 additions & 9 deletions FlipperMockPlugin/src/extension/FlipperConnectionExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@
import Foundation
import FlipperKit


typealias ReceiveSafe = ([AnyHashable:Any],FlipperResponder)->Void
typealias ReceiveSafe = ([AnyHashable: Any], FlipperResponder) -> Void

extension FlipperConnection {

func receiveSafe(_ method:String, _ receiveSafe:@escaping ReceiveSafe){
self.receive(method){ params, responder in
func receiveSafe(_ method: String, _ receiveSafe: @escaping ReceiveSafe) {
receive(method) { params, responder in
safeHandle {
if(params == nil){
if (params == nil) {
throw Exceptions.IllegalStateException(message: "Method: \(method) Received params nil!")
}
if(responder == nil){
if (responder == nil) {
throw Exceptions.IllegalStateException(message: "Method: \(method) Received responder nil!")
}
receiveSafe(params!,responder!)
receiveSafe(params!, responder!)
}
}
}

}


9 changes: 6 additions & 3 deletions FlipperMockPlugin/src/interceptor/FlipMockUrlProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import Alamofire


public class FlipMockUrlProtocol : URLProtocol {



private lazy var mockManagement: MockManagement = {
return MockManagement.shared
}()

private let cannedHeaders = ["Content-Type" : "application/json; charset=utf-8"]


struct MockError : Swift.Error, LocalizedError {
var errorDescription: String?
}

public override func startLoading(){
if let exist = mockManagement.findMockOrNull(request.mapMock()),
let mock = exist.mapResponseData(),
Expand All @@ -37,7 +40,7 @@ public class FlipMockUrlProtocol : URLProtocol {
let mockManagement = MockManagement.shared
let isMockEnable = mockManagement.config.isMockEnable
let exist = mockManagement.findMockOrNull(request.mapMock())
return isMockEnable && exist != nil
return isMockEnable && exist != nil && exist?.isMockEnable == true
}


Expand Down
38 changes: 34 additions & 4 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
swift_version = "4.1"
flipperkit_version = '0.88.0'
use_frameworks!


def flipper_develop_pods
pod 'FlipperKit', '~>' + '0.111.0', :modular_headers => true
# Layout and network plugins are not yet supported for swift projects
pod 'FlipperKit/FlipperKitLayoutComponentKitSupport', '~>' + '0.111.0'
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + '0.111.0'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + '0.111.0'

# If you use `use_frameworks!` in your Podfile,
# uncomment the below $static_framework array and also
# the pre_install section. This will cause Flipper and
# it's dependencies to be static and all other pods to
# be dynamic.
$static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
'CocoaLibEvent', 'OpenSSL-Universal', 'Flipper-Boost-iOSX', 'Flipper-Fmt']

pre_install do |installer|
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
installer.pod_targets.each do |pod|
if $static_framework.include?(pod.name)
def pod.build_type;
Pod::BuildType.static_library
end
end
end
end
end


target 'FlipperMockPlugin' do
platform :ios, '10.0'

pod 'Alamofire', '~> 5.1'
pod 'FlipperKit'
pod 'YogaKit'
flipper_develop_pods

end



0 comments on commit 2915298

Please sign in to comment.