NeoJSON Parsing Nested Objects

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

NeoJSON Parsing Nested Objects

Sean P. DeNigris
Administrator
I'm wrapping the Digital Ocean API. This particular response has a status, and an array of droplet sizes.

For example:
'{"status":"OK","sizes":[{"id":66,"name":"512MB","slug":"512mb","memory":512,"cpu":1,"disk":20,"cost_per_hour":0.00744,"cost_per_month":"5.0"},{"id":63,"name":"1GB","slug":"1gb","memory":1024,"cpu":1,"disk":30,"cost_per_hour":0.01488,"cost_per_month":"10.0"}]}'

As a start, I did:
        reader := NeoJSONReader on: jsonString readStream.
        reader for: DoResponse customDo: [ :m | m decoder: [ :dict |
                        DoResponse new
                                status: (dict at: 'status');
                                contents: (dict at: 'sizes') ] ].
        response := reader nextAs: DoResponse.
        response isOk ifFalse: [ self error: 'Query failed!' ].
        ^ response contents.

However, the size objects are still plain dictionaries. I'd like to convert them to DropletSize objects. And I'd rather leverage NeoJSON than implement a custom DropletSize fromDictionary: if possible.

What's the best way to handle this?

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

Re: NeoJSON Parsing Nested Objects

Sean P. DeNigris
Administrator
Sean P. DeNigris wrote
I'd like to convert them to DropletSize objects
Duh :-P

reader for: DoResponse do: [ :m |
                m mapInstVar: #status.
                (m mapInstVar: #contents to: #sizes) valueSchema: #ArrayOfDropletSizes ].
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: NeoJSON Parsing Nested Objects

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

On 09 Apr 2014, at 19:18, Sean P. DeNigris <[hidden email]> wrote:

> I'm wrapping the Digital Ocean API.

Cool !

Reply | Threaded
Open this post in threaded view
|

Re: NeoJSON Parsing Nested Objects

Esteban A. Maringolo
2014-04-09 14:56 GMT-03:00 Sven Van Caekenberghe <[hidden email]>:
>
> On 09 Apr 2014, at 19:18, Sean P. DeNigris <[hidden email]> wrote:
>
>> I'm wrapping the Digital Ocean API.
>
> Cool !

+1

I use it for my Pharo hosting too (plus a JIRA instance on other droplet).

Anybody using Supervisord or anything similar tool to "manage" pharo instances?

Regards!

Reply | Threaded
Open this post in threaded view
|

Re: NeoJSON Parsing Nested Objects

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

On 09 Apr 2014, at 19:28, Sean P. DeNigris <[hidden email]> wrote:

> Sean P. DeNigris wrote
>> I'd like to convert them to DropletSize objects
>
> Duh :-P
>
> reader for: DoResponse do: [ :m |
> m mapInstVar: #status.
> (m mapInstVar: #contents to: #sizes) valueSchema: #ArrayOfDropletSizes ].

BTW, I did some recent enhancements to NeoJSON mapping that could be interesting.

http://www.smalltalkhub.com/#!/~SvenVanCaekenberghe/Neo/commits

like #nextPut:as:
Reply | Threaded
Open this post in threaded view
|

Re: NeoJSON Parsing Nested Objects

Sean P. DeNigris
Administrator
In reply to this post by Esteban A. Maringolo
Esteban A. Maringolo wrote
>> I'm wrapping the Digital Ocean API.
> Cool !
+1
The embryo is alive. See documentation at http://smalltalkhub.com/#!/~SeanDeNigris/DigitalOcean

A few supported operations:
DoDroplet allActive.
DoDroplet allActive detect: [ :e | e name = 'mycooldomain.org' ].
DoDropletSize all.
DoDropletSize named: '512MB'
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: NeoJSON Parsing Nested Objects

Esteban A. Maringolo
It's basic but it works. :)

THanks sean!
Esteban A. Maringolo


2014-04-09 18:07 GMT-03:00 Sean P. DeNigris <[hidden email]>:

> Esteban A. Maringolo wrote
>>>> I'm wrapping the Digital Ocean API.
>>> Cool !
>> +1
>
> The embryo is alive. See documentation at
> http://smalltalkhub.com/#!/~SeanDeNigris/DigitalOcean
>
> A few supported operations:
> DoDroplet allActive.
> DoDroplet allActive detect: [ :e | e name = 'mycooldomain.org' ].
> DoDropletSize all.
> DoDropletSize named: '512MB'
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/NeoJSON-Parsing-Nested-Objects-tp4753695p4753749.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>