Skip to content

Commit

Permalink
Merge pull request #28 from Ast3r10n/develop
Browse files Browse the repository at this point in the history
Release 0.1.7
  • Loading branch information
Ast3r10n authored Jun 6, 2021
2 parents 5552d33 + a9c9c32 commit 74dd6e2
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Generate coverage report
run: xcodebuild -scheme Requests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11 Pro,OS=13.3' -enableCodeCoverage YES build test
run: xcodebuild -scheme SwiftQuests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 11 Pro' -enableCodeCoverage YES build test
- name: Codecov
uses: codecov/[email protected]
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ fastlane/test_output
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
iOSInjectionProject/
build/
12 changes: 6 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import PackageDescription

let package = Package(
name: "Requests",
name: "SwiftQuests",
products: [
.library(
name: "Requests",
targets: ["Requests"]),
name: "SwiftQuests",
targets: ["SwiftQuests"]),
],
targets: [
.target(
name: "Requests",
name: "SwiftQuests",
dependencies: []),
.testTarget(
name: "RequestsTests",
dependencies: ["Requests"]),
name: "SwiftQuestsTests",
dependencies: ["SwiftQuests"]),
]
)
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Requests
# SwiftQuests

An object-oriented, URLSession-based network library.

![Swift](https://github.com/Ast3r10n/requests/workflows/Swift/badge.svg) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/Ast3r10n/requests) ![Codecov](https://img.shields.io/codecov/c/gh/Ast3r10n/Requests?token=43bbf53852d24e549074f62b39f01e39)
![Swift](https://github.com/Ast3r10n/requests/workflows/Swift/badge.svg) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/Ast3r10n/requests) ![Codecov](https://img.shields.io/codecov/c/gh/Ast3r10n/swiftquests?token=9980b291f6634fe6a969036234755d8c) ![License](https://img.shields.io/github/license/Ast3r10n/swiftquests) ![Cocoapods](https://img.shields.io/cocoapods/p/SwiftQuests) ![LastCommit](https://img.shields.io/github/last-commit/Ast3r10n/swiftquests)

## Installation

### Swift Package Manager

Add a Swift Package Dependency to your project with URL:
```
https://github.com/Ast3r10n/requests
https://github.com/Ast3r10n/swiftquests
```

### Cocoapods

Add `SwiftQuests` to your Podfile:
```ruby
pod 'SwiftQuests'
```

## Usage
Expand All @@ -20,7 +29,7 @@ Once initialised, a `Request` is (for the most part) immutable. Its task will on

To perform a basic `Request`, initialise one:

```
```swift
do {
let request = try Request(.get,
atPath: "/user")
Expand All @@ -30,9 +39,9 @@ do {
```
You then call the `perform` method to launch its associated task.

```
```swift
do {
try request.perform { data, response, error in
try request.perform { result in
// Response implementation
}
} catch {
Expand All @@ -46,11 +55,11 @@ do {

Here's an example `Request` to get a `Decodable` `User` object from the `/user` endpoint.

```
```swift
do {
try Request(.get,
atPath: "/user")
.perform(decoding: User.self) { user, response, error in
.perform(decoding: User.self) { result in

// Your completion handler here
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ public protocol RequestConfiguration {
/// The default Request headers.
///
/// Any headers passed to specific `Requests` would be appended to these.
var defaultHeaders: [String: String] { get set }
var defaultHeaders: [String: String] { get }

/// The Request protocol.
var requestProtocol: String { get set }
var requestProtocol: String { get }

/// The default base URL (not including protocol).
var baseURL: String { get set }
var baseURL: String { get }

/// The default port.
var port: Int { get set }
var port: Int { get }

/// The server's authentication realm.
var authenticationRealm: String { get set }
var authenticationRealm: String { get }

/// The default authentication method to use with Requests.
var authenticationMethod: String { get set }
var authenticationMethod: String { get }
}

public extension RequestConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class Request: AbstractRequest {
/// The request `URLSession`.
///
/// Defaults to a session with a `default` `URLSessionConfiguration` unless otherwise specified.
public var session = URLSession(configuration: .default)
public var session = URLSession(configuration: .ephemeral)

/// The wrapped `URLRequest` object.
public var urlRequest: URLRequest!
Expand Down Expand Up @@ -138,9 +138,10 @@ open class Request: AbstractRequest {
}

if let credential = credential {
URLCredentialStorage.shared.set(credential,
for: configuration.protectionSpace,
task: task)
URLCredentialStorage.shared.set(
credential,
for: configuration.protectionSpace,
task: task)
}

task.resume()
Expand All @@ -155,7 +156,7 @@ open class Request: AbstractRequest {
/// - error: The task error.
open func perform<T: Decodable>(decoding object: T.Type,
_ completionHandler: @escaping (
_ result: Result<(T?, URLResponse?), Error>) throws -> Void) {
_ result: Result<(T, URLResponse?), Error>) throws -> Void) {

perform { result in
switch result {
Expand All @@ -167,8 +168,13 @@ open class Request: AbstractRequest {
return
}

let object = try JSONDecoder().decode(T.self, from: data)
try completionHandler(.success((object, response.urlResponse)))
do {
let object = try JSONDecoder().decode(T.self, from: data)
try completionHandler(.success((object, response.urlResponse)))
} catch let error {
try completionHandler(.failure(error))
}

case .failure(let error):
try completionHandler(.failure(error))
}
Expand All @@ -192,7 +198,7 @@ open class Request: AbstractRequest {

if let headers = headers {
headers.forEach { header in
request.addValue(header.key, forHTTPHeaderField: header.value)
request.setValue(header.value, forHTTPHeaderField: header.key)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public class RequestConfigurationHolder {
/// The holder singleton instance.
public static var shared = RequestConfigurationHolder()

// MARK: - Internal Properties
/// The configuration assigned to the holder.
var configuration: RequestConfiguration
public internal(set) var configuration: RequestConfiguration

// MARK: - Internal Methods
/// Creates a holder object, assigning the specified configuration.
Expand Down
143 changes: 143 additions & 0 deletions SwiftQuests.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#
# Be sure to run `pod spec lint SwiftQuests.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |spec|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#

spec.name = "SwiftQuests"
spec.version = "0.1.3"
spec.summary = "An object-oriented, URLSession-based network library."

# 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!
spec.description = <<-DESC
"An object-oriented, URLSession-based network library, made with simplicity in mind. It's a direct wrapper for URLSession, with no other dependencies."
DESC

spec.homepage = "https://github.com/Ast3r10n/swiftquests"
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See https://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#

spec.license = { :type => "GNU", :file => "LICENSE" }


# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#

spec.author = { "Andrea Sacerdoti" => "[email protected]" }
# Or just: spec.author = "Andrea Sacerdoti"
# spec.authors = { "Andrea Sacerdoti" => "[email protected]" }
spec.social_media_url = "https://twitter.com/AndreaSacerdoti"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#

# spec.platform = :ios
spec.platform = :ios, "8.0"

# When using multiple platforms
# spec.ios.deployment_target = "8.0"
# spec.osx.deployment_target = "10.9"
# spec.watchos.deployment_target = "2.0"
# spec.tvos.deployment_target = "9.0"

spec.swift_versions = "5.0"

# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#

spec.source = { :git => "https://github.com/Ast3r10n/swiftquests.git", :tag => "#{spec.version}" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#

spec.source_files = "Sources", "Sources/**/*.{swift}"
spec.exclude_files = "Sources/Exclude"

spec.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'Tests/**/*.swift'
test_spec.exclude_files = '*/LinuxMain.swift'
end

# spec.public_header_files = "Classes/**/*.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#

# spec.resource = "icon.png"
# spec.resources = "Resources/*.png"

# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"


# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#

# spec.framework = "SomeFramework"
# spec.frameworks = "SomeFramework", "AnotherFramework"

# spec.library = "iconv"
# spec.libraries = "iconv", "xml2"


# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.

# spec.requires_arc = true

# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# spec.dependency "JSONKit", "~> 1.4"

end
4 changes: 2 additions & 2 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XCTest

import RequestsTests
import SwiftQuestsTests

var tests = [XCTestCaseEntry]()
tests += RequestsTests.allTests()
tests += SwiftQuestsTests.allTests()
XCTMain(tests)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import XCTest
@testable import Requests
@testable import SwiftQuests

final class RequestConfigurationTests: XCTestCase {
var configuration = DefaultRequestConfiguration()
Expand Down
Loading

0 comments on commit 74dd6e2

Please sign in to comment.