|
36 | 36 | type: 'oauth2',
|
37 | 37 |
|
38 | 38 | authorization_url: lambda { |connection|
|
39 |
| - "https://#{connection['custom_domain'].presence || 'go.trackvia.com'}/oauth/authorize?response_type=code" |
| 39 | + params = { |
| 40 | + client_id: connection['client_id'], |
| 41 | + client_secret: connection['client_secret'], |
| 42 | + response_type: 'code' |
| 43 | + }.to_param |
| 44 | + "https://#{connection['custom_domain'].presence || 'go.trackvia.com'}/oauth/authorize?" + params |
40 | 45 | },
|
41 | 46 |
|
42 | 47 | acquire: lambda do |connection, auth_code, redirect_uri|
|
|
78 | 83 | },
|
79 | 84 |
|
80 | 85 | base_uri: lambda do |connection|
|
81 |
| - if connection['custom_domain'].presence |
82 |
| - "https://#{connection['custom_domain']}/openapi/" |
83 |
| - else |
84 |
| - "https://go.trackvia.com/openapi/" |
85 |
| - end |
| 86 | + "https://#{connection['custom_domain'].presence || 'go.trackvia.com'}/openapi/" |
86 | 87 | end
|
87 | 88 | },
|
88 | 89 |
|
89 | 90 | test: ->(_connection) { get('views') },
|
90 | 91 |
|
91 | 92 | methods: {
|
92 | 93 | get_all_output_fields: lambda do |input|
|
93 |
| - url = input[:view_id].present? ? "views/#{input[:view_id]}" : "users" |
94 |
| - Array.wrap(get(url)&.[]('structure')).reject { |field| field['name'] == "ID" }.map do |field| |
95 |
| - case field['type'] |
96 |
| - when 'number', 'currency', 'percentage', 'autoIncrement', 'relationship' |
97 |
| - { type: 'number' } |
98 |
| - when 'date' |
99 |
| - { type: 'date' } |
100 |
| - when 'datetime' |
101 |
| - { type: 'date_time' } |
102 |
| - when 'point' |
103 |
| - { type: 'object', properties: [ |
104 |
| - { name: 'latitude', type: 'number', optional: false }, |
105 |
| - { name: 'longitude', type: 'number', optional: false } |
106 |
| - ] } |
107 |
| - when 'checkbox' |
108 |
| - { type: :array, of: :object, properties: [ |
109 |
| - { name: 'choice' } |
110 |
| - ] } |
111 |
| - else |
112 |
| - {} |
113 |
| - end.merge(name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name']) |
114 |
| - end.concat([{ name: 'id' }]) |
115 |
| - end, |
116 |
| - |
117 |
| - get_output_fields: lambda do |input| |
118 |
| - url = input[:view_id].present? ? "views/#{input[:view_id]}" : "users" |
119 |
| - Array.wrap(get(url)&.[]('structure')).reject { |field| field['name'] == "ID" || %w[image document].include?(field['type']) }.map do |field| |
120 |
| - case field['type'] |
121 |
| - when 'number', 'currency', 'percentage', 'autoIncrement', 'relationship' |
122 |
| - { type: 'number' } |
123 |
| - when 'date' |
124 |
| - { type: 'date' } |
125 |
| - when 'datetime' |
126 |
| - { type: 'date_time' } |
127 |
| - when 'point' |
128 |
| - { type: 'object', properties: [ |
129 |
| - { name: 'latitude', type: 'number', optional: false }, |
130 |
| - { name: 'longitude', type: 'number', optional: false } |
131 |
| - ] } |
132 |
| - when 'checkbox' |
133 |
| - { type: :array, of: :object, properties: [ |
134 |
| - { name: 'choice' } |
135 |
| - ] } |
136 |
| - else |
137 |
| - {} |
138 |
| - end.merge(name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name']) |
139 |
| - end.concat([{ name: 'id' }]) |
140 |
| - end, |
141 |
| - |
142 |
| - get_fields: lambda do |input| |
143 |
| - structure = Array.wrap(get("views/#{input[:view_id]}")&.[]('structure')). |
144 |
| - reject { |field| field['canCreate'].is_not_true? || field['canUpdate'].is_not_true? || %w[image document].include?(field['type']) } |
145 |
| - structure.map do |field| |
146 |
| - # properties = { optional: input['id'].present? ? true : !field['required'], label: field['name'], field_name: field['name'] } |
| 94 | + url = input[:view_id].present? ? "views/#{input[:view_id]}" : 'users' |
| 95 | + Array.wrap(get(url)&.[]('structure')).map do |field| |
147 | 96 | case field['type']
|
148 |
| - when 'number', 'currency', 'autoIncrement', 'relationship' |
149 |
| - { type: 'number' } |
150 |
| - when 'percentage' |
151 |
| - { |
152 |
| - type: 'number', |
153 |
| - hint: "Enter in your percentage as a decimal. i.e. 10% should be entered in as 0.10. If necessary, use the '/'' operator in formula mode to adjust your value." |
154 |
| - } |
| 97 | + when 'identifier', 'shortAnswer', 'paragraph', 'userGroup', 'email', 'url' |
| 98 | + [{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'string' }] |
| 99 | + when 'relationship' |
| 100 | + [{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'string' }, |
| 101 | + { name: "f_#{field['fieldMetaId']}(id)", label: "#{field['name']}(id)", field_name: "#{field['name']}(id)", type: 'number' }] |
| 102 | + when 'number', 'percentage', 'currency', 'autoIncrement', 'user' |
| 103 | + [{name: field['name'] == 'ID' ? 'id' : "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'number' }] |
155 | 104 | when 'date'
|
156 |
| - { type: 'date' } |
| 105 | + [{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'date' }] |
157 | 106 | when 'datetime'
|
158 |
| - { type: 'date_time' } |
| 107 | + [{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'date_time' }] |
159 | 108 | when 'point'
|
160 |
| - { type: 'object', properties: [ |
161 |
| - { name: 'latitude', type: 'number', optional: false }, |
162 |
| - { name: 'longitude', type: 'number', optional: false } |
163 |
| - ] } |
164 |
| - when 'user' |
165 |
| - { hint: 'Enter the required user ID. User ID can be foun at the end of URL.' } |
166 |
| - when 'userGroup' |
167 |
| - { hint: 'Enter valid user group ID.' } |
168 |
| - when 'checkbox' |
169 |
| - { |
170 |
| - control_type: 'multiselect', delimiter: ',', options: field['choices'].map { |k| [k, k] }, toggle_hint: 'Select from list', |
171 |
| - toggle_field: { |
172 |
| - name: "f_#{field['fieldMetaId']}", |
173 |
| - type: :string, |
174 |
| - label: field['name'], |
175 |
| - control_type: 'text', |
176 |
| - hint: "Valid values are #{field['choices'].map { |k| k }.join(', ')}. For multiple values, enter values separated by (<b>,</b>). Example: <b>choice1,choice2</b>", |
177 |
| - toggle_hint: 'Enter custom value' |
178 |
| - } |
179 |
| - } |
180 |
| - when 'dropDown' |
181 |
| - { |
182 |
| - control_type: 'select', pick_list: field['choices'].map { |k| [k, k] }, toggle_hint: 'Select from list', |
183 |
| - toggle_field: { |
184 |
| - name: "f_#{field['fieldMetaId']}", |
185 |
| - type: :string, |
186 |
| - label: field['name'], |
187 |
| - control_type: 'text', |
188 |
| - hint: "Valid values are #{field['choices'].map { |k| k }.join(', ')}.", |
189 |
| - toggle_hint: 'Enter custom value' |
190 |
| - } |
191 |
| - } |
192 |
| - when 'email' |
193 |
| - { control_type: 'email' } |
| 109 | + [{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: 'object', |
| 110 | + properties: [ |
| 111 | + { name: 'latitude', type: 'number', optional: false }, |
| 112 | + { name: 'longitude', type: 'number', optional: false } |
| 113 | + ] |
| 114 | + }] |
| 115 | + when 'checkbox', 'dropDown' |
| 116 | + [{ name: "f_#{field['fieldMetaId']}", label: field['name'], field_name: field['name'], type: :array, of: :object, |
| 117 | + properties: [ |
| 118 | + { name: 'choices' } |
| 119 | + ] |
| 120 | + }] |
194 | 121 | else
|
195 |
| - {} |
196 |
| - end.merge(name: "f_#{field['fieldMetaId']}", optional: input['id'].present? ? true : !field['required'], label: field['name'], field_name: field['name']) |
197 |
| - end |
| 122 | + nil |
| 123 | + end |
| 124 | + end.flatten.compact |
198 | 125 | end,
|
199 | 126 |
|
200 | 127 | get_fields_sample_output: lambda do |input|
|
|
223 | 150 | object_definitions: {
|
224 | 151 | record: {
|
225 | 152 | fields: lambda { |_connection, config_fields|
|
226 |
| - call(:get_fields, config_fields) |
| 153 | + call(:get_all_output_fields, config_fields) |
227 | 154 | }
|
228 | 155 | },
|
229 | 156 |
|
|
235 | 162 |
|
236 | 163 | create_record_output: {
|
237 | 164 | fields: lambda { |_connection, config_fields|
|
238 |
| - call(:get_output_fields, view_id: config_fields['view_id']) |
| 165 | + call(:get_all_output_fields, view_id: config_fields['view_id']) |
239 | 166 | }
|
240 | 167 | }
|
241 | 168 | },
|
|
0 commit comments