Skip to content

DevelopMan/mautic-rails

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mautic rails

RoR helper / wrapper for Mautic API and forms

Rails 4 compatible

Usage

Gem provides API connection to your Mautic(s)

  1. Create mautic connection

  2. Authorize it

    In mautic you need add API oauth2 login. For URI callback allow:

    http://localhost:3000/mautic/connections/:ID/oauth2
    

    ID = is your Mautic::Connection ID

Find connection which you want to use:

m = Mautic::Connection.last

Get specify contact:

contact = m.contact.find(1) # => #<Mautic::Contact id=1 ...>

Collections of contacts:

m.contacts.where("gmail").each do |contact|
  #<Mautic::Contact id=12 ...>
  #<Mautic::Contact id=21 ...>
  #<Mautic::Contact id=99 ...>
end

New instance of contacts:

contact = m.contacts.new({ email: "[email protected]"} )
contact.save # => true

Update contact

contact.email = ""
contact.save # => false
contact.errors # => [{"code"=>400, "message"=>"email: This field is required.", "details"=>{"email"=>["This field is required."]}}]

Of course you can use more than contact: assets, emails, companies, forms, points ...

Gem provides simple Mautic form submit

There are two options of usage:

  1. Use default mautic url from configuration and shortcut class method:
  # form: ID of form in Mautic *required*
  # url: Mautic URL - default is from configuration
  # request: request object (for domain, and forward IP...) *optional*
  Mautic::FormHelper.submit(form: "mautic form ID") do |i|
    i.form_field1 = "value1"
    i.form_field2 = "value2"
  end
  1. Or create instance
# request is *optional*
m = Mautic::FormHelper.new("https://mymautic.com", request)
m.data = {} # hash of attributes
m.push # push data to mautic 

Installation

Add this line to your application's Gemfile:

gem 'mautic', '~>0.1'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mautic

Configuration

add to config/initializers/mautic.rb:

Mautic.configure do |config|
  # This is for oauth handshake token url. I need to know where your app listen
  config.base_url = "https://my-rails-app.com"
  # OR it can be Proc 
  # *optional* This is your default mautic URL - used in form helper 
  config.mautic_url = "https://mautic.my.app"
end

add to config/routes.rb

mount Mautic::Engine => "/mautic"

Contributing

Ideas and pull requests are welcome!

License

The gem is available as open source under the terms of the MIT License.

About

Mautic ruby client / wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 85.8%
  • HTML 9.1%
  • CSS 2.8%
  • JavaScript 2.3%