Various API access inquiries

I have been having an email conversation with someone from mockaroo. It was suggested that it might be best to continue on the forum, so I copied our messages thusfar in here
Me:
is it possible to define and store your own datatypes? I wrote a script for defining iCal RRULEs and it would be nice to have a way to save it. Also is there a function for getting the row number? I need to access it but don’t want to compromise any of my datatypes.

I am trying to access the api

Mockaroo:
There isnt a function to access the row number directly but you can always add a row number field and access it by name in a formula. You can exclude the field from the output by naming it starting with two underscores.

There isn’t yet a way to creat custom data types that you can reuse between schemas. Probably the closest thing is just the ability to clone a schema. It seems like a good idea so I might add that soon

  • [Mockaroo tech]

Me:
Another thought: movies and timespan. P.s. this product is incredible

Me:
Thanks for the help [Mockaroo tech],
I have a few more questions:
I have a Data Source titled Meals which has 2 columns type (‘Breakfast’,‘Lunch’, and ‘Dinner’) I want to sequentially select lunches, within a script. Is this possible?
In the API description the fields for the different types give me the impression that they are classes. Is it possible to access those fields? ex: if a field is type ‘Time’ is there a way to get this.max, this.min…?
Ideally it would be nice to get a look at a more complete version of the ruby scripting api. Would that be possible?
Thanks,
Chris

Mockaroo:

Thanks for the help Mark,
I have a few more questions:
I have a Data Source titled Meals which has 2 columns type (‘Breakfast’,‘Lunch’, and ‘Dinner’) I want to sequentially select lunches, within a script. Is this possible?
I don’t think I understand. You can access records in a dataset using the formula function “from_dataset”, but I’m not sure that’s what you’re asking
In the API description the fields for the different types give me the impression that they are classes. Is it possible to access those fields? ex: if a field is type ‘Time’ is there a way to get this.max, this.min…?
Not at the moment. This just refers to the generated value. I can see how getting at the field settings would be useful. I can probably add that soon.
Ideally it would be nice to get a look at a more complete version of the ruby scripting api. Would that be possible?
Formulas basically just run sandboxed ruby code with a few Mockaroo-specific functions added in. Those are listed here: http://mockaroo.com/help/formulas. In addition to those functions, you can access any method on the following Ruby classes:

BasicObject
Fixnum
Integer
Float
String
Time
DateTime
Date,
BigDecimal
Array
Enumerable
Hash
Math

Me:

  1. just found the answer to this: Can I filter a dataset (before selecting from it randomly)?
  2. is there any way to do something like this?
    this = Country([‘The Republic of Dave’])
  3. you have the types very well documented, but the functions themselves are documented with 1 or 2 examples each. It would be helpful to see more formal documentation like you have for the types

Mockaroo:
Is your goal just to change the generated value using an inline formula? If so all you need to do specify that value. So the formula would literally just "The Republic of Dave” (quotes are part of the value).


at which point he suggested we continue on the forum

but that is just an example,
this = Country([‘The Republic of Dave’, ‘Petoria’, ‘Canada’])

If you just want to return a constant value, you could either use the formula data type with the value wrapped in quotes, or use the Template datatype.

I don’t want a constant, that was just a bad example.
this = Country([‘The Republic of Dave’, ‘Petoria’, ‘Canada’])
The general idea is that I want to be able to call one of your data type function in a script.

You can’t call a datatype directly, but you can add a field of that data type, hide it from the output by giving it a name starting with two underscores (for example, __my_field), and referencing it in a formula.

Gotcha, that should work, but my reasoning was:

case field('col_1') 
where a
   this = Country(['The Republic of Dave', 'Petoria', 'Canada'])
where b
   this = Paragraphs(1, 3)
...
end 

now, there could be private fields which stored these 2 different cases, but this is not very scaleable and somewhat inefficient. I can certainly work with your solution, I just wanted to make sure you understood my question.