Git Product home page Git Product logo

twilito's People

Contributors

alexford avatar dependabot[bot] avatar jkring avatar miyucy avatar philnash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

twilito's Issues

Support Twilio's `messaging_service_sid` parameter

Hi there, love the lightweight simplicity of this gem!

Twilio's Messaging Service allows for passing a messaging_service_sid parameter in place of from. The Messaging Service then matches the given recipient with a phone number from a corresponding sender pool. (docs)

It seems this is not presently possible, since from is a required parameter. Perhaps from could be conditionally required unless messaging_service_sid is present? Is there another workaround that I may be missing here?

Thanks! โœŒ๏ธ

result.rb is broken in ruby 2.4.9 "TypeError: {:keyword_init=>true} is not a symbol"

result.rb is broken

Ruby 2.4.9

Short version

result = Struct.new(:success?, :errors, :sid, :response, keyword_init: true) {}
=>
TypeError: {:keyword_init=>true} is not a symbol

https://stackoverflow.com/questions/15055852/how-to-change-the-default-value-of-a-struct-attribute

Full File

$ irb
2.4.9 :001 > Result = Struct.new(:success?, :errors, :sid, :response, keyword_init: true) do
2.4.9 :002 >         def self.success(**args)
2.4.9 :003?>           new(success?: true, **args)
2.4.9 :004?>         end
2.4.9 :005?>   
2.4.9 :006 >         def self.failure(**args)
2.4.9 :007?>           new(success?: false, **args)
2.4.9 :008?>         end
2.4.9 :009?>   
2.4.9 :010 >         def errors
2.4.9 :011?>           to_h[:errors] || []
2.4.9 :012?>         end
2.4.9 :013?>   
2.4.9 :014 >         def data
2.4.9 :015?>           JSON.parse(response_body || '{}')
2.4.9 :016?>         end
2.4.9 :017?>   
2.4.9 :018 >         private
2.4.9 :019?>   
2.4.9 :020 >         def response_body
2.4.9 :021?>           return nil unless to_h[:response]&.respond_to?(:read_body)
2.4.9 :022?>     
2.4.9 :023 >             to_h[:response].read_body
2.4.9 :024?>         end
2.4.9 :025?>     end
TypeError: {:keyword_init=>true} is not a symbol

Possible fix

(from SO link)

A = Struct.new(:a, :b, :c) do
  def initialize(a:, b: 2, c: 3)
    super(a, b, c)
  end
end

Testing examples/helpers

Twilito should be easy to mock/stub/double in tests as is, but some examples of this in the README may be useful because I consider ease of testing a benefit of using Twilito vs the full Twilio gem.

Also (and maybe this is a separate issue), including some little helpers could be nice. For example, in RSpec it'd be cool to be able to something like this:

expect { subject }.to send_sms(body: 'foo')

(The plan here needs fleshed out! Perhaps Twilito needs to be put into some kind of test mode for this to keep track of messages it would have sent rather than actually POSTing)

Address Ruby keyword arg deprecation warnings in `Result`

The .success and .failure class methods (helpers that delegate to initialize with the success: keyword argument set), in Twilito::Result are throwing warnings in Ruby 2.7.0.
This is just noisy now but will break in Ruby 3.0

https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

I messed around with this a bit but wasn't able to get the warnings to go away quickly. Maybe it's just too early in the morning...

/home/runner/work/twilito/twilito/lib/twilito/result.rb:10: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
39
/home/runner/work/twilito/twilito/lib/twilito/result.rb:5: warning: The called method `initialize' is defined here
/home/runner/work/twilito/twilito/lib/twilito/result.rb:14: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
39
/home/runner/work/twilito/twilito/lib/twilito/result.rb:5: warning: The called method `initialize' is defined here

It's possible I'm just doing something fundamentally weird here and this is a sign that it should be simplified or done differently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.