Notisend-Ruby Build Status Gem Version

This is the NotiSend Ruby Library. This library contains methods for easily interacting with the NotiSend API. Below are examples to get you started.

Installation

Run in console:

gem install notisend-ruby

or add to Gemfile:

gem 'notisend-ruby'

Configuration

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

Messages

Send a message

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={}>

Get message's info

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={}>

Send a message using a template

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={}>

Lists

Get the lists

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">

Create a list

list = Notisend::List.create(title: 'New List')
list # => #<Notisend::List id=2, title="New List">

Get list's info

list = Notisend::List.get(id: 2)
list # => #<Notisend::List id=2, title="New List">

Parameters

Get list's parameters

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>

Create a list's parameter

parameter = Notisend::Parameter.create(title: 'Age', kind: 'numeric', list_id: 1)
parameter # => #<Notisend::Parameter id=2, title="Age", kind="numeric", list_id=1>

Recipients

Get list's recipients

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=[]>

Create a recipient

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}]>

Update a recipient

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}]>

Import a batch of recipients

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">

Delete a recipient

Notisend::Recipient.delete(list_id: 1, id: 1) # => nil

Contributing

  1. Fork it
  2. Create your feature branch
  3. Test your feature and follow style guide (feel free to run rake, rspec and rubocop)
  4. Commit your changes
  5. Push to the branch
  6. Create a new Pull Request