This is the NotiSend Ruby Library. This library contains methods for easily interacting with the NotiSend API. Below are examples to get you started.
Run in console:
gem install notisend-ruby
or add to Gemfile:
gem 'notisend-ruby'
First, you need to set up you api token. You can do that by using the environment varialble NOTISEND_API_TOKEN
or set it in code:
require 'notisend'
Notisend.configure do |config|
config.api_token = 'my-secret-token'
end
message = Notisend::Message.deliver(
from_email: '[email protected]',
to: '[email protected]',
subject: 'Hello',
html: '<h1>World</h1>',
text: 'World'
)
message # => #<Notisend::Message id=1, payment="subscriber", from_email="[email protected]", from_name=nil, to="[email protected]", subject="Hello", text="World", html="<h1>World</h1>", attachments=[], status="queued", events={}>
message = Notisend::Message.get(id: 1)
message # => #<Notisend::Message id=1, payment="subscriber", from_email="[email protected]", from_name=nil, to="[email protected]", subject="Hello", text="World", html="<h1>World</h1>", attachments=[], status="queued", events={}>
message = Notisend::Message.deliver_template(template_id: 1, to: '[email protected]')
message # => #<Notisend::Message id=1, payment="subscriber", from_email=nil, from_name=nil, to="recipient_mail.com", subject=nil, text=nil, html=nil, attachments=[], status="queued", events={}>
result = Notisend::List.get_all # get all lists paginated
result = Notisend::List.get_all(params: { page_number: 1, page_size: 1 }) # or get the specific page
result # => #<Notisend::Collection total_count=12, total_pages=12, page_number=1, page_size=1, collection=[#<Notisend::List id=1, title="My List">]>
result.collection.first # => #<Notisend::List id=1, title="My List">
list = Notisend::List.create(title: 'New List')
list # => #<Notisend::List id=2, title="New List">
list = Notisend::List.get(id: 2)
list # => #<Notisend::List id=2, title="New List">
result = Notisend::Parameter.get_all(list_id: 1)
result = Notisend::Parameter.get_all(list_id: 1, params: { page_number: 1, page_size: 1 })
result # => #<Notisend::Collection total_count=1, total_pages=1, page_number=1, page_size=1, collection=[#<Notisend::Parameter id=1, title="Full Name", kind="string", list_id=1>]>
result.collection.first # => #<Notisend::Parameter id=1, title="Full Name", kind="string", list_id=1>
parameter = Notisend::Parameter.create(title: 'Age', kind: 'numeric', list_id: 1)
parameter # => #<Notisend::Parameter id=2, title="Age", kind="numeric", list_id=1>
result = Notisend::Recipient.get_all(list_id: 1)
result = Notisend::Recipient.get_all(list_id: 1, params: { page_number: 1, page_size: 1 })
result # => #<Notisend::Collection total_count=3, total_pages=3, page_number=1, page_size=1, collection=[#<Notisend::Recipient id=1, email="[email protected]", list_id=1, confirmed=true, values=[]>]>
result.collection.first # => #<Notisend::Recipient id=1, email="[email protected]", list_id=1, confirmed=true, values=[]>
recipient = Notisend::Recipient.create(email: '[email protected]', list_id: 1) # create a recipient without values
recipient = Notisend::Recipient.create(email: '[email protected]', list_id: 1, values: [{parameter_id: 1, value: "foobar"}])
recipient # => #<Notisend::Recipient id=1, email="[email protected]", list_id=1, confirmed=true, values=[{"value"=>"foobar", "kind"=>"string", "parameter_id"=>1}]>
recipient = Notisend::Recipient.update(id: 1, list_id: 1, email: '[email protected]')
recipient = Notisend::Recipient.update(id: 1, list_id: 1, values: [{parameter_id: 1, value: "barbaz"}])
recipient # => #<Notisend::Recipient id=1, email="[email protected]", list_id=1, confirmed=true, values=[{"value"=>"barbaz", "kind"=>"string", "parameter_id"=>1}]>
result = Notisend::Recipient.import(
list_id: 1,
recipients: [
{ email: '[email protected]' },
{ email: '[email protected]', values: { [{ parameter_id: 1, value: 'some value' }] } },
]
)
result # => #<Notisend::RecipientsImport id=1, status="queued">
Notisend::Recipient.delete(list_id: 1, id: 1) # => nil
- Fork it
- Create your feature branch
- Test your feature and follow style guide (feel free to run
rake
,rspec
andrubocop
) - Commit your changes
- Push to the branch
- Create a new Pull Request