class Acw::Client

Constants

API_VERSION

Attributes

config[R]

Public Class Methods

new(configs = {}) click to toggle source
# File lib/acw/client.rb, line 13
def initialize(configs = {})
  @config = configs
end

Public Instance Methods

add_contact_tag(args = {}) click to toggle source
# File lib/acw/client.rb, line 95
def add_contact_tag(args = {})
  safe_http_call do
    params = { 'contactTag': args }
    connection.post(
      path: "/api/#{API_VERSION}/contactTags",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end
connection() click to toggle source
# File lib/acw/client.rb, line 19
def connection
  @connection ||= Excon.new(config[:url])
end
contact_list_subscription(args = {}) click to toggle source
# File lib/acw/client.rb, line 72
def contact_list_subscription(args = {})
  safe_http_call do
    args[:status] = (args[:status] == 'subscribe' ? 1 : 2)
    params = { contactList: args }
    connection.post(
      path: "/api/#{API_VERSION}/contactLists",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end
create_contact(args = {}) click to toggle source
# File lib/acw/client.rb, line 23
def create_contact(args = {})
  safe_http_call do
    params = { contact: args }
    connection.post(
      path: "/api/#{API_VERSION}/contacts",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end
create_field_value(args = {}) click to toggle source
# File lib/acw/client.rb, line 115
def create_field_value(args = {})
  safe_http_call do
    params = { 'fieldValue': args }
    connection.post(
      path: "/api/#{API_VERSION}/fieldValues",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end
create_tag(args = {}) click to toggle source
# File lib/acw/client.rb, line 84
def create_tag(args = {})
  safe_http_call do
    params = { tag: args }
    connection.post(
      path: "/api/#{API_VERSION}/tags",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end
remove_contact_tag(id) click to toggle source
# File lib/acw/client.rb, line 106
def remove_contact_tag(id)
  safe_http_call do
    connection.delete(
      path: "/api/#{API_VERSION}/contactTags/#{id}",
      headers: headers(config[:token])
    )
  end
end
retrieve_contact(id) click to toggle source
# File lib/acw/client.rb, line 44
def retrieve_contact(id)
  safe_http_call do
    connection.get(
      path: "/api/#{API_VERSION}/contacts/#{id}",
      headers: headers(config[:token])
    )
  end
end
retrieve_contact_by_email(email) click to toggle source
# File lib/acw/client.rb, line 53
def retrieve_contact_by_email(email)
  safe_http_call do
    uemail = CGI.escape email
    connection.get(
      path: "/api/#{API_VERSION}/contacts?search=#{uemail}",
      headers: headers(config[:token])
    )
  end
end
retrieve_lists() click to toggle source
# File lib/acw/client.rb, line 63
def retrieve_lists
  safe_http_call do
    connection.get(
      path: "/api/#{API_VERSION}/lists",
      headers: headers(config[:token])
    )
  end
end
sync_contact(params) click to toggle source
# File lib/acw/client.rb, line 34
def sync_contact(params)
  safe_http_call do
    connection.post(
      path: "/api/#{API_VERSION}/contact/sync",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end
update_field_value(id, args = {}) click to toggle source
# File lib/acw/client.rb, line 126
def update_field_value(id, args = {})
  safe_http_call do
    params = { 'fieldValue': args }
    connection.put(
      path: "/api/#{API_VERSION}/fieldValues/#{id}",
      headers: headers(config[:token]),
      body: params.to_json
    )
  end
end

Private Instance Methods

safe_http_call() { || ... } click to toggle source
# File lib/acw/client.rb, line 139
def safe_http_call
  response = yield
  raise response.body unless success_http_status(response.status)

  result(true, nil, JSON.parse(response.body))
rescue StandardError => e
  result(false, e.message, nil)
end
success_http_status(status) click to toggle source
# File lib/acw/client.rb, line 148
def success_http_status(status)
  [200, 201, 202].include?(status)
end