Project

smartfocus

0.0
No commit activity in last 3 years
No release in over 3 years
REST API wrapper interacting with Smartfocus (ex Emailvision)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0, ~> 4.0
>= 3.2
~> 0.4.0
~> 0.13.0
 Project Readme

Smartfocus ruby/rails library

Build Status Code Climate Coverage Status Dependency Status

Smartfocus (ex Emailvision) is a REST API wrapper interacting with Smartfocus. It :

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

Support

ruby 1.9.3 ruby 2.0

Install

Without bundler

$ gem install smartfocus

With bundler

Past this line to your Gemfile

gem 'smartfocus'

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/smartfocus.yml file

Generate the config file:

rails generate smartfocus:install

#2a (on loading)

It can also be set when you initialize your object:

emv = Smartfocus::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 = Smartfocus::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/smartfocus.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 = Smartfocus::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 Smartfocus::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=>"Jean"},
        {:key=>"LASTNAME", :value=>"Dupont"}
      ]
    }, 
    :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 :

Smartfocus::Api.http_proxy 'localhost', 8888

Then all requests will be redirected through the given proxy