REST API wrapper interacting with Emailvision
Ruby
Latest commit ce163ac Nov 10, 2013 @basgys [Release] 2.2
Failed to load latest commit information.
lib [Release] 2.2 Nov 10, 2013
spec Refactor API #2 Nov 10, 2013
.gitignore Add yardoc Oct 13, 2013
.irbrc Add irb script Oct 9, 2013
.travis.yml [Travis] Fix Oct 10, 2013
CHANGELOG.markdown [Release] 2.2 Nov 10, 2013
Gemfile Add yardoc Oct 12, 2013
Guardfile [Spec] Add some specs Oct 10, 2013
LICENSE Add license (MIT) #2 Nov 10, 2013
README.markdown Add license (MIT) #2 Nov 10, 2013
Rakefile [Travis] Fix Oct 9, 2013
emailvision.gemspec Add license (MIT) #2 Nov 10, 2013

README.markdown

Emailvision ruby/rails library

Build Status Code Climate Coverage Status Dependency Status

Emailvision is a REST API wrapper interacting with Emailvision. It :

  • Has a very comfortable syntax
  • Will support method addition on Emailvision API (dynamic call)
  • Has a clear documentation
  • Is well integrated with Rails, but can be used alone though
  • Is actively developed

IMPORTANT

If you use one of these versions 2.1.15 - 2.1.19 please update to 2.1.20 immediately. These versions are broken.

Support

ruby 1.9.3 ruby 2.0

Install

Without bundler

$ gem install emailvision

With bundler

Past this line to your Gemfile

gem 'emailvision'

Run bundler

$ bundle

Configuration

Settable parameters

  • server_name
  • login
  • password
  • key
  • endpoint
  • token
  • debug (true/false)

#1 (Rails configuration file)

If you use Rails, you can set your config in the config/emailvision.yml file

Generate the config file:

rails generate emailvision:install

#2a (on loading)

It can also be set when you initialize your object:

emv = Emailvision::Api.new :login => "my_login", :password => "password", :key => "key", :endpoint => "endpoint"

#2b (on loading)

Or if you wanna get fancy, you can use this syntax:

emv = Emailvision::Api.new do |o|
    o.login = "my_login"
    o.password = "password"
    o.key = "key"
    o.endpoint = "endpoint"
end

#3 (afterward)

Of course these parameters can be changed after initialization:

emv.endpoint = "endpoint"

Notice

  • Parameters set in the config/emailvision.yml will be automaticaly added to your object. But if you want to override some of them, you just have to set them again at initialization or later.
  • Beware that if you change your endpoint, you will have to recall the open_connection method.

Endpoints

Endpoints available :

  • apiccmd (segment, campaign, message, ...)
  • apitransactional (transactional message)
  • apimember (member list)
# Set an endpoint
emv = Emailvision::Api.new :endpoint => "apitransactional"

Shortcuts

emv.open_connection # Login to the given endpoint
emv.close_connection # Logout from the given endpoint
emv.connected? # Check connection status

Method calling syntax

emv.get.campaign.last(:limit => 5).call

Explanation

  • emv instance of Emailvision::Api
  • get is the HTTP verb to use
  • campaign.last is the method name
  • (:limit => 5) is the parameter
  • call is the keyword to perform the API call

Notice

  • You cannot change the following order : http verbe / method name / call
  • You can set your API call and perform it later (lazy loading), so you won't have to add your business logic in the view

Parameters

Data can be sent through URI, Query parameters and body. Here is an example of each :

URI

Method to call : member/getMemberByEmail/{token}/{email}

emv.get.member.get_member_by_email(:uri => ["my@email.com"]).call

Query parameters

Method to call : member/getMemberById/

emv.get.member.get_member_by_id(:id => 10).call

Body

Method to call : member/updateMember/

body = {
  :synchro_member=>{
    :dyn_content=>{
      :entry=>[
        {:key=>"FIRSTNAME", :value=>"Bastien"},
        {:key=>"LASTNAME", :value=>"Gysler"}
      ]
    }, 
    :email=>"my@mail.com"
  }
}

emv.post.member.update_member(:body => body).call

Notice

You can also combine these ways to send data

id => 10, :uri => ["my@email.com"], :body => {:foo => "bar"}

DEBUG

Debug mode show request sent/received in the console

It's also possible to monitor the traffic by using a proxy like this :

Emailvision::Api.http_proxy 'localhost', 8888

Then all requests will be redirected through the given proxy

TODO

  • Improves exception system
  • Improves logger (log file, ..)
  • Write some example in wiki pages

License

Please see LICENSE for licensing details.

Author

Bastien Gysler :: bastiengysler.com :: @basgys