Skip to content

Commit

Permalink
Merge pull request #28 from king129/feature/ProtobufSupport
Browse files Browse the repository at this point in the history
Feature/protobuf support
  • Loading branch information
mmoaay authored Mar 22, 2018
2 parents 4f1f069 + 94c3490 commit 908cc7b
Show file tree
Hide file tree
Showing 150 changed files with 21,732 additions and 2,761 deletions.
37 changes: 17 additions & 20 deletions Bamboots.podspec
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
#
# Be sure to run `pod lib lint Bamboots.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Pod spec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'Bamboots'
s.version = '0.6.0'
s.summary = 'Bamboots - Extension 4 Alamofire'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = 'Bamboots is a network request framework based on Alamofire and ObjectMapper, aiming at making network request easier for business development'

s.homepage = 'https://github.com/mmoaay/Bamboots'
Expand All @@ -27,18 +12,30 @@ Pod::Spec.new do |s|
# s.social_media_url = 'http://weibo.com/smmoaay'

s.ios.deployment_target = '8.0'

s.source_files = 'Bamboots/Classes/**/*'
s.resources = 'Bamboots/Assets/**/*'
s.default_subspec = 'Core'

# s.resource_bundles = {
# 'Bamboots' => ['Bamboots/Assets/*.png']
# }

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency 'AlamofireCodable'
s.dependency 'Alamofire'

#s.dependency 'ObjectMapper'
# s.dependency 'RealmSwift'


s.subspec 'Core' do |core|
core.source_files = 'Bamboots/Classes/Core/**/*.swift'
core.resources = 'Bamboots/Assets/**/*'
core.dependency 'AlamofireCodable'
core.dependency 'Alamofire'
end

s.subspec 'BambootsProtobuf' do |pb|
pb.source_files = 'Bamboots/Classes/Protobuf/**/*.swift'
pb.dependency 'Bamboots/Core', s.version.to_s
pb.dependency 'SwiftProtobuf', '1.0.2'
end

end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions Bamboots/Classes/Protobuf/AlamofireProtobuf.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// AlamofireProtobuf.swift
// Pods
//
// Created by sun on 2018/2/27.
//

import Alamofire
import SwiftProtobuf

extension DataRequest {

enum AlamofireProtobufErrorCode: Int {
case noData = 1
case dataSerializationFailed = 2
}

internal static func newError(_ code: AlamofireProtobufErrorCode, failureReason: String) -> NSError {
let errorDomain = "com.alamofireProtobuf.error"
let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
let returnError = NSError(domain: errorDomain, code: code.rawValue, userInfo: userInfo)
return returnError
}

/// Utility function for checking for errors in response
internal static func checkResponseForError(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) -> Error? {
if let error = error {
return error
}
guard let _ = data else {
let failureReason = "Data could not be serialized. Input data was nil."
let error = newError(.noData, failureReason: failureReason)
return error
}
return nil
}

public static func ObjectSerializerPB<T: SwiftProtobuf.Message>(extensions: ExtensionMap?, partial: Bool, options: BinaryDecodingOptions) -> DataResponseSerializer<T> {
return DataResponseSerializer { request, response, data, error in
if let error = checkResponseForError(request: request, response: response, data: data, error: error) {
return .failure(error)
}
do {
let object = try T(serializedData: data!, extensions: extensions, partial: partial, options: options)
return .success(object)
} catch let error {
return .failure(error)
}
}
}

@discardableResult
public func responsePBObject<T: SwiftProtobuf.Message>(queue: DispatchQueue? = nil, keyPath: String? = nil, extensions: ExtensionMap? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions(), completionHandler: @escaping (DataResponse<T>) -> Void) -> Self {
return response(queue: queue, responseSerializer: DataRequest.ObjectSerializerPB(extensions: extensions, partial: partial, options: options), completionHandler: completionHandler)
}
}
242 changes: 146 additions & 96 deletions Example/Bamboots.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
ReferencedContainer = "container:MBNetwork.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A4AF31DD2045045B009BCAF6"
BuildableName = "Bamboots_ExampleTests.xctest"
BlueprintName = "Bamboots_ExampleTests"
ReferencedContainer = "container:Bamboots.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A4AF31DD2045045B009BCAF6"
BuildableName = "Bamboots_ExampleTests.xctest"
BlueprintName = "Bamboots_ExampleTests"
ReferencedContainer = "container:Bamboots.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Loading

0 comments on commit 908cc7b

Please sign in to comment.