Skip to content

Commit

Permalink
Add path tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
iq3addLi committed Oct 31, 2017
1 parent 4b1c9bc commit d20d166
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension ApplicationError : WebSerializable{

```Swift
let basic = try? BasicStruct(
"http://localhost:8080/basic",
path: "http://localhost:8080/basic",
body: RequestStruct(value: "hello")
)
```
Expand All @@ -70,7 +70,7 @@ let basic = try? BasicStruct(
```Swift
do{
let _ = try ErrorStruct(
"http://localhost:8080/error",
path: "http://localhost:8080/error",
body: RequestStruct(value: "hello")
)
}
Expand Down
7 changes: 3 additions & 4 deletions Sources/WebStruct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public protocol WebInitializable : WebSerializable {
Default implement for WebInitializable
*/
extension WebInitializable{
public init(_ path:String, body:Self.bodyType? = nil) throws {
self = try WebStruct<Self,Self.errorType>().get( path, body: body)
public init(path:String, body:Self.bodyType? = nil) throws {
self = try WebStruct<Self,Self.errorType>().get(path: path, body: body)
}

// default values
Expand All @@ -98,7 +98,6 @@ extension WebInitializable{
public static var session:URLSession {
return URLSession(configuration: URLSessionConfiguration.default, delegate: nil, delegateQueue: nil)
}

}


Expand All @@ -109,7 +108,7 @@ fileprivate struct WebStruct <GenT:WebInitializable,ErrorT:WebSerializable>{

fileprivate init(){}

fileprivate func get<BodyT:WebDeserializable>(_ path:String, body:BodyT?) throws -> GenT {
fileprivate func get<BodyT:WebDeserializable>(path:String, body:BodyT?) throws -> GenT {

// setup for request
var request = GenT.request
Expand Down
10 changes: 4 additions & 6 deletions Tests/WebStructTests/OpenWebAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ class OpenWebAPITests: XCTestCase {
}

func testItunesSearch() {
guard let search = try? iTunesSearch(
"https://itunes.apple.com/search?term=twitter&media=software&entity=software&limit=10"
) else { fatalError() }
guard let search = try? iTunesSearch(path: "https://itunes.apple.com/search?term=twitter&media=software&entity=software&limit=10") else{
fatalError()
}
XCTAssertEqual( search.resultCount, 10 )
}

func testItunesSearchTimeout() {
do{
let _ = try iTunesTimeoutSearch(
"https://itunes.apple.com/search?term=twitter&media=software&entity=software&limit=10"
)
let _ = try iTunesTimeoutSearch(path: "https://itunes.apple.com/search?term=twitter&media=software&entity=software&limit=10")
}
catch let error as WebStruct.Error{
if case .network(let e) = error{
Expand Down
2 changes: 1 addition & 1 deletion Tests/WebStructTests/StaticJsonFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StaticJsonFileTests: XCTestCase {

func testGetJSONFile() {
let file:[Place]
do{ file = try [Place]("http://motorhomes.addli.jp/assets/json/places.json") }catch{
do{ file = try [Place](path: "http://motorhomes.addli.jp/assets/json/places.json") }catch{
print(error)
fatalError()
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/WebStructTests/WebStructTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WebStructTests: XCTestCase {

func testBasicInitalize() {
let basic = try? BasicStruct(
"http://localhost:8080/basic",
path: "http://localhost:8080/basic",
body: RequestStruct(value: "hello")
)
XCTAssert(basic != nil,"test is nil.")
Expand All @@ -40,7 +40,7 @@ class WebStructTests: XCTestCase {
func testInitializationFailedServersideError(){
do{
let _ = try ErrorStruct(
"http://localhost:8080/error",
path: "http://localhost:8080/error",
body: RequestStruct(value: "hello")
)
}
Expand Down Expand Up @@ -72,7 +72,7 @@ class WebStructTests: XCTestCase {
func testInitializationFailedDueToTimeout(){
do{
let _ = try CustomRequestStruct(
"http://localhost:8080/timeout",
path: "http://localhost:8080/timeout",
body: RequestStruct(value: "hello")
)
}
Expand All @@ -93,7 +93,7 @@ class WebStructTests: XCTestCase {
let st:CustomHeadersStruct
do{
st = try CustomHeadersStruct(
"http://localhost:8080/headers",
path: "http://localhost:8080/headers",
body: RequestStruct(value: "hello")
)
}
Expand Down

0 comments on commit d20d166

Please sign in to comment.