Newsletter7Api

This is a API interface to export email contact_group to Newsletter7. Accounts signed up Newsletter7 with Bonofa account can export Newsletter7 email contact_group directly on Bonofa sites.

Installation

Add this line to your application's Gemfile:

gem 'newsletter7_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install newsletter7_api

Usage

You can use ContactGroup resources as normal models.

Newsletter7ApiResource.connection.set_header('ACCESS_TOKEN', )
@contact_group = Newsletter7Api::ContactGroup.new(name: '', contacts: [])

@your_contact_group = ...
@your_contact_group.each do |member|
  @contact_group.contacts << member
end

@contact_group.save

This will create a contact_group on Newsletter7.(Imagine memeber has attributes first_name, last_name, email)

Configuration

You can configure Newsletter7 api url and http authentication name and password in initializer(config/initializers/newsletter7_api.rb)

Newsletter7ApiResource.site = 'http://localhost:3000/api/v1'
Newsletter7ApiResource.user = 'newsletter7'
Newsletter7ApiResource.password = 'defaultpw'

This settings should be match with those of Newsletter7.

Account promotion code will be encrypted and set in request header as access token. This promotion code will be used to find Newsletter7 account.

Using Example

Coltroller code can be look like this;

class ContactGroupsController < ApplicationController

  newsletter7_api

  def new
    begin
      @contact_group = Newsletter7Api::ContactGroup.all
    rescue => e
      redirect_to root_path, alert: 'You are not authorized to access Newsletter7.'
      return
    end

    @your_contact_group = ...

    @your_contact_group.each do |member|
      @contact_group.contacts << member
    end
  end  

  def create
    @contact_group = Newsletter7Api::ContactGroup.new(params[:newsletter7_api_contact_group])

    if @contact_group.save
      redirect_to root_path, notice: 'Contacts were successfully exported.'
    else
      redirect_to root_path, alert: 'Error occured while exporting contacts.'
    end
  end
end

Form example(haml)

= form_for(@contact_group, url: url_for(:action => 'create')) do |f|
  %fieldset
    = f.label :name
    = f.text_field :name

    %h4
      Contacts to export
      %small (member with invalid email or not selected will not be exported.)
    = render partial: 'contact', collection: @contact_group.contacts

  = f.submit

Contact partial

.contact_field
  %fieldset
    = text_field_tag "newsletter7_api_contact_group[contacts][][first_name]", contact.first_name, placeholder: 'First Name'
  %fieldset
    = text_field_tag "newsletter7_api_contact_group[contacts][][last_name]", contact.last_name, placeholder: 'Last Name'
  %fieldset
    = text_field_tag "newsletter7_api_contact_group[contacts][][email]", contact.email, placeholder: 'Email'
  %fieldset
    = check_box_tag "newsletter7_api_contact_group[contacts][][selected]", true, checked: true

Contributing

  1. Fork it ( https://github.com/c7devteam/newsletter7_api/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request