Pharo-users
By thread
pharo-users@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
December 2017
- 83 participants
- 547 messages
Re: [Pharo-users] Zinc JSON parsing error handling
by Norbert Hartl
To make your core a little bit more reliable you should not catch the general error but a NeoJSONParseError. And you need to guard the dictionary access. There is no guarantee you get something back that inlcudes key success and message.
Norbert
> Am 13.12.2017 um 09:54 schrieb Ben Coman <btc(a)openinworld.com>:
>
> hi Sven,
>
>> > On 13 Dec 2017, at 07:59, Ben Coman <btc(a)openinworld.com> wrote:
>> >
>> >
>> > With...
>> > Object subclass: #BittrexResponse
>> > instanceVariableNames: 'success message result'
>> > classVariableNames: ''
>> > package: 'Bittrex'
>> >
>> > Object subclass: #BittrexMarketSummary
>> > instanceVariableNames: 'MarketName High Low Volume Last
>> > BaseVolume TimeStamp Bid Ask OpenBuyOrders
>> > OpenSellOrders PrevDay Created DisplayMarketName'
>> > classVariableNames: ''
>> > package: 'Bittrex'
>> >
>> > this code works great when the response holds good data...
>> > ZnClient new
>> > url: 'https://bittrex.com/api/v1.1/public/getmarketSummary?market=BTC-LTC';
>> > enforceHttpSuccess: true;
>> > accept: ZnMimeType applicationJson;
>> > contentReader: [ :entity | |reader|
>> > reader := (NeoJSONReader on: entity readStream).
>> > reader for: BittrexResponse do: [:m|
>> > m mapInstVar: #success.
>> > m mapInstVar: #message.
>> > (m mapInstVar: #result) valueSchema: #ResultArray].
>> > reader for: #ResultArray customDo: [ :mapping |
>> > mapping listOfElementSchema: BittrexMarketSummary ].
>> > reader mapInstVarsFor: BittrexMarketSummary.
>> > reader nextAs: BittrexResponse ];
>> > get.
>> >
>> > i.e. a raw response looking like this....
>> > (ZnClient new
>> > url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-LTC';
>> > get) inspect.
>> > ==> "'{""success"":true,""message"":"",""result"":[{""MarketName"":""BTC-LTC"",""High"":0.01982450,""Low"":0.01285257,""Volume"":1436429.81313360,""Last"":0.01842000,""BaseVolume"":24841.17217724,""TimeStamp"":""2017-12-13T05:56:25.937"",""Bid"":0.01840001,""Ask"":0.01842000,""OpenBuyOrders"":10140,""OpenSellOrders"":6306,""PrevDay"":0.01439800,""Created"":""2014-02-13T00:00:00""}]}'"
>> >
>> >
>> > But for bad response looking like this...
>> > (ZnClient new
>> > url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=INVALID';
>> > get) inspect.
>> > ==> {"success":false,"message":"INVALID_MARKET","result":null}
>> >
>> > the JSON handling code fails deep in the call stack with an error
>> > "NeoJSONParseError: [ expected"
>> > which is not so friendly for users of the Bittrex library.
>> >
>> > What are the different/recommended approaches with Zinc
>> > for catching JSON errors such that I can pass "message"
>> > as a higher level Error up the stack to the Bittrex user.
>> >
>> > cheers -ben
>
>
>> On 13 December 2017 at 15:37, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>> BTW, this is no about Zinc, but about NeoJSON.
>>
>> This is what I meant with variability that is hard to capture with a simple static type schema.
>>
>> I have no time to try myself right now, but a custom mapping for ivar result (as in a block) might be able to see the difference and act accordingly.
>
>
> okay. So I played around tracing this through the debugger and for anyone else
> with a similar need later, I ended up with the following...
>
> response := (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getticker?market=INVALID';
> enforceHttpSuccess: true;
> accept: ZnMimeType applicationJson;
> contentReader:
> [ :entity |
> [ |reader|
> reader := (NeoJSONReader on: entity readStream).
> reader for: BittrexResponse do:
> [:m|
> m mapInstVar: #success.
> m mapInstVar: #message.
> (m mapInstVar: #result) valueSchema: BittrexTicker
> ].
> reader mapInstVarsFor: BittrexTicker.
> reader nextAs: BittrexResponse
> ] on: Error do:
> [ :err | |json|
> json := NeoJSONReader fromString: entity contents.
> (json at: 'success')
> ifFalse: [ self error: (json at: 'message') ]
> ifTrue: [ self error: 'UKNOWN ERROR' ]
> ]
> ]) get.
>
>
> for which I get a nice pre-debug window titled "Error: INVALID_MARKET"
>
> cheers -ben
>
Dec. 13, 2017
Re: [Pharo-users] Zinc JSON parsing error handling
by Ben Coman
hi Sven,
> On 13 Dec 2017, at 07:59, Ben Coman <btc(a)openinworld.com> wrote:
> >
> >
> > With...
> > Object subclass: #BittrexResponse
> > instanceVariableNames: 'success message result'
> > classVariableNames: ''
> > package: 'Bittrex'
> >
> > Object subclass: #BittrexMarketSummary
> > instanceVariableNames: 'MarketName High Low Volume Last
> > BaseVolume TimeStamp Bid Ask OpenBuyOrders
> > OpenSellOrders PrevDay Created DisplayMarketName'
> > classVariableNames: ''
> > package: 'Bittrex'
> >
> > this code works great when the response holds good data...
> > ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarketSummary?
> market=BTC-LTC';
> > enforceHttpSuccess: true;
> > accept: ZnMimeType applicationJson;
> > contentReader: [ :entity | |reader|
> > reader := (NeoJSONReader on: entity readStream).
> > reader for: BittrexResponse do: [:m|
> > m mapInstVar: #success.
> > m mapInstVar: #message.
> > (m mapInstVar: #result) valueSchema: #ResultArray].
> > reader for: #ResultArray customDo: [ :mapping |
> > mapping listOfElementSchema: BittrexMarketSummary
> ].
> > reader mapInstVarsFor: BittrexMarketSummary.
> > reader nextAs: BittrexResponse ];
> > get.
> >
> > i.e. a raw response looking like this....
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?
> market=BTC-LTC';
> > get) inspect.
> > ==> "'{""success"":true,""message"":"",""result"":[{""
> MarketName"":""BTC-LTC"",""High"":0.01982450,""Low"":0.
> 01285257,""Volume"":1436429.81313360,""Last"":0.01842000,"
> "BaseVolume"":24841.17217724,""TimeStamp"":""2017-12-13T05:
> 56:25.937"",""Bid"":0.01840001,""Ask"":0.01842000,""
> OpenBuyOrders"":10140,""OpenSellOrders"":6306,""PrevDay"":0.01439800,""
> Created"":""2014-02-13T00:00:00""}]}'"
> >
> >
> > But for bad response looking like this...
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?
> market=INVALID';
> > get) inspect.
> > ==> {"success":false,"message":"INVALID_MARKET","result":null}
> >
> > the JSON handling code fails deep in the call stack with an error
> > "NeoJSONParseError: [ expected"
> > which is not so friendly for users of the Bittrex library.
> >
> > What are the different/recommended approaches with Zinc
> > for catching JSON errors such that I can pass "message"
> > as a higher level Error up the stack to the Bittrex user.
> >
> > cheers -ben
>
On 13 December 2017 at 15:37, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
> BTW, this is no about Zinc, but about NeoJSON.
>
> This is what I meant with variability that is hard to capture with a
> simple static type schema.
>
> I have no time to try myself right now, but a custom mapping for ivar
> result (as in a block) might be able to see the difference and act
> accordingly.
okay. So I played around tracing this through the debugger and for anyone
else
with a similar need later, I ended up with the following...
response := (ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getticker?market=INVALID';
enforceHttpSuccess: true;
accept: ZnMimeType applicationJson;
contentReader:
[ :entity |
[ |reader|
reader := (NeoJSONReader on: entity readStream).
reader for: BittrexResponse do:
[:m|
m mapInstVar: #success.
m mapInstVar: #message.
(m mapInstVar: #result) valueSchema: BittrexTicker
].
reader mapInstVarsFor: BittrexTicker.
reader nextAs: BittrexResponse
] on: Error do:
[ :err | |json|
json := NeoJSONReader fromString: entity contents.
(json at: 'success')
ifFalse: [ self error: (json at: 'message') ]
ifTrue: [ self error: 'UKNOWN ERROR' ]
]
]) get.
for which I get a nice pre-debug window titled "Error: INVALID_MARKET"
cheers -ben
Dec. 13, 2017
Re: [Pharo-users] REST client hints
by Ben Coman
>
>
> > > On 13 Dec 2017, at 05:37, Ben Coman <btc(a)openinworld.com> wrote:
> > >
> > > Hi Sven (et al),
> > >
> > > On 10 December 2017 at 11:45, Ben Coman <btc(a)openinworld.com> wrote:
> > >
> > > 3. Finally parse into real objects the nested level holding the data
> you really want...
> > >
> > > Object subclass: #Market
> > > instanceVariableNames: 'MarketCurrency BaseCurrency
> MarketCurrencyLong BaseCurrencyLong MinTradeSize MarketName IsActive
> Created Notice IsSponsored LogoUrl'
> > > classVariableNames: ''
> > > package: 'Bittrex'
> > >
> > > (ZnClient new
> > > url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> > > enforceHttpSuccess: true;
> > > accept: ZnMimeType applicationJson;
> > > contentReader: [ :entity | |reader|
> > > reader := (NeoJSONReader on: entity readStream).
> > > reader for: BittrexResponse do: [:m|
> > > m mapInstVar: #success.
> > > m mapInstVar: #message.
> > > (m mapInstVar: #result) valueSchema:
> #ArrayOfMarkets].
> > > reader for: #ArrayOfMarkets customDo: [ :mapping |
> mapping listOfElementSchema: Market ].
> > > reader mapInstVarsFor: Market.
> > > reader nextAs: BittrexResponse ];
> > > get) inspect.
> > >
> > > ==>BittrexResponse
> > > success => true
> > > message => ''
> > > result => an Array(a Market(LTC) a Market(DOGE) a Market(VTC) a
> Market(PPC) a Market(FTC) a Market(RDD)
> > > ... Market(POWR) a Market(BTG) a Market(BTG) a Market(BTG) a
> Market(ADA) a Market(ENG) a Market(ENG))
> > >
> > > So the code of [3.] above works fine when the raw response looks like
> this...
> > > (ZnClient new
> > > url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> > > get) inspect.
> > > ==> {"success":true,
> > > "message":"",
> > > "result": [{"MarketName":"BTC-LTC},{"MarketName":"BTC-NXT}]
> > > }
> > >
> > > But of course [3.] doesn't work when the raw response looks like
> this...
> > > (ZnClient new
> > > url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-
> LTC';
> > > get) inspect.
> > > ==> {"success":true,
> > > "message":"",
> > > "result":{"Bid":0.01765465,"Ask":0.01769000,"Last":0.
> 01763350}
> > > }
> > >
> > > since result is a json-object not a json-array. But I can't work out
> > > how to map the JSON object into the 'result' instance variable of
> BittrexResponse,
> > > where...
> > >
> > > BittrexObject subclass: #BittrexTicker
> > > instanceVariableNames: 'Bid Ask Last'
> > > classVariableNames: ''
> > > package: 'Bittrex'
> > >
> > >
> > > My best guesses so far are uncommenting either [A.] or [B.] below...
> > >
> > > (ZnClient new
> > > url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-
> LTC';
> > > enforceHttpSuccess: true;
> > > accept: ZnMimeType applicationJson;
> > > contentReader: [ :entity | |reader|
> > > reader := (NeoJSONReader on: entity readStream).
> > > reader for: BittrexResponse do: [:m|
> > > m mapInstVar: #success.
> > > m mapInstVar: #message.
> > > (m mapInstVar: #result) valueSchema:
> #BittrexTicker].
> > > "A. reader for: BittrexTicker do: [ :m|
> > > m mapInstVar: #Bid]."
> > > "B. reader for: #BittrexTicker customDo: [ :mapping |
> > > mapping mapWithValueSchema: BittrexTicker]."
> > > reader nextAs: BittrexResponse ];
> > > get).
> > >
> > >
> > > Can you advise what formulation is required?
>
>
> On 13 December 2017 at 15:33, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
>
>>
>>
>> > On 13 Dec 2017, at 07:49, Ben Coman <btc(a)openinworld.com> wrote:
>> >
>> >
>> >
>> > On 13 December 2017 at 14:40, Sven Van Caekenberghe <sven(a)stfx.eu>
>> wrote:
>> > Yeah, that is the main problem with JSON. It cannot capture that
>> variability in its own spec. Sure, there are tons of extensions on top of
>> JSON to address these aspects, but NeoJSON only deals with the raw spec.
>> And any server can use its own version.
>> >
>> > Simple answer is indeed: getmarkets and getticker return different
>> schema, since you know what you call, you can map accordingly. (And hope
>> the server does not do further variability). There cannot be one global
>> mapping.
>> >
>> >
>> > Thats cool. I'm not looking for one global mapping to simultaneously
>> handle getmarkets and getticker together.
>> > I'm just looking to handle getticker in isolation. I can't work that
>> part out.
>>
>> Hmm, your result ivar in response is of type ticker which maps its 3
>> ivars. So uncomment A but add all 3 ivars to ticker. no ?
>
>
Thats what I gathered from the test examples (and [B.] was really grasping
at straws.)
I just assumed my understanding was lacking.
Attacking it with renewed confidence from your response,
tracing through I found the problem was the line before [A.] should have
been....
(m mapInstVar: #result) valueSchema: BittrexTicker].
not
(m mapInstVar: #result) valueSchema: #BittrexTicker].
now it works.
thanks for your assistance.
cheers -ben
Dec. 13, 2017
Re: [Pharo-users] Zinc JSON parsing error handling
by Sven Van Caekenberghe
BTW, this is no about Zinc, but about NeoJSON.
This is what I meant with variability that is hard to capture with a simple static type schema.
I have no time to try myself right now, but a custom mapping for ivar result (as in a block) might be able to see the difference and act accordingly.
> On 13 Dec 2017, at 07:59, Ben Coman <btc(a)openinworld.com> wrote:
>
>
> With...
> Object subclass: #BittrexResponse
> instanceVariableNames: 'success message result'
> classVariableNames: ''
> package: 'Bittrex'
>
> Object subclass: #BittrexMarketSummary
> instanceVariableNames: 'MarketName High Low Volume Last
> BaseVolume TimeStamp Bid Ask OpenBuyOrders
> OpenSellOrders PrevDay Created DisplayMarketName'
> classVariableNames: ''
> package: 'Bittrex'
>
> this code works great when the response holds good data...
> ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getmarketSummary?market=BTC-LTC';
> enforceHttpSuccess: true;
> accept: ZnMimeType applicationJson;
> contentReader: [ :entity | |reader|
> reader := (NeoJSONReader on: entity readStream).
> reader for: BittrexResponse do: [:m|
> m mapInstVar: #success.
> m mapInstVar: #message.
> (m mapInstVar: #result) valueSchema: #ResultArray].
> reader for: #ResultArray customDo: [ :mapping |
> mapping listOfElementSchema: BittrexMarketSummary ].
> reader mapInstVarsFor: BittrexMarketSummary.
> reader nextAs: BittrexResponse ];
> get.
>
> i.e. a raw response looking like this....
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-LTC';
> get) inspect.
> ==> "'{""success"":true,""message"":"",""result"":[{""MarketName"":""BTC-LTC"",""High"":0.01982450,""Low"":0.01285257,""Volume"":1436429.81313360,""Last"":0.01842000,""BaseVolume"":24841.17217724,""TimeStamp"":""2017-12-13T05:56:25.937"",""Bid"":0.01840001,""Ask"":0.01842000,""OpenBuyOrders"":10140,""OpenSellOrders"":6306,""PrevDay"":0.01439800,""Created"":""2014-02-13T00:00:00""}]}'"
>
>
> But for bad response looking like this...
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=INVALID';
> get) inspect.
> ==> {"success":false,"message":"INVALID_MARKET","result":null}
>
> the JSON handling code fails deep in the call stack with an error
> "NeoJSONParseError: [ expected"
> which is not so friendly for users of the Bittrex library.
>
> What are the different/recommended approaches with Zinc
> for catching JSON errors such that I can pass "message"
> as a higher level Error up the stack to the Bittrex user.
>
> cheers -ben
Dec. 13, 2017
Re: [Pharo-users] REST client hints
by Sven Van Caekenberghe
> On 13 Dec 2017, at 07:49, Ben Coman <btc(a)openinworld.com> wrote:
>
>
>
> On 13 December 2017 at 14:40, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
> Yeah, that is the main problem with JSON. It cannot capture that variability in its own spec. Sure, there are tons of extensions on top of JSON to address these aspects, but NeoJSON only deals with the raw spec. And any server can use its own version.
>
> Simple answer is indeed: getmarkets and getticker return different schema, since you know what you call, you can map accordingly. (And hope the server does not do further variability). There cannot be one global mapping.
>
>
> Thats cool. I'm not looking for one global mapping to simultaneously handle getmarkets and getticker together.
> I'm just looking to handle getticker in isolation. I can't work that part out.
Hmm, your result ivar in response is of type ticker which maps its 3 ivars. So uncomment A but add all 3 ivars to ticker. no ?
> cheers -ben
>
>
> > On 13 Dec 2017, at 05:37, Ben Coman <btc(a)openinworld.com> wrote:
> >
> > Hi Sven (et al),
> >
> > On 10 December 2017 at 11:45, Ben Coman <btc(a)openinworld.com> wrote:
> >
> > 3. Finally parse into real objects the nested level holding the data you really want...
> >
> > Object subclass: #Market
> > instanceVariableNames: 'MarketCurrency BaseCurrency MarketCurrencyLong BaseCurrencyLong MinTradeSize MarketName IsActive Created Notice IsSponsored LogoUrl'
> > classVariableNames: ''
> > package: 'Bittrex'
> >
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> > enforceHttpSuccess: true;
> > accept: ZnMimeType applicationJson;
> > contentReader: [ :entity | |reader|
> > reader := (NeoJSONReader on: entity readStream).
> > reader for: BittrexResponse do: [:m|
> > m mapInstVar: #success.
> > m mapInstVar: #message.
> > (m mapInstVar: #result) valueSchema: #ArrayOfMarkets].
> > reader for: #ArrayOfMarkets customDo: [ :mapping | mapping listOfElementSchema: Market ].
> > reader mapInstVarsFor: Market.
> > reader nextAs: BittrexResponse ];
> > get) inspect.
> >
> > ==>BittrexResponse
> > success => true
> > message => ''
> > result => an Array(a Market(LTC) a Market(DOGE) a Market(VTC) a Market(PPC) a Market(FTC) a Market(RDD)
> > ... Market(POWR) a Market(BTG) a Market(BTG) a Market(BTG) a Market(ADA) a Market(ENG) a Market(ENG))
> >
> > So the code of [3.] above works fine when the raw response looks like this...
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> > get) inspect.
> > ==> {"success":true,
> > "message":"",
> > "result": [{"MarketName":"BTC-LTC},{"MarketName":"BTC-NXT}]
> > }
> >
> > But of course [3.] doesn't work when the raw response looks like this...
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';
> > get) inspect.
> > ==> {"success":true,
> > "message":"",
> > "result":{"Bid":0.01765465,"Ask":0.01769000,"Last":0.01763350}
> > }
> >
> > since result is a json-object not a json-array. But I can't work out
> > how to map the JSON object into the 'result' instance variable of BittrexResponse,
> > where...
> >
> > BittrexObject subclass: #BittrexTicker
> > instanceVariableNames: 'Bid Ask Last'
> > classVariableNames: ''
> > package: 'Bittrex'
> >
> >
> > My best guesses so far are uncommenting either [A.] or [B.] below...
> >
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';
> > enforceHttpSuccess: true;
> > accept: ZnMimeType applicationJson;
> > contentReader: [ :entity | |reader|
> > reader := (NeoJSONReader on: entity readStream).
> > reader for: BittrexResponse do: [:m|
> > m mapInstVar: #success.
> > m mapInstVar: #message.
> > (m mapInstVar: #result) valueSchema: #BittrexTicker].
> > "A. reader for: BittrexTicker do: [ :m|
> > m mapInstVar: #Bid]."
> > "B. reader for: #BittrexTicker customDo: [ :mapping |
> > mapping mapWithValueSchema: BittrexTicker]."
> > reader nextAs: BittrexResponse ];
> > get).
> >
> >
> > Can you advise what formulation is required?
> > cheers -ben
>
>
>
Dec. 13, 2017
Zinc JSON parsing error handling
by Ben Coman
With...
Object subclass: #BittrexResponse
instanceVariableNames: 'success message result'
classVariableNames: ''
package: 'Bittrex'
Object subclass: #BittrexMarketSummary
instanceVariableNames: 'MarketName High Low Volume Last
BaseVolume TimeStamp Bid Ask OpenBuyOrders
OpenSellOrders PrevDay Created DisplayMarketName'
classVariableNames: ''
package: 'Bittrex'
this code works great when the response holds good data...
ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getmarketSummary?market=BTC-LTC';
enforceHttpSuccess: true;
accept: ZnMimeType applicationJson;
contentReader: [ :entity | |reader|
reader := (NeoJSONReader on: entity readStream).
reader for: BittrexResponse do: [:m|
m mapInstVar: #success.
m mapInstVar: #message.
(m mapInstVar: #result) valueSchema: #ResultArray].
reader for: #ResultArray customDo: [ :mapping |
mapping listOfElementSchema: BittrexMarketSummary ].
reader mapInstVarsFor: BittrexMarketSummary.
reader nextAs: BittrexResponse ];
get.
i.e. a raw response looking like this....
(ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=BTC-LTC
<https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC>';
get) inspect.
==>
"'{""success"":true,""message"":"",""result"":[{""MarketName"":""BTC-LTC"",""High"":0.01982450,""Low"":0.01285257,""Volume"":1436429.81313360,""Last"":0.01842000,""BaseVolume"":24841.17217724,""TimeStamp"":""2017-12-13T05:56:25.937"",""Bid"":0.01840001,""Ask"":0.01842000,""OpenBuyOrders"":10140,""OpenSellOrders"":6306,""PrevDay"":0.01439800,""Created"":""2014-02-13T00:00:00""}]}'"
But for bad response looking like this...
(ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=INVALID';
get) inspect.
==> {"success":false,"message":"INVALID_MARKET","result":null}
the JSON handling code fails deep in the call stack with an error
"NeoJSONParseError: [ expected"
which is not so friendly for users of the Bittrex library.
What are the different/recommended approaches with Zinc
for catching JSON errors such that I can pass "message"
as a higher level Error up the stack to the Bittrex user.
cheers -ben
Dec. 13, 2017
Re: [Pharo-users] REST client hints
by Ben Coman
On 13 December 2017 at 14:40, Sven Van Caekenberghe <sven(a)stfx.eu> wrote:
> Yeah, that is the main problem with JSON. It cannot capture that
> variability in its own spec. Sure, there are tons of extensions on top of
> JSON to address these aspects, but NeoJSON only deals with the raw spec.
> And any server can use its own version.
>
> Simple answer is indeed: getmarkets and getticker return different schema,
> since you know what you call, you can map accordingly. (And hope the server
> does not do further variability). There cannot be one global mapping.
>
Thats cool. I'm not looking for one global mapping to simultaneously
handle getmarkets and getticker together.
I'm just looking to handle getticker in isolation. I can't work that part
out.
cheers -ben
>
> > On 13 Dec 2017, at 05:37, Ben Coman <btc(a)openinworld.com> wrote:
> >
> > Hi Sven (et al),
> >
> > On 10 December 2017 at 11:45, Ben Coman <btc(a)openinworld.com> wrote:
> >
> > 3. Finally parse into real objects the nested level holding the data you
> really want...
> >
> > Object subclass: #Market
> > instanceVariableNames: 'MarketCurrency BaseCurrency
> MarketCurrencyLong BaseCurrencyLong MinTradeSize MarketName IsActive
> Created Notice IsSponsored LogoUrl'
> > classVariableNames: ''
> > package: 'Bittrex'
> >
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> > enforceHttpSuccess: true;
> > accept: ZnMimeType applicationJson;
> > contentReader: [ :entity | |reader|
> > reader := (NeoJSONReader on: entity readStream).
> > reader for: BittrexResponse do: [:m|
> > m mapInstVar: #success.
> > m mapInstVar: #message.
> > (m mapInstVar: #result) valueSchema:
> #ArrayOfMarkets].
> > reader for: #ArrayOfMarkets customDo: [ :mapping | mapping
> listOfElementSchema: Market ].
> > reader mapInstVarsFor: Market.
> > reader nextAs: BittrexResponse ];
> > get) inspect.
> >
> > ==>BittrexResponse
> > success => true
> > message => ''
> > result => an Array(a Market(LTC) a Market(DOGE) a Market(VTC) a
> Market(PPC) a Market(FTC) a Market(RDD)
> > ... Market(POWR) a Market(BTG) a Market(BTG) a Market(BTG) a Market(ADA)
> a Market(ENG) a Market(ENG))
> >
> > So the code of [3.] above works fine when the raw response looks like
> this...
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> > get) inspect.
> > ==> {"success":true,
> > "message":"",
> > "result": [{"MarketName":"BTC-LTC},{"MarketName":"BTC-NXT}]
> > }
> >
> > But of course [3.] doesn't work when the raw response looks like this...
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC
> ';
> > get) inspect.
> > ==> {"success":true,
> > "message":"",
> > "result":{"Bid":0.01765465,"Ask":0.01769000,"Last":0.
> 01763350}
> > }
> >
> > since result is a json-object not a json-array. But I can't work out
> > how to map the JSON object into the 'result' instance variable of
> BittrexResponse,
> > where...
> >
> > BittrexObject subclass: #BittrexTicker
> > instanceVariableNames: 'Bid Ask Last'
> > classVariableNames: ''
> > package: 'Bittrex'
> >
> >
> > My best guesses so far are uncommenting either [A.] or [B.] below...
> >
> > (ZnClient new
> > url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC
> ';
> > enforceHttpSuccess: true;
> > accept: ZnMimeType applicationJson;
> > contentReader: [ :entity | |reader|
> > reader := (NeoJSONReader on: entity readStream).
> > reader for: BittrexResponse do: [:m|
> > m mapInstVar: #success.
> > m mapInstVar: #message.
> > (m mapInstVar: #result) valueSchema:
> #BittrexTicker].
> > "A. reader for: BittrexTicker do: [ :m|
> > m mapInstVar: #Bid]."
> > "B. reader for: #BittrexTicker customDo: [ :mapping |
> > mapping mapWithValueSchema: BittrexTicker]."
> > reader nextAs: BittrexResponse ];
> > get).
> >
> >
> > Can you advise what formulation is required?
> > cheers -ben
>
>
>
Dec. 13, 2017
Re: [Pharo-users] REST client hints
by Sven Van Caekenberghe
Yeah, that is the main problem with JSON. It cannot capture that variability in its own spec. Sure, there are tons of extensions on top of JSON to address these aspects, but NeoJSON only deals with the raw spec. And any server can use its own version.
Simple answer is indeed: getmarkets and getticker return different schema, since you know what you call, you can map accordingly. (And hope the server does not do further variability). There cannot be one global mapping.
> On 13 Dec 2017, at 05:37, Ben Coman <btc(a)openinworld.com> wrote:
>
> Hi Sven (et al),
>
> On 10 December 2017 at 11:45, Ben Coman <btc(a)openinworld.com> wrote:
>
> 3. Finally parse into real objects the nested level holding the data you really want...
>
> Object subclass: #Market
> instanceVariableNames: 'MarketCurrency BaseCurrency MarketCurrencyLong BaseCurrencyLong MinTradeSize MarketName IsActive Created Notice IsSponsored LogoUrl'
> classVariableNames: ''
> package: 'Bittrex'
>
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> enforceHttpSuccess: true;
> accept: ZnMimeType applicationJson;
> contentReader: [ :entity | |reader|
> reader := (NeoJSONReader on: entity readStream).
> reader for: BittrexResponse do: [:m|
> m mapInstVar: #success.
> m mapInstVar: #message.
> (m mapInstVar: #result) valueSchema: #ArrayOfMarkets].
> reader for: #ArrayOfMarkets customDo: [ :mapping | mapping listOfElementSchema: Market ].
> reader mapInstVarsFor: Market.
> reader nextAs: BittrexResponse ];
> get) inspect.
>
> ==>BittrexResponse
> success => true
> message => ''
> result => an Array(a Market(LTC) a Market(DOGE) a Market(VTC) a Market(PPC) a Market(FTC) a Market(RDD)
> ... Market(POWR) a Market(BTG) a Market(BTG) a Market(BTG) a Market(ADA) a Market(ENG) a Market(ENG))
>
> So the code of [3.] above works fine when the raw response looks like this...
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> get) inspect.
> ==> {"success":true,
> "message":"",
> "result": [{"MarketName":"BTC-LTC},{"MarketName":"BTC-NXT}]
> }
>
> But of course [3.] doesn't work when the raw response looks like this...
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';
> get) inspect.
> ==> {"success":true,
> "message":"",
> "result":{"Bid":0.01765465,"Ask":0.01769000,"Last":0.01763350}
> }
>
> since result is a json-object not a json-array. But I can't work out
> how to map the JSON object into the 'result' instance variable of BittrexResponse,
> where...
>
> BittrexObject subclass: #BittrexTicker
> instanceVariableNames: 'Bid Ask Last'
> classVariableNames: ''
> package: 'Bittrex'
>
>
> My best guesses so far are uncommenting either [A.] or [B.] below...
>
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';
> enforceHttpSuccess: true;
> accept: ZnMimeType applicationJson;
> contentReader: [ :entity | |reader|
> reader := (NeoJSONReader on: entity readStream).
> reader for: BittrexResponse do: [:m|
> m mapInstVar: #success.
> m mapInstVar: #message.
> (m mapInstVar: #result) valueSchema: #BittrexTicker].
> "A. reader for: BittrexTicker do: [ :m|
> m mapInstVar: #Bid]."
> "B. reader for: #BittrexTicker customDo: [ :mapping |
> mapping mapWithValueSchema: BittrexTicker]."
> reader nextAs: BittrexResponse ];
> get).
>
>
> Can you advise what formulation is required?
> cheers -ben
Dec. 13, 2017
Re: [Pharo-users] REST client hints
by Ben Coman
Hi Sven (et al),
On 10 December 2017 at 11:45, Ben Coman <btc(a)openinworld.com> wrote:
>
> 3. Finally parse into real objects the nested level holding the data you
> really want...
>
> Object subclass: #Market
> instanceVariableNames: 'MarketCurrency BaseCurrency MarketCurrencyLong
> BaseCurrencyLong MinTradeSize MarketName IsActive Created Notice
> IsSponsored LogoUrl'
> classVariableNames: ''
> package: 'Bittrex'
>
> (ZnClient new
> url: 'https://bittrex.com/api/v1.1/public/getmarkets';
> enforceHttpSuccess: true;
> accept: ZnMimeType applicationJson;
> contentReader: [ :entity | |reader|
> reader := (NeoJSONReader on: entity readStream).
> reader for: BittrexResponse do: [:m|
> m mapInstVar: #success.
> m mapInstVar: #message.
> (m mapInstVar: #result) valueSchema: #ArrayOfMarkets].
> reader for: #ArrayOfMarkets customDo: [ :mapping | mapping
> listOfElementSchema: Market ].
> reader mapInstVarsFor: Market.
> reader nextAs: BittrexResponse ];
> get) inspect.
>
> ==>BittrexResponse
> success => true
> message => ''
> result => an Array(a Market(LTC) a Market(DOGE) a Market(VTC) a
> Market(PPC) a Market(FTC) a Market(RDD)
> ... Market(POWR) a Market(BTG) a Market(BTG) a Market(BTG) a Market(ADA) a
> Market(ENG) a Market(ENG))
>
So the code of [3.] above works fine when the raw response looks like
this...
(ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getmarkets';
get) inspect.
==> {"success":true,
"message":"",
"result": [{"MarketName":"BTC-LTC},{"MarketName":"BTC-NXT}]
}
But of course [3.] doesn't work when the raw response looks like this...
(ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';
get) inspect.
==> {"success":true,
"message":"",
"result":{"Bid":0.01765465,"Ask":0.01769000,"Last":0.01763350}
}
since result is a json-object not a json-array. But I can't work out
how to map the JSON object into the 'result' instance variable of
BittrexResponse,
where...
BittrexObject subclass: #BittrexTicker
instanceVariableNames: 'Bid Ask Last'
classVariableNames: ''
package: 'Bittrex'
My best guesses so far are uncommenting either [A.] or [B.] below...
(ZnClient new
url: 'https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC';
enforceHttpSuccess: true;
accept: ZnMimeType applicationJson;
contentReader: [ :entity | |reader|
reader := (NeoJSONReader on: entity readStream).
reader for: BittrexResponse do: [:m|
m mapInstVar: #success.
m mapInstVar: #message.
(m mapInstVar: #result) valueSchema: #BittrexTicker].
"A. reader for: BittrexTicker do: [ :m|
m mapInstVar: #Bid]."
"B. reader for: #BittrexTicker customDo: [ :mapping |
mapping mapWithValueSchema: BittrexTicker]."
reader nextAs: BittrexResponse ];
get).
Can you advise what formulation is required?
cheers -ben
Dec. 13, 2017
Re: [Pharo-users] Pharo intro talk in spanish
by Offray Vladimir Luna Cárdenas
Thanks Rafael!
Is good to see more content in native languages and support more
diversity and going away of English as the dominant language monoculture
for science and tech (which reminds me [1]). BTW is a good presentation
with a lot of good points and fighting the balance between the
conceptual and the demo approach (demos with good theoretical background
are hard to build). The only think I miss was a microphone for the ones
making comments and questions in the audience.
[1] https://aeon.co/essays/how-did-science-come-to-speak-only-english
Cheers,
Offray
On 12/12/17 11:10, Rafael Luque wrote:
> Hi all,Â
>
> It has been published the video of the Pharo introduction talk (titled
> "Pharo Smalltalk: Un Entorno de Programación Subversiva") we organized
> from Osoco for the Madrid Software Crafters meetup.
>
> Both, video and slides are in spanish:
> https://www.youtube.com/watch?v=SV_KU4u5mTA
>
> Cheers,
> Rafael Luque
Dec. 13, 2017