Class: Acw::Client

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/acw/client.rb

Constant Summary collapse

API_VERSION =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#headers, #result

Constructor Details

#initialize(configs = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
# File 'lib/acw/client.rb', line 13

def initialize(configs = {})
  @config = configs
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/acw/client.rb', line 17

def config
  @config
end

Instance Method Details

#add_contact_tag(args = {}) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# 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

#connectionObject



19
20
21
# File 'lib/acw/client.rb', line 19

def connection
  @connection ||= Excon.new(config[:url])
end

#contact_list_subscription(args = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# 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 = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# 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 = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# 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 = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# 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) ⇒ Object



106
107
108
109
110
111
112
113
# 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) ⇒ Object



44
45
46
47
48
49
50
51
# 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) ⇒ Object



53
54
55
56
57
58
59
60
61
# 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_listsObject



63
64
65
66
67
68
69
70
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
# 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 = {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# 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