C ? OR JAVA ? TO XOJO CONVERSION

Could one of you skilled C or Java people out there have a look at this snippet of code used to get exchange rates and give me an idea of what it would look like in Xojo. While I am vaguely familiar with C, I am clueless with regard to Java and don’t understand the syntax of the snippet especially with the use of braces in one section of code but not the other. The use of archaic devices such as ‘let’ makes me wonder if I am even looking at a modern language.
let demo = () => {
let rate = fx(1).from(“GBP”).to(“USD”)
alert(“£1 = $” + rate.toFixed(4))
}

fetch(‘https://api.fixer.io/latest’)
.then((resp) => resp.json())
.then((data) => fx.rates = data.rates)
.then(demo)

Start over. It’s clear that you haven’t even attempted to try anything by pasting the code example from the main page of the API here.

New thread: “Help implementing this API”
Provide the link to fixer.io

Tell us what you have tried.
What did you do?
Did it work?
If it failed, what happened?
What did you expect to happen?

Otherwise, if you need a right away solution you can hire a professional developer from here: https://www.xojo.com/resources/consultants.php

Nice attitude Tim!! I see that you have probably had too much coffee or something else that has led you to the mistaken belief that seeking the opinion of those more skilled than me is being lazy or trying to plagiarise code. I thought that my question and its responses may be of assistance to others trying to formulate e-commerce applications. I have been attempting to get this code to work for the last week off and on in various incarnations. In case you were not aware fixer.io is a free API for FOREX transactions.
Having used this forum for a few years, this is the first time I have received a negative response for asking a question. Maybe its a place for some to showcase their egos and and annoyance.

I found, in mere minutes, what language the pseudo-code was and what dependencies it had by simply exploring the website and trying to figure out how to use the API. I also provided you the questions to answer that show us that you did indeed try to figure it out yourself.

You’ve offered us nothing in terms of what you tried and what didn’t work.

I am more than happy to help people understand and learn, but you have to show the effort you’ve put forward. What are the incarnations you’ve tried? Did they work? If they failed, what happened? What did you expect to happen? Answer these questions, and you’ll find there’s a lot of people here who will help!

And you’ll know when I’m stroking my ego. I’ll post screenshots of things that work, but not tell you how to get them to work.

[quote=363797:@chris benton]The use of archaic devices such as ‘let’ makes me wonder if I am even looking at a modern language.
let demo = () => {
let rate = fx(1).from(“GBP”).to(“USD”)
alert(“£1 = $” + rate.toFixed(4))
}

fetch(‘https://api.fixer.io/latest’)
.then((resp) => resp.json())
.then((data) => fx.rates = data.rates)
.then(demo)[/quote]

I wish Xojo had archaic devices such as lambda/anonymous functions.

Clearly you have a much better internet connection than me. Drilling down into a web site to get information to solve your own puzzles is a frustrating and very time consuming. I know that this sounds like I am going off on a convenient tangent, but it is the reality of my location. With bad internet I often expedite the learning process by skipping the web and posting questions here.
When you allude to the fact that I must prove or justify why I am asking a question, then this is a demonstration of ego unless somebody made you the new Nazi moderator. All jibes aside; if you didn’t like the style, context or content of my OP then you should have ignored it. If I really knew the answer then I wouldn’t have asked. I think that you are in the same boat as me;i.e.:you don’t have a clue as to the answer.

Asking for code solutions is not asking a question. I didn’t have to drill down either, it was on the github page. You didn’t even look at the github page (which is where things tend to be documented).

My first response was not warm-and-fluffy, but it wasn’t wrong or uncalled for.

You still haven’t shown us any of the things you’ve attempted, and you’ve focused mostly on personal attacks. I think it’s safe to assume that you did not make any attempts to implement the API yourself.

This, a great example of “Trying To Get What You Want For Free 101” - challenge the person who won’t give you the free thing to prove that they can and then take it. If you want someone to implement it for you, hire a professional: https://www.xojo.com/resources/consultants.php

If you want to show any work at all, even that you took step one and tried to use a socket to get the latest conversion rates, I’m still willing to help. Get the latest rates with a socket, parse the JSON, make your conversion. Hiccups may occur along the way, and asking for help with those is what the forum is for.

Converts AUD to USD. Had not heard of fixer.io - nice.


Dim _currencySocket As New HTTPSocket
Dim _currencyResponse As String
_currencyResponse = _currencySocket.Get(“https://api.fixer.io/latest?base=AUD”, 5)

Dim _jsonText As Text
_jsonText = DefineEncoding(_currencyResponse, Encodings.UTF8).ToText()

Dim _json As Xojo.Core.Dictionary
_json = Xojo.Data.ParseJSON(_jsonText)
Dim _rates As Xojo.Core.Dictionary
_rates = _json.Value(“rates”)

Dim _conversionRate As Currency
_conversionRate = _rates.Value(“USD”)

Dim _initial As Currency
_initial = 10.00

Dim _converted As Currency
_converted = _initial * _conversionRate

Tim: Thanks for the tempered response, but I have many retorts and don’t want to bore you or the audience. I am not after anything for free, but I do want clues. Like you, I also get annoyed by people who post with the intention of having responders do all the leg work. To reiterate, all I wanted was some clues and was not asking you to divulge NASA secrets. It appears that Phillip Zedalis has posted a complete solution to my original question. Please do not be disrespectful to him for being helpful.

Phillip: Thanks kindly for your code snippet. I haven’t tested it yet, but it looks the business. I am pretty sure that others will benefit from your big brain and kind contribution. What the hell will Tim and I argue about now??

We can argue about how the documentation explicitly asks you to cache the conversion rates not to overload the service, and how copying and pasting the code given ignores that entirely :slight_smile:

Create ‘Rates’ property as Xojo.Core.Dictionary in App.


If (App.Rates = Nil) Then

 Dim _currencySocket As New HTTPSocket
 Dim _currencyResponse As String
 _currencyResponse = _currencySocket.Get("https://api.fixer.io/latest?base=AUD", 5)

 Dim _jsonText As Text
 _jsonText = DefineEncoding(_currencyResponse, Encodings.UTF8).ToText()

 Dim _json As Xojo.Core.Dictionary
 _json = Xojo.Data.ParseJSON(_jsonText)
 App.Rates = _json.Value("rates")

End If

Dim _conversionRate As Currency
_conversionRate = App.Rates.Value(“USD”)

Dim _initial As Currency
_initial = 10.00

Dim _converted As Currency
_converted = _initial * _conversionRate

Not really. I need to get past the ‘understanding what the code is doing’ before I move onto that rocket science. It maybe straightforward to you, but you are talking to a programming infant here.

Damn that Phillip and his great answers. he is destroying our combative relationship.

You’ll get stuck in that position forever if you continue to ask for code and copy / paste it.
But you got what you wanted, free code, so my opportunity to help you grow is now gone.

On the contrary I know I learned from practice and tweaking code samples more than reading documentation or books. As the project GitHub has no Xojo HTTPSocket examples or Xojo JSON examples it is actually a small but challenging hurdle.

Suffice to say this example is simple enough that I suspect (hope) Chris can take this and learn from it. It has an easy HTTPSocket GET and conversion from JSON to Dictionary to evaluate the values. A useful exercise for any beginner to play with.

Lastly I would not charge a customer if they approached me with this task. It took me less than 3 minutes and was no effort.

You still don’t get it Tim. I didn’t want ‘free’ code, but if you want the adulation and applause of your peers you are probably better off as a college teacher. At 60yo, Im done with growing. Yes, I understand that you probably did want to lead me to an understanding of how this snippet could work with Xojo, but attacking somebody for asking a question is a teaching fail. I hope we can converse again under better attitudes.
Big thanks to Phillip for digging into this thread.

That is not a question, and I did not attack you.

I asked you to tell us what you tried.
I even gave you questions to help you explain yourself:

[quote]What did you do?
Did it work?
If it failed, what happened?
What did you expect to happen?[/quote]

You then proceeded to say you had spent a week trying various things, but did not provide any evidence to support that. When asked for evidence you went on to attack me calling me names. I never once called you any name, or questioned your skill level (you did this to me).

I only asked for evidence that you had tried anything before coming here and asking for code.

I will close with this: If you are 60 years old and done growing, then why are you here? If you don’t want to learn to program, why are you here? If you just want something done you can easily do that by hiring people.

I’m sorry for assuming that you were here to learn anything.