add static versions of methods, add base method for override request
This commit is contained in:
parent
c5afc6f33c
commit
6af656effd
|
|
@ -2,10 +2,20 @@ import LeadKit
|
|||
import RxSwift
|
||||
import Alamofire
|
||||
|
||||
extension NetworkService {
|
||||
{% set serviceName = concat(networkServiceName, "NetworkService") -%}
|
||||
|
||||
extension {{ serviceName }} {
|
||||
|
||||
{% for method in methods %}
|
||||
{%- include 'blocks/method/method-func.twig' with { method: method } %}
|
||||
{%- include 'blocks/method/method-func.twig' with { method: method, isStatic: false } %}
|
||||
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
extension Singleton where Self: {{ serviceName }} {
|
||||
|
||||
{% for method in methods %}
|
||||
{%- include 'blocks/method/method-func.twig' with { method: method, isStatic: true } %}
|
||||
|
||||
{% endfor %}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import LeadKit
|
||||
import RxSwift
|
||||
|
||||
{% set serviceName = concat(networkServiceName, "NetworkService") -%}
|
||||
class {{ serviceName }}: NetworkService, ConfigurableNetworkService {
|
||||
|
|
@ -11,5 +12,9 @@ class {{ serviceName }}: NetworkService, ConfigurableNetworkService {
|
|||
self.init(sessionManager: {{ serviceName }}.sessionManager)
|
||||
}
|
||||
|
||||
func apiRequest<T: ImmutableMappable>(with parameters: ApiRequestParameters) -> Single<T> {
|
||||
return rxRequest(with: parameters).map { $0.model }.asSingle()
|
||||
}
|
||||
|
||||
}
|
||||
{{ "\n" }}
|
||||
|
|
@ -11,15 +11,21 @@
|
|||
{%- set funcName = utils.decapitalize(method.name) -%}
|
||||
|
||||
/// {{ method.description }}
|
||||
func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ "\n " }}{%- endif -%}
|
||||
{{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ "\n " }}{%- endif -%}
|
||||
encoding: ParameterEncoding = URLEncoding.default,
|
||||
headers: HTTPHeaders? = nil) -> Single<{{ method.responseType.type.typeName }}> {
|
||||
|
||||
let parameters = ApiRequestParameters(url: "{{ method.url }}",
|
||||
{% if isStatic -%}
|
||||
return shared.{{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyParamName }},{{ "\n " }}{%- endif -%}
|
||||
encoding: encoding,
|
||||
headers: headers)
|
||||
{%- else %}
|
||||
let parameters = ApiRequestParameters(url: "{{ method.url }}",
|
||||
method: .{{ methodType }},
|
||||
parameters: {% if hasBody -%}{{ bodyParamName }}.toJSON(){%- else -%}nil{%- endif -%},
|
||||
encoding: encoding,
|
||||
headers: headers)
|
||||
|
||||
return rxRequest(with: parameters).map { $0.model }.asSingle()
|
||||
return apiRequest(with: parameters)
|
||||
{%- endif %}
|
||||
}
|
||||
Loading…
Reference in New Issue