Skip to content

Commit

Permalink
- Added Alamofire plugin
Browse files Browse the repository at this point in the history
- Added `Client` protocol docs - #2
  • Loading branch information
Aron Balog committed Mar 6, 2018
1 parent 83cd6f2 commit e02efd5
Show file tree
Hide file tree
Showing 53 changed files with 322 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
os: osx
osx_image: xcode9.2
language: swift
before_install:
- pod repo update > /dev/null
script:
- set -o pipefail
- xcodebuild test -workspace Vox.xcworkspace -scheme Vox -destination 'platform=iOS Simulator,name=iPhone 8,OS=11.2' ONLY_ACTIVE_ARCH=NO
Expand Down
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target 'Vox' do
use_frameworks!

pod 'Alamofire', '~> 4.7'

target 'VoxTests' do
inherit! :search_paths
Expand Down
5 changes: 4 additions & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
PODS:
- Alamofire (4.7.0)
- Nimble (7.0.3)
- Quick (1.2.0)

DEPENDENCIES:
- Alamofire (~> 4.7)
- Nimble
- Quick

SPEC CHECKSUMS:
Alamofire: 907e0a98eb68cdb7f9d1f541a563d6ac5dc77b25
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08

PODFILE CHECKSUM: 66b133f477257acc4bcbde7cbe44557233e54c46
PODFILE CHECKSUM: d6370329bd52b0306d7c72b4a2cf75a0248944c9

COCOAPODS: 1.4.0
65 changes: 59 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ Vox is a Swift JSONAPI standard implementation.
- [Defining resource](#defining-resource)
- [Serializing](#serializing)
- [Single resource](#single-resource)
- [Alamofire plugin](#alamofire-plugin)
- [Resource collection](#resource-collection)
- [Nullability](#nullability)
- [Deserializing](#deserializing)
- [Single resource](#single-resource)
- [Resource collection](#resource-collection)
- [Networking](#networking)
- [Client protocol](#client-protocol)
- [Alamofire client plugin](#alamofire-client-plugin)
- [Fetching single resource](#fetching-single-resource)
- [Fetching resource collection](#fetching-resource-collection)
- [Creating resource](#creating-resource)
Expand Down Expand Up @@ -84,10 +87,18 @@ This opens up the possibility to easily handle the cases with:
* Xcode 9
* Cocoapods

Basic

```ruby
pod 'Vox'
```

With [Alamofire](https://github.com/Alamofire/Alamofire) plugin

```ruby
pod 'Vox/Alamofire'
```

## Usage

### Defining resource
Expand Down Expand Up @@ -157,7 +168,7 @@ let person = Person()

let json: [String: Any] = try! person.documentDictionary()

// or if you need Data
// or if `Data` is needed
let data: Data = try! person.documentData()
```

Expand Down Expand Up @@ -208,8 +219,8 @@ let person2 = Person()

let json: [String: Any] = try! [person1, person2].documentDictionary()

// or if you need Data
let data: Data = try! person.documentData()
// or if `Data` is needed
let data: Data = try! [person1, person2].documentData()
```

Previous example will resolve to following JSON:
Expand Down Expand Up @@ -271,7 +282,7 @@ let data: Data // -> provide data received from JSONAPI server
let deserializer = Deserializer.Single<Article>()

do {
let document = try sut.deserialize(data: self.data)
let document = try deserializer.deserialize(data: self.data)

// `document.data` is an Article object

Expand All @@ -296,7 +307,7 @@ let data: Data // -> provide data received from JSONAPI server

let deserializer = Deserializer.Collection<Article>()

let document = try! sut.deserialize(data: self.data)
let document = try! deserializer.deserialize(data: self.data)

// `document.data` is an [Article] object
```
Expand All @@ -319,7 +330,49 @@ Deserializer can also be declared without generic parameter but in that case the

### Networking

You can use `<id>` and `<type>` annotations in path strings. If possible, they'll get replaced with adequate values.
`<id>` and `<type>` annotations can be used in path strings. If possible, they'll get replaced with adequate values.

#### Client protocol

Implement following method from `Client` protocol:

```swift
func executeRequest(path: String,
method: String,
queryItems: [URLQueryItem],
bodyParameters: [String : Any]?,
success: @escaping ClientSuccessBlock,
failure: @escaping ClientFailureBlock)
```

where

- `ClientSuccessBlock` = `(HTTPURLResponse?, Data?) -> Void`
- `ClientFailureBlock` = `(Error?, Data?) -> Void`

#### Alamofire client plugin

If custom networking is not required, there is a plugin which wraps [Alamofire](https://github.com/Alamofire/Alamofire) and provides networking client in accordance with JSON:API specification.

> Alamofire is Elegant HTTP Networking in Swift
Example:

```swift
let baseURL = URL(string: "http://demo7377577.mockable.io")!
let client = JSONAPIClient.Alamofire(baseURL: baseURL)
let dataSource = DataSource<Article>(strategy: .path("vox/articles"), client: client)

dataSource
.fetch()
...
```

##### Installation

```ruby
pod 'Vox/Alamofire'
```

#### Fetching single resource

Expand Down
35 changes: 24 additions & 11 deletions Vox.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
Pod::Spec.new do |spec|
spec.name = 'Vox'
spec.version = '1.0.4'
spec.license = 'MIT'
spec.summary = 'A Swift JSONAPI framework'
spec.author = 'Aron Balog'
spec.homepage = 'http://undabot.com'
spec.source = { :git => 'https://github.com/aronbalog/Vox.git', :tag => spec.version }
spec.source_files = 'Vox/**/*'
spec.requires_arc = true
spec.xcconfig = { 'SWIFT_VERSION' => '4.0' }
spec.platform = :ios, '8.0'
spec.name = 'Vox'
spec.version = '1.1.0'
spec.license = 'MIT'
spec.summary = 'A Swift JSONAPI framework'
spec.author = 'Aron Balog'
spec.homepage = 'http://undabot.com'
spec.source = { :git => 'https://github.com/aronbalog/Vox.git', :tag => spec.version }
spec.requires_arc = true
spec.xcconfig = { 'SWIFT_VERSION' => '4.0' }
spec.platform = :ios, '8.0'
spec.default_subspec = 'Core'

spec.subspec 'Core' do |core|
core.source_files = 'Vox/Core/**/*.{swift,m,h}'
end

spec.subspec 'Alamofire' do |alamofire|
alamofire.source_files = 'Vox/Plugins/Alamofire/**/*.{swift}'
alamofire.pod_target_xcconfig = {
'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'ALAMOFIRE',
}
alamofire.dependency 'Vox/Core'
alamofire.dependency 'Alamofire', '~> 4.7'
end
end
68 changes: 62 additions & 6 deletions Vox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
3811C014203D888700EE52B8 /* ErrorsWithoutSource.json in Resources */ = {isa = PBXBuildFile; fileRef = 3811C013203D888700EE52B8 /* ErrorsWithoutSource.json */; };
3821D26A2039E51D00AE241E /* Context_Query.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3821D2692039E51D00AE241E /* Context_Query.swift */; };
3821D26C2039F64F00AE241E /* ResourcePool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3821D26B2039F64F00AE241E /* ResourcePool.swift */; };
384F03B5204E04FE0086F5E1 /* JSONAPIClient_Alamofire.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384F03B4204E04FE0086F5E1 /* JSONAPIClient_Alamofire.swift */; };
384F03B8204E0B070086F5E1 /* AlamofireClientSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 384F03B7204E0B070086F5E1 /* AlamofireClientSpec.swift */; };
3872FA3820379F8300CC26BD /* Vox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3872FA2E20379F8300CC26BD /* Vox.framework */; };
3872FA3D20379F8300CC26BD /* VoxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3872FA3C20379F8300CC26BD /* VoxTests.swift */; };
3872FA3F20379F8300CC26BD /* Vox.h in Headers */ = {isa = PBXBuildFile; fileRef = 3872FA3120379F8300CC26BD /* Vox.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -72,6 +74,7 @@
38E00D41203911A100B45B4C /* ErrorObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E00D40203911A100B45B4C /* ErrorObject.swift */; };
38E00D44203911B700B45B4C /* JSONAPIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E00D43203911B700B45B4C /* JSONAPIError.swift */; };
38E00D4620391CE500B45B4C /* DeserializerSinglePolymorphic.json in Resources */ = {isa = PBXBuildFile; fileRef = 38E00D4520391CE400B45B4C /* DeserializerSinglePolymorphic.json */; };
38EE017B204E2124009A1FCF /* JSONAPIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38EE017A204E2124009A1FCF /* JSONAPIClient.swift */; };
70EC6E6C7F0EC2212D677322 /* Pods_Vox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8F6BBA32DFBB2745B08DC67C /* Pods_Vox.framework */; };
/* End PBXBuildFile section */

Expand All @@ -93,6 +96,8 @@
3821D26B2039F64F00AE241E /* ResourcePool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourcePool.swift; sourceTree = "<group>"; };
3821D273203A02B200AE241E /* SerializerCollectionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializerCollectionSpec.swift; sourceTree = "<group>"; };
3821D274203A02B200AE241E /* SerializerSingleSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SerializerSingleSpec.swift; sourceTree = "<group>"; };
384F03B4204E04FE0086F5E1 /* JSONAPIClient_Alamofire.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONAPIClient_Alamofire.swift; sourceTree = "<group>"; };
384F03B7204E0B070086F5E1 /* AlamofireClientSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlamofireClientSpec.swift; sourceTree = "<group>"; };
3872FA2E20379F8300CC26BD /* Vox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Vox.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3872FA3120379F8300CC26BD /* Vox.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Vox.h; sourceTree = "<group>"; };
3872FA3220379F8300CC26BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,6 +158,7 @@
38E00D4520391CE400B45B4C /* DeserializerSinglePolymorphic.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = DeserializerSinglePolymorphic.json; sourceTree = "<group>"; };
38E00D4820391D3A00B45B4C /* DataSourceSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSourceSpec.swift; sourceTree = "<group>"; };
38E00D4B20391E2A00B45B4C /* PerformanceSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceSpec.swift; sourceTree = "<group>"; };
38EE017A204E2124009A1FCF /* JSONAPIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONAPIClient.swift; sourceTree = "<group>"; };
4C377C4C5E8EC0F47CC8A09A /* Pods_VoxTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_VoxTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
57CD3473858065C0C3F263AF /* Pods-Vox.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Vox.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Vox/Pods-Vox.debug.xcconfig"; sourceTree = "<group>"; };
8F6BBA32DFBB2745B08DC67C /* Pods_Vox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Vox.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -200,6 +206,30 @@
path = Serializer;
sourceTree = "<group>";
};
384F03B2204E04480086F5E1 /* Plugins */ = {
isa = PBXGroup;
children = (
384F03B3204E045E0086F5E1 /* Alamofire */,
);
path = Plugins;
sourceTree = "<group>";
};
384F03B3204E045E0086F5E1 /* Alamofire */ = {
isa = PBXGroup;
children = (
384F03B4204E04FE0086F5E1 /* JSONAPIClient_Alamofire.swift */,
);
path = Alamofire;
sourceTree = "<group>";
};
384F03B6204E0AFE0086F5E1 /* Alamofire */ = {
isa = PBXGroup;
children = (
384F03B7204E0B070086F5E1 /* AlamofireClientSpec.swift */,
);
path = Alamofire;
sourceTree = "<group>";
};
3872FA2420379F8300CC26BD = {
isa = PBXGroup;
children = (
Expand All @@ -224,12 +254,8 @@
3872FA3020379F8300CC26BD /* Vox */ = {
isa = PBXGroup;
children = (
38E00D42203911B700B45B4C /* Enum */,
38E00CFF20390C2D00B45B4C /* Networking */,
38E00CFC2038D30400B45B4C /* Helpers */,
3872FA532037ABC600CC26BD /* Protocol */,
3872FA4820379FD600CC26BD /* Class */,
3872FA3120379F8300CC26BD /* Vox.h */,
38EE017C204E2569009A1FCF /* Core */,
384F03B2204E04480086F5E1 /* Plugins */,
3872FA3220379F8300CC26BD /* Info.plist */,
);
path = Vox;
Expand All @@ -238,6 +264,7 @@
3872FA3B20379F8300CC26BD /* VoxTests */ = {
isa = PBXGroup;
children = (
384F03B6204E0AFE0086F5E1 /* Alamofire */,
3821D272203A02B200AE241E /* Serializer */,
38E00D4A20391E2A00B45B4C /* Performance */,
38E00D4720391D3A00B45B4C /* DataSource */,
Expand Down Expand Up @@ -316,6 +343,7 @@
38E00CFF20390C2D00B45B4C /* Networking */ = {
isa = PBXGroup;
children = (
38EE0179204E2110009A1FCF /* Client */,
3899555E20430EBC007E2DE5 /* Extensions */,
38E00D0020390C2D00B45B4C /* Class */,
38E00D0320390C2D00B45B4C /* Protocol */,
Expand Down Expand Up @@ -392,6 +420,27 @@
path = Performance;
sourceTree = "<group>";
};
38EE0179204E2110009A1FCF /* Client */ = {
isa = PBXGroup;
children = (
38EE017A204E2124009A1FCF /* JSONAPIClient.swift */,
);
path = Client;
sourceTree = "<group>";
};
38EE017C204E2569009A1FCF /* Core */ = {
isa = PBXGroup;
children = (
3872FA3120379F8300CC26BD /* Vox.h */,
38E00D42203911B700B45B4C /* Enum */,
38E00CFF20390C2D00B45B4C /* Networking */,
38E00CFC2038D30400B45B4C /* Helpers */,
3872FA532037ABC600CC26BD /* Protocol */,
3872FA4820379FD600CC26BD /* Class */,
);
path = Core;
sourceTree = "<group>";
};
F88997C466CC6768904BE1D9 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -573,11 +622,13 @@
"${SRCROOT}/Pods/Target Support Files/Pods-VoxTests/Pods-VoxTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Quick/Quick.framework",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -626,9 +677,11 @@
3899556620431121007E2DE5 /* Pagination_CursorBased.swift in Sources */,
38E00D41203911A100B45B4C /* ErrorObject.swift in Sources */,
38E00D1A20390C2D00B45B4C /* FetchConfigurable.swift in Sources */,
38EE017B204E2124009A1FCF /* JSONAPIClient.swift in Sources */,
38E00D1520390C2D00B45B4C /* Creatable.swift in Sources */,
38E00D2720390D5B00B45B4C /* Deserializer_Single.swift in Sources */,
38995564204310D0007E2DE5 /* Pagination_OffsetBased.swift in Sources */,
384F03B5204E04FE0086F5E1 /* JSONAPIClient_Alamofire.swift in Sources */,
38E00D44203911B700B45B4C /* JSONAPIError.swift in Sources */,
3872FA502037A10800CC26BD /* Resource.swift in Sources */,
38E00D1D20390C2D00B45B4C /* FetchIncludable.swift in Sources */,
Expand Down Expand Up @@ -674,6 +727,7 @@
387FB92B203D08C100CE47F9 /* SerializerCollectionSpec.swift in Sources */,
387FB927203D07A500CE47F9 /* DataSourceSpec.swift in Sources */,
387FB925203D030800CE47F9 /* DeserializerCollectionSpec.swift in Sources */,
384F03B8204E0B070086F5E1 /* AlamofireClientSpec.swift in Sources */,
387FB91E203CF04700CE47F9 /* DeserializerSingleSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -820,6 +874,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.aronbalog.Vox;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG ALAMOFIRE";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -844,6 +899,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.aronbalog.Vox;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = ALAMOFIRE;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>2</real>
<real>2.5</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
<key>maxPercentRelativeStandardDeviation</key>
Expand Down
5 changes: 0 additions & 5 deletions Vox.xcodeproj/xcshareddata/xcschemes/Vox.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
BlueprintName = "VoxTests"
ReferencedContainer = "container:Vox.xcodeproj">
</BuildableReference>
<SkippedTests>
<Test
Identifier = "PerformanceSpec">
</Test>
</SkippedTests>
</TestableReference>
</Testables>
<MacroExpansion>
Expand Down
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e02efd5

Please sign in to comment.