Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faker.Phone API #44

Open
igas opened this issue Jan 16, 2016 · 7 comments
Open

Faker.Phone API #44

igas opened this issue Jan 16, 2016 · 7 comments

Comments

@igas
Copy link
Member

igas commented Jan 16, 2016

Hey folks,

I thinking about API for phones, here is my thoughts:

  • number/0 as general entry for mobile/landline numbers;
  • cell_number/0 & mobile_number/0;
  • landline_number/0;
  • area_code/0
  • exchange_code/0
  • subscriber_number/0
  • extension/0

In some cases arity can be 1 cause of rules length of subscriber_number based on area_code etc

Reasons behind separation is sometimes number split in db or UI.

I prefer to use Faker.format/1 there it is possible, because ideas of faker is to provide wide range of real world data (see Russian example below), so phone numbers is not just sequence of number and rules, but also style of formatting. Here is an example of code https://github.com/igas/faker/blob/0eb4aa3334e97e8a9ce41207934d1d631c92cc51/lib/faker/phone/en_gb.ex#L48-L55

And here is example from St. Petersburg, Russia of the same number how it can be written:

  • 8 812 123 45 67
  • 8 (812) 123 45 67
  • 8 812 1234567
  • 8 (812) 1234567
  • 8 (812) 123-45-67
  • 88121234567
  • 8812 1234567
  • 8-812-123-45-67
  • for every example on top first 8 can be replaced by +7
  • 1234567
  • 123 45 67
  • 123-45-67
  • etc

I'll be glad to discuss this before 0.7 release and decide API. Any thoughts, suggestions? Pros/cons?

/cc @vforvova @johnhamelink @devshane @efexen @saulecabrera @awanninger

@johnhamelink
Copy link
Contributor

I thinking about API for phones, here is my thoughts:

  • number/0 as general entry for mobile/landline numbers;
  • cell_number/0 & mobile_number/0;
  • landline_number/0;
  • area_code/0
  • exchange_code/0
  • subscriber_number/0
  • extension/0

I think that seems sensible.

I prefer to use Faker.format/1 there it is possible, because ideas of faker is to provide wide range of real world data (see Russian example below), so phone numbers is not just sequence of number and rules, but also style of formatting.

The problem is that in order for UK phone numbers to be truely valid, they actually follow quite a specific pattern (See here for more info - parts of the number denote different areas of the UK, prefixes define different types of phone number, they can have different lengths depending on the type of number, etc etc).

Because of this, Faker.format/1 has limited use. What we can use it for, is filling in the blanks after we choose a number format "template", such as in your example.

It might be worth noting, I've begun maintaining a project called elibphonenumber, which is an Erlang NIF wrapper of libphonenumber - a phone number parsing, validation & formatting library written by Google.

We could potentially use elibphonenumber to:

  • Produce different formatted outputs (national phone number style, international style, e164, RFC3966, etc).
  • Parse example phone numbers, then return the numbers chunked into their parts
  • Retrieve the expected cost to call the number
  • Probably lots more

If we go down the elibphonenumber route, we can do this across many locales automatically.

Thoughts?

@saulecabrera
Copy link
Contributor

saulecabrera commented Jun 17, 2016

Hey @igas @johnhamelink,

I spent some time reading/investigating about telephone numbers and came across E.164 which basically states that a phone number consists of mainly three parts:

  • Country Code (equivalent to area code I guess)
  • National Destination Code (equivalent to exchange code I guess)
  • Subscriber Number
    Subscriber Number and National Destination Code make up what's called the Significant number.

According to what I described above, I was thinking if it would be a good approach to have a separation of concerns here: the generation of the phone number in one side (without any specific format, just the sequence of digits) and have an extra set of rules to actually format the phone number according to the locale, because as @johnhamelink mentioned in the previous comment, in the UK phones are valid only if they follow a specific pattern, which might also be the case for all other countries.

I'm by no means a telephone number expert 😁 just was dropping my suggestion here; let me know what you think!

@mayppong
Copy link

mayppong commented Jun 22, 2016

I would love to see a phone number module!

Hmm I just saw this after I posted: https://github.com/igas/faker/blob/master/lib/faker/phone/en_us.ex

Perhaps the README file just needed to be updated.

@igas
Copy link
Member Author

igas commented Jun 22, 2016

well, we want to make it right, and I think first we need to do before it, decide how we'll manage langs and locales. Like en_UK & en_US. it should on one hand work with all ens but also pick US/UK when available. Sadly I don't have enough time to do that 😞

@anthonator
Copy link
Collaborator

Having the E.164 format would be awesome. Anytime you use a calling service (i.e. Twilio) you need to use this format. It's a pretty common use case.

@anthonator
Copy link
Collaborator

@igas do you have any interest in E.164 numbers? I'd be happy to submit a PR when I get a chance.

@igas
Copy link
Member Author

igas commented Jul 12, 2017

Hi @anthonator I'm not very familiar with this standard, but I would be happy to look at it, we can always prefix it if we decide not to make it default one. PR is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants