stvnmcdonald
stvnmcdonald

Reputation: 27

Parse.com Class Update From API

I have a Parse Class called Currency that provides static exchange rates using the exact format from https://openexchangerates.org/. I do not need the rates "real time" so I would like to somehow GET the info using cloud code/scheduled job once a day and then overwrite the existing entry in Currency. When users query against the rates throughout the day, it uses the Parse class and not an API call to https://openexchangerates.org. Can overwriting a class or an object in the class be done in Parse.com? If not, are there suggestions on how to go about this? Thanks in advance.

Upvotes: 1

Views: 27

Answers (1)

Wain
Wain

Reputation: 119031

Create your job and set it to run once a day as required. In the job, make the http request. Iterate the result received to process each conversion. For that conversion, run a query to find the existing item in the data store (if one exists) by matching the conversion currencies. Update this object or create a new one if no match was found.

An alternative would be to batch delete all conversions before processing the result. This isn't great though as it leaves a finite time when no conversions will be available to users and if there is an error not even an old conversion will be available.

Upvotes: 1

Related Questions