Skip to content

Commit 6a20241

Browse files
authored
Merge pull request #1 from microcmsio/feature/api-key
新しいAPIキーに対応
2 parents 79de454 + faceaeb commit 6a20241

File tree

3 files changed

+11
-35
lines changed

3 files changed

+11
-35
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Next, create a client.
2323
```swift
2424
let client = MicrocmsClient(
2525
serviceDomain: "YOUR_DOMAIN", // YOUR_DOMAIN is the XXXX part of XXXX.microcms.io
26-
apiKey: "YOUR_API_KEY",
27-
globalDraftKey: "YOUR_GLOBAL_DRAFT_KEY" // if needed
26+
apiKey: "YOUR_API_KEY"
2827
)
2928
```
3029

Sources/MicrocmsSDK/MicrocmsSDK.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ public struct MicrocmsClient {
77

88
private let serviceDomain: String
99
private let apiKey: String
10-
private let globalDrafyKey: String?
1110

1211
public init(serviceDomain: String,
13-
apiKey: String,
14-
globalDraftKey: String? = nil) {
12+
apiKey: String) {
1513
self.serviceDomain = serviceDomain
1614
self.apiKey = apiKey
17-
self.globalDrafyKey = globalDraftKey
1815
}
1916

2017
var baseUrl: String {
@@ -51,10 +48,7 @@ public struct MicrocmsClient {
5148

5249
var request = URLRequest(url: components.url!)
5350
request.httpMethod = "GET"
54-
request.setValue(apiKey, forHTTPHeaderField: "X-API-KEY")
55-
if let globalDraftKey = globalDrafyKey {
56-
request.setValue(globalDraftKey, forHTTPHeaderField: "X-GLOBAL-DRAFT-KEY")
57-
}
51+
request.setValue(apiKey, forHTTPHeaderField: "X-MICROCMS-API-KEY")
5852

5953
return request
6054
}

Tests/MicrocmsSDKTests/MicrocmsSDKTests.swift

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,15 @@ final class MicrocmsSDKTests: XCTestCase {
6363
}
6464

6565
func testMakeRequest_headers() {
66-
XCTContext.runActivity(named: "normal") { _ in
67-
let client = MicrocmsClient(
68-
serviceDomain: "test-service",
69-
apiKey: "test-api-key")
70-
71-
let request = client.makeRequest(endpoint: "endpoint",
72-
contentId: nil,
73-
params: nil)
74-
75-
XCTAssertEqual(request?.allHTTPHeaderFields, ["X-API-KEY": "test-api-key"])
76-
}
66+
let client = MicrocmsClient(
67+
serviceDomain: "test-service",
68+
apiKey: "test-api-key")
69+
70+
let request = client.makeRequest(endpoint: "endpoint",
71+
contentId: nil,
72+
params: nil)
7773

78-
XCTContext.runActivity(named: "with_draft") { _ in
79-
let client = MicrocmsClient(
80-
serviceDomain: "test-service",
81-
apiKey: "test-api-key",
82-
globalDraftKey: "test-global-draft-key")
83-
84-
let request = client.makeRequest(endpoint: "endpoint",
85-
contentId: nil,
86-
params: nil)
87-
88-
XCTAssertEqual(request?.allHTTPHeaderFields,
89-
["X-API-KEY": "test-api-key",
90-
"X-GLOBAL-DRAFT-KEY": "test-global-draft-key"])
91-
}
74+
XCTAssertEqual(request?.allHTTPHeaderFields, ["X-MICROCMS-API-KEY": "test-api-key"])
9275
}
9376

9477
func testGet() {

0 commit comments

Comments
 (0)