robotoworks / mechanoid

Eclipse plugin providing a set of DSL's for the rapid development of Android apps
58 stars 26 forks source link

dynamic url for MecheNet #223

Closed hannesa2 closed 10 years ago

hannesa2 commented 10 years ago

I've to communicate with an service like

http://server.com/dir/1.js
http://server.com/dir/2.js
..
http://server.com/dir/any-number.js

Problem 1: MechNet can't handle leading numbers

get getVal /api/1.js {
    response {
        created:String,
        ...
    }
}

to fix Problem1, Problem 2 is blocking: the url is not changeable during runtime, how to change PATH ?:

public class GetValRequest extends ServiceRequest {

    private static String PATH = "/api/x1.js";  
    … 
    @Override
    public String createUrl(String baseUrl){
        Uri.Builder uriBuilder = Uri.parse(baseUrl + PATH).buildUpon(); 
        return uriBuilder.toString();           
    }
}

The best would be a solution for problem2, but I see one workaround: can MechNet use a local file for source ? eg

client MyClient „file://temp/dir" {
    get getVal /tempfile.tmp {
        response {
            created:String,
            ...
        }
    }
fluxtah commented 10 years ago

Hi, as a workaround you could define the last part as a segment:

get getVal /api/resource_name:String {
    response {
        created:String
    }
}

then just pass in "1.js" as the segment during construction of the request.

Also it is possible to override the construction of the URL for:

public class GetValRequest extends ServiceRequest {

    private static String PATH = "/api/x1.js";  
… 
    @Override
    public String createUrl(String baseUrl){
        Uri.Builder uriBuilder = Uri.parse(baseUrl + PATH).buildUpon(); 
        return uriBuilder.toString();           
    }
}

Just subclass AdaptedGetValRequest extends GetVallRequest and override createUrl(...).

hannesa2 commented 10 years ago

awesome !

get getVal /api/resource_name:String {

is perfect for me.

Thank you !