Ruby Sample: OptInCustomer

Note: In the OptInCustomer method, first_name and last_name are required parameters, but you may leave the value blank.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require "net/http"
require "uri"

CRM_REST_API_URL = "https://resturlgiven.com"
CRM_API_USERNAME = "YOURUSERNAME"
CRM_API_PASSWORD = "YOURPASSWORD"
CRM_API_KEYWORD = "YOURKEYWORD"

namespace :crm_api do

  desc "Send opt-in request"
  task :send_opt_in_request, [:source] => :environment do |t, args|
    first_name = "Big"
    last_name = "Foot"
    phone_number = "9995553333"

    uri = URI.parse(CRM_REST_API_URL)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data({
      method: "optincustomer",
      firstname: "first_name",
      firstname: "last_name",
      firstname: "phone_number"
    })

    # Basic Auth
    password = "#{CRM_API_PASSWORD}:#{CRM_API_KEYWORD}"
    request.basic_auth CRM_API_USERNAME, password

    response = http.request(request)
    puts response
    puts response.body
end

Ruby Sample: SendSMSmsg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "net/http"
require "uri"

CRM_REST_API_URL = "https://resturlgiven.com"
CRM_API_USERNAME = "YOURUSERNAME"
CRM_API_PASSWORD = "YOURPASSWORD"
CRM_API_KEYWORD = "YOURKEYWORD"

namespace :crm_api do

  desc "Send an SMS"
  task :send_sms, [:source] => :environment do |t, args|
    phone_number = "9995553333"
    message = "Do you really exist? I mean come on man, show yourself already."

    puri = URI.parse(CRM_REST_API_URL)
    http = Net::HTTP.new(uri.host, uri.port)
    use_ssl = true

    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data({
      method: "sendsmsmsg",
      phone_number: phone_number,
      message: message
    })

    # Basic Auth
    password = "#{CRM_API_PASSWORD}:#{CRM_API_KEYWORD}"
    request.basic_auth CRM_API_USERNAME, password

    response = http.request(request)
    puts response
    puts response.body
end

Ruby Sample: SetCallback

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require "net/http"
require "uri"

CRM_REST_API_URL = "https://resturlgiven.com"
CRM_API_USERNAME = "YOURUSERNAME"
CRM_API_PASSWORD = "YOURPASSWORD"
CRM_API_KEYWORD = "YOURKEYWORD"

namespace :crm_api do

  desc "Set callback url"
  task :set_callback_url, [:source] => :environment do |t, args|
    callback_url = "https://yourcallbackurl.com"

    uri = URI.parse(CRM_REST_API_URL)
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data({
      method: "setcallback"
      callback: callback_url
    })

    # Basic Auth
    password = "#{CRM_API_PASSWORD}:#{CRM_API_KEYWORD}"
    request.basic_auth CRM_API_USERNAME, password

    response = http.request(request)
    puts response
    puts response.body
end