lib/acw/client.rb in acw-1.2.0 vs lib/acw/client.rb in acw-1.3.0
- old
+ new
@@ -1,11 +1,10 @@
# frozen_string_literal: true
require 'excon'
require 'cgi'
require 'json'
-require 'pry'
module Acw
class Client
API_VERSION = 3
Result = Struct.new(:success?, :error, :value)
@@ -19,11 +18,11 @@
def connection
@connection ||= Excon.new(config[:url])
end
# CONTACTS
- def create_contact(args={})
+ def create_contact(args = {})
safe_http_call do
params = { contact: args }
connection.post(
path: "/api/#{API_VERSION}/contacts",
headers: headers,
@@ -64,11 +63,11 @@
end
# TAGS
def create_tag(args = {})
safe_http_call do
- params = { 'tag': args }
+ params = { tag: args }
connection.post(
path: "/api/#{API_VERSION}/tags",
headers: headers,
body: params.to_json
)
@@ -90,10 +89,33 @@
safe_http_call do
connection.delete(path: "/api/#{API_VERSION}/contactTags/#{id}", headers: headers)
end
end
+ # FIELD_VALUES
+ def create_field_value(args = {})
+ safe_http_call do
+ params = { 'fieldValue': args }
+ connection.post(
+ path: "/api/#{API_VERSION}/fieldValues",
+ headers: headers,
+ body: params.to_json
+ )
+ end
+ end
+
+ def update_field_value(id, args = {})
+ safe_http_call do
+ params = { 'fieldValue': args }
+ connection.put(
+ path: "/api/#{API_VERSION}/fieldValues/#{id}",
+ headers: headers,
+ body: params.to_json
+ )
+ end
+ end
+
private
def headers
{
'Accept': 'application/json',
@@ -110,9 +132,9 @@
rescue StandardError => e
Result.new(false, e.message, nil)
end
def success_http_status(status)
- [200, 201].include?(status)
+ [200, 201, 202].include?(status)
end
end
end