methods of same group are contained in same file

This commit is contained in:
Ivan Smolin 2017-06-20 19:41:48 +03:00
parent 9192487cee
commit 8bfcf89e59
3 changed files with 29 additions and 26 deletions

View File

@ -1,26 +0,0 @@
{%- import 'utils.twig' as utils -%}
{%- set bodyParamName = utils.decapitalize(bodyType.type.typeName) -%}
{%- set funcName = utils.decapitalize(name) -%}
import LeadKit
import RxSwift
import Alamofire
extension NetworkService {
/// {{ description }}
func {{ funcName }}({{ bodyParamName }}: {{ bodyType.type.typeName }},
encoding: ParameterEncoding = URLEncoding.default,
headers: HTTPHeaders? = nil) -> Single<{{ responseType.type.typeName }}> {
let parameters = ApiRequestParameters(url: "{{ url }}",
method: .post,
parameters: {{ bodyParamName }}.toJSON(),
encoding: encoding,
headers: headers)
return rxRequest(with: parameters).map { $0.model }.asSingle()
}
}

11
Swift/Methods.swift.twig Normal file
View File

@ -0,0 +1,11 @@
import LeadKit
import RxSwift
import Alamofire
extension NetworkService {
{% for method in methods %}
{%- include 'blocks/method/method-func.twig' with { method: method } %}
{% endfor %}
}

View File

@ -0,0 +1,18 @@
{%- import '../../utils.twig' as utils -%}
{%- set bodyParamName = utils.decapitalize(method.bodyType.type.typeName) -%}
{%- set funcName = utils.decapitalize(method.name) -%}
/// {{ description }}
func {{ funcName }}({{ bodyParamName }}: {{ method.bodyType.type.typeName }},
encoding: ParameterEncoding = URLEncoding.default,
headers: HTTPHeaders? = nil) -> Single<{{ method.responseType.type.typeName }}> {
let parameters = ApiRequestParameters(url: "{{ method.url }}",
method: .post,
parameters: {{ bodyParamName }}.toJSON(),
encoding: encoding,
headers: headers)
return rxRequest(with: parameters).map { $0.model }.asSingle()
}