appnigma-sdk 0.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +230 -97
  4. data/lib/appnigma/checks.rb +29 -5
  5. data/lib/appnigma/client.rb +38 -37
  6. data/lib/appnigma/connections.rb +25 -5
  7. data/lib/appnigma/constants.rb +15 -8
  8. data/lib/appnigma/crm.rb +63 -6
  9. data/lib/appnigma/errors.rb +45 -4
  10. data/lib/appnigma/generated/api/default_api.rb +824 -129
  11. data/lib/appnigma/generated/api_client.rb +1 -1
  12. data/lib/appnigma/generated/api_error.rb +1 -1
  13. data/lib/appnigma/generated/api_model_base.rb +1 -1
  14. data/lib/appnigma/generated/configuration.rb +1 -1
  15. data/lib/appnigma/generated/models/action_entry.rb +341 -0
  16. data/lib/appnigma/generated/models/connection_status.rb +3 -2
  17. data/lib/appnigma/generated/models/create_connection_link_input.rb +2 -13
  18. data/lib/appnigma/generated/models/create_connection_link_output.rb +2 -2
  19. data/lib/appnigma/generated/models/{post_output.rb → create_portal_link_input.rb} +20 -46
  20. data/lib/appnigma/generated/models/{pull_output_records_inner.rb → create_portal_link_output.rb} +37 -37
  21. data/lib/appnigma/generated/models/crm_company.rb +1 -1
  22. data/lib/appnigma/generated/models/crm_company_get_output.rb +1 -1
  23. data/lib/appnigma/generated/models/crm_company_list_output.rb +1 -1
  24. data/lib/appnigma/generated/models/crm_company_write_output.rb +177 -0
  25. data/lib/appnigma/generated/models/crm_contact.rb +1 -1
  26. data/lib/appnigma/generated/models/crm_contact_get_output.rb +1 -1
  27. data/lib/appnigma/generated/models/crm_contact_list_output.rb +1 -1
  28. data/lib/appnigma/generated/models/crm_contact_write_output.rb +177 -0
  29. data/lib/appnigma/generated/models/crm_create_input.rb +245 -0
  30. data/lib/appnigma/generated/models/crm_custom_field.rb +1 -1
  31. data/lib/appnigma/generated/models/crm_deal.rb +1 -1
  32. data/lib/appnigma/generated/models/{post_input.rb → crm_deal_create_input.rb} +48 -92
  33. data/lib/appnigma/generated/models/crm_deal_get_output.rb +1 -1
  34. data/lib/appnigma/generated/models/crm_deal_list_output.rb +1 -1
  35. data/lib/appnigma/generated/models/crm_deal_write_output.rb +177 -0
  36. data/lib/appnigma/generated/models/crm_email.rb +1 -1
  37. data/lib/appnigma/generated/models/crm_get_input.rb +2 -13
  38. data/lib/appnigma/generated/models/crm_labelled.rb +1 -1
  39. data/lib/appnigma/generated/models/crm_list_input.rb +2 -13
  40. data/lib/appnigma/generated/models/crm_phone.rb +1 -1
  41. data/lib/appnigma/generated/models/{pull_input.rb → crm_update_input.rb} +67 -112
  42. data/lib/appnigma/generated/models/end_customer.rb +247 -0
  43. data/lib/appnigma/generated/models/end_customer_connection.rb +239 -0
  44. data/lib/appnigma/generated/models/function_entry.rb +74 -5
  45. data/lib/appnigma/generated/models/function_owner.rb +1 -1
  46. data/lib/appnigma/generated/models/function_owner_one_of.rb +1 -1
  47. data/lib/appnigma/generated/models/function_owner_one_of1.rb +18 -17
  48. data/lib/appnigma/generated/models/get_connection_input.rb +216 -0
  49. data/lib/appnigma/generated/models/get_connection_output.rb +18 -5
  50. data/lib/appnigma/generated/models/get_guide_output.rb +1 -1
  51. data/lib/appnigma/generated/models/json_value.rb +1 -1
  52. data/lib/appnigma/generated/models/list_actions_output.rb +179 -0
  53. data/lib/appnigma/generated/models/{pull_output.rb → list_connections_output.rb} +23 -21
  54. data/lib/appnigma/generated/models/list_functions_output.rb +1 -1
  55. data/lib/appnigma/generated/models/list_platforms_output.rb +179 -0
  56. data/lib/appnigma/generated/models/logic_conditional.rb +247 -0
  57. data/lib/appnigma/generated/models/platform_entry.rb +269 -0
  58. data/lib/appnigma/generated/models/platform_entry_coverage_inner.rb +219 -0
  59. data/lib/appnigma/generated/models/platform_request_input.rb +2 -13
  60. data/lib/appnigma/generated/models/platform_request_input_body.rb +1 -1
  61. data/lib/appnigma/generated/models/platform_request_output.rb +1 -1
  62. data/lib/appnigma/generated/models/ran_as.rb +4 -6
  63. data/lib/appnigma/generated/models/run_action_input.rb +266 -0
  64. data/lib/appnigma/generated/models/run_action_output.rb +178 -0
  65. data/lib/appnigma/generated/models/run_input.rb +39 -26
  66. data/lib/appnigma/generated/models/run_output.rb +1 -1
  67. data/lib/appnigma/generated/models/sdk_error.rb +1 -1
  68. data/lib/appnigma/generated/models/sdk_error_error.rb +3 -3
  69. data/lib/appnigma/generated/models/sdk_error_error_details.rb +41 -3
  70. data/lib/appnigma/generated/models/sdk_problem.rb +1 -1
  71. data/lib/appnigma/generated/version.rb +1 -1
  72. data/lib/appnigma/generated.rb +21 -7
  73. data/lib/appnigma/names.rb +9 -0
  74. data/lib/appnigma/platforms.rb +18 -0
  75. data/lib/appnigma/portal.rb +21 -0
  76. data/lib/appnigma/retry.rb +3 -3
  77. data/lib/appnigma/transport.rb +4 -4
  78. data/lib/appnigma/version.rb +2 -2
  79. metadata +23 -7
  80. data/lib/appnigma/generated/models/post_input_record_value.rb +0 -104
@@ -7,6 +7,8 @@ require_relative "retry"
7
7
  require_relative "transport"
8
8
  require_relative "connections"
9
9
  require_relative "crm"
10
+ require_relative "platforms"
11
+ require_relative "portal"
10
12
 
11
13
  module Appnigma
12
14
  # What a customer creates. The key comes from `key:` or from the
@@ -15,12 +17,12 @@ module Appnigma
15
17
  # before any call.
16
18
  #
17
19
  # Every call takes keyword arguments in Ruby style and answers a Hash with
18
- # symbol keys in Ruby style, except inside content that is not ours (a
19
- # record's properties, a function's input and output, a platform's answer),
20
- # which comes back exactly as it was sent. Every call also takes
21
- # `timeout_ms:`, the time limit of one attempt.
20
+ # symbol keys in Ruby style, except inside content that is not ours (a CRM
21
+ # record's raw form and custom field names, a function's input and output,
22
+ # a platform's answer), which comes back exactly as it was sent. Every call
23
+ # also takes `timeout_ms:`, the time limit of one attempt.
22
24
  class Client
23
- attr_reader :base_url, :timeout_ms, :max_retries, :max_retry_wait_ms, :connections, :crm
25
+ attr_reader :base_url, :timeout_ms, :max_retries, :max_retry_wait_ms, :connections, :crm, :platforms, :portal
24
26
 
25
27
  # `transport` is for tests; a customer never passes it.
26
28
  def initialize(key: nil, timeout_ms: DEFAULT_TIMEOUT_MS, max_retries: DEFAULT_MAX_RETRIES,
@@ -31,45 +33,34 @@ module Appnigma
31
33
  @max_retries = Checks.max_retries!(max_retries)
32
34
  @max_retry_wait_ms = Checks.max_retry_wait_ms!(max_retry_wait_ms)
33
35
  @policy = Retry::Policy.new(max_retries: @max_retries, max_retry_wait_ms: @max_retry_wait_ms)
34
- # A write whose repeat is not harmless gets one attempt. create_link
35
- # makes a new link every time; run is your own function, and only you
36
+ # A write whose repeat is not harmless gets one attempt. Each
37
+ # create_link, the connect link's and the portal's, makes a new link
38
+ # every time; run is your own function, and only you
36
39
  # know whether running it twice is harmless; request with a method
37
- # other than GET may change the platform. post is retried because the
38
- # server updates the record that matches.
40
+ # other than GET may change the platform; a crm create with nothing to
41
+ # match on could make a second record. A crm create that matches, and
42
+ # a crm update, are retried because a repeat changes the same record.
39
43
  @one_attempt = Retry::Policy.new(max_retries: 0, max_retry_wait_ms: @max_retry_wait_ms)
40
44
  @transport = transport || Transport.new(base_url: @base_url, key: @key)
41
- @connections = Connections.new(self)
42
- @crm = Crm.new(self)
43
- end
44
-
45
- # Creates a record in the end customer's HubSpot, or updates the one that
46
- # already matches on `unique_by` (email for a contact unless you name
47
- # another property; required for a company and a deal).
48
- def post(end_customer_id:, platform:, object:, record:, unique_by: nil, timeout_ms: nil)
49
- body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform, object: object, record: record,
50
- unique_by: unique_by)
51
- call(:post_record, body, timeout_ms: timeout_ms)
52
- end
53
-
54
- # One page of records and a marker for the next; `next` is nil on the
55
- # last page. `limit` is 1 to 100.
56
- def pull(end_customer_id:, platform:, object:, limit: nil, after: nil, timeout_ms: nil)
57
- body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform, object: object, limit: limit,
58
- after: after)
59
- call(:pull_records, body, timeout_ms: timeout_ms)
45
+ start_groups
60
46
  end
61
47
 
62
- # One of your own functions, by platform and name: its live version runs,
63
- # and the answer's `ran_as` says whose it was. Made once, never retried.
64
- def run(end_customer_id:, platform:, function_name:, input:, timeout_ms: nil)
48
+ # One of your own functions, by platform and either `function_name` or
49
+ # `function_id`, never both: its live version runs, and the answer's
50
+ # `ran_as` says whose it was. Made once, never retried.
51
+ def run(end_customer_id:, platform:, input:, function_name: nil, function_id: nil, timeout_ms: nil)
52
+ Checks.function_name_or_id!(function_name, function_id)
65
53
  body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform, function_name: function_name,
66
- input: input)
54
+ function_id: function_id, input: input)
67
55
  call(:run_function, body, policy: @one_attempt, timeout_ms: timeout_ms)
68
56
  end
69
57
 
70
- # Your own functions, with their shapes. `platform` narrows the list.
71
- def catalog(platform: nil, timeout_ms: nil)
72
- call(:list_functions, opts: platform.nil? ? {} : { platform: platform }, timeout_ms: timeout_ms)
58
+ # Your own functions, with their ids and shapes. `platform` narrows the
59
+ # list to one platform; `end_customer_id` to your own functions and that
60
+ # end customer's.
61
+ def catalog(platform: nil, end_customer_id: nil, timeout_ms: nil)
62
+ opts = { platform: platform, end_customer_id: end_customer_id }.compact
63
+ call(:list_functions, opts: opts, timeout_ms: timeout_ms)
73
64
  end
74
65
 
75
66
  # The guide for your developers, as markdown, written for your company
@@ -96,11 +87,21 @@ module Appnigma
96
87
  read_answer(answer)
97
88
  end
98
89
 
99
- # Used by Connections for the one call that is never retried.
100
- attr_reader :one_attempt
90
+ # Used by Connections and Crm: the policy for a call made once, and the
91
+ # one for a call that is retried.
92
+ attr_reader :one_attempt, :policy
101
93
 
102
94
  private
103
95
 
96
+ # The calls grouped by what they reach: `connections`, `crm`,
97
+ # `platforms` and `portal`.
98
+ def start_groups
99
+ @connections = Connections.new(self)
100
+ @crm = Crm.new(self)
101
+ @platforms = Platforms.new(self)
102
+ @portal = Portal.new(self)
103
+ end
104
+
104
105
  # A success whose body is not JSON is a server error: a proxy page or an
105
106
  # empty body is never handed back as data.
106
107
  def read_answer(answer)
@@ -5,7 +5,8 @@ require_relative "names"
5
5
 
6
6
  module Appnigma
7
7
  # Connecting an end customer to their account on a platform:
8
- # `client.connections.create_link` and `client.connections.get`.
8
+ # `client.connections.create_link` and `client.connections.get`, and the
9
+ # list of them all, `client.connections.list`.
9
10
  class Connections
10
11
  def initialize(client)
11
12
  @client = client
@@ -19,13 +20,32 @@ module Appnigma
19
20
  @client.call(:create_connection_link, body, policy: @client.one_attempt, timeout_ms: timeout_ms)
20
21
  end
21
22
 
22
- # Whether one end customer is connected on one platform. The id travels
23
- # in the path, so it is checked here first: a bad one is refused as the
24
- # server would refuse it, and never becomes a wrong route.
23
+ # Whether one end customer is connected on one platform, and the key of
24
+ # their logic folder. The id may be any text, so it travels in the body
25
+ # of POST /connections/get (19.2); it is checked here first, by the
26
+ # server's own rule, so a bad one is refused before any call. A read, so
27
+ # it is retried.
25
28
  def get(end_customer_id:, platform:, timeout_ms: nil)
26
29
  Checks.end_customer_id!(end_customer_id)
27
30
  Checks.platform!(platform)
28
- @client.call(:get_connection, end_customer_id, platform, timeout_ms: timeout_ms)
31
+ body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform)
32
+ @client.call(:get_connection, body, timeout_ms: timeout_ms)
33
+ end
34
+
35
+ # Your end customers, a page at a time, in id order, each with every
36
+ # connection of theirs (19.3). `platform` and `status` list the end
37
+ # customers with at least one connection that matches; `limit` is 1 to
38
+ # 100, 50 when left out; `cursor` is the `next` of the previous page. A
39
+ # platform that is not text and a status outside the four are refused
40
+ # here first, with the server's words. Only the values given travel, in
41
+ # the query. A read, so it is retried.
42
+ def list(platform: nil, status: nil, limit: nil, cursor: nil, timeout_ms: nil)
43
+ opts = {}
44
+ opts[:platform] = Checks.platform!(platform) unless platform.nil?
45
+ opts[:status] = Checks.connection_status!(status) unless status.nil?
46
+ opts[:limit] = limit unless limit.nil?
47
+ opts[:cursor] = cursor unless cursor.nil?
48
+ @client.call(:list_connections, opts: opts, timeout_ms: timeout_ms)
29
49
  end
30
50
  end
31
51
  end
@@ -43,13 +43,18 @@ module Appnigma
43
43
  # The one 409 that sends an end customer through the connect flow again.
44
44
  RECONNECT_ERROR_CODE = "CONNECTION_NEEDS_RECONNECT"
45
45
 
46
- # An end customer id is 1 to 100 of letters, digits, dot, dash or underscore.
47
- END_CUSTOMER_ID_PATTERN = /\A[A-Za-z0-9._-]{1,100}\z/
48
- END_CUSTOMER_ID_RULE = "must be 1 to 100 characters: letters, digits, dot, dash or underscore"
49
-
50
- # `.` and `..` fit the pattern but cannot travel in a URL path.
51
- END_CUSTOMER_ID_PATH_UNSAFE = [".", ".."].freeze
52
- END_CUSTOMER_ID_PATH_RULE = "cannot be only dots, it travels in the URL path"
46
+ # The one 422 that is your own logic failing, not the platform refusing.
47
+ LOGIC_FAILED_ERROR_CODE = "LOGIC_FAILED"
48
+
49
+ # 19.2: an end customer id is any text of the customer's, 1 to 255
50
+ # characters (code points, as the server and its database count), with no
51
+ # control character and not only spaces. Checked before `connections.get`,
52
+ # which posts it, so a bad one is refused with the server's words before
53
+ # any call.
54
+ END_CUSTOMER_ID_MAX_LENGTH = 255
55
+ END_CUSTOMER_ID_FORBIDDEN_PATTERN = /\p{Cc}/
56
+ END_CUSTOMER_ID_ONLY_SPACES_PATTERN = /\A +\z/
57
+ END_CUSTOMER_ID_RULE = "must be 1 to 255 characters, with no control characters and not only spaces"
53
58
 
54
59
  # The server's error codes (the API description, 18.2). This gem keeps its
55
60
  # own copy: it is published on its own. A test compares it with the
@@ -61,12 +66,14 @@ module Appnigma
61
66
  SDK_KEY_CANCELLED
62
67
  MICROSERVER_NOT_ENABLED
63
68
  PLATFORM_NOT_ENABLED
69
+ PORTAL_NOT_ENABLED
64
70
  END_CUSTOMER_NOT_FOUND
65
71
  FUNCTION_NOT_FOUND
66
72
  FUNCTION_RETIRED
67
73
  CONNECTION_NEEDS_RECONNECT
68
74
  RATE_LIMITED
69
75
  PLATFORM_RATE_LIMITED
76
+ PLATFORM_REFUSED
70
77
  PLATFORM_ERROR
71
78
  TIMED_OUT
72
79
  LOGIC_FAILED
@@ -78,6 +85,6 @@ module Appnigma
78
85
  ].freeze
79
86
 
80
87
  OBJECTS = %w[contact company deal].freeze
81
- CONNECTION_STATUSES = %w[connected needs_reconnect disconnected].freeze
88
+ CONNECTION_STATUSES = %w[pending connected needs_reconnect disconnected].freeze
82
89
  PLATFORM_REQUEST_METHODS = %w[GET POST PUT PATCH DELETE].freeze
83
90
  end
data/lib/appnigma/crm.rb CHANGED
@@ -5,22 +5,57 @@ require_relative "names"
5
5
  module Appnigma
6
6
  # An end customer's CRM data in one shape, whichever CRM they use:
7
7
  # `client.crm.contacts`, `client.crm.companies` and `client.crm.deals`,
8
- # each with `list` and `get`. Reads, so they are retried.
8
+ # each with `list`, `get`, `create` and `update`.
9
9
  class Crm
10
10
  attr_reader :contacts, :companies, :deals
11
11
 
12
12
  def initialize(client)
13
- @contacts = Objects.new(client, list: :list_crm_contacts, get: :get_crm_contact)
14
- @companies = Objects.new(client, list: :list_crm_companies, get: :get_crm_company)
15
- @deals = Objects.new(client, list: :list_crm_deals, get: :get_crm_deal)
13
+ @contacts = Objects.new(client, list: :list_crm_contacts, get: :get_crm_contact, create: :create_crm_contact,
14
+ update: :update_crm_contact, matches_on: ->(record, _key) { Crm.email?(record) })
15
+ @companies = Objects.new(client, list: :list_crm_companies, get: :get_crm_company,
16
+ create: :create_crm_company, update: :update_crm_company,
17
+ matches_on: ->(record, _key) { Crm.domain?(Crm.field(record, :domain)) })
18
+ @deals = Objects.new(client, list: :list_crm_deals, get: :get_crm_deal, create: :create_crm_deal,
19
+ update: :update_crm_deal, matches_on: ->(_record, key) { Crm.text?(key) })
16
20
  end
17
21
 
18
- # The two reads of one CRM object.
22
+ # A record's field, whether it was given as a symbol or a string, in
23
+ # Ruby's name or the wire's.
24
+ def self.field(record, name)
25
+ return nil unless record.is_a?(Hash)
26
+
27
+ [name, name.to_s, Names.to_camel(name), Names.to_camel(name).to_sym].each do |key|
28
+ return record[key] if record.key?(key)
29
+ end
30
+ nil
31
+ end
32
+
33
+ def self.text?(value)
34
+ value.is_a?(String) && !value.strip.empty?
35
+ end
36
+
37
+ # As the server reads a domain to match on: something with a dot once any
38
+ # scheme, `www.` and path are taken off.
39
+ def self.domain?(value)
40
+ return false unless value.is_a?(String)
41
+
42
+ value.strip.downcase.sub(%r{\Ahttps?://}, "").sub(/\Awww\./, "").split(%r{[/?#]}).first.to_s.include?(".")
43
+ end
44
+
45
+ def self.email?(record)
46
+ emails = field(record, :emails)
47
+ emails.is_a?(Array) && text?(field(emails.first, :value))
48
+ end
49
+
50
+ # The reads and writes of one CRM object.
19
51
  class Objects
20
- def initialize(client, list:, get:)
52
+ def initialize(client, list:, get:, create:, update:, matches_on:)
21
53
  @client = client
22
54
  @list = list
23
55
  @get = get
56
+ @create = create
57
+ @update = update
58
+ @matches_on = matches_on
24
59
  end
25
60
 
26
61
  # One page of records and a marker for the next; pass `next` as
@@ -35,6 +70,28 @@ module Appnigma
35
70
  body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform, id: id)
36
71
  @client.call(@get, body, timeout_ms: timeout_ms)
37
72
  end
73
+
74
+ # Creates a record from the fields given, in the shapes they are read
75
+ # in, and answers it as `get` reads it. A contact with an email, a
76
+ # company with a domain, or a deal with a `match_key` of your own
77
+ # updates the record that already has it, so the call is retried like
78
+ # a read; with nothing to match on it is made once, because a repeat
79
+ # could make a second record.
80
+ def create(end_customer_id:, platform:, record:, match_key: nil, timeout_ms: nil)
81
+ body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform,
82
+ record: Names.record_keys(record), match_key: match_key)
83
+ policy = @matches_on.call(record, match_key) ? @client.policy : @client.one_attempt
84
+ @client.call(@create, body, policy: policy, timeout_ms: timeout_ms)
85
+ end
86
+
87
+ # Changes the fields given on the record with this id, and answers it as
88
+ # `get` reads it. `nil` clears a field; a field left out is left alone.
89
+ # Sending the same values again changes nothing, so it is retried.
90
+ def update(end_customer_id:, platform:, id:, record:, timeout_ms: nil)
91
+ body = Names.camel_keys(end_customer_id: end_customer_id, platform: platform, id: id,
92
+ record: Names.record_keys(record))
93
+ @client.call(@update, body, timeout_ms: timeout_ms)
94
+ end
38
95
  end
39
96
  end
40
97
  end
@@ -21,8 +21,9 @@ module Appnigma
21
21
  end
22
22
 
23
23
  # 400. The server names each field it could not accept, as `problems`:
24
- # a list of `{ field:, problem: }`. Also raised locally for a bad setting
25
- # or a bad end customer id, before any call.
24
+ # a list of `{ field:, problem: }`. Also raised locally for a bad setting,
25
+ # a bad end customer id, or a `run` naming its function both by name and
26
+ # by id or neither, before any call.
26
27
  class InputError < Error
27
28
  attr_reader :problems
28
29
 
@@ -48,6 +49,36 @@ module Appnigma
48
49
  # Any other 409: the platform cannot give this yet.
49
50
  class NotAvailableError < Error; end
50
51
 
52
+ # 422 PLATFORM_REFUSED: the end customer's platform refused the call, and
53
+ # `message` is its reason. Never tried again: the same call would be
54
+ # refused the same way. `platform_status` is the status the platform
55
+ # answered, or nil.
56
+ class PlatformRefusedError < Error
57
+ attr_reader :platform_status
58
+
59
+ def initialize(**args)
60
+ super
61
+ status = details["status"]
62
+ @platform_status = status.is_a?(Integer) ? status : nil
63
+ end
64
+ end
65
+
66
+ # 422 LOGIC_FAILED: one of your functions, or always-on logic around the
67
+ # call, failed. Always-on logic before a call stopped it, so nothing was
68
+ # written or returned, `message` names the logic and its id, and `logic_ids`
69
+ # lists the ids the server named; a function `run` called may have written
70
+ # before it failed, `message` is what it threw, and `logic_ids` is empty. The
71
+ # same call fails the same way until the logic or what it is given changes,
72
+ # so it is never tried again.
73
+ class LogicFailedError < Error
74
+ attr_reader :logic_ids
75
+
76
+ def initialize(**args)
77
+ super
78
+ @logic_ids = Errors.read_logic_ids(details)
79
+ end
80
+ end
81
+
51
82
  # 429. `retry_after_seconds` is what the server's Retry-After header said,
52
83
  # or nil when it sent none.
53
84
  class RateLimitError < Error
@@ -81,7 +112,7 @@ module Appnigma
81
112
  PROBLEM_KEYS = %w[field problem].freeze
82
113
 
83
114
  # Every status the server's table names; any other is a ServerError. 409
84
- # is chosen by code as well, in error_class.
115
+ # and 422 are chosen by code as well, in error_class.
85
116
  CLASS_BY_STATUS = {
86
117
  400 => InputError,
87
118
  401 => AuthError,
@@ -103,9 +134,11 @@ module Appnigma
103
134
  end
104
135
 
105
136
  # Only CONNECTION_NEEDS_RECONNECT asks for a reconnect; any other 409 is
106
- # something the platform cannot give yet.
137
+ # something the platform cannot give yet. A 422 is the platform refusing
138
+ # the call, unless it is LOGIC_FAILED: your own logic failing.
107
139
  def error_class(status, code)
108
140
  return code == RECONNECT_ERROR_CODE ? ReconnectError : NotAvailableError if status == 409
141
+ return code == LOGIC_FAILED_ERROR_CODE ? LogicFailedError : PlatformRefusedError if status == 422
109
142
 
110
143
  CLASS_BY_STATUS.fetch(status, ServerError)
111
144
  end
@@ -126,6 +159,14 @@ module Appnigma
126
159
  }
127
160
  end
128
161
 
162
+ # The server names one logic as `logicId`, or several as `logicIds`.
163
+ def read_logic_ids(details)
164
+ ids = details["logicIds"]
165
+ return ids.grep(String) if ids.is_a?(Array)
166
+
167
+ details["logicId"].is_a?(String) ? [details["logicId"]] : []
168
+ end
169
+
129
170
  def read_problems(details)
130
171
  list = details["problems"]
131
172
  return [] unless list.is_a?(Array)