class Bolzter::Bolzter

Public Class Methods

api_key() click to toggle source

> Getting api_key. It can be found in your Bolzter account page.

# File lib/bolzter.rb, line 54
def self.api_key

        @@api_key
end
api_root() click to toggle source

> Getting api root uri

# File lib/bolzter.rb, line 42
def self.api_root

        @@api_root
end
campaign(id) click to toggle source

> Response: Properties of a campaign object identified by {id} (id, name, description, start_date, end_date, status).

# File lib/bolzter.rb, line 108
def self.campaign id
        uri = URI.parse(make_uri("campaign/" + id.to_s))
        Net::HTTP.start(uri.host, uri.port,
                                        :use_ssl => uri.scheme == 'https', 
                                        :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Get.new uri.request_uri

                @response = http.request request # Net::HTTPResponse object
        end

        JSON.parse @response.body
end
campaigns() click to toggle source

> Campaign resources of a user.

> Response: List of campaigns of a user (id, name, description, start_date, end_date, status).

# File lib/bolzter.rb, line 93
def self.campaigns
        uri = URI.parse(make_uri("campaign"))
        Net::HTTP.start(uri.host, uri.port,
                                        :use_ssl => uri.scheme == 'https', 
                                        :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Get.new uri.request_uri

                @response = http.request request # Net::HTTPResponse object
        end

        JSON.parse @response.body
end
create_lead(params) click to toggle source

> Creating Person object and register it for the appropriate Campaign in one step.

> Field name Required Description

> first_name yes First name in max. 75 length

> last_name yes Last name in max. 75 length

> email yes Valid email address in max. 100 length

> campaign yes Campaign resource identifier which can be a numeric ID or a resource URI (eg. /api/v2.1/campaign/42/)

> phone no Phone number in max. 100 length

> birthday no Birthday in form YYYY-MM-DD

> country no Country name according to ISO-3166 in max. 50 length

> state no State of the country in max. 50 length

> city no City name in max. 100 length

> facebook_access_token no Valid Facebook User Access Token which is given by the user. Pay attention that the FB App which requested the permission must be the same as set for the campaign in Bolzter.

> tracking_cookie no For such cases when the user’s activities are tracked in browsers and the registration process is not going through a web page but the API. In order to be able to associate this tracked history to the lead we need the tracking cookie (bolzter_premarker).

# File lib/bolzter.rb, line 192
def self.create_lead(params)
        uri = URI.parse(make_uri("lead"))
        Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Post.new(uri.request_uri)
                request.add_field('Content-Type', 'application/json')
                request.body = JSON.dump(params)

                @response = http.request request
        end
end
delete_person(id) click to toggle source

> Response: The proper HTTP status code.

# File lib/bolzter.rb, line 169
def self.delete_person(id)
        uri = URI.parse(make_uri("person/" + id.to_s))
        Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Delete.new(uri.request_uri)

                @response = http.request request
        end
end
make_uri(end_point) click to toggle source

> Creating uri path

# File lib/bolzter.rb, line 36
def self.make_uri(end_point)

        @@api_root + end_point + "/?username=" + @@username + "&api_key=" + @@api_key
end
person(id) click to toggle source

> Response: Properties of a person object identified by {id} (id, first_name, last_name, email, birthday, gender, phone, converted).

# File lib/bolzter.rb, line 139
def self.person id
        uri = URI.parse(make_uri("person/" + id.to_s))
        Net::HTTP.start(uri.host, uri.port,
                                        :use_ssl => uri.scheme == 'https', 
                                        :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Get.new uri.request_uri

                @response = http.request request # Net::HTTPResponse object
        end

        JSON.parse @response.body
end
persons() click to toggle source

> Person resources of a user.

> Response: List of person belongs to the user’s campaigns (id, first_name, last_name, email, birthday, gender, phone, converted).

# File lib/bolzter.rb, line 124
def self.persons
        uri = URI.parse(make_uri("person"))
        Net::HTTP.start(uri.host, uri.port,
                                        :use_ssl => uri.scheme == 'https', 
                                        :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Get.new uri.request_uri

                @response = http.request request # Net::HTTPResponse object
        end

        JSON.parse @response.body
end
set_credentials(*args) click to toggle source

> Set credential. It should be called before call APIs.

# File lib/bolzter.rb, line 16
def self.set_credentials(*args)
        if args.length < 2
                conf_file = File.join(Rails.root, 'config', 'bolzter.yml').to_s
                if File.exists?(conf_file)
                        config = YAML.load_file(conf_file)
                        self.set_credentials(config["username"], config["api_key"])
                else
                        puts "conf/bolzter.yml file does not exist. Please copy bolzter.yml.example file."
                end
        elsif args.length == 2
                @@username = args[0]
                @@api_key = args[1]
                {:username => @@username, :api_key => @@api_key}
        else
                # To do:
                puts "Invalid parameters."
        end
end
update_person(id, params) click to toggle source

> Response: Properties of a person object identified by {id} (id, first_name, last_name, email, birthday, gender, phone, converted).

> Request: The required changes must be in JSON encoded format and don’t forget to set the content type to ‘application/json’ (eg. {“converted”: true}).

> Response: The proper HTTP code according to the success of the request.

# File lib/bolzter.rb, line 156
def self.update_person(id, params)
        uri = URI.parse(make_uri("person/" + id.to_s))
        Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Patch.new(uri.request_uri)
                request.add_field('Content-Type', 'application/json')
                request.body = JSON.dump(params)

                @response = http.request request
        end
end
user(id) click to toggle source

> Getting a user from user Identity

> A list of your users, actually there is 1 user in the list (id, first_name, last_name, email, last_login).

# File lib/bolzter.rb, line 77
def self.user id
        uri = URI.parse(make_uri("user/" + id.to_s))
        Net::HTTP.start(uri.host, uri.port,
                                        :use_ssl => uri.scheme == 'https', 
                                        :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Get.new uri.request_uri

                @response = http.request request # Net::HTTPResponse object
        end

        JSON.parse @response.body
end
username() click to toggle source

> Getting username. It will be email address.

# File lib/bolzter.rb, line 48
def self.username

        @@username
end
users() click to toggle source

> Getting all users

> A list of your users, actually there is 1 user in the list (id, first_name, last_name, email, last_login).

# File lib/bolzter.rb, line 61
def self.users
        uri = URI.parse(make_uri("user"))
        Net::HTTP.start(uri.host, uri.port,
                                        :use_ssl => uri.scheme == 'https', 
                                        :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

                request = Net::HTTP::Get.new uri.request_uri

                @response = http.request request # Net::HTTPResponse object
        end

        JSON.parse @response.body
end