ZnUrl: Add multiple segment string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

ZnUrl: Add multiple segment string

Sean P. DeNigris
Administrator
What's the best way to do the following (non-working):
aZnUrl / 'path/segment/string'.

Ways I thought of:
- Ugly: (url asString, 'path/segment/string') asZnUrl.
- Non-working: #addPathSegment:
- Tedious: url / 'path' / 'segment' / 'string'

It seems like a common-enough thing to do, but I couldn't find a way that I liked...

Thanks,
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sven Van Caekenberghe-2
Hi Sean,

On 28 Feb 2013, at 16:08, Sean P. DeNigris <[hidden email]> wrote:

> What's the best way to do the following (non-working):
> aZnUrl / 'path/segment/string'.
>
> Ways I thought of:
> - Ugly: (url asString, 'path/segment/string') asZnUrl.
> - Non-working: #addPathSegment:
> - Tedious: url / 'path' / 'segment' / 'string'
>
> It seems like a common-enough thing to do, but I couldn't find a way that I
> liked...
>
> Thanks,
> Sean

I am guessing you are lazy and want to type as little as possible, then the following are possible:

'http://endpoint.service.com:9090/v1' asZnUrl
        withPathSegments: '/foo/bar/resource.txt' asZnUrl pathSegments.
       
'http://endpoint.service.com:9090/v1' asZnUrl / #foo / #bar / 'resource.txt'.

'http://endpoint.service.com:9090/v1' asZnUrl
        withPathSegments: #(foo bar 'resource.txt').

There is an important difference between the internal and external representation of URL elements, #asZnUrl actually parses:

'http://endpoint.service.com:9090/v1' asZnUrl
        withPathSegments: '/foo%20bar' asZnUrl pathSegments.
       
'http://endpoint.service.com:9090/v1' asZnUrl / 'foo bar'.

ZnUrl is not a general URL construction packages, the #/ #? and #? that I added for you help a bit, but they are limited.

There is also #inContextOf:
 
'/foo/bar/resource.txt' asZnUrl
        inContextOf: 'http://endpoint.service.com:9090/v1' asZnUrl

but that does not merge paths (the v1 part is gone in the last expression).
Maybe we could think about  an algorithm or semantics to do path merging.

Regards,

Sven

--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sean P. DeNigris
Administrator
Sven Van Caekenberghe-2 wrote
I am guessing you are lazy and want to type as little as possible
You know me too well ;)

Sven Van Caekenberghe-2 wrote
'http://endpoint.service.com:9090/v1' asZnUrl
        withPathSegments: '/foo/bar/resource.txt' asZnUrl pathSegments.
I like this one the best for now, as I didn't want to break up the string, to make it easier to change.

Sven Van Caekenberghe-2 wrote
       
'http://endpoint.service.com:9090/v1' asZnUrl
        withPathSegments: #(foo bar 'resource.txt').
How about a double dispatch under the covers of withPathSegments:, which does the current behavior for OrderedCollection; and for String, do something like "self findTokens: '/'." and pass that as the argument to withPathSegments:?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sven Van Caekenberghe-2
Hi Sean,

On 28 Feb 2013, at 23:31, Sean P. DeNigris <[hidden email]> wrote:

> Sven Van Caekenberghe-2 wrote
>> I am guessing you are lazy and want to type as little as possible
>
> You know me too well ;)
>
>
> Sven Van Caekenberghe-2 wrote
>> 'http://endpoint.service.com:9090/v1' asZnUrl
>> withPathSegments: '/foo/bar/resource.txt' asZnUrl pathSegments.
>
> I like this one the best for now, as I didn't want to break up the string,
> to make it easier to change.
>
>
> Sven Van Caekenberghe-2 wrote
>>
>> 'http://endpoint.service.com:9090/v1' asZnUrl
>> withPathSegments: #(foo bar 'resource.txt').
>
> How about a double dispatch under the covers of withPathSegments:, which
> does the current behavior for OrderedCollection; and for String, do
> something like "self findTokens: '/'." and pass that as the argument to
> withPathSegments:?

I didn't forget about you ;-)

So here is what I did in the latest version of Zinc-Resource-Meta (ConfigurationOfZincHTTPComponents project bleedingEdge load):

------
Change the implementation of ZnUrl>>#/ to do a double-dispatch on its argument using #addedToZnUrl:
Implemented #addedToZnUrl: on Collection, String and ZnUrl with the added feature that a String is split into path elements on $/ using #findTokens: - Do note that this is an internal path representation, not an encoded external representation.
Extended unit tests to cover the new functionality
------

Basically you can now do any of the following:

| baseUrl |

baseUrl := 'http://api.host.com' asZnUrl.

baseUrl / 'doc' / 'file.html'.
baseUrl / 'doc/file.html'.
baseUrl / #( 'doc' 'file.html' ).
baseUrl / 'doc/file.html' asZnUrl.

And they are all equivalent, except for the subtle difference noted in the commit message above.

What do you think ?

Regards,

Sven

--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

stephane ducasse
may be this is stupid but I still say it :)

This is cool and in fact may be having the interface than FS would be really cool :)

> ------
> Change the implementation of ZnUrl>>#/ to do a double-dispatch on its argument using #addedToZnUrl:
> Implemented #addedToZnUrl: on Collection, String and ZnUrl with the added feature that a String is split into path elements on $/ using #findTokens: - Do note that this is an internal path representation, not an encoded external representation.
> Extended unit tests to cover the new functionality
> ------
>
> Basically you can now do any of the following:
>
> | baseUrl |
>
> baseUrl := 'http://api.host.com' asZnUrl.
>
> baseUrl / 'doc' / 'file.html'.
> baseUrl / 'doc/file.html'.
> baseUrl / #( 'doc' 'file.html' ).
> baseUrl / 'doc/file.html' asZnUrl.
>
> And they are all equivalent, except for the subtle difference noted in the commit message above.
>
> What do you think ?
>
> Regards,
>
> Sven
>
> --
> Sven Van Caekenberghe
> http://stfx.eu
> Smalltalk is the Red Pill
>
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sven Van Caekenberghe-2

On 17 Mar 2013, at 17:55, stephane ducasse <[hidden email]> wrote:

> may be this is stupid but I still say it :)
>
> This is cool and in fact may be having the interface than FS would be really cool :)

Thanks, we all do continuous little improvements in our part of the Pharo ecosystem, together we are moving forward at an ever accelerating pace.

Yes, I think AbstractFileReference>>#/ could probably be extended in a similar way, but I am no FileSystem expert...

>> ------
>> Change the implementation of ZnUrl>>#/ to do a double-dispatch on its argument using #addedToZnUrl:
>> Implemented #addedToZnUrl: on Collection, String and ZnUrl with the added feature that a String is split into path elements on $/ using #findTokens: - Do note that this is an internal path representation, not an encoded external representation.
>> Extended unit tests to cover the new functionality
>> ------
>>
>> Basically you can now do any of the following:
>>
>> | baseUrl |
>>
>> baseUrl := 'http://api.host.com' asZnUrl.
>>
>> baseUrl / 'doc' / 'file.html'.
>> baseUrl / 'doc/file.html'.
>> baseUrl / #( 'doc' 'file.html' ).
>> baseUrl / 'doc/file.html' asZnUrl.
>>
>> And they are all equivalent, except for the subtle difference noted in the commit message above.
>>
>> What do you think ?
>>
>> Regards,
>>
>> Sven
>>
>> --
>> Sven Van Caekenberghe
>> http://stfx.eu
>> Smalltalk is the Red Pill
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sean P. DeNigris
Administrator
In reply to this post by Sven Van Caekenberghe-2
Sven Van Caekenberghe-2 wrote
So here is what I did in the latest version of Zinc-Resource-Meta (ConfigurationOfZincHTTPComponents project bleedingEdge load):
Sounds great, but #addedToZnUrl: does not exist after loading bleeding edge... maybe the config at http://www.squeaksource.com/MetacelloRepository needs to be updated?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sean P. DeNigris
Administrator
In reply to this post by Sven Van Caekenberghe-2
Sven Van Caekenberghe-2 wrote
Yes, I think AbstractFileReference>>#/ could probably be extended in a similar way, but I am no FileSystem expert...
ref1 := '/' asFileReference / 'Users' / 'me'.
gives a FileReference with Path / 'Users' / 'me'

ref2 := '/' asFileReference / 'Users/me'.
gives a FileReference with Path / 'Users/me'

I use the second version all the time, and even though the internal path representation is different, it still "works" e.g. ref1 exists = ref2 exists
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Sven Van Caekenberghe-2
In reply to this post by Sean P. DeNigris
Hi Sean,

On 21 Mar 2013, at 15:34, "Sean P. DeNigris" <[hidden email]> wrote:

> Sven Van Caekenberghe-2 wrote
>> So here is what I did in the latest version of Zinc-Resource-Meta
>> (ConfigurationOfZincHTTPComponents project bleedingEdge load):
>
> Sounds great, but #addedToZnUrl: does not exist after loading bleeding
> edge... maybe the config at http://www.squeaksource.com/MetacelloRepository
> needs to be updated?

My 'canonical' repository is http://mc.stfx.eu/ZincHTTPComponents, but that should not make any difference (but I must admit it is a pain to keep all those repositories in sync).

You need

Name: Zinc-Resource-Meta-Core-SvenVanCaekenberghe.12
Author: SvenVanCaekenberghe
Time: 17 March 2013, 4:21:09.316 pm
UUID: d571a909-0d2b-4e26-b219-89d1bb5f2640

and

Name: Zinc-Resource-Meta-Tests-SvenVanCaekenberghe.8
Author: SvenVanCaekenberghe
Time: 17 March 2013, 4:24:02.237 pm
UUID: aee46c39-5c83-46e5-a7bc-c661f0bc5782

Sven


--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill


Reply | Threaded
Open this post in threaded view
|

Re: ZnUrl: Add multiple segment string

Ben Coman
In reply to this post by Sean P. DeNigris
Sean P. DeNigris wrote:

> Sven Van Caekenberghe-2 wrote
>  
>> Yes, I think AbstractFileReference>>#/ could probably be extended in a
>> similar way, but I am no FileSystem expert...
>>    
>
> ref1 := '/' asFileReference / 'Users' / 'me'.
> gives a FileReference with Path / 'Users' / 'me'
>
> ref2 := '/' asFileReference / 'Users/me'.
> gives a FileReference with Path / 'Users/me'
>
> I use the second version all the time, and even though the internal path
> representation is different, it still "works" e.g. ref1 exists = ref2 exists
>
>  
What about iterating through the parts of a path?    Does the following
produce output spread over lines the same way?  (I haven't used
FileSystem yet so treat this as pseudo-code...).
ref1 parts do: [ :pathPath | Transcript crShow: pathPart ]
Just wild speculation.... but it might be nice if the internal
representation of ref2 splits up on the separator. Haven't thought about
what might be the downside.

cheers -ben

>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/ZnUrl-Add-multiple-segment-string-tp4672728p4677657.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>
>