Last active
December 21, 2015 04:29
-
-
Save LeiHao0/8b31ffc56de0a6157ffc to your computer and use it in GitHub Desktop.
Auto Generator FlooNetwork Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $url = "api/show" | |
| $prefix = "TF" | |
| def className | |
| refineStr = $url.gsub("api", '') | |
| a , b = refineStr.split('/') | |
| return $prefix + a.capitalize + b.capitalize | |
| end | |
| def requestName | |
| className + "Request" | |
| end | |
| def fileName | |
| requestName + ".swift" | |
| end | |
| def requestGenerator | |
| commentStr = """// | |
| // #{fileName} | |
| // | |
| // Created by HaoLei on 12/17/15. | |
| // Copyright © 2015. All rights reserved. | |
| // Model file Generated using FlooNetworkRequestGenerator: https://gist.github.com/Artwalk/8b31ffc56de0a6157ffc | |
| // | |
| """ | |
| importStr = ''' | |
| import Foundation | |
| import FlooNetwork | |
| ''' | |
| classStr = """ | |
| public class #{requestName} : FLRequestType, FLRequestClientAuthType { | |
| public let url = #$url | |
| public let completion : FLRequestCompletion? | |
| public let httpMethod = FLHttpMethod.Get | |
| public let objectType:Any = #{className}.self | |
| public init(completion:FLRequestCompletion?) { | |
| self.completion = completion | |
| } | |
| } | |
| """ | |
| tempateStr = commentStr + importStr + classStr | |
| return tempateStr | |
| end | |
| def fileGenerator | |
| name = fileName | |
| f = File.open(name, "w") { |f| f.write(requestGenerator) } | |
| end | |
| if ARGV[0] != nil | |
| $url = ARGV[0] | |
| end | |
| if ARGV[1] != nil | |
| $prefix = ARGV[1] | |
| end | |
| fileGenerator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment