-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatuNetwork.podspec
More file actions
209 lines (173 loc) · 17 KB
/
Copy pathCreatuNetwork.podspec
File metadata and controls
209 lines (173 loc) · 17 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
209
#
# Be sure to run `pod lib lint CreatuNetwork.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'CreatuNetwork'
s.version = '0.2.1'
s.summary = 'This is Network request library. depends upon RXSwift, RxXoxoa, Moya/RxSwift, ReachabilitySwift '
# 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!
s.description = <<-DESC
## Requirements
- Swift 4 or higher
- target IOS 10 or higher
## Linked Library
- Alamofire (4.7.0)
- KeychainSwift (10.0.0)
- Moya (11.0.1)
- ReachabilitySwift (4.1.0)
- Result (3.2.4)
- RxCocoa (4.1.2)
- RxSwift (4.1.2)
## Installation
CreatuNetwork is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'CreatuNetwork'
```
## Api Model
In you api add extention [ApiTargetType]()
```Swift
import Foundation
import Moya
import CreatuNetwork
enum UserApi {
case login([String: Any])
case logout([String: Any])
case register([String: Any])
}
extension UserApi: ApiTargetType {
var checkTokenValidity: Bool {
return false
}
var baseURL: URL {
return URL(string: "{{ YOUR-BASE-URL-HERE }}")!
}
var path: String {
switch self {
case .register:
return "{{ REGISTER }}"
case .login:
return "{{ LOGIN}}"
case .logout:
return "{{ LOGOUT }}"
}
}
var method: Moya.Method {
switch self {
case .register,
.login,
.logout:
return .post
}
}
var sampleData: Data {
return Data()
}
var task: Task {
switch self {
case .register(let parameters),
.login(let parameters),
.logout(let parameters):
return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
}
}
var headers: [String: String]? {
return ["Accept": "application/json"]
}
var authTokenType: AuthHeaderType {
switch self {
case .login:
return .basic
case .register,
.logout:
return .bearer
}
}
}
```
## Request
- request
```Swift
Network.request(UserApi.login(["username": "{{ USERNAME }}", "password": "{{ PASSWORD }}"])).subscribe(onNext: {(response) in
debugPrint(response)
}, onError: { (error) in
debugPrint(error)
}).disposed(by: bag)
```
- network check
```Swift
Network.available() -> Bool // true if netowk available
```
## Response
- response model
```swift
var shouldTokenRefresh = false // true if your token out of date and you need to refresh token
var response: Any? // your response data
var message: String? // error message
var success = true // true if your request successfully completed
```
## For token based life cycle
- if custom authorization header
```Swift
Authorize.customHeader {get set}
```
- get access token
```Swift
Authorize.accessToken {get}
```
- get refresh token
```Swift
Authorize.refreshToken {get}
```
- get authorize model
```Swift
Authorize.authorizeModel { get }
```
- set access token with client id and client secret
```Swift
Authorize.setAccessToken(_ clientId: String, clientSecret: String) -> Bool
```
- set accesstoken with token string
```Swift
Authorize.setAccessToken(_ token: String) -> Bool
```
- clear all authorize saved data
```Swift
Authorize.clearSavedData() -> Bool
```
- update authorize model
```Swift
Authorize.updateAuthorize(_ authorize: AuthorizeModel) -> Bool
```
- update authorize model with json
```Swift
Authorize.updateAuthorize(_ authorize: [String: Any]) -> Bool
```
DESC
s.homepage = 'https://github.com/mohansinghthagunna/CreatuNetwork'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'mohansinghthagunna' => 'mohansingh_thagunna@outlook.com' }
s.source = { :git => 'https://github.com/mohansinghthagunna/CreatuNetwork.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/sngmon'
s.ios.deployment_target = '10.0'
s.swift_version = '4.0'
s.source_files = 'CreatuNetwork/**/*'
# s.resource_bundles = {
# 'CreatuNetwork' => ['CreatuNetwork/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
s.dependency "RxSwift"
s.dependency "RxCocoa"
s.dependency "Moya/RxSwift"
s.dependency "ReachabilitySwift"
end