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
If you use one of these versions 2.1.15 - 2.1.19 please update to 2.1.20 immediately. These versions are broken.
ruby 1.9.3 ruby 2.0
$ gem install emailvision
Past this line to your Gemfile
gem 'emailvision'
Run bundler
$ bundle
- server_name
- login
- password
- key
- endpoint
- token
- debug (true/false)
If you use Rails, you can set your config in the config/emailvision.yml file
Generate the config file:
rails generate emailvision:install
It can also be set when you initialize your object:
emv = Emailvision::Api.new :login => "my_login", :password => "password", :key => "key", :endpoint => "endpoint"
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
Of course these parameters can be changed after initialization:
emv.endpoint = "endpoint"
- 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 available :
- apiccmd (segment, campaign, message, ...)
- apitransactional (transactional message)
- apimember (member list)
# Set an endpoint
emv = Emailvision::Api.new :endpoint => "apitransactional"
emv.open_connection # Login to the given endpoint
emv.close_connection # Logout from the given endpoint
emv.connected? # Check connection status
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
- 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
Data can be sent through URI, Query parameters and body. Here is an example of each :
Method to call : member/getMemberByEmail/{token}/{email}
emv.get.member.get_member_by_email(:uri => ["[email protected]"]).call
Method to call : member/getMemberById/
emv.get.member.get_member_by_id(:id => 10).call
Method to call : member/updateMember/
body = {
:synchro_member=>{
:dyn_content=>{
:entry=>[
{:key=>"FIRSTNAME", :value=>"Bastien"},
{:key=>"LASTNAME", :value=>"Gysler"}
]
},
:email=>"[email protected]"
}
}
emv.post.member.update_member(:body => body).call
You can also combine these ways to send data
id => 10, :uri => ["[email protected]"], :body => {:foo => "bar"}
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
- Improves exception system
- Improves logger (log file, ..)
- Write some example in wiki pages
Please see LICENSE for licensing details.
Bastien Gysler :: bastiengysler.com :: @basgys