Repository navigation
Expand file tree
/
Copy pathMarvelAPI.swift
More file actions
209 lines (161 loc) · 7.71 KB
/
Copy pathMarvelAPI.swift
File metadata and controls
209 lines (161 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//
// MarvelAPI.swift
// Relax
//
// Created by Jo Albright on 1/12/16.
// Copyright (c) 2016 Jo Albright. All rights reserved.
//
import Foundation
import CryptoSwift
// Documentation : http://developer.marvel.com
private let _m = MarvelAPI()
open class MarvelAPI: API {
open override class func session() -> MarvelAPI { return _m }
var ts: String { return "\(Int(Date().timeIntervalSince1970))" }
var hash: String { return "\(ts)\(MARVEL_CLIENT_SECRET)\(MARVEL_CLIENT_ID)".md5() }
open override func start() {
baseURL = "https://gateway.marvel.com/v1/public/"
authTokenKey = "Marvel"
authBasic = [
"apikey" : MARVEL_CLIENT_ID,
"ts" : ts,
"hash" : hash
]
}
public enum Endpoints: String {
// Characters
/// Fetches List of Characters
case characters
/// Fetches a single character by :character_id
case characterId
/// Fetches lists of comics filtered by a :character_id
case characterIdComics
/// Fetches lists of events filtered by a :character_id
case characterIdEvents
/// Fetches lists of series filtered by a :character_id
case characterIdSeries
/// Fetches lists of stories filtered by a :character_id
case characterIdStories
// Comics
/// Fetches lists of comics
case comics
/// Fetches a single comic by :comic_id
case comicId
/// Fetches lists of characters filtered by a :comic_id
case comicIdCharacters
/// Fetches lists of creators filtered by a :comic_id
case comicIdCreators
/// Fetches lists of events filtered by a :comic_id
case comicIdEvents
/// Fetches lists of stories filtered by a :comic_id
case comicIdStories
// Creators
/// Fetches lists of creators
case creators
/// Fetches a single creator by :creator_id
case creatorId
/// Fetches lists of comics filtered by a :creator_id
case creatorIdComics
/// Fetches lists of events filtered by a :creator_id
case creatorIdEvents
/// Fetches lists of series filtered by a :creator_id
case creatorIdSeries
/// Fetches lists of stories filtered by a :creator_id
case creatorIdStories
// Events
/// Fetches lists of events
case events
/// Fetches a single event by :event_id
case eventId
/// Fetches lists of characters filtered by an :event_id
case eventIdCharacters
/// Fetches lists of comics filtered by an :event_id
case eventIdComics
/// Fetches lists of creators filtered by an :event_id
case eventIdCreators
/// Fetches lists of series filtered by an :event_id
case eventIdSeries
/// Fetches lists of stories filtered by an :event_id
case eventIdStories
// Series
/// Fetches lists of series
case series
/// Fetches a single comic series by :series_id
case seriesId
/// Fetches lists of characters filtered by a :series_id
case seriesIdCharacters
/// Fetches lists of comics filtered by a :series_id
case seriesIdComics
/// Fetches lists of creators filtered by a :series_id
case seriesIdCreators
/// Fetches lists of events filtered by a :series_id
case seriesIdEvents
/// Fetches lists of stories filtered by a :series_id
case seriesIdStories
// Stories
/// Fetches lists of stories
case stories
/// Fetches a single comic story by :story_id
case storyId
/// Fetches lists of characters filtered by a :story_id
case storyIdCharacters
/// Fetches lists of comics filtered by a :story_id
case storyIdComics
/// Fetches lists of creators filtered by a :story_id
case storyIdCreators
/// Fetches lists of events filtered by a :story_id
case storyIdEvents
/// Fetches lists of series filtered by a :story_id
case storyIdSeries
public var endpoint: Endpoint { return _endpoints[self]! }
var _endpoints: [Endpoints:Endpoint] {
return [
// Characters
.characters : Endpoint(path: "characters"),
.characterId : Endpoint(path: "characters/:character_id"),
.characterIdComics : Endpoint(path: "characters/:character_id/comics"),
.characterIdEvents : Endpoint(path: "characters/:character_id/events"),
.characterIdSeries : Endpoint(path: "characters/:character_id/series"),
.characterIdStories : Endpoint(path: "characters/:character_id/stories"),
// Comics
.comics : Endpoint(path: "comics"),
.comicId : Endpoint(path: "comics/:comic_id"),
.comicIdCharacters : Endpoint(path: "comics/:comic_id/characters"),
.comicIdCreators : Endpoint(path: "comics/:comic_id/creators"),
.comicIdEvents : Endpoint(path: "comics/:comic_id/events"),
.comicIdStories : Endpoint(path: "comics/:comic_id/stories"),
// Creators
.creators : Endpoint(path: "creators"),
.creatorId : Endpoint(path: "creators/:creator_id"),
.creatorIdComics : Endpoint(path: "creators/:creator_id/comics"),
.creatorIdEvents : Endpoint(path: "creators/:creator_id/events"),
.creatorIdSeries : Endpoint(path: "creators/:creator_id/series"),
.creatorIdStories : Endpoint(path: "creators/:creator_id/stories"),
// Events
.events : Endpoint(path: "events"),
.eventId : Endpoint(path: "events/:event_id"),
.eventIdCharacters : Endpoint(path: "events/:event_id/characters"),
.eventIdComics : Endpoint(path: "events/:event_id/comics"),
.eventIdCreators : Endpoint(path: "events/:event_id/creators"),
.eventIdSeries : Endpoint(path: "events/:event_id/series"),
.eventIdStories : Endpoint(path: "events/:event_id/stories"),
// Series
.series : Endpoint(path: "series"),
.seriesId : Endpoint(path: "series/:series_id"),
.seriesIdCharacters : Endpoint(path: "series/:series_id/characters"),
.seriesIdComics : Endpoint(path: "series/:series_id/comics"),
.seriesIdCreators : Endpoint(path: "series/:series_id/creators"),
.seriesIdEvents : Endpoint(path: "series/:series_id/events"),
.seriesIdStories : Endpoint(path: "series/:series_id/stories"),
// Stories
.stories : Endpoint(path: "stories"),
.storyId : Endpoint(path: "stories/:story_id"),
.storyIdCharacters : Endpoint(path: "stories/:story_id/characters"),
.storyIdComics : Endpoint(path: "stories/:story_id/comics"),
.storyIdCreators : Endpoint(path: "stories/:story_id/creators"),
.storyIdEvents : Endpoint(path: "stories/:story_id/events"),
.storyIdSeries : Endpoint(path: "stories/:story_id/series")
]
}
}
}