import opts
redef class Int
- fun android_path: String do return "drawable-{resolution_name}/icon.png"
-
+ # Android name for this resolution
fun resolution_name: String
do
if self == 36 then return "ldpi"
var opt_out = new OptionString("Where to output PNG files", "--out", "-o")
var opt_id = new OptionString("Extract only object with given ID", "--id", "-i")
var opt_android = new OptionBool("Generate in the file structure for Android", "--android", "-a")
+var opt_android_name = new OptionString("Name of the resource for Android", "--name", "-n")
var opt_large = new OptionBool("Generate large icons (512 and 1024 px)", "--large", "-l")
var opt_help = new OptionBool("Print this help message", "--help", "-h")
var opt_context = new OptionContext
-opt_context.add_option(opt_out, opt_id, opt_android, opt_large, opt_help)
+opt_context.add_option(opt_out, opt_id, opt_android, opt_android_name, opt_large, opt_help)
opt_context.parse(args)
var rest = opt_context.rest
resolutions = [512, 1024]
else abort
+var android_res_name = opt_android_name.value or else "icon"
+
for wh in resolutions do
var png_path
if opt_android.value then
- png_path = "{out_path}/{wh.android_path}"
+ png_path = out_path / "drawable-" + wh.resolution_name / android_res_name + ".png"
var dir = png_path.dirname
if not dir.file_exists then dir.mkdir
else
end
end
-# CURL HTTP Request
+# HTTP request builder
+#
+# The request itself is sent by either `execute` or `download_to_file`.
+# The attributes of this class must be set before calling either of these two methods.
+#
+# ## Minimal usage example
+#
+# ~~~
+# var request = new CurlHTTPRequest("http://example.org/")
+# var response = request.execute
+# if response isa CurlResponseSuccess then
+# print "Response status code: {response.status_code}"
+# print response.body_str
+# else if response isa CurlResponseFailed then
+# print_error response.error_msg
+# end
+# ~~~
class CurlHTTPRequest
super CurlRequest
super NativeCurlCallbacks
+ # Address of the remote resource to request
var url: String
- var datas: nullable HeaderMap is writable
+
+ # Data for the body of a POST request
+ var data: nullable HeaderMap is writable
+
+ # Header content of the request
var headers: nullable HeaderMap is writable
+
+ # Delegates to customize the behavior when running `execute`
var delegate: nullable CurlCallbacks is writable
# Set the user agent for all following HTTP requests
var user_agent: nullable String is writable
- # Execute HTTP request with settings configured through attribute
+ # Execute HTTP request
+ #
+ # By default, the response body is returned in an instance of `CurlResponse`.
+ # This behavior can be customized by setting a custom `delegate`.
fun execute: CurlResponse
do
if not self.curl.is_ok then return answer_failure(0, "Curl instance is not correctly initialized")
end
# Datas
- var datas = self.datas
- if datas != null then
- var postdatas = datas.to_url_encoded(self.curl)
+ var data = self.data
+ if data != null then
+ var postdatas = data.to_url_encoded(self.curl)
err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
end
var my_http_fetcher = new MyHttpFetcher
request.delegate = my_http_fetcher
- var post_datas = new HeaderMap
- post_datas["Bugs Bunny"] = "Daffy Duck"
- post_datas["Batman"] = "Robin likes special characters @#ùà!è§'(\"é&://,;<>∞~*"
- post_datas["Batman"] = "Yes you can set multiple identical keys, but APACHE will consider only one, the last one"
- request.datas = post_datas
+ var post_data = new HeaderMap
+ post_data["Bugs Bunny"] = "Daffy Duck"
+ post_data["Batman"] = "Robin likes special characters @#ùà!è§'(\"é&://,;<>∞~*"
+ post_data["Batman"] = "Yes you can set multiple identical keys, but APACHE will consider only one, the last one"
+ request.data = post_data
var response = request.execute
print "Our body from the callback: {my_http_fetcher.fetched_body}"
class JsonPOST
super JsonCurlRequest
- var data: nullable Jsonable = null is writable
+ var json_data: nullable Jsonable = null is writable
redef fun init_headers do
super
var err = self.curl.native.easy_setopt(new CURLOption.post, true)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
- if self.data != null then
- var postdatas = self.data.to_json
+ if self.json_data != null then
+ var postdatas = self.json_data.to_json
err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
end
class JsonPUT
super JsonCurlRequest
- var data: nullable Jsonable = null is writable
+ var json_data: nullable Jsonable = null is writable
redef fun init_headers do
super
var err = self.curl.native.easy_setopt(new CURLOption.custom_request, "PUT")
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
- if self.data != null then
- var postdatas = self.data.to_json
+ if self.json_data != null then
+ var postdatas = self.json_data.to_json
err = self.curl.native.easy_setopt(new CURLOption.postfields, postdatas)
if not err.is_ok then return answer_failure(err.to_i, err.to_s)
end
# POST `params` to `url`
fun post(url: String, params: Jsonable): Jsonable do
var request = new JsonPOST(url)
- request.data = params
+ request.json_data = params
var response = request.execute
return parse_response(response)
end
# PUT `params` at `url`
fun put(url: String, params: Jsonable): Jsonable do
var request = new JsonPUT(url)
- request.data = params
+ request.json_data = params
var response = request.execute
return parse_response(response)
end
# request.headers["X-Stream"] = "true"
var json_jobs = new JsonArray
for job in jobs.values do json_jobs.add job.to_rest
- request.data = json_jobs
+ request.json_data = json_jobs
var response = request.execute
var res = client.parse_response(response)
return finalize_batch(res)
var props = self.model.get_mproperties_by_name(name)
if props == null then return null
var res: nullable MMethod = null
+ var recvtype = recv.intro.bound_mtype
for mprop in props do
assert mprop isa MMethod
- var intro = mprop.intro_mclassdef
- for mclassdef in recv.mclassdefs do
- if not self.in_importation.greaters.has(mclassdef.mmodule) then continue
- if not mclassdef.in_hierarchy.greaters.has(intro) then continue
- if res == null then
- res = mprop
- else if res != mprop then
- print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
- abort
- end
+ if not recvtype.has_mproperty(self, mprop) then continue
+ if res == null then
+ res = mprop
+ else if res != mprop then
+ print("Fatal Error: ambigous property name '{name}'; conflict between {mprop.full_name} and {res.full_name}")
+ abort
end
end
return res