Merge pull request #56 from TouchInstinct/feature/network_protocol
Feature/network protocol
This commit is contained in:
commit
2abb3050e0
|
|
@ -2,9 +2,9 @@ import LeadKit
|
|||
import RxSwift
|
||||
import Alamofire
|
||||
|
||||
{% set serviceName = concat(networkServiceName, "NetworkService") -%}
|
||||
{% set protocolName = concat(networkServiceName, "NetworkProtocol") -%}
|
||||
|
||||
extension {{ serviceName }} {
|
||||
extension {{ protocolName }} {
|
||||
|
||||
{% for method in methods %}
|
||||
{%- include 'blocks/method/method-func.twig' with { method: method, isStatic: false } %}
|
||||
|
|
@ -12,11 +12,11 @@ extension {{ serviceName }} {
|
|||
{% endfor %}
|
||||
}
|
||||
|
||||
extension Singleton where Self: {{ serviceName }} {
|
||||
extension Singleton where Self: {{ protocolName }} {
|
||||
|
||||
{% for method in methods %}
|
||||
{%- include 'blocks/method/method-func.twig' with { method: method, isStatic: true } %}
|
||||
|
||||
|
||||
{% endfor %}
|
||||
}
|
||||
{{ "\n" }}
|
||||
{{ "\n" }}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,23 @@ import RxSwift
|
|||
import Alamofire
|
||||
|
||||
{% set serviceName = concat(networkServiceName, "NetworkService") -%}
|
||||
class {{ serviceName }}: NetworkService {
|
||||
{% set protocolName = concat(networkServiceName, "NetworkProtocol") -%}
|
||||
|
||||
protocol {{ protocolName }} {
|
||||
|
||||
func apiRequest<T: Decodable>(with parameters: ApiRequestParameters, decoder: JSONDecoder) -> Single<T>
|
||||
func apiRequestParameters(relativeUrl: String,
|
||||
method: HTTPMethod,
|
||||
parameters: Parameters?,
|
||||
requestEncoding: ParameterEncoding?,
|
||||
requestHeaders: HTTPHeaders?) -> ApiRequestParameters
|
||||
|
||||
{% for method in methods %}
|
||||
{%- include 'blocks/method/method-declaration.twig' with { method: method, isStatic: false } -%}
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
class {{ serviceName }}: NetworkService, {{ protocolName }} {
|
||||
|
||||
static let apiBaseUrl = "{{ apiUrl }}"
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
{%- import '../../macroses/common.utils.twig' as utils -%}
|
||||
|
||||
{%- if (method.bodyType is not null) -%}
|
||||
{%- set bodyParamName = utils.decapitalize(method.bodyType.type.typeName) -%}
|
||||
{%- set bodyTypeName = method.bodyType.type.typeName -%}
|
||||
|
||||
{%- set hasBody = true -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- set funcName = utils.decapitalize(method.name) -%}
|
||||
|
||||
{{ isStatic ? "static " : "" }}func {{ funcName }}({%- if hasBody -%}{{ bodyParamName }}: {{ bodyTypeName }},{{ " " }}{%- endif -%}requestEncoding: ParameterEncoding?, requestHeaders: HTTPHeaders?) -> Single<{{ method.responseType.type.typeName }}>
|
||||
|
|
@ -26,6 +26,6 @@
|
|||
requestEncoding: requestEncoding,
|
||||
requestHeaders: requestHeaders)
|
||||
|
||||
return apiRequest(with: parameters)
|
||||
return apiRequest(with: parameters, decoder: JSONDecoder())
|
||||
{%- endif %}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue