Skip to content

Commit

Permalink
Add default value for API.Endpoint.makeRequest options parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
pranjalsatija committed Sep 10, 2017
1 parent 3e1d8a1 commit 25251ca
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Sources/ParseSwift/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public struct API {
func makeRequest(method: Method,
params: [URLQueryItem]? = nil,
body: Encodable? = nil,
options: Option,
options: Option = [],
callback: ((Data?, Error?) -> Void)? = nil) -> Cancellable {

let bodyData = try? getJSONEncoder().encode(body)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Object Protocols/ObjectType+Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public extension ObjectType {
public static func find(callback: @escaping (([Self]?, Error?) -> Void)) -> Cancellable {
return query().find(options: [], callback: callback)
return query().find(callback: callback)
}

public static func query() -> Query<Self> {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ParseSwift/Object Protocols/ObjectType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public extension ObjectType {
public func save(options: API.Option, callback: ((Self?, Error?) -> Void)? = nil) -> Cancellable {
let requestMethod: API.Method = isSaved ? .put : .post

return endpoint.makeRequest(method: requestMethod, options: []) {(data, error) in
return endpoint.makeRequest(method: requestMethod) {(data, error) in
if let data = data {
do {
var object: Self!
Expand Down Expand Up @@ -96,7 +96,7 @@ public extension ObjectType {
return nil
}

return endpoint.makeRequest(method: .get, options: []) {(data, error) in
return endpoint.makeRequest(method: .get) {(data, error) in
if let data = data {
do {
let object = try getDecoder().decode(UpdateResponse.self, from: data).apply(self)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ParseSwift/Object Protocols/UserType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension UserType {
URLQueryItem(name: $0, value: $1)
}

return API.Endpoint.login.makeRequest(method: .get, params: params, options: []) {(data, error) in
return API.Endpoint.login.makeRequest(method: .get, params: params) {(data, error) in
if let data = data {
do {
let user = try getDecoder().decode(Self.self, from: data)
Expand All @@ -62,15 +62,15 @@ extension UserType {
}

static func logOut(callback: (() -> Void)? = nil) -> Cancellable? {
return API.Endpoint.logout.makeRequest(method: .post, options: []) {(_, _) in
return API.Endpoint.logout.makeRequest(method: .post) {(_, _) in
callback?()
}
}

static func signUp(username: String, password: String, callback: ((Self?, Error?) -> Void)? = nil) -> Cancellable {
let body = SignupBody(username: username, password: password)

return API.Endpoint.signup.makeRequest(method: .post, body: body, options: []) {(data, error) in
return API.Endpoint.signup.makeRequest(method: .post, body: body) {(data, error) in
if let data = data {
do {
let response = try getDecoder().decode(LoginSignupResponse.self, from: data)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Types/Pointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct Pointer<T: ObjectType>: Fetching, Codable {
extension Pointer {
public func fetch(options: API.Option = [], callback: @escaping ((T?, Error?) -> Void)) -> Cancellable? {
let endpoint = API.Endpoint.object(className: className, objectId: objectId)
return endpoint.makeRequest(method: .get, options: []) {(data, error) in
return endpoint.makeRequest(method: .get) {(data, error) in
if let data = data {
do {
let object = try getDecoder().decode(T.self, from: data)
Expand Down
12 changes: 6 additions & 6 deletions Sources/ParseSwift/Types/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public protocol Querying {

extension Querying {
func find(callback: @escaping (([ResultType]?, Error?) -> Void)) -> Cancellable {
return find(options: [], callback: callback)
return find(callback: callback)
}
func first(callback: @escaping ((ResultType?, Error?) -> Void)) -> Cancellable {
return first(options: [], callback: callback)
return first(callback: callback)
}
func count(callback: @escaping ((Int?, Error?) -> Void)) -> Cancellable {
return count(options: [], callback: callback)
return count(callback: callback)
}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ extension Query: Querying {
public typealias ResultType = T

public func find(options: API.Option, callback: @escaping ([T]?, Error?) -> Void) -> Cancellable {
return endpoint.makeRequest(method: .post, body: self, options: []) {(data, error) in
return endpoint.makeRequest(method: .post, body: self) {(data, error) in
if let data = data {
do {
let results = try getDecoder().decode(FindResult<T>.self, from: data).results
Expand All @@ -217,7 +217,7 @@ extension Query: Querying {
public func first(options: API.Option, callback: @escaping ((T?, Error?) -> Void)) -> Cancellable {
var query = self
query.limit = 1
return endpoint.makeRequest(method: .post, body: query, options: []) {(data, error) in
return endpoint.makeRequest(method: .post, body: query) {(data, error) in
if let data = data {
do {
let result = try getDecoder().decode(FindResult<T>.self, from: data).results.first
Expand All @@ -237,7 +237,7 @@ extension Query: Querying {
var query = self
query.isCount = true
query.limit = 1
return endpoint.makeRequest(method: .post, body: query, options: []) {(data, error) in
return endpoint.makeRequest(method: .post, body: query) {(data, error) in
if let data = data {
do {
let count = try getDecoder().decode(FindResult<T>.self, from: data).count ?? 0
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Utilities/Fetching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public protocol Fetching: Codable {

extension Fetching {
public func fetch(callback: @escaping ((FetchingType?, Error?) -> Void)) -> Cancellable? {
return fetch(options: [], callback: callback)
return fetch(callback: callback)
}
}
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Utilities/Saving.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public protocol Saving: Codable {

extension Saving {
public func save(callback: @escaping ((SavingType?, Error?) -> Void)) -> Cancellable {
return save(options: [], callback: callback)
return save(callback: callback)
}
}

0 comments on commit 25251ca

Please sign in to comment.