All Files (93.75% covered at 16.69 hits/line)
73 files in total.
1583 relevant lines.
1484 lines covered and
99 lines missed
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require 'json'
- 1
require 'rest-client'
- 1
require 'create_api_gem/api_request.rb'
- 1
Gem.find_files('create_api_gem/**/*.rb').each do |path|
- 73
require path
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class APIConfig
- 1
def self.token
- 33
ENV['TYPEFORM_API_TOKEN']
end
- 1
def self.image_api_request_url
- 252
'https://images.typeform.com'
end
- 1
def self.api_request_url
- 37
'https://api.typeform.com'
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class APIRequest
- 1
def self.execute(*args)
- 8
new(*args).tap do |request|
- 8
raise StandardError, 'Failed asserting that the request succeeds' unless request.success?
end
end
- 1
def headers
@response.headers
end
- 1
def inspect
"#{@response.code}\n#{@response}"
end
- 1
def bad_request?
@response.code == 400
end
- 1
def unauthorized?
@response.code == 401
end
- 1
def payment_required?
@response.code == 402
end
- 1
def forbidden?
@response.code == 403
end
- 1
def not_found?
@response.code == 404
end
- 1
def service_unavailable?
@response.code == 502 || @response.code == 503
end
- 1
def error_code
json.fetch(:code)
end
- 1
private
- 1
def request(args = {})
- 70
RestClient::Request.execute(args) { |r| @response = r }
end
- 1
def json
- 54
JSON.parse(@response, symbolize_names: true)
end
- 1
def json?
- 20
json
- 20
true
rescue JSON::ParserError
false
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require 'ffaker'
- 1
module DataGenerator
- 1
def self.title
- 116
FFaker::Movie.title
end
- 1
def self.description
- 100
FFaker::Lorem.paragraph
end
- 1
def self.email
FFaker::Internet.email
end
- 1
def self.color_code
- 8
'#' + SecureRandom.hex(3)
end
- 1
def self.field_ref
- 130
SecureRandom.hex(6)
end
- 1
def self.uuid
SecureRandom.uuid
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Block
- 1
def self.all_types
{
'date block' => DateBlock,
'dropdown block' => DropdownBlock,
'email block' => EmailBlock,
'file upload block' => FileUploadBlock,
'group block' => GroupBlock,
'legal block' => LegalBlock,
'long text block' => LongTextBlock,
'multiple choice block' => MultipleChoiceBlock,
'number block' => NumberBlock,
'opinion scale block' => OpinionScaleBlock,
'payment block' => PaymentBlock,
'picture choice block' => PictureChoiceBlock,
'rating block' => RatingBlock,
'short text block' => ShortTextBlock,
'statement block' => StatementBlock,
'website block' => WebsiteBlock,
'yes no block' => YesNoBlock
- 198
}
end
- 1
def self.from_response(response)
- 192
response[:type] = response[:type].to_sym
- 192
if response[:type] == :group
- 96
response[:properties][:fields].map! { |field| Block.from_response(field) } unless response[:properties][:fields].nil?
end
- 192
properties = response[:properties] || {}
- 192
validations = response[:validations] || {}
- 1470
block_params = response.keep_if { |k, _| k != :properties && k != :validations } || {}
- 192
params = properties.merge(validations).merge(block_params)
- 192
all_types.fetch(block_symbol_to_string(response[:type])).new(params)
end
- 1
def same?(actual)
- 134
(id.nil? || id == actual.id) &&
- 134
type == actual.type &&
title == actual.title &&
- 134
(ref.nil? || ref == actual.ref) &&
- 133
(description.nil? || description == actual.description) &&
- 133
(respond_to?(:attachment) ? same_attachment?(actual.attachment) : true) &&
same_extra_attributes?(actual)
end
- 1
def same_attachment?(actual_attachment)
- 105
return true if attachment.nil?
- 105
type = attachment[:type]
- 105
case type
when 'image'
- 55
return (attachment[:href].start_with?("#{APIConfig.image_api_request_url}/images/") && actual_attachment[:href].start_with?("#{APIConfig.image_api_request_url}/images/"))
when 'video'
- 50
return attachment == actual_attachment
else
return false
end
end
- 1
def self.attachment
- 79
[Block.image_attachment_payload, Block.video_attachment_payload].sample
end
- 1
def self.image_attachment_payload(image_id: 'default')
- 91
{ type: 'image', href: "#{APIConfig.image_api_request_url}/images/#{image_id}" }
end
- 1
def self.video_attachment_payload(video_url: 'https://www.youtube.com/watch?v=Uui3oT-XBxs', scale: 0.6)
- 79
{ type: 'video', href: video_url, scale: scale }
end
- 1
def self.block_symbol_to_string(symbol)
- 600
string = symbol.to_s
- 600
string.sub!('_', ' ')
- 600
string + ' block'
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class DateBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :structure, :separator, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :date, ref: nil, description: nil, structure: nil,
separator: nil, required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@structure = structure
- 18
@separator = separator
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil? && structure.nil? && separator.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:structure] = structure unless structure.nil?
- 4
payload[:properties][:separator] = separator unless separator.nil?
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(structure.nil? ? DateBlock.default.structure : structure) == actual.structure &&
- 16
(separator.nil? ? DateBlock.default.separator : separator) == actual.separator &&
- 8
(required.nil? ? DateBlock.default.required : required) == actual.required
end
- 1
def self.default
DateBlock.new(
structure: 'MMDDYYYY',
separator: '/',
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
DateBlock.new(
ref: DataGenerator.field_ref,
separator: '-',
structure: 'DDMMYYYY',
required: true,
id: id,
description: DataGenerator.description,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class DropdownBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :alphabetical_order, :choices, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :dropdown, ref: nil, description: nil, alphabetical_order: nil,
choices: nil, required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@alphabetical_order = alphabetical_order
- 18
@choices = choices || DropdownBlock.choices
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def self.choices
[
- 6
{ label: 'choice 1' },
{ label: 'choice 2' }
]
end
- 1
def payload
- 4
payload = {}
- 4
payload[:properties] = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:ref] = ref unless ref.nil?
- 4
payload[:id] = id unless id.nil?
- 4
payload[:properties][:choices] = choices
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:alphabetical_order] = alphabetical_order unless alphabetical_order.nil?
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
same_choices?(actual.choices) &&
- 8
(alphabetical_order.nil? ? DropdownBlock.default.alphabetical_order : alphabetical_order) == actual.alphabetical_order &&
- 8
(required.nil? ? DropdownBlock.default.required : required) == actual.required
end
- 1
def same_choices?(actual_choices)
- 8
choices.zip(actual_choices).all? do |expected, actual|
- 16
(!expected.key?(:id) || expected[id] == actual[id]) &&
- 16
expected[:label] == actual[:label]
end
end
- 1
def self.default
DropdownBlock.new(
choices: choices,
alphabetical_order: false,
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
DropdownBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
choices: choices,
alphabetical_order: true,
required: true,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class EmailBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :email, ref: nil, description: nil, required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(required.nil? ? EmailBlock.default.required : required) == actual.required
end
- 1
def self.default
EmailBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
EmailBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
required: true,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class FileUploadBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required
- 1
def initialize(id: nil, title: nil, type: :file_upload, ref: nil, description: nil, required: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(required.nil? ? FileUploadBlock.default.required : required) == actual.required
end
- 1
def self.default
FileUploadBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
FileUploadBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
required: true,
id: id
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class GroupBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :show_button, :button_text, :attachment, :fields
- 1
def initialize(id: nil, title: nil, type: :group, ref: nil, description: nil, show_button: nil, button_text: nil, attachment: nil, fields: [])
- 9
@id = id
- 9
@title = title || DataGenerator.title
- 9
@type = type
- 9
@ref = ref
- 9
@description = description
- 9
@show_button = show_button
- 9
@button_text = button_text
- 9
@attachment = attachment
- 9
@fields = fields
end
- 1
def payload
- 2
payload = {}
- 2
payload[:title] = title
- 2
payload[:type] = type.to_s
- 2
payload[:id] = id unless id.nil?
- 2
payload[:ref] = ref unless ref.nil?
- 2
unless description.nil? && fields.nil? && show_button.nil? && button_text.nil?
- 2
payload[:properties] = {}
- 2
payload[:properties][:description] = description unless description.nil?
- 2
payload[:properties][:show_button] = show_button unless show_button.nil?
- 2
payload[:properties][:button_text] = button_text unless button_text.nil?
- 2
unless fields.nil?
- 2
p = []
- 32
fields.each { |field| p << field.payload unless field.nil? }
- 2
payload[:properties][:fields] = p
end
end
- 2
payload[:attachment] = attachment unless attachment.nil?
- 2
payload
end
- 1
def same_extra_attributes?(actual)
- 4
same_fields?(actual.fields)
end
- 1
def same_fields?(actual_fields)
fields.zip(actual_fields).all? do |expected, actual|
- 60
expected.same?(actual)
- 4
end && fields.length == actual_fields.length
end
- 1
def self.default
GroupBlock.new(
fields: [],
button_text: 'Continue',
show_button: false
)
end
- 1
def self.full_example(id: nil, blocks: nil)
- 3
fields = if blocks.nil?
- 3
Block.all_types.values.map do |block|
- 51
block.full_example unless [GroupBlock, PaymentBlock].include?(block)
end
else
blocks.map do |block|
block.class.full_example(id: block.id) unless [GroupBlock, PaymentBlock].include?(block)
end
end
- 3
GroupBlock.new(
ref: DataGenerator.field_ref,
id: id,
description: DataGenerator.description,
button_text: 'Click me!',
show_button: true,
fields: fields.compact,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class LegalBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required
- 1
def initialize(id: nil, title: nil, type: :legal, ref: nil, description: nil, required: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(required.nil? ? LegalBlock.default.required : required) == actual.required
end
- 1
def self.default
LegalBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
LegalBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
required: true,
id: id
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class LongTextBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required, :max_length, :attachment
- 1
def initialize(id: nil, title: nil, type: :long_text, ref: nil, description: nil, required: nil,
max_length: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
- 18
@max_length = max_length
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil? && max_length.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required unless required.nil?
- 4
payload[:validations][:max_length] = max_length unless max_length.nil?
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(max_length.nil? || max_length == actual.max_length) &&
- 16
(required.nil? ? LongTextBlock.default.required : required) == actual.required
end
- 1
def self.default
LongTextBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
LongTextBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
required: true,
max_length: 500,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class MultipleChoiceBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :randomize, :allow_multiple_selection, :allow_other_choice,
:vertical_alignment, :choices, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :multiple_choice, ref: nil, description: nil, randomize: nil,
allow_multiple_selection: nil, allow_other_choice: nil, vertical_alignment: nil,
choices: nil, required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@randomize = randomize
- 18
@allow_multiple_selection = allow_multiple_selection
- 18
@allow_other_choice = allow_other_choice
- 18
@vertical_alignment = vertical_alignment
- 18
@choices = choices || MultipleChoiceBlock.choices
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def self.choices
[
{
label: 'choice 1',
ref: DataGenerator.field_ref
- 6
},
{
label: 'choice 2',
ref: DataGenerator.field_ref
}
]
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:ref] = ref unless ref.nil?
- 4
payload[:id] = id unless id.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:choices] = choices
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:randomize] = randomize unless randomize.nil?
- 4
payload[:properties][:allow_multiple_selection] = allow_multiple_selection unless allow_multiple_selection.nil?
- 4
payload[:properties][:allow_other_choice] = allow_other_choice unless allow_other_choice.nil?
- 4
payload[:properties][:vertical_alignment] = vertical_alignment unless vertical_alignment.nil?
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
same_choices?(actual.choices) &&
- 8
(randomize.nil? ? MultipleChoiceBlock.default.randomize : randomize) == actual.randomize &&
- 8
(allow_multiple_selection.nil? ? MultipleChoiceBlock.default.allow_multiple_selection : allow_multiple_selection) == actual.allow_multiple_selection &&
- 8
(allow_other_choice.nil? ? MultipleChoiceBlock.default.allow_other_choice : allow_other_choice) == actual.allow_other_choice &&
- 8
(vertical_alignment.nil? ? MultipleChoiceBlock.default.vertical_alignment : vertical_alignment) == actual.vertical_alignment &&
- 8
(required.nil? ? MultipleChoiceBlock.default.required : required) == actual.required
end
- 1
def same_choices?(actual_choices)
- 8
choices.zip(actual_choices).all? do |expected, actual|
- 16
(!expected.key?(:id) || expected[:id] == actual[:id]) &&
- 32
(!expected.key?(:ref) || expected[:ref] == actual[:ref]) &&
expected[:label] == actual[:label]
end
end
- 1
def self.default
MultipleChoiceBlock.new(
choices: choices,
randomize: false,
allow_multiple_selection: false,
allow_other_choice: false,
vertical_alignment: true,
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
MultipleChoiceBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
randomize: true,
allow_multiple_selection: true,
allow_other_choice: true,
vertical_alignment: true,
choices: choices,
required: true,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class NumberBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required, :min_value, :max_value, :attachment
- 1
def initialize(id: nil, title: nil, type: :number, ref: nil, description: nil, required: nil, min_value: nil,
max_value: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
- 18
@min_value = min_value
- 18
@max_value = max_value
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:ref] = ref unless ref.nil?
- 4
payload[:id] = id unless id.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil? && min_value.nil? && max_value.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required unless required.nil?
- 4
payload[:validations][:min_value] = min_value unless min_value.nil?
- 4
payload[:validations][:max_value] = max_value unless max_value.nil?
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(min_value.nil? || min_value == actual.min_value) &&
- 16
(max_value.nil? || max_value == actual.max_value) &&
- 8
(required.nil? ? NumberBlock.default.required : required) == actual.required
end
- 1
def self.default
NumberBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
NumberBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
required: true,
min_value: 1,
max_value: 500,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class OpinionScaleBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :steps, :start_at_one, :labels, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :opinion_scale, ref: nil, description: nil, steps: nil, start_at_one: nil,
labels: nil, required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@steps = steps
- 18
@start_at_one = start_at_one
- 18
@labels = labels
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil? && steps.nil? && start_at_one.nil? && labels.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:steps] = steps unless steps.nil?
- 4
payload[:properties][:start_at_one] = start_at_one unless start_at_one.nil?
- 4
payload[:properties][:labels] = labels unless labels.nil?
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required unless required.nil?
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(labels.nil? || labels == actual.labels) &&
- 16
(steps.nil? ? OpinionScaleBlock.default.steps : steps) == actual.steps &&
- 8
(start_at_one.nil? ? OpinionScaleBlock.default.start_at_one : start_at_one) == actual.start_at_one &&
- 8
(required.nil? ? OpinionScaleBlock.default.required : required) == actual.required
end
- 1
def self.default
OpinionScaleBlock.new(
steps: 11,
start_at_one: false,
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
OpinionScaleBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
steps: 7,
id: id,
start_at_one: true,
labels: { left: 'beg', center: 'mid', right: 'end' },
required: true,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class PaymentBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required, :currency, :price, :show_button, :button_text, :attachment
- 1
def initialize(id: nil, title: nil, type: :payment, ref: nil, description: nil, required: nil, currency: nil, price: nil,
show_button: nil, button_text: nil, attachment: nil)
- 9
@id = id
- 9
@title = title || DataGenerator.title
- 9
@type = type
- 9
@ref = ref
- 9
@description = description
- 9
@required = required
- 9
@currency = currency || 'EUR'
- 9
@price = price || { type: 'variable', value: 'price' }
- 9
@show_button = show_button
- 9
@button_text = button_text
- 9
@attachment = attachment
end
- 1
def payload
- 2
payload = {}
- 2
payload[:title] = title
- 2
payload[:type] = type.to_s
- 2
payload[:id] = id unless id.nil?
- 2
payload[:ref] = ref unless ref.nil?
- 2
unless description.nil? && currency.nil? && price.nil? && show_button.nil? && button_text.nil?
- 2
payload[:properties] = {}
- 2
payload[:properties][:description] = description unless description.nil?
- 2
payload[:properties][:currency] = currency unless currency.nil?
- 2
payload[:properties][:price] = price unless price.nil?
- 2
payload[:properties][:show_button] = show_button unless show_button.nil?
- 2
payload[:properties][:button_text] = button_text unless button_text.nil?
end
- 2
unless required.nil?
- 2
payload[:validations] = {}
- 2
payload[:validations][:required] = required
end
- 2
payload[:attachment] = attachment unless attachment.nil?
- 2
payload
end
- 1
def same_extra_attributes?(actual)
- 4
(required.nil? ? PaymentBlock.default.required : required) == actual.required &&
- 8
(price.nil? ? PaymentBlock.default.price : price) == actual.price &&
- 4
(currency.nil? ? PaymentBlock.default.currency : currency) == actual.currency &&
- 4
(show_button.nil? || show_button == actual.show_button) &&
- 4
(button_text.nil? || button_text == actual.button_text)
end
- 1
def self.default
PaymentBlock.new(
required: false,
price: { type: 'variable', value: 'price' },
currency: 'EUR'
)
end
- 1
def self.full_example(id: nil)
- 3
PaymentBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
required: true,
currency: 'USD',
price: { type: 'variable', value: 'price' },
show_button: true, button_text: 'Click me!',
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class PictureChoiceBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :randomize, :allow_multiple_selection, :allow_other_choice,
:supersized, :show_labels, :choices, :required
- 1
def initialize(id: nil, title: nil, type: :picture_choice, ref: nil, description: nil, randomize: nil,
allow_multiple_selection: nil, allow_other_choice: nil, supersized: nil, show_labels: nil,
choices: nil, required: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@randomize = randomize
- 18
@allow_multiple_selection = allow_multiple_selection
- 18
@allow_other_choice = allow_other_choice
- 18
@supersized = supersized
- 18
@show_labels = show_labels
- 18
@choices = choices || PictureChoiceBlock.choices
- 18
@required = required
end
- 1
def self.choices
[
{
label: 'label 1',
ref: DataGenerator.field_ref,
attachment: Block.image_attachment_payload(image_id: 'default')
- 6
},
{
label: 'label 2',
ref: DataGenerator.field_ref,
attachment: Block.image_attachment_payload(image_id: 'default')
}
]
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:ref] = ref unless ref.nil?
- 4
payload[:id] = id unless id.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:choices] = choices
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:randomize] = randomize unless randomize.nil?
- 4
payload[:properties][:allow_multiple_selection] = allow_multiple_selection unless allow_multiple_selection.nil?
- 4
payload[:properties][:allow_other_choice] = allow_other_choice unless allow_other_choice.nil?
- 4
payload[:properties][:supersized] = supersized unless supersized.nil?
- 4
payload[:properties][:show_labels] = show_labels unless show_labels.nil?
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload
end
- 1
def same_extra_attributes?(actual)
same_choices?(actual.choices) &&
- 8
(randomize.nil? ? PictureChoiceBlock.default.randomize : randomize) == actual.randomize &&
- 8
(allow_multiple_selection.nil? ? PictureChoiceBlock.default.allow_multiple_selection : allow_multiple_selection) == actual.allow_multiple_selection &&
- 8
(allow_other_choice.nil? ? PictureChoiceBlock.default.allow_other_choice : allow_other_choice) == actual.allow_other_choice &&
- 8
(supersized.nil? ? PictureChoiceBlock.default.supersized : supersized) == actual.supersized &&
- 8
(show_labels.nil? ? PictureChoiceBlock.default.show_labels : show_labels) == actual.show_labels &&
- 8
(required.nil? ? PictureChoiceBlock.default.required : required) == actual.required
end
- 1
def same_choices?(actual_choices)
- 8
choices.zip(actual_choices).all? do |expected, actual|
- 16
(!expected.key?(:id) || expected[:id] == actual[:id]) &&
- 32
(!expected.key?(:ref) || expected[:ref] == actual[:ref]) &&
expected[:label] == actual[:label] &&
- 16
(expected[:attachment][:href].start_with?("#{APIConfig.image_api_request_url}/images/") && actual[:attachment][:href].start_with?("#{APIConfig.image_api_request_url}/images/"))
end
end
- 1
def self.default
PictureChoiceBlock.new(
randomize: false,
allow_multiple_selection: false,
allow_other_choice: false,
supersized: false,
show_labels: true,
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
PictureChoiceBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
randomize: true,
allow_multiple_selection: true,
allow_other_choice: true,
supersized: true,
choices: choices,
show_labels: false,
required: true
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class RatingBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :steps, :shape, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :rating, ref: nil, description: nil, steps: nil, shape: nil,
required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@steps = steps
- 18
@shape = shape
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:ref] = ref unless ref.nil?
- 4
payload[:id] = id unless id.nil?
- 4
unless description.nil? && steps.nil? && shape.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:steps] = steps unless steps.nil?
- 4
payload[:properties][:shape] = shape unless shape.nil?
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required unless required.nil?
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(steps.nil? ? RatingBlock.default.steps : steps) == actual.steps &&
- 16
(shape.nil? ? RatingBlock.default.shape : shape) == actual.shape &&
- 8
(required.nil? ? RatingBlock.default.required : required) == actual.required
end
- 1
def self.default
RatingBlock.new(
steps: 3,
shape: 'star',
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
RatingBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
steps: 8,
shape: 'heart',
id: id,
required: true,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class ShortTextBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required, :max_length, :attachment
- 1
def initialize(id: nil, title: nil, type: :short_text, ref: nil, description: nil, required: nil,
max_length: nil, attachment: nil)
- 19
@id = id
- 19
@title = title || DataGenerator.title
- 19
@type = type
- 19
@ref = ref
- 19
@description = description
- 19
@required = required
- 19
@max_length = max_length
- 19
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil? && max_length.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required unless required.nil?
- 4
payload[:validations][:max_length] = max_length unless max_length.nil?
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 9
(max_length.nil? || max_length == actual.max_length) &&
- 18
(required.nil? ? ShortTextBlock.default.required : required) == actual.required
end
- 1
def self.default
ShortTextBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 7
ShortTextBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
id: id,
required: true,
max_length: 50,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class StatementBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :hide_marks, :button_text, :attachment
- 1
def initialize(id: nil, title: nil, type: :statement, ref: nil, description: nil, hide_marks: nil,
button_text: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@hide_marks = hide_marks
- 18
@button_text = button_text
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil? && hide_marks.nil? && button_text.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description unless description.nil?
- 4
payload[:properties][:hide_marks] = hide_marks unless hide_marks.nil?
- 4
payload[:properties][:button_text] = button_text unless button_text.nil?
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(hide_marks.nil? ? StatementBlock.default.hide_marks : hide_marks) == actual.hide_marks &&
- 16
(button_text.nil? ? StatementBlock.default.button_text : button_text) == actual.button_text
end
- 1
def self.default
StatementBlock.new(button_text: 'Continue', hide_marks: false)
end
- 1
def self.full_example(id: nil)
- 6
StatementBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
hide_marks: true,
id: id,
button_text: 'Click me!',
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class ThankYouScreen < Block
- 1
attr_accessor :title, :ref, :show_button, :button_text, :button_mode, :redirect_url, :share_icons, :attachment
- 1
def initialize(title: nil, ref: nil, show_button: nil, button_text: nil, button_mode: nil, redirect_url: nil, share_icons: nil, attachment: nil)
- 17
@title = title || DataGenerator.title
- 17
@ref = ref
- 17
@show_button = show_button
- 17
@button_text = button_text
- 17
@button_mode = button_mode
- 17
@redirect_url = redirect_url
- 17
@share_icons = share_icons
- 17
@attachment = attachment
end
- 1
def self.from_response(response)
- 14
properties = response[:properties]
- 62
block_params = response.keep_if { |k, _| k != :properties }
- 14
params = properties.merge(block_params)
- 14
ThankYouScreen.new(params)
end
- 1
def payload
- 3
payload = {}
- 3
payload[:title] = title
- 3
payload[:ref] = ref unless ref.nil?
- 3
unless show_button.nil? && button_text.nil? && button_mode.nil? && redirect_url.nil? && share_icons.nil?
- 3
payload[:properties] = {}
- 3
payload[:properties][:show_button] = show_button unless show_button.nil?
- 3
payload[:properties][:button_text] = button_text unless button_text.nil?
- 3
payload[:properties][:button_mode] = button_mode unless button_mode.nil?
- 3
payload[:properties][:redirect_url] = redirect_url unless redirect_url.nil?
- 3
payload[:properties][:share_icons] = share_icons unless share_icons.nil?
end
- 3
payload[:attachment] = attachment unless attachment.nil?
- 3
payload
end
- 1
def same?(actual)
title == actual.title &&
- 4
(ref.nil? || ref == actual.ref) &&
- 4
(show_button.nil? ? ThankYouScreen.default.show_button == actual.show_button : show_button == actual.show_button) &&
- 4
(button_text.nil? || button_text == actual.button_text) &&
- 4
((button_mode.nil? ? ThankYouScreen.default.button_mode == actual.button_mode : button_mode == actual.button_mode) || ref == 'default_tys') &&
- 4
(redirect_url.nil? || redirect_url == actual.redirect_url) &&
- 4
(share_icons.nil? ? ThankYouScreen.default.share_icons == actual.share_icons : share_icons == actual.share_icons) &&
- 4
(attachment.nil? || same_attachment?(actual.attachment) || ref == 'default_tys')
end
- 1
def self.default
ThankYouScreen.new(
show_button: true,
button_mode: 'reload',
share_icons: true
)
end
- 1
def self.default_basic
ThankYouScreen.new(
title: "Thanks for completing this typeform\nNow *create your own* — it's free, easy, & beautiful",
ref: 'default_tys',
show_button: true,
share_icons: false,
button_mode: 'redirect',
button_text: 'Create a *typeform*',
redirect_url: 'https://admin.typeform.com/signup?utm_campaign=Oi4jqT&utm_source=typeform.com-207-Basic&utm_medium=typeform&utm_content=typeform-thankyoubutton&utm_term=EN',
attachment: {
type: 'image',
href: "#{APIConfig.image_api_request_url}/images/2dpnUBBkz2VN"
}
)
end
- 1
def self.default_pro
ThankYouScreen.new(
title: 'Done! Your information was sent perfectly.',
ref: 'default_tys',
show_button: false,
share_icons: false
)
end
- 1
def self.full_example
- 3
ThankYouScreen.new(
ref: DataGenerator.field_ref,
show_button: false,
button_text: 'Click me!',
button_mode: 'redirect',
redirect_url: 'http://www.google.com',
share_icons: false,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class WebsiteBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required
- 1
def initialize(id: nil, title: nil, type: :website, ref: nil, description: nil, required: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(required.nil? ? WebsiteBlock.default.required : required) == actual.required
end
- 1
def self.default
WebsiteBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
WebsiteBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
required: true,
id: id
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class WelcomeScreen < Block
- 1
attr_accessor :id, :title, :ref, :type, :description, :show_button, :button_text, :attachment
- 1
def initialize(id: nil, title: nil, type: :welcome_screen, ref: nil, description: nil, show_button: nil, button_text: nil, attachment: nil)
- 9
@id = id
- 9
@title = title || DataGenerator.title
- 9
@ref = ref
- 9
@type = type
- 9
@description = description
- 9
@show_button = show_button
- 9
@button_text = button_text
- 9
@attachment = attachment
end
- 1
def self.from_response(response)
- 6
properties = response[:properties]
- 30
block_params = response.keep_if { |k, _| k != :properties }
- 6
params = properties.merge(block_params)
- 6
WelcomeScreen.new(params)
end
- 1
def payload
- 2
payload = {}
- 2
payload[:properties] = {}
- 2
payload[:title] = title
- 2
payload[:ref] = ref unless ref.nil?
- 2
payload[:properties][:description] = description unless description.nil?
- 2
payload[:properties][:show_button] = show_button unless show_button.nil?
- 2
payload[:properties][:button_text] = button_text unless button_text.nil?
- 2
payload[:attachment] = attachment unless attachment.nil?
- 2
payload
end
- 1
def same_extra_attributes?(actual)
- 4
(show_button.nil? ? WelcomeScreen.default.show_button == actual.show_button : show_button == actual.show_button) &&
- 8
(button_text.nil? ? WelcomeScreen.default.button_text == actual.button_text : button_text == actual.button_text)
end
- 1
def self.default
WelcomeScreen.new(show_button: true, button_text: 'start')
end
- 1
def self.full_example(id: nil)
- 3
WelcomeScreen.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
show_button: false,
button_text: 'Click me!',
id: id,
attachment: Block.attachment
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'block'
- 1
class YesNoBlock < Block
- 1
attr_accessor :id, :title, :type, :ref, :description, :required, :attachment
- 1
def initialize(id: nil, title: nil, type: :yes_no, ref: nil, description: nil, required: nil, attachment: nil)
- 18
@id = id
- 18
@title = title || DataGenerator.title
- 18
@type = type
- 18
@ref = ref
- 18
@description = description
- 18
@required = required
- 18
@attachment = attachment
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:type] = type.to_s
- 4
payload[:id] = id unless id.nil?
- 4
payload[:ref] = ref unless ref.nil?
- 4
unless description.nil?
- 4
payload[:properties] = {}
- 4
payload[:properties][:description] = description
end
- 4
unless required.nil?
- 4
payload[:validations] = {}
- 4
payload[:validations][:required] = required
end
- 4
payload[:attachment] = attachment unless attachment.nil?
- 4
payload
end
- 1
def same_extra_attributes?(actual)
- 8
(required.nil? ? YesNoBlock.default.required : required) == actual.required
end
- 1
def self.default
YesNoBlock.new(
required: false
)
end
- 1
def self.full_example(id: nil)
- 6
YesNoBlock.new(
ref: DataGenerator.field_ref,
description: DataGenerator.description,
required: true,
attachment: Block.attachment,
id: id
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Form
- 1
attr_accessor :id, :title, :blocks, :hidden, :theme_url, :workspace_url, :welcome_screens, :thank_you_screens, :logic, :settings, :variables
- 1
def initialize(id: nil, title: nil, blocks: [], hidden: [], theme_url: nil, workspace_url: nil, welcome_screens: [], thank_you_screens: [], logic: [], settings: nil, variables: nil)
- 13
@id = id
- 13
@title = title || DataGenerator.title
- 13
@blocks = blocks
- 13
@hidden = hidden
- 13
@theme_url = theme_url
- 13
@workspace_url = workspace_url
- 13
@welcome_screens = welcome_screens
- 13
@thank_you_screens = thank_you_screens
- 13
@logic = logic
- 13
@settings = settings
- 13
@variables = variables
end
- 1
def self.from_response(payload)
- 110
blocks = payload[:fields].nil? ? [] : payload[:fields].map { |field_payload| Block.from_response(field_payload) }
- 14
welcome_screens = payload[:welcome_screens].nil? ? [] : payload[:welcome_screens].map { |welcome_screen_payload| WelcomeScreen.from_response(welcome_screen_payload) }
- 22
thank_you_screens = payload[:thankyou_screens].map { |thank_you_screen_payload| ThankYouScreen.from_response(thank_you_screen_payload) }
- 8
hidden_fields = payload[:hidden].nil? ? [] : payload[:hidden]
- 110
logic = payload[:logic].nil? ? [] : payload[:logic].map { |logic_payload| FieldLogic.from_response(logic_payload) }
- 8
settings = Settings.from_response(payload[:settings])
- 8
variables = payload[:variables].nil? ? nil : Variables.from_response(payload[:variables])
- 8
new(
id: payload[:id],
title: payload[:title],
blocks: blocks,
hidden: hidden_fields,
theme_url: payload[:theme][:href],
workspace_url: payload[:workspace][:href],
welcome_screens: welcome_screens,
thank_you_screens: thank_you_screens,
logic: logic,
settings: settings,
variables: variables
)
end
- 1
def payload
- 4
payload = {}
- 4
payload[:title] = title
- 4
payload[:id] = id unless id.nil?
- 4
payload[:hidden] = hidden unless hidden.empty?
- 4
payload[:theme] = { href: theme_url } unless theme_url.nil?
- 4
payload[:workspace] = { href: workspace_url } unless workspace_url.nil?
- 4
payload[:fields] = blocks.map(&:payload) unless blocks.empty?
- 4
payload[:welcome_screens] = welcome_screens.map(&:payload) unless welcome_screens.empty?
- 4
payload[:thankyou_screens] = thank_you_screens.map(&:payload) unless thank_you_screens.empty?
- 4
payload[:logic] = logic.map(&:payload) unless logic.empty?
- 4
payload[:settings] = settings.payload unless settings.nil?
- 4
payload[:variables] = variables.payload unless variables.nil?
- 4
payload.to_json
end
- 1
def same?(actual)
- 5
(id.nil? || id == actual.id) &&
- 10
(hidden.nil? || hidden == actual.hidden) &&
- 5
(theme_url.nil? || theme_url.include?('default') || theme_url == actual.theme_url) &&
- 5
(workspace_url.nil? || workspace_url == actual.workspace_url) &&
title == actual.title &&
same_blocks?(actual.blocks) &&
same_welcome_screens?(actual.welcome_screens) &&
same_thank_you_screens?(actual.thank_you_screens) &&
same_logic?(actual.logic) &&
- 4
(settings.nil? ? Settings.default : settings).same?(actual.settings) &&
- 4
(variables.nil? || variables.same?(actual.variables))
end
- 1
def same_blocks?(actual_blocks)
blocks.zip(actual_blocks).all? do |expected, actual|
- 68
expected.same?(actual)
- 4
end && blocks.length == actual_blocks.length
end
- 1
def same_welcome_screens?(actual_welcome_screens)
welcome_screens.zip(actual_welcome_screens).all? do |expected, actual|
- 4
expected.same?(actual)
- 4
end && welcome_screens.length == actual_welcome_screens.length
end
- 1
def same_thank_you_screens?(actual_thank_you_screens)
- 10
thank_you_screens.delete_if { |tys| tys.ref == 'default_tys' }
- 11
actual_thank_you_screens.delete_if { |tys| tys.ref == 'default_tys' }
- 4
thank_you_screens.zip(actual_thank_you_screens).all? do |expected, actual|
- 4
expected.same?(actual)
end
end
- 1
def same_logic?(actual_logic)
logic.all? do |field_logic|
- 680
actual_field_logic = actual_logic.find { |fl| fl.field_ref == field_logic.field_ref }
- 68
field_logic.same?(actual_field_logic)
- 4
end && logic.length == actual_logic.length
end
- 1
def theme_id
theme_url.split('/themes/')[1]
end
- 1
def workspace_id
workspace_url.split('/workspaces/')[1]
end
- 1
def add_logic_action(field_ref, logic_action)
field_logic = logic.find { |current_field_logic| current_field_logic.field_ref == field_ref }
field_logic.nil? ? logic << FieldLogic.new(type: 'field', field_ref: field_ref, actions: [logic_action]) : field_logic.actions << logic_action
end
- 1
def self.with_all_blocks
blocks = Block.all_types.values.map(&:new)
Form.new(
blocks: blocks
)
end
- 1
def self.full_example(id: nil)
- 3
blocks = Block.all_types.values.map(&:full_example)
- 12
email_block = blocks.find { |current_block| current_block.type == :email }
- 3
form = Form.new(
id: id,
hidden: %w[hiddenfield1 hiddenfield2],
theme_url: "#{APIConfig.api_request_url}/themes/default",
blocks: blocks,
welcome_screens: [WelcomeScreen.full_example],
thank_you_screens: [ThankYouScreen.full_example],
settings: Settings.full_example(email_block.ref),
variables: Variables.full_example
)
- 54
form.logic = blocks.map { |block| FieldLogic.full_example(block, form) }
- 3
form
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative '../logic_action'
- 1
class Calculation < LogicAction
- 1
attr_accessor :action_type, :numeric_value, :target_ref, :logic_condition
- 1
def initialize(action_type: nil, numeric_value: nil, target_ref: nil, logic_condition: nil)
- 126
@action_type = action_type
- 126
@numeric_value = numeric_value
- 126
@target_ref = target_ref
- 126
@logic_condition = logic_condition
end
- 1
def self.from_response(payload)
- 84
action_type = payload[:action]
- 84
target_ref = payload[:details][:target][:value]
- 84
numeric_value = payload[:details][:value][:value]
- 84
logic_condition = LogicCondition.from_response(payload[:condition])
- 84
Calculation.new(action_type: action_type, numeric_value: numeric_value, target_ref: target_ref, logic_condition: logic_condition)
end
- 1
def payload
- 28
payload = {}
- 28
payload[:action] = action_type
- 28
payload[:details] = { target: { type: 'variable', value: target_ref } }
- 28
payload[:details][:value] = { type: 'constant', value: numeric_value }
- 28
payload[:condition] = logic_condition.payload
- 28
payload
end
- 1
def self.full_example(block)
- 42
is_blocks = %i[multiple_choice picture_choice yes_no legal]
- 42
logic_condition = if is_blocks.include?(block.type)
- 12
LogicCondition.generate_from_block(block, op: 'is')
- 30
elsif block.type == :date
- 3
LogicCondition.generate_from_block(block, op: 'on')
- 27
elsif block.type == :file_upload
- 3
LogicCondition.generate_from_block(block, op: 'answered')
else
- 24
LogicCondition.generate_from_block(block, op: 'equal')
end
- 42
Calculation.new(
action_type: 'add',
numeric_value: 5,
target_ref: 'score',
logic_condition: logic_condition
)
end
- 1
def same?(actual)
action_type == actual.action_type &&
- 154
target_ref == actual.target_ref &&
numeric_value == actual.numeric_value &&
logic_condition.same?(actual.logic_condition)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative '../logic_action'
- 1
class LogicJump < LogicAction
- 1
attr_accessor :to_type, :to_ref, :logic_condition
- 1
def initialize(to_type: nil, to_ref: nil, logic_condition: nil)
- 154
@to_type = to_type
- 154
@to_ref = to_ref
- 154
@logic_condition = logic_condition
end
- 1
def self.from_response(payload)
- 102
to_type = payload[:details][:to][:type]
- 102
to_ref = payload[:details][:to][:value]
- 102
logic_condition = LogicCondition.from_response(payload[:condition])
- 102
LogicJump.new(to_type: to_type, to_ref: to_ref, logic_condition: logic_condition)
end
- 1
def self.create_field_logic_jump(form, block_type)
- 408
logic_block = form.blocks.find { |block| Block.block_symbol_to_string(block.type) == block_type }
- 42
to_ref = if form.blocks.last.ref == logic_block.ref
- 3
form.blocks.first.ref
else
- 39
form.blocks.last.ref
end
- 42
logic_condition = LogicCondition.generate_from_block(logic_block)
- 42
LogicJump.new(to_type: 'field', to_ref: to_ref, logic_condition: logic_condition)
end
- 1
def self.create_always_jump(form)
- 10
LogicJump.new(to_type: 'field', to_ref: form.blocks.first.ref, logic_condition: LogicCondition.new(op: 'always'))
end
- 1
def self.create_hidden_logic_jump(form)
logic_condition_details = LogicConditionDetails.new(reference_type: 'hidden', reference: form.hidden[0], value_type: 'constant', value: 'abc')
logic_condition = LogicCondition.new(op: 'equal', vars: [logic_condition_details])
LogicJump.new(to_type: 'field', to_ref: form.blocks.first.ref, logic_condition: logic_condition)
end
- 1
def self.create_variable_logic_jump(form)
logic_condition_details = LogicConditionDetails.new(reference_type: 'variable', reference: 'score', value_type: 'constant', value: 5)
logic_condition = LogicCondition.new(op: 'equal', vars: [logic_condition_details])
LogicJump.new(to_type: 'field', to_ref: form.blocks.first.ref, logic_condition: logic_condition)
end
- 1
def self.create_nested_logic_jump(form)
logic_condition1 = LogicCondition.generate_from_block(form.blocks[0])
logic_condition2 = LogicCondition.generate_from_block(form.blocks[1])
logic_condition3 = LogicCondition.generate_from_block(form.blocks[2])
and_logic_condition = LogicCondition.new(op: 'and', vars: [logic_condition1, logic_condition2])
or_logic_condition = LogicCondition.new(op: 'or', vars: [logic_condition3, and_logic_condition])
LogicJump.new(to_type: 'field', to_ref: form.blocks.last.ref, logic_condition: or_logic_condition)
end
- 1
def self.create_thankyou_logic_jump(form)
logic_condition = LogicCondition.generate_from_block(form.blocks[0])
LogicJump.new(to_type: 'thankyou', to_ref: form.thank_you_screens.first.ref, logic_condition: logic_condition)
end
- 1
def payload
- 34
payload = {}
- 34
payload[:action] = 'jump'
- 34
payload[:details] = { to: { type: to_type, value: to_ref } }
- 34
payload[:condition] = logic_condition.payload
- 34
payload
end
- 1
def same?(actual)
to_type == actual.to_type &&
- 152
to_ref == actual.to_ref &&
logic_condition.same?(actual.logic_condition)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class FieldLogic
- 1
attr_accessor :field_ref, :type, :actions
- 1
def initialize(field_ref: nil, type: nil, actions: [])
- 153
@field_ref = field_ref
- 153
@actions = actions
- 153
@type = type
end
- 1
def self.from_response(payload)
- 102
field_ref = payload[:ref] unless payload[:ref].nil?
- 288
actions = payload[:actions].nil? ? [] : payload[:actions].map { |action_payload| LogicAction.from_response(action_payload) }
- 102
type = payload[:type]
- 102
FieldLogic.new(field_ref: field_ref, type: type, actions: actions)
end
- 1
def payload
- 34
payload = {}
- 34
payload[:ref] = field_ref unless field_ref.nil?
- 34
payload[:type] = type unless type.nil?
- 34
payload[:actions] = actions.map(&:payload) unless actions.empty?
- 34
payload
end
- 1
def same?(actual)
- 68
(field_ref.nil? || field_ref == actual.field_ref) &&
- 68
type == actual.type &&
actions.all? do |action|
- 124
actual_action = actual.actions.find do |a|
- 180
begin
- 180
a.same?(action)
rescue NoMethodError
- 56
false
end
end
- 124
action.same?(actual_action)
end && actions.length == actual.actions.length
end
- 1
def self.full_example(logic_block, form)
- 51
non_logic_blocks = %i[group payment statement]
- 51
actions = if non_logic_blocks.include?(logic_block.type)
[
- 9
LogicJump.create_always_jump(form)
]
else
[
- 42
LogicJump.create_field_logic_jump(form, Block.block_symbol_to_string(logic_block.type)),
Calculation.full_example(logic_block)
]
end
- 51
FieldLogic.new(field_ref: logic_block.ref, type: 'field', actions: actions)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class LogicAction
- 1
def self.from_response(payload)
- 186
case payload[:action]
when 'jump'
- 102
LogicJump.from_response(payload)
when 'add', 'subtract', 'multiply', 'divide'
- 84
Calculation.from_response(payload)
end
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class LogicCondition
- 1
attr_accessor :op, :vars
- 1
def initialize(op: nil, vars: [])
- 280
@op = op
- 280
@vars = vars
end
- 1
def vars_are_condition_details?
vars.is_a?(LogicConditionDetails)
end
- 1
def self.from_response(payload)
- 186
vars = []
- 186
if payload[:vars].any?
- 504
is_logic_condition_details = payload[:vars].detect { |var| var.key?(:op) }.nil?
- 168
vars = is_logic_condition_details ? [LogicConditionDetails.from_response(payload[:vars])] : payload[:vars].map { |condition_payload| LogicCondition.from_response(condition_payload) }
end
- 186
LogicCondition.new(op: payload[:op], vars: vars)
end
- 1
def self.generate_from_block(block, op: nil)
- 84
case block.type
when :number, :opinion_scale, :rating
- 18
op ||= 'lower_equal_than'
- 18
logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: 15)
when :date
- 6
op ||= 'not_on'
- 6
logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: '2017-01-01')
when :yes_no, :legal
- 12
op ||= 'is'
- 12
logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: true)
when :file_upload
- 6
op ||= 'answered'
- 6
logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: true)
when :multiple_choice, :picture_choice
- 12
op ||= 'is'
- 12
logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'choice', value: block.choices.first.fetch(:ref))
else
- 30
op ||= 'contains'
- 30
logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: 'hello')
end
- 84
LogicCondition.new(op: op, vars: [logic_condition_details])
end
- 1
def payload
- 62
payload = {}
- 62
payload[:op] = op
- 62
if vars.empty?
- 6
payload[:vars] = []
else
- 56
payload[:vars] = vars.map(&:payload)
- 56
payload[:vars].flatten!
end
- 62
payload
end
- 1
def same?(actual)
op == actual.op &&
- 249
same_vars?(actual.vars)
end
- 1
def same_vars?(actual_vars)
- 249
vars.zip(actual_vars).all? do |expected, actual|
- 224
expected.same?(actual)
end
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class LogicConditionDetails
- 1
attr_accessor :reference_type, :reference, :value_type, :value
- 1
def initialize(reference_type: nil, reference: nil, value_type: nil, value: nil)
- 252
@reference_type = reference_type
- 252
@reference = reference
- 252
@value_type = value_type
- 252
@value = value
end
- 1
def self.from_response(payload)
- 168
reference_object = payload.first
- 168
value_object = payload.last
- 168
reference_type = reference_object[:type] unless reference_object.nil?
- 168
reference = reference_object[:value] unless reference_object.nil?
- 168
value_type = value_object[:type] unless value_object.nil?
- 168
value = value_object[:value] unless value_object.nil?
- 168
LogicConditionDetails.new(
reference_type: reference_type,
reference: reference,
value_type: value_type,
value: value
)
end
- 1
def payload
- 56
if reference_type.nil?
[]
else
- 56
[{ type: reference_type, value: reference }, { type: value_type, value: value }]
end
end
- 1
def same?(actual)
reference_type == actual.reference_type &&
- 224
reference == actual.reference &&
value_type == actual.value_type &&
value == actual.value
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Messages
- 1
attr_accessor :messages
- 1
def initialize(messages)
- 4
@messages = Hash[messages.map { |(k, v)| [k.to_sym, v] }]
end
- 1
def self.from_response(response)
- 1
Messages.new(response)
end
- 1
def payload
- 1
messages.to_json
end
- 1
def same?(actual)
- 1
messages == actual.messages
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
class CreateFormRequest < FormRequest
- 1
def initialize(form, token: APIConfig.token)
- 3
request(
method: :post,
url: "#{APIConfig.api_request_url}/forms",
headers: {
'Authorization' => "Bearer #{token}"
},
payload: form.payload
)
end
- 1
def success?
- 3
@response.code == 201 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
class DeleteFormRequest < FormRequest
- 1
def initialize(form, token: APIConfig.token)
- 3
request(
method: :delete,
url: "#{APIConfig.api_request_url}/forms/#{form.id}",
headers: {
'Authorization' => "Bearer #{token}"
}
)
end
- 1
def success?
- 3
@response.code == 204
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative '../../api_request'
- 1
class FormRequest < APIRequest
- 1
def form
- 8
Form.from_response(json)
end
- 1
def error_code
json.fetch(:code)
end
- 1
def invalid_form?
@response.code == 400 && %w[VALIDATION_ERROR BAD_REQUEST INVALID_JSON].include?(error_code)
end
- 1
def unauthorized?
@response.code == 401
end
- 1
def payment_required?
@response.code == 402
end
- 1
def forbidden?
@response.code == 403
end
- 1
def not_found?
@response.code == 404
end
- 1
def conflict?
@response.code == 409
end
- 1
def service_unavailable?
@response.code == 502 || @response.code == 503
end
- 1
def last_modified
Time.parse(@response.headers[:last_modified])
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
class HeadFormRequest < FormRequest
- 1
def initialize(form, token: APIConfig.token)
- 1
r = {
method: :head,
url: "#{APIConfig.api_request_url}/forms/#{form.id}"
}
- 1
r[:headers] = { 'Authorization' => "Bearer #{token}" } unless token.nil?
- 1
request(r)
end
- 1
def success?
- 1
@response.code == 200
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class RetrieveMessagesRequest < APIRequest
- 1
def initialize(form, token: APIConfig.token)
- 2
request(
method: :get,
url: "#{APIConfig.api_request_url}/forms/#{form.id}/messages",
headers: {
'Authorization' => "Bearer #{token}"
}
)
end
- 1
def success?
- 2
@response.code == 200 && json?
end
- 1
def messages
- 1
Messages.from_response(json)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class UpdateMessagesRequest < APIRequest
- 1
def initialize(form, messages, token: APIConfig.token)
- 1
request(
method: :put,
url: "#{APIConfig.api_request_url}/forms/#{form.id}/messages",
headers: {
'Authorization' => "Bearer #{token}"
},
payload: messages.payload
)
end
- 1
def success?
- 1
@response.code == 204
end
- 1
def payment_required?
@response.code == 402
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
require 'open-uri'
- 1
class RetrieveAllFormsRequest < FormRequest
- 1
def initialize(token: APIConfig.token, forms_per_page: 10, page: nil, search: nil, theme: nil, workspace: nil, from_id: nil)
- 1
url = "#{APIConfig.api_request_url}/forms?"
- 1
url << "page_size=#{forms_per_page}&" unless forms_per_page.nil?
- 1
url << "page=#{page}&" unless page.nil?
- 1
url << "search=#{URI.encode_www_form_component(search)}&" unless search.nil?
- 1
url << "theme_id=#{theme.id}&" unless theme.nil?
- 1
url << "workspace_id=#{workspace.id}&" unless workspace.nil?
- 1
url << "from_id=#{from_id}&" unless from_id.nil?
- 1
r = {
method: :get,
url: url
}
- 1
r[:headers] = { 'Authorization' => "Bearer #{token}" } unless token.nil?
- 1
request(r)
end
- 1
def success?
- 1
@response.code == 200 && json?
end
- 1
def forms
json.fetch(:items)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
class RetrieveFormRequest < FormRequest
- 1
def initialize(form, token: APIConfig.token)
- 1
r = {
method: :get,
url: "#{APIConfig.api_request_url}/forms/#{form.id}"
}
- 1
r[:headers] = { 'Authorization' => "Bearer #{token}" } unless token.nil?
- 1
request(r)
end
- 1
def success?
- 1
@response.code == 200 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
class UpdateFormPatchRequest < FormRequest
- 1
def initialize(form, operations, token: APIConfig.token)
- 1
request(
method: :patch,
url: "#{APIConfig.api_request_url}/forms/#{form.id}",
headers: {
'Authorization' => "Bearer #{token}",
'Content-Type' => 'application/json'
},
payload: operations.map(&:payload).to_json
)
end
- 1
def success?
- 1
@response.code == 204
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'form_request'
- 1
class UpdateFormRequest < FormRequest
- 1
def initialize(form, token: APIConfig.token)
- 1
request(
method: :put,
url: "#{APIConfig.api_request_url}/forms/#{form.id}",
headers: {
'Authorization' => "Bearer #{token}"
},
payload: form.payload
)
end
- 1
def success?
- 1
@response.code == 200 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Notifications
- 1
attr_accessor :self_enabled, :self_recipients, :self_reply_to, :self_subject, :self_message,
:respondent_enabled, :respondent_recipient, :respondent_reply_to, :respondent_subject, :respondent_message
- 1
def initialize(self_enabled: nil, self_recipients: nil, self_reply_to: nil, self_subject: nil, self_message: nil,
respondent_enabled: nil, respondent_recipient: nil, respondent_reply_to: nil, respondent_subject: nil, respondent_message: nil)
- 10
@self_enabled = self_enabled
- 10
@self_recipients = self_recipients
- 10
@self_reply_to = self_reply_to
- 10
@self_subject = self_subject
- 10
@self_message = self_message
- 10
@respondent_enabled = respondent_enabled
- 10
@respondent_recipient = respondent_recipient
- 10
@respondent_reply_to = respondent_reply_to
- 10
@respondent_subject = respondent_subject
- 10
@respondent_message = respondent_message
end
- 1
def self.from_response(response)
- 6
self_payload = response[:self]
- 6
new_self_payload = {}
- 6
self_payload.each_key do |key|
- 30
new_key = 'self_' + key.to_s
- 30
new_self_payload[new_key.to_sym] = self_payload.delete(key)
end
- 6
respondent_payload = response[:respondent]
- 6
new_respondent_payload = {}
- 6
respondent_payload.each_key do |key|
- 30
new_key = 'respondent_' + key.to_s
- 30
new_respondent_payload[new_key.to_sym] = respondent_payload.delete(key)
end
- 6
params = new_respondent_payload.merge(new_self_payload)
- 6
Notifications.new(params)
end
- 1
def payload
- 2
payload = {}
- 2
unless self_recipients.nil? && self_subject.nil? && self_message.nil?
- 2
payload[:self] = {}
- 2
payload[:self][:enabled] = self_enabled unless self_enabled.nil?
- 2
payload[:self][:reply_to] = self_reply_to unless self_reply_to.nil?
- 2
payload[:self][:recipients] = self_recipients unless self_recipients.nil?
- 2
payload[:self][:subject] = self_subject unless self_subject.nil?
- 2
payload[:self][:message] = self_message unless self_message.nil?
end
- 2
unless respondent_recipient.nil? && respondent_subject.nil? && respondent_message.nil?
- 2
payload[:respondent] = {}
- 2
payload[:respondent][:enabled] = respondent_enabled unless respondent_enabled.nil?
- 2
payload[:respondent][:reply_to] = respondent_reply_to unless respondent_reply_to.nil?
- 2
payload[:respondent][:recipient] = respondent_recipient unless respondent_recipient.nil?
- 2
payload[:respondent][:subject] = respondent_subject unless respondent_subject.nil?
- 2
payload[:respondent][:message] = respondent_message unless respondent_message.nil?
end
- 2
payload
end
- 1
def same?(actual)
- 6
(self_enabled.nil? || self_enabled == actual.self_enabled) &&
- 12
(self_reply_to.nil? || self_reply_to == actual.self_reply_to) &&
- 6
(self_recipients.nil? || self_recipients == actual.self_recipients) &&
- 6
(self_subject.nil? || self_subject == actual.self_subject) &&
- 6
(self_message.nil? || self_message == actual.self_message) &&
- 6
(respondent_enabled.nil? || respondent_enabled == actual.respondent_enabled) &&
- 6
(respondent_reply_to.nil? || respondent_reply_to == actual.respondent_reply_to) &&
- 6
(respondent_recipient.nil? || respondent_recipient == actual.respondent_recipient) &&
- 6
(respondent_subject.nil? || respondent_subject == actual.respondent_subject) &&
- 6
(respondent_message.nil? || respondent_message == actual.respondent_message)
end
- 1
def self.full_example(email_block_for_notifications_ref)
- 4
Notifications.new(self_enabled: true, self_reply_to: '{{field:' + email_block_for_notifications_ref + '}}', self_recipients<EMAIL_ADDRESS><EMAIL_ADDRESS>self_subject: 'An email subject', self_message: 'This is a message that will be in an email',
respondent_enabled: true, respondent_reply_to<EMAIL_ADDRESS>respondent_recipient: '{{field:' + email_block_for_notifications_ref + '}}',
respondent_subject: 'An email subject', respondent_message: 'This is a message that will be in an email')
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Settings
- 1
attr_accessor :redirect_after_submit_url, :show_typeform_branding, :progress_bar,
:show_progress_bar, :description, :allow_indexing, :image, :language,
:is_public, :is_trial, :google_analytics, :notifications
- 1
def initialize(redirect_after_submit_url: nil, show_typeform_branding: nil, progress_bar: nil,
show_progress_bar: nil, description: nil, allow_indexing: nil, image: nil, language: nil,
is_public: nil, is_trial: nil, google_analytics: nil, notifications: nil)
- 12
@redirect_after_submit_url = redirect_after_submit_url
- 12
@show_typeform_branding = show_typeform_branding
- 12
@progress_bar = progress_bar
- 12
@show_progress_bar = show_progress_bar
- 12
@description = description
- 12
@allow_indexing = allow_indexing
- 12
@language = language
- 12
@is_public = is_public
- 12
@is_trial = is_trial
- 12
@image = image
- 12
@google_analytics = google_analytics
- 12
@notifications = notifications
end
- 1
def self.from_response(response)
- 8
meta = response[:meta]
- 82
settings_params = response.keep_if { |k, _| k != :meta }
- 8
params = meta.merge(settings_params)
- 8
params[:notifications] = Notifications.from_response(response[:notifications]) unless response[:notifications].nil?
- 8
Settings.new(params)
end
- 1
def payload
- 2
payload = {}
- 2
payload[:redirect_after_submit_url] = redirect_after_submit_url unless redirect_after_submit_url.nil?
- 2
payload[:show_typeform_branding] = show_typeform_branding unless show_typeform_branding.nil?
- 2
payload[:progress_bar] = progress_bar unless progress_bar.nil?
- 2
payload[:show_progress_bar] = show_progress_bar unless show_progress_bar.nil?
- 2
payload[:language] = language unless language.nil?
- 2
payload[:is_public] = is_public unless is_public.nil?
- 2
payload[:google_analytics] = google_analytics unless google_analytics.nil?
- 2
payload[:notifications] = notifications.payload unless notifications.nil?
- 2
unless description.nil? && allow_indexing.nil?
- 2
payload[:meta] = {}
- 2
payload[:meta][:description] = description unless description.nil?
- 2
payload[:meta][:allow_indexing] = allow_indexing unless allow_indexing.nil?
- 2
payload[:meta][:image] = image unless image.nil?
end
- 2
payload
end
- 1
def same?(actual)
- 6
(redirect_after_submit_url.nil? || redirect_after_submit_url == actual.redirect_after_submit_url) &&
- 12
(google_analytics.nil? || google_analytics == actual.google_analytics) &&
- 6
(notifications.nil? || notifications.same?(actual.notifications)) &&
- 6
(description.nil? || description == actual.description) &&
- 6
(image.nil? || image[:href].start_with?("#{APIConfig.image_api_request_url}/images/") && actual.image[:href].start_with?("#{APIConfig.image_api_request_url}/images/")) &&
- 6
(show_typeform_branding.nil? ? Settings.default.show_typeform_branding : show_typeform_branding) == actual.show_typeform_branding &&
- 6
(progress_bar.nil? ? Settings.default.progress_bar : progress_bar) == actual.progress_bar &&
- 6
(language.nil? ? Settings.default.language : language) == actual.language &&
- 6
(is_public.nil? ? Settings.default.is_public : is_public) == actual.is_public &&
- 5
(allow_indexing.nil? ? Settings.default.allow_indexing : allow_indexing) == actual.allow_indexing
end
- 1
def self.default
Settings.new(show_typeform_branding: true, progress_bar: 'proportion', show_progress_bar: true,
allow_indexing: false, language: 'en', is_public: true, is_trial: false)
end
- 1
def self.full_example(email_block_for_notifications_ref)
- 4
image = { href: APIConfig.image_api_request_url + '/images/default' }
- 4
Settings.new(redirect_after_submit_url: 'http://google.com', show_typeform_branding: false, progress_bar: 'percentage',
show_progress_bar: false, description: 'some meta description', allow_indexing: true, image: image,
language: 'fr', is_public: true, google_analytics: 'UA-1234-12', notifications: Notifications.full_example(email_block_for_notifications_ref))
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Variables
- 1
attr_accessor :price, :score
- 1
def initialize(price: nil, score: nil)
- 9
@price = price
- 9
@score = score
end
- 1
def self.from_response(payload)
- 6
new(
price: payload[:price],
score: payload[:score]
)
end
- 1
def self.default
Variables.new
end
- 1
def self.full_example
- 3
Variables.new(price: 10, score: 0)
end
- 1
def payload
- 2
payload = {}
- 2
payload[:score] = score unless score.nil?
- 2
payload[:price] = price unless price.nil?
- 2
payload
end
- 1
def same?(actual)
- 4
(score.nil? || score == actual.score) &&
- 8
(price.nil? || price == actual.price)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Image
- 1
attr_accessor :id, :image, :media_type, :file_name, :width, :height, :has_alpha, :avg_color
- 1
def initialize(id: nil, image: nil, media_type: nil, file_name: nil, width: nil, height: nil, has_alpha: nil, avg_color: nil)
- 7
@id = id
- 7
@image = image
- 7
@media_type = media_type
- 7
@file_name = file_name
- 7
@width = width
- 7
@height = height
- 7
@has_alpha = has_alpha
- 7
@avg_color = avg_color
end
- 1
def self.from_response(payload)
- 5
Image.new(
id: payload[:id],
media_type: payload[:media_type],
file_name: payload[:file_name],
width: payload[:width],
height: payload[:height],
has_alpha: payload[:has_alpha],
avg_color: payload[:avg_color]
)
end
- 1
def payload
{
image: image,
media_type: media_type,
file_name: file_name
- 1
}.to_json
end
- 1
def same?(actual)
- 2
(id.nil? || id == actual.id) &&
- 4
(media_type.nil? || media_type == actual.media_type) &&
- 2
(file_name.nil? || file_name == actual.file_name) &&
- 1
(width.nil? || width == actual.width) &&
- 1
(height.nil? || height == actual.height) &&
- 1
(has_alpha.nil? || has_alpha == actual.has_alpha) &&
- 1
(avg_color.nil? || avg_color == actual.avg_color)
end
- 1
def src
"#{APIConfig.image_api_request_url}/images/#{id}"
end
- 1
def self.full_example
- 2
Image.new(
image: File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data', 'typeform_image.txt'))),
media_type: 'image/gif',
file_name: 'typeform.gif',
width: 530,
height: 350,
has_alpha: true,
avg_color: '5a6067'
)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'image_request'
- 1
class CreateImageFromUrlRequest < ImageRequest
- 1
def initialize(image_url, token: APIConfig.token)
request(
method: :post,
url: "#{APIConfig.api_request_url}/images",
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
},
payload: {
url: image_url
}.to_json
)
end
- 1
def success?
@response.code == 201 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'image_request'
- 1
class CreateImageRequest < ImageRequest
- 1
def initialize(image, token: APIConfig.token)
- 1
request(
method: :post,
url: "#{APIConfig.api_request_url}/images",
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
},
payload: image.payload
)
end
- 1
def success?
- 1
@response.code == 201 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'image_request'
- 1
class DeleteImageRequest < ImageRequest
- 1
def initialize(image, token: APIConfig.token)
- 1
request(
method: :delete,
url: "#{APIConfig.api_request_url}/images/#{image.id}",
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
}
)
end
- 1
def success?
- 1
@response.code == 204
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative '../../api_request'
- 1
class ImageRequest < APIRequest
- 1
def image
- 5
Image.from_response(json)
end
- 1
def src
json.fetch(:src)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'image_request'
- 1
class RetrieveAllImagesRequest < ImageRequest
- 1
def initialize(token: APIConfig.token)
- 1
request(
method: :get,
url: "#{APIConfig.api_request_url}/images",
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{token}"
}
)
end
- 1
def images
json.map { |image| Image.from_response(image) }
end
- 1
def success?
- 1
@response.code == 200 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'image_request'
- 1
class RetrieveFrameRequest < ImageRequest
- 1
def initialize(image, frame)
- 1
request(
method: :get,
url: "#{APIConfig.image_api_request_url}/images/#{image.id}/image/default-#{frame}frame.png",
headers: {
'Content-Type' => 'application/json'
}
)
end
- 1
def success?
- 1
@response.code == 200
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'image_request'
- 1
class RetrieveImageRequest < ImageRequest
- 1
def initialize(image, type: nil, size: nil, accept: nil)
- 1
url = if type.nil? && size.nil?
- 1
"#{APIConfig.api_request_url}/images/#{image.id}"
else
"#{APIConfig.api_request_url}/images/#{image.id}/#{type}/#{size}"
end
- 1
headers = { 'Content-Type' => 'application/json' }
- 1
headers['Accept'] = 'application/json' if accept == 'json'
- 1
request(
method: :get,
url: url,
headers: headers
)
end
- 1
def success?
- 1
@response.code == 200
end
- 1
def body
@response.body
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class PatchOperation
- 1
attr_accessor :op, :value, :path
- 1
def initialize(op: nil, path: nil, value: nil)
- 6
@op = op
- 6
@path = path
- 6
@value = value
end
- 1
def payload
{
op: op,
path: path,
value: value
- 6
}
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'team_request'
- 1
class RetrieveTeamRequest < TeamRequest
- 1
def initialize(token: APIConfig.token)
- 1
request(
method: :get,
url: "#{APIConfig.api_request_url}/teams/mine",
headers: {
'Authorization' => "Bearer #{token}"
}
)
end
- 1
def success?
- 1
@response.code == 200 && json? && json.key?(:members) && json.key?(:total_seats)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative '../../api_request'
- 1
class TeamRequest < APIRequest
- 1
def not_found?
@response.code == 404
end
- 1
def forbidden?
@response.code == 403
end
- 1
def bad_request?
@response.code == 400
end
- 1
def payment_required?
@response.code == 402
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'team_request'
- 1
class UpdateTeamRequest < TeamRequest
- 1
def initialize(operations, token: APIConfig.token)
- 1
request(
method: :patch,
url: "#{APIConfig.api_request_url}/teams/mine",
headers: {
'Authorization' => "Bearer #{token}"
},
payload: operations.map(&:payload).to_json
)
end
- 1
def success?
- 1
@response.code == 204
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
class Background
- 1
attr_accessor :href, :brightness, :layout
- 1
def initialize(href: nil, brightness: nil, layout: nil)
- 8
@href = href
- 8
@brightness = brightness
- 8
@layout = layout
end
- 1
def payload
- 2
payload = {
href: href
}
- 2
payload[:brightness] = brightness unless brightness.nil?
- 2
payload[:layout] = layout unless layout.nil?
- 2
payload
end
- 1
def self.from_response(payload)
- 6
new(
href: payload[:href],
layout: payload[:layout],
brightness: payload[:brightness]
)
end
- 1
def self.default
Background.new(
brightness: 0,
layout: 'repeat'
)
end
- 1
def self.full_example
- 2
Background.new(
href: "#{APIConfig.image_api_request_url}/images/default",
brightness: 0.5,
layout: 'no-repeat'
)
end
- 1
def same?(actual)
- 4
(layout.nil? ? Background.default.layout : layout) == actual.layout &&
- 8
(brightness.nil? ? Background.default.brightness : brightness) == actual.brightness
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'theme_request'
- 1
class CreateThemeRequest < ThemeRequest
- 1
def initialize(theme, token: APIConfig.token)
- 1
request(
method: :post,
url: "#{APIConfig.api_request_url}/themes",
headers: {
'Authorization' => "Bearer #{token}"
},
payload: theme.payload
)
end
- 1
def success?
- 1
@response.code == 201 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'theme_request'
- 1
class DeleteThemeRequest < ThemeRequest
- 1
def initialize(theme, token: APIConfig.token)
- 1
request(
method: :delete,
url: "#{APIConfig.api_request_url}/themes/#{theme.id}",
headers: {
'Authorization' => "Bearer #{token}"
}
)
end
- 1
def success?
- 1
@response.code == 204
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'theme_request'
- 1
require 'rack'
- 1
class RetrieveAllThemesRequest < APIRequest
- 1
def initialize(token: APIConfig.token, page: nil, page_size: nil, visibility: nil)
- 1
filters = {}
- 1
filters[:page] = page unless page.nil?
- 1
filters[:page_size] = page_size unless page_size.nil?
- 1
filters[:visibility] = visibility unless visibility.nil?
- 1
parameters = Rack::Utils.build_query(filters)
- 1
request(
method: :get,
url: "#{APIConfig.api_request_url}/themes?" + parameters,
headers: {
'Authorization' => "Bearer #{token}"
},
verify_ssl: OpenSSL::SSL::VERIFY_NONE
)
end
- 1
def bad_request?
@response.code == 400 && json?
end
- 1
def success?
- 1
@response.code == 200 && json?
end
- 1
def themes
json.fetch(:items)
end
- 1
def total_items
json.fetch(:total_items)
end
- 1
def page_count
json.fetch(:page_count)
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'theme_request'
- 1
class RetrieveThemeRequest < ThemeRequest
- 1
def initialize(theme, token: APIConfig.token)
- 1
headers = {}
- 1
headers = { 'Authorization' => "Bearer #{token}" } unless token.nil?
- 1
request(
method: :get,
url: "#{APIConfig.api_request_url}/themes/#{theme.id}",
headers: headers
)
end
- 1
def success?
- 1
@response.code == 200 && json?
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative '../../api_request'
- 1
class ThemeRequest < APIRequest
- 1
def location_header
headers.fetch(:location)
end
- 1
def theme
- 6
Theme.from_response(json)
end
- 1
def invalid_theme?
@response.code == 400
end
- 1
def not_found_theme?
@response.code == 404
end
- 1
def forbidden?
@response.code == 403
end
- 1
def theme_id
headers.fetch(:location).split('/themes/')[1]
end
end
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
- 1
require_relative 'theme_request'
- 1