mcorp / locasms

Client to consume LocaSMS api's
MIT License
4 stars 7 forks source link

URL Callback #16

Closed danieldocki closed 6 years ago

danieldocki commented 8 years ago

Place the callback URL would be great. It intends to do this?

http://54.173.24.177/painel/api.ashx?action=sendsms&lgn=&pwd=&msg=&numbers=319413 6747&url_callback=<URL>
vyper commented 8 years ago

@danieldocki can you are open a PR with this feature? (:

danieldocki commented 8 years ago

@vyper It does so is good?

def deliver(message, *mobiles, **opts)
  attrs = {
    msg: message,
    numbers: numbers(mobiles)
  }.merge(opts)
  rest.get(:sendsms, attrs)['data']
end

# delivering message to one mobile
cli.deliver 'my message', '1155559999'

# delivering message to one mobile with callback
cli.deliver 'my message', '1155559999', url_callback: 'http://mysite.com/callback'

# delivering the same message to multiple mobliles at once
cli.deliver 'my message', '1199998888,5500002222'
cli.deliver 'my message', '1199998888', '5500002222'
cli.deliver 'my message', ['1199998888', '5500002222']
cli.deliver 'my message', %w(1199998888 5500002222)

# delivering the same message to multiple mobliles at once with callback
cli.deliver 'my message', '1199998888,5500002222', url_callback: 'http://mysite.com/callback'
cli.deliver 'my message', '1199998888', '5500002222', url_callback: 'http://mysite.com/callback'
cli.deliver 'my message', ['1199998888', '5500002222'], url_callback: 'http://mysite.com/callback'
cli.deliver 'my message', %w(1199998888 5500002222), url_callback: 'http://mysite.com/callback'
def deliver_at(message, datetime, *mobiles, **opts)
  date, time = Helpers::DateTimeHelper.split datetime
  attrs = {
    msg: message,
    numbers: numbers(mobiles),
    jobdate: date,
    jobtime: time
  }.merge(opts)
  rest.get(:sendsms, attrs)['data']
end

# scheduling the deliver of a message to one mobile
cli.deliver_at 'my message', '2013-10-12 20:33:00', '1155559999'

# scheduling the deliver of a message to one mobile with callback
cli.deliver_at 'my message', '2013-10-12 20:33:00', '1155559999', url_callback: 'http://mysite.com/callback'

# scheduling the deliver of a message to multiple mobiles at once
cli.deliver_at 'my message', '2013-10-12 20:33:00', '1199998888,5500002222'
cli.deliver_at 'my message', '2013-10-12 20:33:00', '1199998888', '5500002222'
cli.deliver_at 'my message', '2013-10-12 20:33:00', ['1199998888', '5500002222']
cli.deliver_at 'my message', '2013-10-12 20:33:00', %w(1199998888 5500002222)

# scheduling the deliver of a message to multiple mobiles at once with callback
cli.deliver_at 'my message', '2013-10-12 20:33:00', '1199998888,5500002222', url_callback: 'http://mysite.com/callback'
cli.deliver_at 'my message', '2013-10-12 20:33:00', '1199998888', '5500002222', url_callback: 'http://mysite.com/callback'
cli.deliver_at 'my message', '2013-10-12 20:33:00', ['1199998888', '5500002222'], url_callback: 'http://mysite.com/callback'
cli.deliver_at 'my message', '2013-10-12 20:33:00', %w(1199998888 5500002222), url_callback: 'http://mysite.com/callback'
adilsoncarvalho commented 8 years ago

If the callback is the same to all requests doesn't make sense to keep it as a configuration?

vyper commented 8 years ago

@adilsoncarvalho in locasms doc specified the url_callback in each call of the sendsms.

vyper commented 8 years ago

@danieldocki for me it's so ugly, but... locasms works well 😁

:+1:

adilsoncarvalho commented 8 years ago

I see but we could have is a configuration option that would provide a default callback that could be override on a call. What do you think about that @danieldocki ?

danieldocki commented 8 years ago

@adilsoncarvalho I think it's okay. How can we design it?

tiagopog commented 8 years ago

It's interesting to think that there can be cases where clients of this gem are using it to serve SMS' for many applications with distinct domains. Probably a good design would provide the callback_url key argument with a fallback to a default URL.

danieldocki commented 8 years ago

@tiagopog I agree with you 👍

AlessandroMinali commented 6 years ago

Happy Hacktoberfest! I'll be looking into this!

adilsoncarvalho commented 6 years ago

Solved on #18

All hail @AlessandroMinali 🎉