├── .github └── workflows │ ├── ci-standard-checks.yml │ └── ruby.yml ├── .gitignore ├── .rubocop.yml ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── coverage ├── .last_run.json ├── .resultset.json ├── .resultset.json.lock ├── assets │ ├── 0.10.2 │ │ ├── application.css │ │ ├── application.js │ │ ├── colorbox │ │ │ ├── border.png │ │ │ ├── controls.png │ │ │ ├── loading.gif │ │ │ └── loading_background.png │ │ ├── favicon_green.png │ │ ├── favicon_red.png │ │ ├── favicon_yellow.png │ │ ├── loading.gif │ │ ├── magnify.png │ │ └── smoothness │ │ │ └── images │ │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ │ ├── ui-bg_flat_75_ffffff_40x100.png │ │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ │ ├── ui-bg_highlight-soft_75_cccccc_1x100.png │ │ │ ├── ui-icons_222222_256x240.png │ │ │ ├── ui-icons_2e83ff_256x240.png │ │ │ ├── ui-icons_454545_256x240.png │ │ │ ├── ui-icons_888888_256x240.png │ │ │ └── ui-icons_cd0a0a_256x240.png │ └── 0.12.2 │ │ ├── DataTables-1.10.20 │ │ └── images │ │ │ ├── sort_asc.png │ │ │ ├── sort_asc_disabled.png │ │ │ ├── sort_both.png │ │ │ ├── sort_desc.png │ │ │ └── sort_desc_disabled.png │ │ ├── application.css │ │ ├── application.js │ │ ├── colorbox │ │ ├── border.png │ │ ├── controls.png │ │ ├── loading.gif │ │ └── loading_background.png │ │ ├── favicon_green.png │ │ ├── favicon_red.png │ │ ├── favicon_yellow.png │ │ ├── images │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ ├── ui-bg_flat_75_ffffff_40x100.png │ │ ├── ui-bg_glass_55_fbf9ee_1x400.png │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ ├── ui-bg_glass_75_dadada_1x400.png │ │ ├── ui-bg_glass_75_e6e6e6_1x400.png │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ ├── ui-bg_highlight-soft_75_cccccc_1x100.png │ │ ├── ui-icons_222222_256x240.png │ │ ├── ui-icons_2e83ff_256x240.png │ │ ├── ui-icons_454545_256x240.png │ │ ├── ui-icons_888888_256x240.png │ │ └── ui-icons_cd0a0a_256x240.png │ │ ├── loading.gif │ │ └── magnify.png └── index.html ├── create_api_gem.gemspec ├── data └── typeform_image.txt ├── lib ├── create_api_gem.rb └── create_api_gem │ ├── api_config.rb │ ├── api_request.rb │ ├── data_generator.rb │ ├── forms │ ├── blocks │ │ ├── block.rb │ │ ├── date_block.rb │ │ ├── dropdown_block.rb │ │ ├── email_block.rb │ │ ├── file_upload_block.rb │ │ ├── group_block.rb │ │ ├── legal_block.rb │ │ ├── long_text_block.rb │ │ ├── multiple_choice_block.rb │ │ ├── number_block.rb │ │ ├── opinion_scale_block.rb │ │ ├── payment_block.rb │ │ ├── phone_number_block.rb │ │ ├── picture_choice_block.rb │ │ ├── rating_block.rb │ │ ├── short_text_block.rb │ │ ├── statement_block.rb │ │ ├── thank_you_screen.rb │ │ ├── website_block.rb │ │ ├── welcome_screen.rb │ │ └── yes_no_block.rb │ ├── form.rb │ ├── logic │ │ ├── actions │ │ │ ├── calculation.rb │ │ │ └── logic_jump.rb │ │ ├── field_logic.rb │ │ ├── logic_action.rb │ │ ├── logic_condition.rb │ │ └── logic_condition_details.rb │ ├── messages.rb │ ├── requests │ │ ├── create_form_request.rb │ │ ├── delete_form_request.rb │ │ ├── form_request.rb │ │ ├── head_form_request.rb │ │ ├── messages │ │ │ ├── retrieve_messages_request.rb │ │ │ └── update_messages_request.rb │ │ ├── retrieve_all_forms_request.rb │ │ ├── retrieve_form_request.rb │ │ ├── update_form_patch_request.rb │ │ └── update_form_request.rb │ ├── settings │ │ ├── notifications.rb │ │ └── settings.rb │ └── variables.rb │ ├── images │ ├── image.rb │ └── requests │ │ ├── create_image_from_url_request.rb │ │ ├── create_image_request.rb │ │ ├── delete_image_request.rb │ │ ├── image_request.rb │ │ ├── retrieve_all_images_request.rb │ │ ├── retrieve_frame_request.rb │ │ └── retrieve_image_request.rb │ ├── patch_operation.rb │ ├── themes │ ├── background.rb │ ├── requests │ │ ├── create_theme_request.rb │ │ ├── delete_theme_request.rb │ │ ├── retrieve_all_themes_request.rb │ │ ├── retrieve_theme_request.rb │ │ ├── theme_request.rb │ │ └── update_theme_request.rb │ └── theme.rb │ ├── version.rb │ └── workspaces │ ├── requests │ ├── create_workspace_request.rb │ ├── delete_workspace_request.rb │ ├── retrieve_all_workspaces_request.rb │ ├── retrieve_default_workspace_request.rb │ ├── retrieve_workspace_request.rb │ ├── update_workspace_request.rb │ └── workspace_request.rb │ └── workspace.rb ├── package-lock.json └── test ├── test_base.rb ├── test_forms.rb ├── test_images.rb ├── test_themes.rb └── test_workspaces.rb /.github/workflows/ci-standard-checks.yml: -------------------------------------------------------------------------------- 1 | name: CI Standard Checks 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | types: [opened, edited, synchronize, reopened] 8 | branches: 9 | - master 10 | 11 | jobs: 12 | ci-standard-checks: 13 | runs-on: [ubuntu-latest] 14 | 15 | steps: 16 | - name: Check Out Source Code 17 | uses: actions/checkout@v2 18 | with: 19 | fetch-depth: 0 20 | 21 | - name: CI Standard Checks 22 | uses: Typeform/ci-standard-checks@v1 23 | with: 24 | githubToken: ${{ secrets.GITHUB_TOKEN }} 25 | dockerUsername: ${{ secrets.GITLEAKS_DOCKER_USERNAME }} 26 | dockerPassword: ${{ secrets.GITLEAKS_DOCKER_PASSWORD }} 27 | -------------------------------------------------------------------------------- /.github/workflows/ruby.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | name: Ruby 7 | 8 | on: 9 | push: 10 | branches: [ master ] 11 | pull_request: 12 | branches: [ master ] 13 | 14 | jobs: 15 | test: 16 | 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - uses: actions/checkout@v2 21 | - name: Set up Ruby 22 | uses: ruby/setup-ruby@v1 23 | with: 24 | ruby-version: 2.3.3 25 | - name: Install dependencies 26 | run: | 27 | gem install bundler:2.1.4 28 | bundle _2.1.4_ install 29 | - name: Rubocop 30 | run: bundle _2.1.4_ exec rubocop 31 | - name: Run tests 32 | run: bundle _2.1.4_ exec rake 33 | 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | **/.idea 10 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | AllCops: 19 | TargetRubyVersion: 2.3.3 20 | Exclude: 21 | - create_api_gem.gemspec 22 | - '**/vendor/**/*' 23 | - '**/vendor/**/.*' 24 | 25 | Style/Documentation: 26 | Enabled: false 27 | 28 | Style/SafeNavigation: 29 | Enabled: false 30 | 31 | Naming/VariableNumber: 32 | Enabled: false 33 | 34 | Metrics/AbcSize: 35 | Max: 70 36 | 37 | Metrics/CyclomaticComplexity: 38 | Max: 25 39 | 40 | Metrics/PerceivedComplexity: 41 | Max: 25 42 | 43 | Metrics/LineLength: 44 | Max: 200 45 | 46 | Metrics/MethodLength: 47 | Max: 100 48 | 49 | Metrics/ModuleLength: 50 | Max: 195 51 | 52 | Metrics/ParameterLists: 53 | Max: 16 54 | 55 | Metrics/ClassLength: 56 | Max: 150 57 | 58 | Naming/MethodParameterName: 59 | AllowedNames: 60 | - op 61 | - id 62 | 63 | Style/FrozenStringLiteralComment: 64 | Enabled: false 65 | 66 | Lint/UnusedMethodArgument: 67 | Enabled: true 68 | Exclude: 69 | - ./lib/create_api_gem/forms/settings/settings.rb 70 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @Typeform/reach-team 2 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Citizen Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of Typeform Open-source is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 6 | 7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 8 | 9 | We invite all those who participate in Typeform Open-source to help us create safe and positive experiences for everyone. 10 | 11 | ## 2. Open [Source/Culture/Tech] Citizenship 12 | 13 | A supplemental goal of this Code of Conduct is to increase open [source/culture/tech] citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 14 | 15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 16 | 17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 18 | 19 | ## 3. Expected Behavior 20 | 21 | The following behaviors are expected and requested of all community members: 22 | 23 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 24 | * Exercise consideration and respect in your speech and actions. 25 | * Attempt collaboration before conflict. 26 | * Refrain from demeaning, discriminatory, or harassing behavior and speech. 27 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. 28 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 29 | 30 | ## 4. Unacceptable Behavior 31 | 32 | The following behaviors are considered harassment and are unacceptable within our community: 33 | 34 | * Violence, threats of violence or violent language directed against another person. 35 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 36 | * Posting or displaying sexually explicit or violent material. 37 | * Posting or threatening to post other people's personally identifying information ("doxing"). 38 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 39 | * Inappropriate photography or recording. 40 | * Inappropriate physical contact. You should have someone's consent before touching them. 41 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 42 | * Deliberate intimidation, stalking or following (online or in person). 43 | * Advocating for, or encouraging, any of the above behavior. 44 | * Sustained disruption of community events, including talks and presentations. 45 | 46 | ## 5. Weapons Policy 47 | 48 | No weapons will be allowed at Typeform Open-source events, community spaces, or in other spaces covered by the scope of this Code of Conduct. Weapons include but are not limited to guns, explosives (including fireworks), and large knives such as those used for hunting or display, as well as any other item used for the purpose of causing injury or harm to others. Anyone seen in possession of one of these items will be asked to leave immediately, and will only be allowed to return without the weapon. Community members are further expected to comply with all state and local laws on this matter. 49 | 50 | ## 6. Consequences of Unacceptable Behavior 51 | 52 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 53 | 54 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 55 | 56 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 57 | 58 | ## 7. Reporting Guidelines 59 | 60 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. [Contact Typeform Open-Source](https://open-source.typeform.com/to/xYAH1q) 61 | 62 | 63 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 64 | 65 | ## 8. Addressing Grievances 66 | 67 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify Typeform OSS Committee with a concise description of your grievance. 68 | 69 | ## 9. Scope 70 | 71 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business. 72 | 73 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. 74 | 75 | ## 10. Contact info 76 | 77 | [Contact Typeform Open-Source](https://open-source.typeform.com/to/xYAH1q) 78 | 79 | ## 11. License and attribution 80 | 81 | The Citizen Code of Conduct is distributed by [Stumptown Syndicate](http://stumptownsyndicate.org) under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 82 | 83 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 84 | 85 | _Revision 2.3. Posted 6 March 2017._ 86 | 87 | _Revision 2.2. Posted 4 February 2016._ 88 | 89 | _Revision 2.1. Posted 23 June 2014._ 90 | 91 | _Revision 2.0, adopted by the [Stumptown Syndicate](http://stumptownsyndicate.org) board on 10 January 2013. Posted 17 March 2013._ 92 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | source 'https://rubygems.org' 19 | 20 | ruby '2.3.3' 21 | 22 | gem 'simplecov', group: :test 23 | 24 | gemspec 25 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require 'bundler/gem_tasks' 19 | require 'rake/testtask' 20 | 21 | desc 'Start up the irb console with the gem required' 22 | task :console do 23 | exec 'irb -r create_api_gem -I ./lib' 24 | end 25 | 26 | desc 'Run the tests' 27 | task default: :test 28 | 29 | Rake::TestTask.new do |t| 30 | t.libs << 'test' 31 | end 32 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | #!/usr/bin/env ruby 19 | 20 | require 'bundler/setup' 21 | require 'create_api_gem' 22 | 23 | require 'irb' 24 | IRB.start(__FILE__) 25 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | #!/usr/bin/env bash 19 | set -euo pipefail 20 | IFS=$'\n\t' 21 | set -vx 22 | 23 | bundle install 24 | -------------------------------------------------------------------------------- /coverage/.last_run.json: -------------------------------------------------------------------------------- 1 | { 2 | "result": { 3 | "covered_percent": 87.7 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /coverage/.resultset.json.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/.resultset.json.lock -------------------------------------------------------------------------------- /coverage/assets/0.10.2/colorbox/border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/colorbox/border.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/colorbox/controls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/colorbox/controls.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/colorbox/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/colorbox/loading.gif -------------------------------------------------------------------------------- /coverage/assets/0.10.2/colorbox/loading_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/colorbox/loading_background.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/favicon_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/favicon_green.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/favicon_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/favicon_red.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/favicon_yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/favicon_yellow.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/loading.gif -------------------------------------------------------------------------------- /coverage/assets/0.10.2/magnify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/magnify.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/DataTables-1.10.20/images/sort_asc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/DataTables-1.10.20/images/sort_asc.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/DataTables-1.10.20/images/sort_asc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/DataTables-1.10.20/images/sort_asc_disabled.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/DataTables-1.10.20/images/sort_both.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/DataTables-1.10.20/images/sort_both.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/DataTables-1.10.20/images/sort_desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/DataTables-1.10.20/images/sort_desc.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/DataTables-1.10.20/images/sort_desc_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/DataTables-1.10.20/images/sort_desc_disabled.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/colorbox/border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/colorbox/border.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/colorbox/controls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/colorbox/controls.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/colorbox/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/colorbox/loading.gif -------------------------------------------------------------------------------- /coverage/assets/0.12.2/colorbox/loading_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/colorbox/loading_background.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/favicon_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/favicon_green.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/favicon_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/favicon_red.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/favicon_yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/favicon_yellow.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_flat_0_aaaaaa_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_flat_0_aaaaaa_40x100.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_flat_75_ffffff_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_flat_75_ffffff_40x100.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_glass_55_fbf9ee_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_glass_55_fbf9ee_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_glass_75_dadada_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_glass_75_dadada_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_glass_75_e6e6e6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_glass_75_e6e6e6_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_glass_95_fef1ec_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_glass_95_fef1ec_1x400.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-bg_highlight-soft_75_cccccc_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-bg_highlight-soft_75_cccccc_1x100.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-icons_2e83ff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-icons_2e83ff_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-icons_454545_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-icons_454545_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-icons_888888_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-icons_888888_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /coverage/assets/0.12.2/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/loading.gif -------------------------------------------------------------------------------- /coverage/assets/0.12.2/magnify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Typeform/create-api-gem/7ec3c1ad1bbacaeec678b246353cf609c9b3dca7/coverage/assets/0.12.2/magnify.png -------------------------------------------------------------------------------- /create_api_gem.gemspec: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | lib = File.expand_path('../lib', __FILE__) 19 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 20 | require 'create_api_gem/version' 21 | 22 | Gem::Specification.new do |spec| 23 | spec.name = 'create_api_gem' 24 | spec.version = CreateApiGem::VERSION 25 | spec.authors = ['Typeform'] 26 | spec.email = ['opensource@typeform.com'] 27 | 28 | spec.summary = 'Typeform Create API Gem' 29 | spec.description = 'Ruby gem for using the Typeform Create API' 30 | spec.post_install_message = "WARNING: This gem has been deprecated." 31 | 32 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 33 | # to allow pushing to a single host or delete this section to allow pushing to any host. 34 | if spec.respond_to?(:metadata) 35 | spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'" 36 | else 37 | raise 'RubyGems 2.0 or newer is required to protect against ' \ 38 | 'public gem pushes.' 39 | end 40 | 41 | spec.files = `git ls-files -z`.split("\x0").reject do |f| 42 | f.match(%r{^(test|spec|features)/}) 43 | end 44 | spec.bindir = 'exe' 45 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 46 | spec.require_paths = ['lib'] 47 | 48 | spec.add_development_dependency 'bundler', '~> 2.1.4' 49 | spec.add_development_dependency 'rake', '~> 10.0' 50 | spec.add_development_dependency 'minitest' 51 | spec.add_development_dependency 'rubocop' 52 | 53 | spec.add_dependency 'rest-client', '>=2' 54 | spec.add_dependency 'ffaker' 55 | spec.add_dependency 'json' 56 | spec.add_dependency 'rack' 57 | end 58 | -------------------------------------------------------------------------------- /lib/create_api_gem.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require 'json' 19 | require 'rest-client' 20 | require 'create_api_gem/api_request.rb' 21 | 22 | Gem.find_files('create_api_gem/**/*.rb').each do |path| 23 | require path 24 | end 25 | -------------------------------------------------------------------------------- /lib/create_api_gem/api_config.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class APIConfig 19 | def self.token 20 | ENV['TYPEFORM_API_TOKEN'] 21 | end 22 | 23 | def self.image_api_request_url 24 | 'https://images.typeform.com' 25 | end 26 | 27 | def self.workspaces_api_request_url 28 | 'https://api.typeform.com/workspaces' 29 | end 30 | 31 | def self.api_request_url 32 | 'https://api.typeform.com' 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/api_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class APIRequest 19 | def self.execute(*args) 20 | new(*args).tap do |request| 21 | raise StandardError, 'Failed asserting that the request succeeds' unless request.success? 22 | end 23 | end 24 | 25 | def headers 26 | @response.headers 27 | end 28 | 29 | def inspect 30 | "#{@response.code}\n#{@response}" 31 | end 32 | 33 | def bad_request? 34 | @response.code == 400 35 | end 36 | 37 | def unauthorized? 38 | @response.code == 401 39 | end 40 | 41 | def payment_required? 42 | @response.code == 402 43 | end 44 | 45 | def forbidden? 46 | @response.code == 403 47 | end 48 | 49 | def not_found? 50 | @response.code == 404 51 | end 52 | 53 | def service_unavailable? 54 | @response.code == 502 || @response.code == 503 55 | end 56 | 57 | def error_code 58 | json.fetch(:code) 59 | end 60 | 61 | private 62 | 63 | def request(args = {}) 64 | RestClient::Request.execute(args) { |r| @response = r } 65 | end 66 | 67 | def json 68 | JSON.parse(@response, symbolize_names: true) 69 | end 70 | 71 | def json? 72 | json 73 | true 74 | rescue JSON::ParserError 75 | false 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/create_api_gem/data_generator.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require 'ffaker' 19 | 20 | module DataGenerator 21 | def self.title 22 | FFaker::Movie.title 23 | end 24 | 25 | def self.description 26 | FFaker::Lorem.paragraph 27 | end 28 | 29 | def self.email 30 | FFaker::Internet.email 31 | end 32 | 33 | def self.color_code 34 | '#' + SecureRandom.hex(3) 35 | end 36 | 37 | def self.field_ref 38 | SecureRandom.hex(6) 39 | end 40 | 41 | def self.uuid 42 | SecureRandom.uuid 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Block 19 | def self.all_types 20 | { 21 | 'date block' => DateBlock, 22 | 'dropdown block' => DropdownBlock, 23 | 'email block' => EmailBlock, 24 | 'file upload block' => FileUploadBlock, 25 | 'group block' => GroupBlock, 26 | 'legal block' => LegalBlock, 27 | 'long text block' => LongTextBlock, 28 | 'multiple choice block' => MultipleChoiceBlock, 29 | 'number block' => NumberBlock, 30 | 'opinion scale block' => OpinionScaleBlock, 31 | 'payment block' => PaymentBlock, 32 | 'picture choice block' => PictureChoiceBlock, 33 | 'rating block' => RatingBlock, 34 | 'short text block' => ShortTextBlock, 35 | 'statement block' => StatementBlock, 36 | 'website block' => WebsiteBlock, 37 | 'yes no block' => YesNoBlock, 38 | 'phone number block' => PhoneNumberBlock 39 | } 40 | end 41 | 42 | def self.from_response(response) 43 | response[:type] = response[:type].to_sym 44 | if response[:type] == :group 45 | response[:properties][:fields].map! { |field| Block.from_response(field) } unless response[:properties][:fields].nil? 46 | end 47 | properties = response[:properties] || {} 48 | validations = response[:validations] || {} 49 | block_params = response.keep_if { |k, _| k != :properties && k != :validations } || {} 50 | params = properties.merge(validations).merge(block_params) 51 | all_types.fetch(block_symbol_to_string(response[:type])).new(params) 52 | end 53 | 54 | def same?(actual) 55 | (id.nil? || id == actual.id) && 56 | type == actual.type && 57 | title == actual.title && 58 | (ref.nil? || ref == actual.ref) && 59 | (description.nil? || description == actual.description) && 60 | (respond_to?(:attachment) ? same_attachment?(actual.attachment) : true) && 61 | same_extra_attributes?(actual) 62 | end 63 | 64 | def same_attachment?(actual_attachment) 65 | return true if attachment.nil? 66 | 67 | type = attachment[:type] 68 | case type 69 | when 'image' 70 | (attachment[:href].start_with?("#{APIConfig.image_api_request_url}/images/") && actual_attachment[:href].start_with?("#{APIConfig.image_api_request_url}/images/")) 71 | when 'video' 72 | attachment == actual_attachment 73 | else 74 | false 75 | end 76 | end 77 | 78 | def self.attachment 79 | [Block.image_attachment_payload, Block.video_attachment_payload].sample 80 | end 81 | 82 | def self.image_attachment_payload(image_id: 'default') 83 | { type: 'image', href: "#{APIConfig.image_api_request_url}/images/#{image_id}" } 84 | end 85 | 86 | def self.video_attachment_payload(video_url: 'https://www.youtube.com/watch?v=Uui3oT-XBxs', scale: 0.6) 87 | { type: 'video', href: video_url, scale: scale } 88 | end 89 | 90 | def self.block_symbol_to_string(symbol) 91 | string = symbol.to_s 92 | string.sub!('_', ' ') 93 | string + ' block' 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/date_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class DateBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :structure, :separator, :required, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :date, ref: nil, description: nil, structure: nil, 24 | separator: nil, required: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @structure = structure 31 | @separator = separator 32 | @required = required 33 | @attachment = attachment 34 | end 35 | 36 | def payload 37 | payload = {} 38 | payload[:title] = title 39 | payload[:type] = type.to_s 40 | payload[:id] = id unless id.nil? 41 | payload[:ref] = ref unless ref.nil? 42 | unless description.nil? && structure.nil? && separator.nil? 43 | payload[:properties] = {} 44 | payload[:properties][:description] = description unless description.nil? 45 | payload[:properties][:structure] = structure unless structure.nil? 46 | payload[:properties][:separator] = separator unless separator.nil? 47 | end 48 | unless required.nil? 49 | payload[:validations] = {} 50 | payload[:validations][:required] = required 51 | end 52 | payload[:attachment] = attachment unless attachment.nil? 53 | payload 54 | end 55 | 56 | def same_extra_attributes?(actual) 57 | (structure.nil? ? DateBlock.default.structure : structure) == actual.structure && 58 | (separator.nil? ? DateBlock.default.separator : separator) == actual.separator && 59 | (required.nil? ? DateBlock.default.required : required) == actual.required 60 | end 61 | 62 | def self.default 63 | DateBlock.new( 64 | structure: 'MMDDYYYY', 65 | separator: '/', 66 | required: false 67 | ) 68 | end 69 | 70 | def self.full_example(id: nil) 71 | DateBlock.new( 72 | ref: DataGenerator.field_ref, 73 | separator: '-', 74 | structure: 'DDMMYYYY', 75 | required: true, 76 | id: id, 77 | description: DataGenerator.description, 78 | attachment: Block.attachment 79 | ) 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/dropdown_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class DropdownBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :alphabetical_order, :choices, :required, :attachment, :randomize 22 | 23 | def initialize(id: nil, title: nil, type: :dropdown, ref: nil, description: nil, alphabetical_order: nil, 24 | choices: nil, required: nil, attachment: nil, randomize: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @alphabetical_order = alphabetical_order 31 | @randomize = randomize 32 | @choices = choices || DropdownBlock.choices 33 | @required = required 34 | @attachment = attachment 35 | end 36 | 37 | def self.choices 38 | [ 39 | { label: 'choice 1' }, 40 | { label: 'choice 2' } 41 | ] 42 | end 43 | 44 | def payload 45 | payload = {} 46 | payload[:properties] = {} 47 | payload[:title] = title 48 | payload[:type] = type.to_s 49 | payload[:ref] = ref unless ref.nil? 50 | payload[:id] = id unless id.nil? 51 | payload[:properties][:choices] = choices 52 | payload[:properties][:description] = description unless description.nil? 53 | payload[:properties][:alphabetical_order] = alphabetical_order unless alphabetical_order.nil? 54 | payload[:properties][:randomize] = randomize unless randomize.nil? 55 | unless required.nil? 56 | payload[:validations] = {} 57 | payload[:validations][:required] = required 58 | end 59 | payload[:attachment] = attachment unless attachment.nil? 60 | payload 61 | end 62 | 63 | def same_extra_attributes?(actual) 64 | same_choices?(actual.choices) && 65 | (alphabetical_order.nil? ? DropdownBlock.default.alphabetical_order : alphabetical_order) == actual.alphabetical_order && 66 | (required.nil? ? DropdownBlock.default.required : required) == actual.required 67 | end 68 | 69 | def same_choices?(actual_choices) 70 | choices.zip(actual_choices).all? do |expected, actual| 71 | (!expected.key?(:id) || expected[id] == actual[id]) && 72 | expected[:label] == actual[:label] 73 | end 74 | end 75 | 76 | def self.default 77 | DropdownBlock.new( 78 | choices: choices, 79 | alphabetical_order: false, 80 | randomize: false, 81 | required: false 82 | ) 83 | end 84 | 85 | def self.full_example(id: nil) 86 | DropdownBlock.new( 87 | ref: DataGenerator.field_ref, 88 | description: DataGenerator.description, 89 | id: id, 90 | choices: choices, 91 | alphabetical_order: true, 92 | randomize: false, 93 | required: true, 94 | attachment: Block.attachment 95 | ) 96 | end 97 | end 98 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/email_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class EmailBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :email, ref: nil, description: nil, required: nil, attachment: nil) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @required = required 30 | @attachment = attachment 31 | end 32 | 33 | def payload 34 | payload = {} 35 | payload[:title] = title 36 | payload[:type] = type.to_s 37 | payload[:id] = id unless id.nil? 38 | payload[:ref] = ref unless ref.nil? 39 | unless description.nil? 40 | payload[:properties] = {} 41 | payload[:properties][:description] = description 42 | end 43 | unless required.nil? 44 | payload[:validations] = {} 45 | payload[:validations][:required] = required 46 | end 47 | payload[:attachment] = attachment unless attachment.nil? 48 | payload 49 | end 50 | 51 | def same_extra_attributes?(actual) 52 | (required.nil? ? EmailBlock.default.required : required) == actual.required 53 | end 54 | 55 | def self.default 56 | EmailBlock.new( 57 | required: false 58 | ) 59 | end 60 | 61 | def self.full_example(id: nil) 62 | EmailBlock.new( 63 | ref: DataGenerator.field_ref, 64 | description: DataGenerator.description, 65 | id: id, 66 | required: true, 67 | attachment: Block.attachment 68 | ) 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/file_upload_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class FileUploadBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required 22 | 23 | def initialize(id: nil, title: nil, type: :file_upload, ref: nil, description: nil, required: nil) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @required = required 30 | end 31 | 32 | def payload 33 | payload = {} 34 | payload[:title] = title 35 | payload[:type] = type.to_s 36 | payload[:id] = id unless id.nil? 37 | payload[:ref] = ref unless ref.nil? 38 | unless description.nil? 39 | payload[:properties] = {} 40 | payload[:properties][:description] = description 41 | end 42 | unless required.nil? 43 | payload[:validations] = {} 44 | payload[:validations][:required] = required 45 | end 46 | payload 47 | end 48 | 49 | def same_extra_attributes?(actual) 50 | (required.nil? ? FileUploadBlock.default.required : required) == actual.required 51 | end 52 | 53 | def self.default 54 | FileUploadBlock.new( 55 | required: false 56 | ) 57 | end 58 | 59 | def self.full_example(id: nil) 60 | FileUploadBlock.new( 61 | ref: DataGenerator.field_ref, 62 | description: DataGenerator.description, 63 | required: true, 64 | id: id 65 | ) 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/group_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class GroupBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :show_button, :button_text, :attachment, :fields 22 | 23 | def initialize(id: nil, title: nil, type: :group, ref: nil, description: nil, show_button: nil, button_text: nil, attachment: nil, fields: []) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @show_button = show_button 30 | @button_text = button_text 31 | @attachment = attachment 32 | @fields = fields 33 | end 34 | 35 | def payload 36 | payload = {} 37 | payload[:title] = title 38 | payload[:type] = type.to_s 39 | payload[:id] = id unless id.nil? 40 | payload[:ref] = ref unless ref.nil? 41 | unless description.nil? && fields.nil? && show_button.nil? && button_text.nil? 42 | payload[:properties] = {} 43 | payload[:properties][:description] = description unless description.nil? 44 | payload[:properties][:show_button] = show_button unless show_button.nil? 45 | payload[:properties][:button_text] = button_text unless button_text.nil? 46 | unless fields.nil? 47 | p = [] 48 | fields.each { |field| p << field.payload unless field.nil? } 49 | payload[:properties][:fields] = p 50 | end 51 | end 52 | payload[:attachment] = attachment unless attachment.nil? 53 | payload 54 | end 55 | 56 | def same_extra_attributes?(actual) 57 | same_fields?(actual.fields) 58 | end 59 | 60 | def same_fields?(actual_fields) 61 | fields.zip(actual_fields).all? do |expected, actual| 62 | expected.same?(actual) 63 | end && fields.length == actual_fields.length 64 | end 65 | 66 | def self.default 67 | GroupBlock.new( 68 | fields: [], 69 | button_text: 'Continue', 70 | show_button: false 71 | ) 72 | end 73 | 74 | def self.full_example(id: nil, blocks: nil) 75 | fields = if blocks.nil? 76 | Block.all_types.values.map do |block| 77 | block.full_example unless [GroupBlock, PaymentBlock].include?(block) 78 | end 79 | else 80 | blocks.map do |block| 81 | block.class.full_example(id: block.id) unless [GroupBlock, PaymentBlock].include?(block) 82 | end 83 | end 84 | GroupBlock.new( 85 | ref: DataGenerator.field_ref, 86 | id: id, 87 | description: DataGenerator.description, 88 | button_text: 'Click me!', 89 | show_button: true, 90 | fields: fields.compact, 91 | attachment: Block.attachment 92 | ) 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/legal_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class LegalBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required 22 | 23 | def initialize(id: nil, title: nil, type: :legal, ref: nil, description: nil, required: nil) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @required = required 30 | end 31 | 32 | def payload 33 | payload = {} 34 | payload[:title] = title 35 | payload[:type] = type.to_s 36 | payload[:id] = id unless id.nil? 37 | payload[:ref] = ref unless ref.nil? 38 | unless description.nil? 39 | payload[:properties] = {} 40 | payload[:properties][:description] = description 41 | end 42 | unless required.nil? 43 | payload[:validations] = {} 44 | payload[:validations][:required] = required 45 | end 46 | payload 47 | end 48 | 49 | def same_extra_attributes?(actual) 50 | (required.nil? ? LegalBlock.default.required : required) == actual.required 51 | end 52 | 53 | def self.default 54 | LegalBlock.new( 55 | required: false 56 | ) 57 | end 58 | 59 | def self.full_example(id: nil) 60 | LegalBlock.new( 61 | ref: DataGenerator.field_ref, 62 | description: DataGenerator.description, 63 | required: true, 64 | id: id 65 | ) 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/long_text_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class LongTextBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :max_length, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :long_text, ref: nil, description: nil, required: nil, 24 | max_length: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @required = required 31 | @max_length = max_length 32 | @attachment = attachment 33 | end 34 | 35 | def payload 36 | payload = {} 37 | payload[:title] = title 38 | payload[:type] = type.to_s 39 | payload[:id] = id unless id.nil? 40 | payload[:ref] = ref unless ref.nil? 41 | unless description.nil? 42 | payload[:properties] = {} 43 | payload[:properties][:description] = description 44 | end 45 | unless required.nil? && max_length.nil? 46 | payload[:validations] = {} 47 | payload[:validations][:required] = required unless required.nil? 48 | payload[:validations][:max_length] = max_length unless max_length.nil? 49 | end 50 | payload[:attachment] = attachment unless attachment.nil? 51 | payload 52 | end 53 | 54 | def same_extra_attributes?(actual) 55 | (max_length.nil? || max_length == actual.max_length) && 56 | (required.nil? ? LongTextBlock.default.required : required) == actual.required 57 | end 58 | 59 | def self.default 60 | LongTextBlock.new( 61 | required: false 62 | ) 63 | end 64 | 65 | def self.full_example(id: nil) 66 | LongTextBlock.new( 67 | ref: DataGenerator.field_ref, 68 | description: DataGenerator.description, 69 | id: id, 70 | required: true, 71 | max_length: 500, 72 | attachment: Block.attachment 73 | ) 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/multiple_choice_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class MultipleChoiceBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :randomize, :allow_multiple_selection, :allow_other_choice, 22 | :vertical_alignment, :choices, :required, :attachment 23 | 24 | def initialize(id: nil, title: nil, type: :multiple_choice, ref: nil, description: nil, randomize: nil, 25 | allow_multiple_selection: nil, allow_other_choice: nil, vertical_alignment: nil, 26 | choices: nil, required: nil, attachment: nil) 27 | @id = id 28 | @title = title || DataGenerator.title 29 | @type = type 30 | @ref = ref 31 | @description = description 32 | @randomize = randomize 33 | @allow_multiple_selection = allow_multiple_selection 34 | @allow_other_choice = allow_other_choice 35 | @vertical_alignment = vertical_alignment 36 | @choices = choices || MultipleChoiceBlock.choices 37 | @required = required 38 | @attachment = attachment 39 | end 40 | 41 | def self.choices 42 | [ 43 | { 44 | label: 'choice 1', 45 | ref: DataGenerator.field_ref 46 | }, 47 | { 48 | label: 'choice 2', 49 | ref: DataGenerator.field_ref 50 | } 51 | ] 52 | end 53 | 54 | def payload 55 | payload = {} 56 | payload[:title] = title 57 | payload[:type] = type.to_s 58 | payload[:ref] = ref unless ref.nil? 59 | payload[:id] = id unless id.nil? 60 | payload[:properties] = {} 61 | payload[:properties][:choices] = choices 62 | payload[:properties][:description] = description unless description.nil? 63 | payload[:properties][:randomize] = randomize unless randomize.nil? 64 | payload[:properties][:allow_multiple_selection] = allow_multiple_selection unless allow_multiple_selection.nil? 65 | payload[:properties][:allow_other_choice] = allow_other_choice unless allow_other_choice.nil? 66 | payload[:properties][:vertical_alignment] = vertical_alignment unless vertical_alignment.nil? 67 | unless required.nil? 68 | payload[:validations] = {} 69 | payload[:validations][:required] = required 70 | end 71 | payload[:attachment] = attachment unless attachment.nil? 72 | payload 73 | end 74 | 75 | def same_extra_attributes?(actual) 76 | same_choices?(actual.choices) && 77 | (randomize.nil? ? MultipleChoiceBlock.default.randomize : randomize) == actual.randomize && 78 | (allow_multiple_selection.nil? ? MultipleChoiceBlock.default.allow_multiple_selection : allow_multiple_selection) == actual.allow_multiple_selection && 79 | (allow_other_choice.nil? ? MultipleChoiceBlock.default.allow_other_choice : allow_other_choice) == actual.allow_other_choice && 80 | (vertical_alignment.nil? ? MultipleChoiceBlock.default.vertical_alignment : vertical_alignment) == actual.vertical_alignment && 81 | (required.nil? ? MultipleChoiceBlock.default.required : required) == actual.required 82 | end 83 | 84 | def same_choices?(actual_choices) 85 | choices.zip(actual_choices).all? do |expected, actual| 86 | (!expected.key?(:id) || expected[:id] == actual[:id]) && 87 | (!expected.key?(:ref) || expected[:ref] == actual[:ref]) && 88 | expected[:label] == actual[:label] 89 | end 90 | end 91 | 92 | def self.default 93 | MultipleChoiceBlock.new( 94 | choices: choices, 95 | randomize: false, 96 | allow_multiple_selection: false, 97 | allow_other_choice: false, 98 | vertical_alignment: true, 99 | required: false 100 | ) 101 | end 102 | 103 | def self.full_example(id: nil) 104 | MultipleChoiceBlock.new( 105 | ref: DataGenerator.field_ref, 106 | description: DataGenerator.description, 107 | id: id, 108 | randomize: true, 109 | allow_multiple_selection: true, 110 | allow_other_choice: true, 111 | vertical_alignment: true, 112 | choices: choices, 113 | required: true, 114 | attachment: Block.attachment 115 | ) 116 | end 117 | end 118 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/number_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class NumberBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :min_value, :max_value, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :number, ref: nil, description: nil, required: nil, min_value: nil, 24 | max_value: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @required = required 31 | @min_value = min_value 32 | @max_value = max_value 33 | @attachment = attachment 34 | end 35 | 36 | def payload 37 | payload = {} 38 | payload[:title] = title 39 | payload[:type] = type.to_s 40 | payload[:ref] = ref unless ref.nil? 41 | payload[:id] = id unless id.nil? 42 | unless description.nil? 43 | payload[:properties] = {} 44 | payload[:properties][:description] = description 45 | end 46 | unless required.nil? && min_value.nil? && max_value.nil? 47 | payload[:validations] = {} 48 | payload[:validations][:required] = required unless required.nil? 49 | payload[:validations][:min_value] = min_value unless min_value.nil? 50 | payload[:validations][:max_value] = max_value unless max_value.nil? 51 | end 52 | payload[:attachment] = attachment unless attachment.nil? 53 | payload 54 | end 55 | 56 | def same_extra_attributes?(actual) 57 | (min_value.nil? || min_value == actual.min_value) && 58 | (max_value.nil? || max_value == actual.max_value) && 59 | (required.nil? ? NumberBlock.default.required : required) == actual.required 60 | end 61 | 62 | def self.default 63 | NumberBlock.new( 64 | required: false 65 | ) 66 | end 67 | 68 | def self.full_example(id: nil) 69 | NumberBlock.new( 70 | ref: DataGenerator.field_ref, 71 | description: DataGenerator.description, 72 | id: id, 73 | required: true, 74 | min_value: 1, 75 | max_value: 500, 76 | attachment: Block.attachment 77 | ) 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/opinion_scale_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class OpinionScaleBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :steps, :start_at_one, :labels, :required, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :opinion_scale, ref: nil, description: nil, steps: nil, start_at_one: nil, 24 | labels: nil, required: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @steps = steps 31 | @start_at_one = start_at_one 32 | @labels = labels 33 | @required = required 34 | @attachment = attachment 35 | end 36 | 37 | def payload 38 | payload = {} 39 | payload[:title] = title 40 | payload[:type] = type.to_s 41 | payload[:id] = id unless id.nil? 42 | payload[:ref] = ref unless ref.nil? 43 | unless description.nil? && steps.nil? && start_at_one.nil? && labels.nil? 44 | payload[:properties] = {} 45 | payload[:properties][:description] = description unless description.nil? 46 | payload[:properties][:steps] = steps unless steps.nil? 47 | payload[:properties][:start_at_one] = start_at_one unless start_at_one.nil? 48 | payload[:properties][:labels] = labels unless labels.nil? 49 | end 50 | unless required.nil? 51 | payload[:validations] = {} 52 | payload[:validations][:required] = required unless required.nil? 53 | end 54 | payload[:attachment] = attachment unless attachment.nil? 55 | payload 56 | end 57 | 58 | def same_extra_attributes?(actual) 59 | (labels.nil? || labels == actual.labels) && 60 | (steps.nil? ? OpinionScaleBlock.default.steps : steps) == actual.steps && 61 | (start_at_one.nil? ? OpinionScaleBlock.default.start_at_one : start_at_one) == actual.start_at_one && 62 | (required.nil? ? OpinionScaleBlock.default.required : required) == actual.required 63 | end 64 | 65 | def self.default 66 | OpinionScaleBlock.new( 67 | steps: 11, 68 | start_at_one: false, 69 | required: false 70 | ) 71 | end 72 | 73 | def self.full_example(id: nil) 74 | OpinionScaleBlock.new( 75 | ref: DataGenerator.field_ref, 76 | description: DataGenerator.description, 77 | steps: 7, 78 | id: id, 79 | start_at_one: true, 80 | labels: { left: 'beg', center: 'mid', right: 'end' }, 81 | required: true, 82 | attachment: Block.attachment 83 | ) 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/payment_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class PaymentBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :currency, :price, :show_button, :button_text, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :payment, ref: nil, description: nil, required: nil, currency: nil, price: nil, 24 | show_button: nil, button_text: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @required = required 31 | @currency = currency || 'EUR' 32 | @price = price || { type: 'variable', value: 'price' } 33 | @show_button = show_button 34 | @button_text = button_text 35 | @attachment = attachment 36 | end 37 | 38 | def payload 39 | payload = {} 40 | payload[:title] = title 41 | payload[:type] = type.to_s 42 | payload[:id] = id unless id.nil? 43 | payload[:ref] = ref unless ref.nil? 44 | unless description.nil? && currency.nil? && price.nil? && show_button.nil? && button_text.nil? 45 | payload[:properties] = {} 46 | payload[:properties][:description] = description unless description.nil? 47 | payload[:properties][:currency] = currency unless currency.nil? 48 | payload[:properties][:price] = price unless price.nil? 49 | payload[:properties][:show_button] = show_button unless show_button.nil? 50 | payload[:properties][:button_text] = button_text unless button_text.nil? 51 | end 52 | unless required.nil? 53 | payload[:validations] = {} 54 | payload[:validations][:required] = required 55 | end 56 | payload[:attachment] = attachment unless attachment.nil? 57 | payload 58 | end 59 | 60 | def same_extra_attributes?(actual) 61 | (required.nil? ? PaymentBlock.default.required : required) == actual.required && 62 | (price.nil? ? PaymentBlock.default.price : price) == actual.price && 63 | (currency.nil? ? PaymentBlock.default.currency : currency) == actual.currency && 64 | (show_button.nil? || show_button == actual.show_button) && 65 | (button_text.nil? || button_text == actual.button_text) 66 | end 67 | 68 | def self.default 69 | PaymentBlock.new( 70 | required: false, 71 | price: { type: 'variable', value: 'price' }, 72 | currency: 'EUR' 73 | ) 74 | end 75 | 76 | def self.full_example(id: nil) 77 | PaymentBlock.new( 78 | ref: DataGenerator.field_ref, 79 | description: DataGenerator.description, 80 | id: id, 81 | required: true, 82 | currency: 'USD', 83 | price: { type: 'variable', value: 'price' }, 84 | show_button: true, button_text: 'Click me!', 85 | attachment: Block.attachment 86 | ) 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/phone_number_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class PhoneNumberBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :attachment, :default_country_code 22 | 23 | def initialize(id: nil, title: nil, type: :phone_number, ref: nil, description: nil, required: nil, attachment: nil, default_country_code: nil) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @required = required 30 | @attachment = attachment 31 | @default_country_code = default_country_code 32 | end 33 | 34 | def payload 35 | payload = {} 36 | payload[:title] = title 37 | payload[:type] = type.to_s 38 | payload[:id] = id unless id.nil? 39 | payload[:ref] = ref unless ref.nil? 40 | payload[:properties] = {} 41 | payload[:properties][:description] = description unless description.nil? 42 | payload[:properties][:default_country_code] = default_country_code unless default_country_code.nil? 43 | unless required.nil? 44 | payload[:validations] = {} 45 | payload[:validations][:required] = required 46 | end 47 | payload[:attachment] = attachment unless attachment.nil? 48 | payload 49 | end 50 | 51 | def same_extra_attributes?(actual) 52 | (required.nil? ? PhoneNumberBlock.default.required : required) == actual.required 53 | end 54 | 55 | def self.default 56 | PhoneNumberBlock.new( 57 | required: false 58 | ) 59 | end 60 | 61 | def self.full_example(id: nil) 62 | PhoneNumberBlock.new( 63 | ref: DataGenerator.field_ref, 64 | description: DataGenerator.description, 65 | id: id, 66 | required: true, 67 | attachment: Block.attachment, 68 | default_country_code: 'us' 69 | ) 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/picture_choice_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class PictureChoiceBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :randomize, :allow_multiple_selection, :allow_other_choice, 22 | :supersized, :show_labels, :choices, :required 23 | 24 | def initialize(id: nil, title: nil, type: :picture_choice, ref: nil, description: nil, randomize: nil, 25 | allow_multiple_selection: nil, allow_other_choice: nil, supersized: nil, show_labels: nil, 26 | choices: nil, required: nil) 27 | @id = id 28 | @title = title || DataGenerator.title 29 | @type = type 30 | @ref = ref 31 | @description = description 32 | @randomize = randomize 33 | @allow_multiple_selection = allow_multiple_selection 34 | @allow_other_choice = allow_other_choice 35 | @supersized = supersized 36 | @show_labels = show_labels 37 | @choices = choices || PictureChoiceBlock.choices 38 | @required = required 39 | end 40 | 41 | def self.choices 42 | [ 43 | { 44 | label: 'label 1', 45 | ref: DataGenerator.field_ref, 46 | attachment: Block.image_attachment_payload(image_id: 'default') 47 | }, 48 | { 49 | label: 'label 2', 50 | ref: DataGenerator.field_ref, 51 | attachment: Block.image_attachment_payload(image_id: 'default') 52 | } 53 | ] 54 | end 55 | 56 | def payload 57 | payload = {} 58 | payload[:title] = title 59 | payload[:type] = type.to_s 60 | payload[:ref] = ref unless ref.nil? 61 | payload[:id] = id unless id.nil? 62 | payload[:properties] = {} 63 | payload[:properties][:choices] = choices 64 | payload[:properties][:description] = description unless description.nil? 65 | payload[:properties][:randomize] = randomize unless randomize.nil? 66 | payload[:properties][:allow_multiple_selection] = allow_multiple_selection unless allow_multiple_selection.nil? 67 | payload[:properties][:allow_other_choice] = allow_other_choice unless allow_other_choice.nil? 68 | payload[:properties][:supersized] = supersized unless supersized.nil? 69 | payload[:properties][:show_labels] = show_labels unless show_labels.nil? 70 | unless required.nil? 71 | payload[:validations] = {} 72 | payload[:validations][:required] = required 73 | end 74 | payload 75 | end 76 | 77 | def same_extra_attributes?(actual) 78 | same_choices?(actual.choices) && 79 | (randomize.nil? ? PictureChoiceBlock.default.randomize : randomize) == actual.randomize && 80 | (allow_multiple_selection.nil? ? PictureChoiceBlock.default.allow_multiple_selection : allow_multiple_selection) == actual.allow_multiple_selection && 81 | (allow_other_choice.nil? ? PictureChoiceBlock.default.allow_other_choice : allow_other_choice) == actual.allow_other_choice && 82 | (supersized.nil? ? PictureChoiceBlock.default.supersized : supersized) == actual.supersized && 83 | (show_labels.nil? ? PictureChoiceBlock.default.show_labels : show_labels) == actual.show_labels && 84 | (required.nil? ? PictureChoiceBlock.default.required : required) == actual.required 85 | end 86 | 87 | def same_choices?(actual_choices) 88 | choices.zip(actual_choices).all? do |expected, actual| 89 | (!expected.key?(:id) || expected[:id] == actual[:id]) && 90 | (!expected.key?(:ref) || expected[:ref] == actual[:ref]) && 91 | expected[:label] == actual[:label] && 92 | (expected[:attachment][:href].start_with?("#{APIConfig.image_api_request_url}/images/") && actual[:attachment][:href].start_with?("#{APIConfig.image_api_request_url}/images/")) 93 | end 94 | end 95 | 96 | def self.default 97 | PictureChoiceBlock.new( 98 | randomize: false, 99 | allow_multiple_selection: false, 100 | allow_other_choice: false, 101 | supersized: false, 102 | show_labels: true, 103 | required: false 104 | ) 105 | end 106 | 107 | def self.full_example(id: nil) 108 | PictureChoiceBlock.new( 109 | ref: DataGenerator.field_ref, 110 | description: DataGenerator.description, 111 | id: id, 112 | randomize: true, 113 | allow_multiple_selection: true, 114 | allow_other_choice: true, 115 | supersized: true, 116 | choices: choices, 117 | show_labels: false, 118 | required: true 119 | ) 120 | end 121 | end 122 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/rating_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class RatingBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :steps, :shape, :required, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :rating, ref: nil, description: nil, steps: nil, shape: nil, 24 | required: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @steps = steps 31 | @shape = shape 32 | @required = required 33 | @attachment = attachment 34 | end 35 | 36 | def payload 37 | payload = {} 38 | payload[:title] = title 39 | payload[:type] = type.to_s 40 | payload[:ref] = ref unless ref.nil? 41 | payload[:id] = id unless id.nil? 42 | unless description.nil? && steps.nil? && shape.nil? 43 | payload[:properties] = {} 44 | payload[:properties][:description] = description unless description.nil? 45 | payload[:properties][:steps] = steps unless steps.nil? 46 | payload[:properties][:shape] = shape unless shape.nil? 47 | end 48 | unless required.nil? 49 | payload[:validations] = {} 50 | payload[:validations][:required] = required unless required.nil? 51 | end 52 | payload[:attachment] = attachment unless attachment.nil? 53 | payload 54 | end 55 | 56 | def same_extra_attributes?(actual) 57 | (steps.nil? ? RatingBlock.default.steps : steps) == actual.steps && 58 | (shape.nil? ? RatingBlock.default.shape : shape) == actual.shape && 59 | (required.nil? ? RatingBlock.default.required : required) == actual.required 60 | end 61 | 62 | def self.default 63 | RatingBlock.new( 64 | steps: 3, 65 | shape: 'star', 66 | required: false 67 | ) 68 | end 69 | 70 | def self.full_example(id: nil) 71 | RatingBlock.new( 72 | ref: DataGenerator.field_ref, 73 | description: DataGenerator.description, 74 | steps: 8, 75 | shape: 'heart', 76 | id: id, 77 | required: true, 78 | attachment: Block.attachment 79 | ) 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/short_text_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class ShortTextBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :max_length, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :short_text, ref: nil, description: nil, required: nil, 24 | max_length: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @required = required 31 | @max_length = max_length 32 | @attachment = attachment 33 | end 34 | 35 | def payload 36 | payload = {} 37 | payload[:title] = title 38 | payload[:type] = type.to_s 39 | payload[:id] = id unless id.nil? 40 | payload[:ref] = ref unless ref.nil? 41 | unless description.nil? 42 | payload[:properties] = {} 43 | payload[:properties][:description] = description 44 | end 45 | unless required.nil? && max_length.nil? 46 | payload[:validations] = {} 47 | payload[:validations][:required] = required unless required.nil? 48 | payload[:validations][:max_length] = max_length unless max_length.nil? 49 | end 50 | payload[:attachment] = attachment unless attachment.nil? 51 | payload 52 | end 53 | 54 | def same_extra_attributes?(actual) 55 | (max_length.nil? || max_length == actual.max_length) && 56 | (required.nil? ? ShortTextBlock.default.required : required) == actual.required 57 | end 58 | 59 | def self.default 60 | ShortTextBlock.new( 61 | required: false 62 | ) 63 | end 64 | 65 | def self.full_example(id: nil) 66 | ShortTextBlock.new( 67 | ref: DataGenerator.field_ref, 68 | description: DataGenerator.description, 69 | id: id, 70 | required: true, 71 | max_length: 50, 72 | attachment: Block.attachment 73 | ) 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/statement_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class StatementBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :hide_marks, :button_text, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :statement, ref: nil, description: nil, hide_marks: nil, 24 | button_text: nil, attachment: nil) 25 | @id = id 26 | @title = title || DataGenerator.title 27 | @type = type 28 | @ref = ref 29 | @description = description 30 | @hide_marks = hide_marks 31 | @button_text = button_text 32 | @attachment = attachment 33 | end 34 | 35 | def payload 36 | payload = {} 37 | payload[:title] = title 38 | payload[:type] = type.to_s 39 | payload[:id] = id unless id.nil? 40 | payload[:ref] = ref unless ref.nil? 41 | unless description.nil? && hide_marks.nil? && button_text.nil? 42 | payload[:properties] = {} 43 | payload[:properties][:description] = description unless description.nil? 44 | payload[:properties][:hide_marks] = hide_marks unless hide_marks.nil? 45 | payload[:properties][:button_text] = button_text unless button_text.nil? 46 | end 47 | payload[:attachment] = attachment unless attachment.nil? 48 | payload 49 | end 50 | 51 | def same_extra_attributes?(actual) 52 | (hide_marks.nil? ? StatementBlock.default.hide_marks : hide_marks) == actual.hide_marks && 53 | (button_text.nil? ? StatementBlock.default.button_text : button_text) == actual.button_text 54 | end 55 | 56 | def self.default 57 | StatementBlock.new(button_text: 'Continue', hide_marks: false) 58 | end 59 | 60 | def self.full_example(id: nil) 61 | StatementBlock.new( 62 | ref: DataGenerator.field_ref, 63 | description: DataGenerator.description, 64 | hide_marks: true, 65 | id: id, 66 | button_text: 'Click me!', 67 | attachment: Block.attachment 68 | ) 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/thank_you_screen.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class ThankYouScreen < Block 19 | attr_accessor :title, :ref, :show_button, :button_text, :button_mode, :redirect_url, :share_icons, :attachment 20 | 21 | def initialize(title: nil, ref: nil, show_button: nil, button_text: nil, button_mode: nil, redirect_url: nil, share_icons: nil, attachment: nil, id: nil) 22 | @id = id 23 | @title = title || DataGenerator.title 24 | @ref = ref 25 | @show_button = show_button 26 | @button_text = button_text 27 | @button_mode = button_mode 28 | @redirect_url = redirect_url 29 | @share_icons = share_icons 30 | @attachment = attachment 31 | end 32 | 33 | def self.from_response(response) 34 | properties = response[:properties] 35 | block_params = response.keep_if { |k, _| k != :properties } 36 | params = properties.merge(block_params) 37 | ThankYouScreen.new(params) 38 | end 39 | 40 | def payload 41 | payload = {} 42 | 43 | payload[:title] = title 44 | payload[:ref] = ref unless ref.nil? 45 | unless show_button.nil? && button_text.nil? && button_mode.nil? && redirect_url.nil? && share_icons.nil? 46 | payload[:properties] = {} 47 | payload[:properties][:show_button] = show_button unless show_button.nil? 48 | payload[:properties][:button_text] = button_text unless button_text.nil? 49 | payload[:properties][:button_mode] = button_mode unless button_mode.nil? 50 | payload[:properties][:redirect_url] = redirect_url unless redirect_url.nil? 51 | payload[:properties][:share_icons] = share_icons unless share_icons.nil? 52 | end 53 | payload[:attachment] = attachment unless attachment.nil? 54 | payload 55 | end 56 | 57 | def same?(actual) 58 | title == actual.title && 59 | (ref.nil? || ref == actual.ref) && 60 | (show_button.nil? ? ThankYouScreen.default.show_button == actual.show_button : show_button == actual.show_button) && 61 | (button_text.nil? || button_text == actual.button_text) && 62 | ((button_mode.nil? ? ThankYouScreen.default.button_mode == actual.button_mode : button_mode == actual.button_mode) || ref == 'default_tys') && 63 | (redirect_url.nil? || (redirect_url == actual.redirect_url && ref != 'default_tys') || (redirect_url.include?(actual.redirect_url) || ref == 'default_tys')) && 64 | (share_icons.nil? ? ThankYouScreen.default.share_icons == actual.share_icons : share_icons == actual.share_icons) && 65 | (attachment.nil? || same_attachment?(actual.attachment) || ref == 'default_tys') 66 | end 67 | 68 | def self.default 69 | ThankYouScreen.new( 70 | show_button: true, 71 | button_mode: 'reload', 72 | share_icons: true 73 | ) 74 | end 75 | 76 | def self.default_basic(account_id: nil, form_uid: nil) 77 | ThankYouScreen.new( 78 | title: "Thanks for completing this typeform\nNow *create your own* — it's free, easy, & beautiful", 79 | ref: 'default_tys', 80 | show_button: true, 81 | share_icons: false, 82 | button_mode: 'redirect', 83 | button_text: 'Create a *typeform*', 84 | redirect_url: "/signup?utm_campaign=#{form_uid}&utm_source=typeform.com-#{account_id}-Basic&utm_medium=typeform&utm_content=typeform-thankyoubutton&utm_term=EN", 85 | attachment: { 86 | type: 'image', 87 | href: "#{APIConfig.image_api_request_url}/images/2dpnUBBkz2VN" 88 | } 89 | ) 90 | end 91 | 92 | def self.default_pro 93 | ThankYouScreen.new( 94 | title: 'Done! Your information was sent perfectly.', 95 | ref: 'default_tys', 96 | show_button: false, 97 | share_icons: false 98 | ) 99 | end 100 | 101 | def self.full_example 102 | ThankYouScreen.new( 103 | ref: DataGenerator.field_ref, 104 | show_button: false, 105 | button_text: 'Click me!', 106 | button_mode: 'redirect', 107 | redirect_url: 'http://www.google.com', 108 | share_icons: false, 109 | attachment: Block.attachment 110 | ) 111 | end 112 | end 113 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/website_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class WebsiteBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required 22 | 23 | def initialize(id: nil, title: nil, type: :website, ref: nil, description: nil, required: nil) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @required = required 30 | end 31 | 32 | def payload 33 | payload = {} 34 | payload[:title] = title 35 | payload[:type] = type.to_s 36 | payload[:id] = id unless id.nil? 37 | payload[:ref] = ref unless ref.nil? 38 | unless description.nil? 39 | payload[:properties] = {} 40 | payload[:properties][:description] = description 41 | end 42 | unless required.nil? 43 | payload[:validations] = {} 44 | payload[:validations][:required] = required 45 | end 46 | payload 47 | end 48 | 49 | def same_extra_attributes?(actual) 50 | (required.nil? ? WebsiteBlock.default.required : required) == actual.required 51 | end 52 | 53 | def self.default 54 | WebsiteBlock.new( 55 | required: false 56 | ) 57 | end 58 | 59 | def self.full_example(id: nil) 60 | WebsiteBlock.new( 61 | ref: DataGenerator.field_ref, 62 | description: DataGenerator.description, 63 | required: true, 64 | id: id 65 | ) 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/welcome_screen.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class WelcomeScreen < Block 19 | attr_accessor :id, :title, :ref, :type, :description, :show_button, :button_text, :attachment 20 | 21 | def initialize(id: nil, title: nil, type: :welcome_screen, ref: nil, description: nil, show_button: nil, button_text: nil, attachment: nil) 22 | @id = id 23 | @title = title || DataGenerator.title 24 | @ref = ref 25 | @type = type 26 | @description = description 27 | @show_button = show_button 28 | @button_text = button_text 29 | @attachment = attachment 30 | end 31 | 32 | def self.from_response(response) 33 | properties = response[:properties] 34 | block_params = response.keep_if { |k, _| k != :properties } 35 | params = properties.merge(block_params) 36 | WelcomeScreen.new(params) 37 | end 38 | 39 | def payload 40 | payload = {} 41 | payload[:properties] = {} 42 | 43 | payload[:title] = title 44 | payload[:ref] = ref unless ref.nil? 45 | payload[:properties][:description] = description unless description.nil? 46 | payload[:properties][:show_button] = show_button unless show_button.nil? 47 | payload[:properties][:button_text] = button_text unless button_text.nil? 48 | payload[:attachment] = attachment unless attachment.nil? 49 | payload 50 | end 51 | 52 | def same_extra_attributes?(actual) 53 | (show_button.nil? ? WelcomeScreen.default.show_button == actual.show_button : show_button == actual.show_button) && 54 | (button_text.nil? ? WelcomeScreen.default.button_text == actual.button_text : button_text == actual.button_text) 55 | end 56 | 57 | def self.default 58 | WelcomeScreen.new(show_button: true, button_text: 'start') 59 | end 60 | 61 | def self.full_example(id: nil) 62 | WelcomeScreen.new( 63 | ref: DataGenerator.field_ref, 64 | description: DataGenerator.description, 65 | show_button: false, 66 | button_text: 'Click me!', 67 | id: id, 68 | attachment: Block.attachment 69 | ) 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/blocks/yes_no_block.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'block' 19 | 20 | class YesNoBlock < Block 21 | attr_accessor :id, :title, :type, :ref, :description, :required, :attachment 22 | 23 | def initialize(id: nil, title: nil, type: :yes_no, ref: nil, description: nil, required: nil, attachment: nil) 24 | @id = id 25 | @title = title || DataGenerator.title 26 | @type = type 27 | @ref = ref 28 | @description = description 29 | @required = required 30 | @attachment = attachment 31 | end 32 | 33 | def payload 34 | payload = {} 35 | payload[:title] = title 36 | payload[:type] = type.to_s 37 | payload[:id] = id unless id.nil? 38 | payload[:ref] = ref unless ref.nil? 39 | unless description.nil? 40 | payload[:properties] = {} 41 | payload[:properties][:description] = description 42 | end 43 | unless required.nil? 44 | payload[:validations] = {} 45 | payload[:validations][:required] = required 46 | end 47 | payload[:attachment] = attachment unless attachment.nil? 48 | payload 49 | end 50 | 51 | def same_extra_attributes?(actual) 52 | (required.nil? ? YesNoBlock.default.required : required) == actual.required 53 | end 54 | 55 | def self.default 56 | YesNoBlock.new( 57 | required: false 58 | ) 59 | end 60 | 61 | def self.full_example(id: nil) 62 | YesNoBlock.new( 63 | ref: DataGenerator.field_ref, 64 | description: DataGenerator.description, 65 | required: true, 66 | attachment: Block.attachment, 67 | id: id 68 | ) 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/form.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Form 19 | attr_accessor :id, :title, :blocks, :hidden, :theme_url, :workspace_url, :welcome_screens, :thank_you_screens, :logic, :settings, :variables 20 | 21 | def initialize(id: nil, title: nil, blocks: [], hidden: [], theme_url: nil, workspace_url: nil, welcome_screens: [], thank_you_screens: [], logic: [], settings: nil, variables: nil) 22 | @id = id 23 | @title = title || DataGenerator.title 24 | @blocks = blocks 25 | @hidden = hidden 26 | @theme_url = theme_url 27 | @workspace_url = workspace_url 28 | @welcome_screens = welcome_screens 29 | @thank_you_screens = thank_you_screens 30 | @logic = logic 31 | @settings = settings 32 | @variables = variables 33 | end 34 | 35 | def self.from_response(payload) 36 | blocks = payload[:fields].nil? ? [] : payload[:fields].map { |field_payload| Block.from_response(field_payload) } 37 | welcome_screens = payload[:welcome_screens].nil? ? [] : payload[:welcome_screens].map { |welcome_screen_payload| WelcomeScreen.from_response(welcome_screen_payload) } 38 | thank_you_screens = payload[:thankyou_screens].map { |thank_you_screen_payload| ThankYouScreen.from_response(thank_you_screen_payload) } 39 | hidden_fields = payload[:hidden].nil? ? [] : payload[:hidden] 40 | logic = payload[:logic].nil? ? [] : payload[:logic].map { |logic_payload| FieldLogic.from_response(logic_payload) } 41 | settings = Settings.from_response(payload[:settings]) 42 | variables = payload[:variables].nil? ? nil : Variables.from_response(payload[:variables]) 43 | new( 44 | id: payload[:id], 45 | title: payload[:title], 46 | blocks: blocks, 47 | hidden: hidden_fields, 48 | theme_url: payload[:theme][:href], 49 | workspace_url: payload[:workspace][:href], 50 | welcome_screens: welcome_screens, 51 | thank_you_screens: thank_you_screens, 52 | logic: logic, 53 | settings: settings, 54 | variables: variables 55 | ) 56 | end 57 | 58 | def payload 59 | payload = {} 60 | payload[:title] = title 61 | payload[:id] = id unless id.nil? 62 | payload[:hidden] = hidden unless hidden.empty? 63 | payload[:theme] = { href: theme_url } unless theme_url.nil? 64 | payload[:workspace] = { href: workspace_url } unless workspace_url.nil? 65 | payload[:fields] = blocks.map(&:payload) unless blocks.empty? 66 | payload[:welcome_screens] = welcome_screens.map(&:payload) unless welcome_screens.empty? 67 | payload[:thankyou_screens] = thank_you_screens.map(&:payload) unless thank_you_screens.empty? 68 | payload[:logic] = logic.map(&:payload) unless logic.empty? 69 | payload[:settings] = settings.payload unless settings.nil? 70 | payload[:variables] = variables.payload unless variables.nil? 71 | payload.to_json 72 | end 73 | 74 | def same?(actual) 75 | (id.nil? || id == actual.id) && 76 | (hidden.nil? || hidden == actual.hidden) && 77 | (theme_url.nil? || theme_url.include?('default') || theme_url == actual.theme_url) && 78 | (workspace_url.nil? || workspace_url == actual.workspace_url) && 79 | title == actual.title && 80 | same_blocks?(actual.blocks) && 81 | same_welcome_screens?(actual.welcome_screens) && 82 | same_thank_you_screens?(actual.thank_you_screens) && 83 | same_logic?(actual.logic) && 84 | (settings.nil? ? Settings.default : settings).same?(actual.settings) && 85 | (variables.nil? || variables.same?(actual.variables)) 86 | end 87 | 88 | def same_blocks?(actual_blocks) 89 | blocks.zip(actual_blocks).all? do |expected, actual| 90 | expected.same?(actual) 91 | end && blocks.length == actual_blocks.length 92 | end 93 | 94 | def same_welcome_screens?(actual_welcome_screens) 95 | welcome_screens.zip(actual_welcome_screens).all? do |expected, actual| 96 | expected.same?(actual) 97 | end && welcome_screens.length == actual_welcome_screens.length 98 | end 99 | 100 | def same_thank_you_screens?(actual_thank_you_screens) 101 | thank_you_screens.delete_if { |tys| tys.ref == 'default_tys' } 102 | actual_thank_you_screens.delete_if { |tys| tys.ref == 'default_tys' } 103 | thank_you_screens.zip(actual_thank_you_screens).all? do |expected, actual| 104 | expected.same?(actual) 105 | end 106 | end 107 | 108 | def same_logic?(actual_logic) 109 | logic.all? do |field_logic| 110 | actual_field_logic = actual_logic.find { |fl| fl.field_ref == field_logic.field_ref } 111 | field_logic.same?(actual_field_logic) 112 | end && logic.length == actual_logic.length 113 | end 114 | 115 | def theme_id 116 | theme_url.split('/themes/')[1] 117 | end 118 | 119 | def workspace_id 120 | workspace_url.split('/workspaces/')[1] 121 | end 122 | 123 | def add_logic_action(field_ref, logic_action) 124 | field_logic = logic.find { |current_field_logic| current_field_logic.field_ref == field_ref } 125 | field_logic.nil? ? logic << FieldLogic.new(type: 'field', field_ref: field_ref, actions: [logic_action]) : field_logic.actions << logic_action 126 | end 127 | 128 | def self.with_all_blocks 129 | blocks = Block.all_types.values.map(&:new) 130 | Form.new( 131 | blocks: blocks 132 | ) 133 | end 134 | 135 | def self.full_example(id: nil) 136 | blocks = Block.all_types.values.map(&:full_example) 137 | email_block = blocks.find { |current_block| current_block.type == :email } 138 | form = Form.new( 139 | id: id, 140 | hidden: %w[hiddenfield1 hiddenfield2], 141 | theme_url: "#{APIConfig.api_request_url}/themes/default", 142 | blocks: blocks, 143 | welcome_screens: [WelcomeScreen.full_example], 144 | thank_you_screens: [ThankYouScreen.full_example], 145 | settings: Settings.full_example(email_block.ref), 146 | variables: Variables.full_example 147 | ) 148 | form.logic = blocks.map { |block| FieldLogic.full_example(block, form) } 149 | form 150 | end 151 | end 152 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/logic/actions/calculation.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative '../logic_action' 19 | 20 | class Calculation < LogicAction 21 | attr_accessor :action_type, :numeric_value, :target_ref, :logic_condition 22 | 23 | def initialize(action_type: nil, numeric_value: nil, target_ref: nil, logic_condition: nil) 24 | @action_type = action_type 25 | @numeric_value = numeric_value 26 | @target_ref = target_ref 27 | @logic_condition = logic_condition 28 | end 29 | 30 | def self.from_response(payload) 31 | action_type = payload[:action] 32 | target_ref = payload[:details][:target][:value] 33 | numeric_value = payload[:details][:value][:value] 34 | logic_condition = LogicCondition.from_response(payload[:condition]) 35 | Calculation.new(action_type: action_type, numeric_value: numeric_value, target_ref: target_ref, logic_condition: logic_condition) 36 | end 37 | 38 | def payload 39 | payload = {} 40 | payload[:action] = action_type 41 | payload[:details] = { target: { type: 'variable', value: target_ref } } 42 | payload[:details][:value] = { type: 'constant', value: numeric_value } 43 | payload[:condition] = logic_condition.payload 44 | payload 45 | end 46 | 47 | def self.full_example(block) 48 | is_blocks = %i[multiple_choice picture_choice yes_no legal] 49 | logic_condition = if is_blocks.include?(block.type) 50 | LogicCondition.generate_from_block(block, op: 'is') 51 | elsif block.type == :date 52 | LogicCondition.generate_from_block(block, op: 'on') 53 | elsif block.type == :file_upload 54 | LogicCondition.generate_from_block(block, op: 'answered') 55 | else 56 | LogicCondition.generate_from_block(block, op: 'equal') 57 | end 58 | Calculation.new( 59 | action_type: 'add', 60 | numeric_value: 5, 61 | target_ref: 'score', 62 | logic_condition: logic_condition 63 | ) 64 | end 65 | 66 | def same?(actual) 67 | action_type == actual.action_type && 68 | target_ref == actual.target_ref && 69 | numeric_value == actual.numeric_value && 70 | logic_condition.same?(actual.logic_condition) 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/logic/actions/logic_jump.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative '../logic_action' 19 | 20 | class LogicJump < LogicAction 21 | attr_accessor :to_type, :to_ref, :logic_condition 22 | 23 | def initialize(to_type: nil, to_ref: nil, logic_condition: nil) 24 | @to_type = to_type 25 | @to_ref = to_ref 26 | @logic_condition = logic_condition 27 | end 28 | 29 | def self.from_response(payload) 30 | to_type = payload[:details][:to][:type] 31 | to_ref = payload[:details][:to][:value] 32 | logic_condition = LogicCondition.from_response(payload[:condition]) 33 | LogicJump.new(to_type: to_type, to_ref: to_ref, logic_condition: logic_condition) 34 | end 35 | 36 | def self.create_field_logic_jump(form, block_type) 37 | logic_block = form.blocks.find { |block| Block.block_symbol_to_string(block.type) == block_type } 38 | to_ref = if form.blocks.last.ref == logic_block.ref 39 | form.blocks.first.ref 40 | else 41 | form.blocks.last.ref 42 | end 43 | logic_condition = LogicCondition.generate_from_block(logic_block) 44 | LogicJump.new(to_type: 'field', to_ref: to_ref, logic_condition: logic_condition) 45 | end 46 | 47 | def self.create_always_jump(form) 48 | LogicJump.new(to_type: 'field', to_ref: form.blocks.first.ref, logic_condition: LogicCondition.new(op: 'always')) 49 | end 50 | 51 | def self.create_hidden_logic_jump(form) 52 | logic_condition_details = LogicConditionDetails.new(reference_type: 'hidden', reference: form.hidden[0], value_type: 'constant', value: 'abc') 53 | logic_condition = LogicCondition.new(op: 'equal', vars: [logic_condition_details]) 54 | LogicJump.new(to_type: 'field', to_ref: form.blocks.first.ref, logic_condition: logic_condition) 55 | end 56 | 57 | def self.create_variable_logic_jump(form) 58 | logic_condition_details = LogicConditionDetails.new(reference_type: 'variable', reference: 'score', value_type: 'constant', value: 5) 59 | logic_condition = LogicCondition.new(op: 'equal', vars: [logic_condition_details]) 60 | LogicJump.new(to_type: 'field', to_ref: form.blocks.first.ref, logic_condition: logic_condition) 61 | end 62 | 63 | def self.create_nested_logic_jump(form) 64 | logic_condition1 = LogicCondition.generate_from_block(form.blocks[0]) 65 | logic_condition2 = LogicCondition.generate_from_block(form.blocks[1]) 66 | logic_condition3 = LogicCondition.generate_from_block(form.blocks[2]) 67 | and_logic_condition = LogicCondition.new(op: 'and', vars: [logic_condition1, logic_condition2]) 68 | or_logic_condition = LogicCondition.new(op: 'or', vars: [logic_condition3, and_logic_condition]) 69 | LogicJump.new(to_type: 'field', to_ref: form.blocks.last.ref, logic_condition: or_logic_condition) 70 | end 71 | 72 | def self.create_thankyou_logic_jump(form) 73 | logic_condition = LogicCondition.generate_from_block(form.blocks[0]) 74 | LogicJump.new(to_type: 'thankyou', to_ref: form.thank_you_screens.first.ref, logic_condition: logic_condition) 75 | end 76 | 77 | def payload 78 | payload = {} 79 | payload[:action] = 'jump' 80 | payload[:details] = { to: { type: to_type, value: to_ref } } 81 | payload[:condition] = logic_condition.payload 82 | payload 83 | end 84 | 85 | def same?(actual) 86 | to_type == actual.to_type && 87 | to_ref == actual.to_ref && 88 | logic_condition.same?(actual.logic_condition) 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/logic/field_logic.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class FieldLogic 19 | attr_accessor :field_ref, :type, :actions 20 | 21 | def initialize(field_ref: nil, type: nil, actions: []) 22 | @field_ref = field_ref 23 | @actions = actions 24 | @type = type 25 | end 26 | 27 | def self.from_response(payload) 28 | field_ref = payload[:ref] unless payload[:ref].nil? 29 | actions = payload[:actions].nil? ? [] : payload[:actions].map { |action_payload| LogicAction.from_response(action_payload) } 30 | type = payload[:type] 31 | FieldLogic.new(field_ref: field_ref, type: type, actions: actions) 32 | end 33 | 34 | def payload 35 | payload = {} 36 | payload[:ref] = field_ref unless field_ref.nil? 37 | payload[:type] = type unless type.nil? 38 | payload[:actions] = actions.map(&:payload) unless actions.empty? 39 | payload 40 | end 41 | 42 | def same?(actual) 43 | (field_ref.nil? || field_ref == actual.field_ref) && 44 | type == actual.type && 45 | actions.all? do |action| 46 | actual_action = actual.actions.find do |a| 47 | begin 48 | a.same?(action) 49 | rescue NoMethodError 50 | false 51 | end 52 | end 53 | action.same?(actual_action) 54 | end && actions.length == actual.actions.length 55 | end 56 | 57 | def self.full_example(logic_block, form) 58 | non_logic_blocks = %i[group payment statement] 59 | actions = if non_logic_blocks.include?(logic_block.type) 60 | [ 61 | LogicJump.create_always_jump(form) 62 | ] 63 | else 64 | [ 65 | LogicJump.create_field_logic_jump(form, Block.block_symbol_to_string(logic_block.type)), 66 | Calculation.full_example(logic_block) 67 | ] 68 | end 69 | FieldLogic.new(field_ref: logic_block.ref, type: 'field', actions: actions) 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/logic/logic_action.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class LogicAction 19 | def self.from_response(payload) 20 | case payload[:action] 21 | when 'jump' 22 | LogicJump.from_response(payload) 23 | when 'add', 'subtract', 'multiply', 'divide' 24 | Calculation.from_response(payload) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/logic/logic_condition.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class LogicCondition 19 | attr_accessor :op, :vars 20 | 21 | def initialize(op: nil, vars: []) 22 | @op = op 23 | @vars = vars 24 | end 25 | 26 | def vars_are_condition_details? 27 | vars.is_a?(LogicConditionDetails) 28 | end 29 | 30 | def self.from_response(payload) 31 | vars = [] 32 | if payload[:vars].any? 33 | is_logic_condition_details = payload[:vars].detect { |var| var.key?(:op) }.nil? 34 | vars = is_logic_condition_details ? [LogicConditionDetails.from_response(payload[:vars])] : payload[:vars].map { |condition_payload| LogicCondition.from_response(condition_payload) } 35 | end 36 | LogicCondition.new(op: payload[:op], vars: vars) 37 | end 38 | 39 | def self.generate_from_block(block, op: nil) 40 | case block.type 41 | when :number, :opinion_scale, :rating 42 | op ||= 'lower_equal_than' 43 | logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: 15) 44 | when :date 45 | op ||= 'not_on' 46 | logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: '2017-01-01') 47 | when :yes_no, :legal 48 | op ||= 'is' 49 | logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: true) 50 | when :file_upload 51 | op ||= 'answered' 52 | logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: true) 53 | when :multiple_choice, :picture_choice 54 | op ||= 'is' 55 | logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'choice', value: block.choices.first.fetch(:ref)) 56 | else 57 | op ||= 'contains' 58 | logic_condition_details = LogicConditionDetails.new(reference_type: 'field', reference: block.ref, value_type: 'constant', value: 'hello') 59 | end 60 | LogicCondition.new(op: op, vars: [logic_condition_details]) 61 | end 62 | 63 | def payload 64 | payload = {} 65 | payload[:op] = op 66 | if vars.empty? 67 | payload[:vars] = [] 68 | else 69 | payload[:vars] = vars.map(&:payload) 70 | payload[:vars].flatten! 71 | end 72 | payload 73 | end 74 | 75 | def same?(actual) 76 | op == actual.op && 77 | same_vars?(actual.vars) 78 | end 79 | 80 | def same_vars?(actual_vars) 81 | vars.zip(actual_vars).all? do |expected, actual| 82 | expected.same?(actual) 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/logic/logic_condition_details.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class LogicConditionDetails 19 | attr_accessor :reference_type, :reference, :value_type, :value 20 | 21 | def initialize(reference_type: nil, reference: nil, value_type: nil, value: nil) 22 | @reference_type = reference_type 23 | @reference = reference 24 | @value_type = value_type 25 | @value = value 26 | end 27 | 28 | def self.from_response(payload) 29 | reference_object = payload.first 30 | value_object = payload.last 31 | reference_type = reference_object[:type] unless reference_object.nil? 32 | reference = reference_object[:value] unless reference_object.nil? 33 | value_type = value_object[:type] unless value_object.nil? 34 | value = value_object[:value] unless value_object.nil? 35 | LogicConditionDetails.new( 36 | reference_type: reference_type, 37 | reference: reference, 38 | value_type: value_type, 39 | value: value 40 | ) 41 | end 42 | 43 | def payload 44 | if reference_type.nil? 45 | [] 46 | else 47 | [{ type: reference_type, value: reference }, { type: value_type, value: value }] 48 | end 49 | end 50 | 51 | def same?(actual) 52 | reference_type == actual.reference_type && 53 | reference == actual.reference && 54 | value_type == actual.value_type && 55 | value == actual.value 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/messages.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Messages 19 | attr_accessor :messages 20 | 21 | def initialize(messages) 22 | @messages = Hash[messages.map { |(k, v)| [k.to_sym, v] }] 23 | end 24 | 25 | def self.from_response(response) 26 | Messages.new(response) 27 | end 28 | 29 | def payload 30 | messages.to_json 31 | end 32 | 33 | def same?(actual) 34 | messages == actual.messages 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/create_form_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | 20 | class CreateFormRequest < FormRequest 21 | def initialize(form, token: APIConfig.token) 22 | request( 23 | method: :post, 24 | url: "#{APIConfig.api_request_url}/forms", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}" 27 | }, 28 | payload: form.payload 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 201 && json? 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/delete_form_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | 20 | class DeleteFormRequest < FormRequest 21 | def initialize(form, token: APIConfig.token) 22 | request( 23 | method: :delete, 24 | url: "#{APIConfig.api_request_url}/forms/#{form.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}" 27 | } 28 | ) 29 | end 30 | 31 | def success? 32 | @response.code == 204 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/form_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative '../../api_request' 19 | 20 | class FormRequest < APIRequest 21 | def form 22 | Form.from_response(json) 23 | end 24 | 25 | def error_code 26 | json.fetch(:code) 27 | end 28 | 29 | def invalid_form? 30 | @response.code == 400 && %w[VALIDATION_ERROR BAD_REQUEST INVALID_JSON].include?(error_code) 31 | end 32 | 33 | def unauthorized? 34 | @response.code == 401 35 | end 36 | 37 | def payment_required? 38 | @response.code == 402 39 | end 40 | 41 | def forbidden? 42 | @response.code == 403 43 | end 44 | 45 | def not_found? 46 | @response.code == 404 47 | end 48 | 49 | def conflict? 50 | @response.code == 409 51 | end 52 | 53 | def service_unavailable? 54 | @response.code == 502 || @response.code == 503 55 | end 56 | 57 | def last_modified 58 | Time.parse(@response.headers[:last_modified]) 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/head_form_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | 20 | class HeadFormRequest < FormRequest 21 | def initialize(form, token: APIConfig.token) 22 | r = { 23 | method: :head, 24 | url: "#{APIConfig.api_request_url}/forms/#{form.id}" 25 | } 26 | r[:headers] = { 'Authorization' => "Bearer #{token}" } unless token.nil? 27 | 28 | request(r) 29 | end 30 | 31 | def success? 32 | @response.code == 200 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/messages/retrieve_messages_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class RetrieveMessagesRequest < APIRequest 19 | def initialize(form, token: APIConfig.token) 20 | request( 21 | method: :get, 22 | url: "#{APIConfig.api_request_url}/forms/#{form.id}/messages", 23 | headers: { 24 | 'Authorization' => "Bearer #{token}" 25 | } 26 | ) 27 | end 28 | 29 | def success? 30 | @response.code == 200 && json? 31 | end 32 | 33 | def messages 34 | Messages.from_response(json) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/messages/update_messages_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class UpdateMessagesRequest < APIRequest 19 | def initialize(form, messages, token: APIConfig.token) 20 | request( 21 | method: :put, 22 | url: "#{APIConfig.api_request_url}/forms/#{form.id}/messages", 23 | headers: { 24 | 'Authorization' => "Bearer #{token}" 25 | }, 26 | payload: messages.payload 27 | ) 28 | end 29 | 30 | def success? 31 | @response.code == 204 32 | end 33 | 34 | def payment_required? 35 | @response.code == 402 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/retrieve_all_forms_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | require 'open-uri' 20 | 21 | class RetrieveAllFormsRequest < FormRequest 22 | def initialize(token: APIConfig.token, forms_per_page: 10, page: nil, search: nil, theme: nil, workspace: nil, from_id: nil) 23 | url = "#{APIConfig.api_request_url}/forms?" 24 | url << "page_size=#{forms_per_page}&" unless forms_per_page.nil? 25 | url << "page=#{page}&" unless page.nil? 26 | url << "search=#{URI.encode_www_form_component(search)}&" unless search.nil? 27 | url << "theme_id=#{theme.id}&" unless theme.nil? 28 | url << "workspace_id=#{workspace.id}&" unless workspace.nil? 29 | url << "from_id=#{from_id}&" unless from_id.nil? 30 | r = { 31 | method: :get, 32 | url: url 33 | } 34 | r[:headers] = { 'Authorization' => "Bearer #{token}" } unless token.nil? 35 | 36 | request(r) 37 | end 38 | 39 | def success? 40 | @response.code == 200 && json? 41 | end 42 | 43 | def forms 44 | json.fetch(:items) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/retrieve_form_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | 20 | class RetrieveFormRequest < FormRequest 21 | def initialize(form, token: APIConfig.token) 22 | r = { 23 | method: :get, 24 | url: "#{APIConfig.api_request_url}/forms/#{form.id}" 25 | } 26 | r[:headers] = { 'Authorization' => "Bearer #{token}" } unless token.nil? 27 | 28 | request(r) 29 | end 30 | 31 | def success? 32 | @response.code == 200 && json? 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/update_form_patch_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | 20 | class UpdateFormPatchRequest < FormRequest 21 | def initialize(form, operations, token: APIConfig.token) 22 | request( 23 | method: :patch, 24 | url: "#{APIConfig.api_request_url}/forms/#{form.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}", 27 | 'Content-Type' => 'application/json' 28 | }, 29 | payload: operations.map(&:payload).to_json 30 | ) 31 | end 32 | 33 | def success? 34 | @response.code == 204 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/requests/update_form_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'form_request' 19 | 20 | class UpdateFormRequest < FormRequest 21 | def initialize(form, token: APIConfig.token) 22 | request( 23 | method: :put, 24 | url: "#{APIConfig.api_request_url}/forms/#{form.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}" 27 | }, 28 | payload: form.payload 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 200 && json? 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/settings/notifications.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Notifications 19 | attr_accessor :self_enabled, :self_recipients, :self_reply_to, :self_subject, :self_message, 20 | :respondent_enabled, :respondent_recipient, :respondent_reply_to, :respondent_subject, :respondent_message 21 | 22 | def initialize(self_enabled: nil, self_recipients: nil, self_reply_to: nil, self_subject: nil, self_message: nil, 23 | respondent_enabled: nil, respondent_recipient: nil, respondent_reply_to: nil, respondent_subject: nil, respondent_message: nil) 24 | @self_enabled = self_enabled 25 | @self_recipients = self_recipients 26 | @self_reply_to = self_reply_to 27 | @self_subject = self_subject 28 | @self_message = self_message 29 | @respondent_enabled = respondent_enabled 30 | @respondent_recipient = respondent_recipient 31 | @respondent_reply_to = respondent_reply_to 32 | @respondent_subject = respondent_subject 33 | @respondent_message = respondent_message 34 | end 35 | 36 | def self.from_response(response) 37 | self_payload = response[:self] 38 | new_self_payload = {} 39 | if self_payload 40 | self_payload.each_key do |key| 41 | new_key = 'self_' + key.to_s 42 | new_self_payload[new_key.to_sym] = self_payload.delete(key) 43 | end 44 | end 45 | 46 | respondent_payload = response[:respondent] 47 | new_respondent_payload = {} 48 | if respondent_payload 49 | respondent_payload.each_key do |key| 50 | new_key = 'respondent_' + key.to_s 51 | new_respondent_payload[new_key.to_sym] = respondent_payload.delete(key) 52 | end 53 | end 54 | 55 | params = new_respondent_payload.merge(new_self_payload) 56 | Notifications.new(params) 57 | end 58 | 59 | def payload 60 | payload = {} 61 | unless self_recipients.nil? && self_subject.nil? && self_message.nil? 62 | payload[:self] = {} 63 | payload[:self][:enabled] = self_enabled unless self_enabled.nil? 64 | payload[:self][:reply_to] = self_reply_to unless self_reply_to.nil? 65 | payload[:self][:recipients] = self_recipients unless self_recipients.nil? 66 | payload[:self][:subject] = self_subject unless self_subject.nil? 67 | payload[:self][:message] = self_message unless self_message.nil? 68 | end 69 | unless respondent_recipient.nil? && respondent_subject.nil? && respondent_message.nil? 70 | payload[:respondent] = {} 71 | payload[:respondent][:enabled] = respondent_enabled unless respondent_enabled.nil? 72 | payload[:respondent][:reply_to] = respondent_reply_to unless respondent_reply_to.nil? 73 | payload[:respondent][:recipient] = respondent_recipient unless respondent_recipient.nil? 74 | payload[:respondent][:subject] = respondent_subject unless respondent_subject.nil? 75 | payload[:respondent][:message] = respondent_message unless respondent_message.nil? 76 | end 77 | payload 78 | end 79 | 80 | def same?(actual) 81 | (self_enabled.nil? || self_enabled == actual.self_enabled) && 82 | (self_reply_to.nil? || self_reply_to == actual.self_reply_to) && 83 | (self_recipients.nil? || self_recipients == actual.self_recipients) && 84 | (self_subject.nil? || self_subject == actual.self_subject) && 85 | (self_message.nil? || self_message == actual.self_message) && 86 | (respondent_enabled.nil? || respondent_enabled == actual.respondent_enabled) && 87 | (respondent_reply_to.nil? || respondent_reply_to == actual.respondent_reply_to) && 88 | (respondent_recipient.nil? || respondent_recipient == actual.respondent_recipient) && 89 | (respondent_subject.nil? || respondent_subject == actual.respondent_subject) && 90 | (respondent_message.nil? || respondent_message == actual.respondent_message) 91 | end 92 | 93 | def self.full_example(email_block_for_notifications_ref) 94 | Notifications.new(self_enabled: true, self_reply_to: '{{field:' + email_block_for_notifications_ref + '}}', self_recipients: ['recipient1@email.com', 'recipient2@email.com'], 95 | self_subject: 'An email subject', self_message: 'This is a message that will be in an email', 96 | respondent_enabled: true, respondent_reply_to: ['hello@email.com'], respondent_recipient: '{{field:' + email_block_for_notifications_ref + '}}', 97 | respondent_subject: 'An email subject', respondent_message: 'This is a message that will be in an email') 98 | end 99 | end 100 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/settings/settings.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Settings 19 | attr_accessor :redirect_after_submit_url, :show_typeform_branding, :progress_bar, 20 | :show_progress_bar, :description, :allow_indexing, :image, :language, 21 | :is_public, :is_trial, :google_analytics, :facebook_pixel, :google_tag_manager, 22 | :notifications 23 | 24 | def initialize(redirect_after_submit_url: nil, show_typeform_branding: nil, progress_bar: nil, 25 | show_progress_bar: nil, description: nil, allow_indexing: nil, image: nil, language: nil, 26 | is_public: nil, is_trial: nil, google_analytics: nil, facebook_pixel: nil, 27 | google_tag_manager: nil, notifications: nil, are_uploads_public: nil, 28 | show_time_to_complete: nil) 29 | 30 | @redirect_after_submit_url = redirect_after_submit_url 31 | @show_typeform_branding = show_typeform_branding 32 | @progress_bar = progress_bar 33 | @show_progress_bar = show_progress_bar 34 | @description = description 35 | @allow_indexing = allow_indexing 36 | @language = language 37 | @is_public = is_public 38 | @is_trial = is_trial 39 | @image = image 40 | @google_analytics = google_analytics 41 | @facebook_pixel = facebook_pixel 42 | @google_tag_manager = google_tag_manager 43 | @notifications = notifications 44 | end 45 | 46 | def self.from_response(response) 47 | meta = response[:meta] 48 | settings_params = response.keep_if { |k, _| k != :meta } 49 | params = meta.merge(settings_params) 50 | params[:notifications] = Notifications.from_response(response[:notifications]) unless response[:notifications].nil? 51 | Settings.new(params) 52 | end 53 | 54 | def payload 55 | payload = {} 56 | payload[:redirect_after_submit_url] = redirect_after_submit_url unless redirect_after_submit_url.nil? 57 | payload[:show_typeform_branding] = show_typeform_branding unless show_typeform_branding.nil? 58 | payload[:progress_bar] = progress_bar unless progress_bar.nil? 59 | payload[:show_progress_bar] = show_progress_bar unless show_progress_bar.nil? 60 | payload[:language] = language unless language.nil? 61 | payload[:is_public] = is_public unless is_public.nil? 62 | payload[:google_analytics] = google_analytics unless google_analytics.nil? 63 | payload[:facebook_pixel] = facebook_pixel unless facebook_pixel.nil? 64 | payload[:google_tag_manager] = google_tag_manager unless google_tag_manager.nil? 65 | payload[:notifications] = notifications.payload unless notifications.nil? 66 | unless description.nil? && allow_indexing.nil? 67 | payload[:meta] = {} 68 | payload[:meta][:description] = description unless description.nil? 69 | payload[:meta][:allow_indexing] = allow_indexing unless allow_indexing.nil? 70 | payload[:meta][:image] = image unless image.nil? 71 | end 72 | payload 73 | end 74 | 75 | def same?(actual) 76 | (redirect_after_submit_url.nil? || redirect_after_submit_url == actual.redirect_after_submit_url) && 77 | (google_analytics.nil? || google_analytics == actual.google_analytics) && 78 | (facebook_pixel.nil? || facebook_pixel == actual.facebook_pixel) && 79 | (google_tag_manager.nil? || google_tag_manager == actual.google_tag_manager) && 80 | (notifications.nil? || notifications.same?(actual.notifications)) && 81 | (description.nil? || description == actual.description) && 82 | (show_typeform_branding.nil? ? Settings.default.show_typeform_branding : show_typeform_branding) == actual.show_typeform_branding && 83 | (progress_bar.nil? ? Settings.default.progress_bar : progress_bar) == actual.progress_bar && 84 | (language.nil? ? Settings.default.language : language) == actual.language && 85 | (is_public.nil? ? Settings.default.is_public : is_public) == actual.is_public && 86 | (allow_indexing.nil? ? Settings.default.allow_indexing : allow_indexing) == actual.allow_indexing && 87 | same_image?(actual) 88 | end 89 | 90 | def same_image?(actual) 91 | image.nil? || image[:href].start_with?("#{APIConfig.image_api_request_url}/images/") && actual.image[:href].start_with?("#{APIConfig.image_api_request_url}/images/") 92 | end 93 | 94 | def self.default 95 | Settings.new(show_typeform_branding: true, progress_bar: 'proportion', show_progress_bar: true, 96 | allow_indexing: false, language: 'en', is_public: true, is_trial: false) 97 | end 98 | 99 | def self.full_example(email_block_for_notifications_ref) 100 | image = { href: APIConfig.image_api_request_url + '/images/default' } 101 | Settings.new(redirect_after_submit_url: 'http://google.com', show_typeform_branding: false, progress_bar: 'percentage', 102 | show_progress_bar: false, description: 'some meta description', allow_indexing: true, image: image, 103 | language: 'fr', is_public: true, google_analytics: 'UA-1234-12', facebook_pixel: '12345678901234567', 104 | google_tag_manager: 'GTM-PLWP6TS', notifications: Notifications.full_example(email_block_for_notifications_ref)) 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /lib/create_api_gem/forms/variables.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Variables 19 | attr_accessor :price, :score 20 | 21 | def initialize(price: nil, score: nil) 22 | @price = price 23 | @score = score 24 | end 25 | 26 | def self.from_response(payload) 27 | new( 28 | price: payload[:price], 29 | score: payload[:score] 30 | ) 31 | end 32 | 33 | def self.default 34 | Variables.new 35 | end 36 | 37 | def self.full_example 38 | Variables.new(price: 10, score: 0) 39 | end 40 | 41 | def payload 42 | payload = {} 43 | payload[:score] = score unless score.nil? 44 | payload[:price] = price unless price.nil? 45 | payload 46 | end 47 | 48 | def same?(actual) 49 | (score.nil? || score == actual.score) && 50 | (price.nil? || price == actual.price) 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/image.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Image 19 | attr_accessor :id, :image, :media_type, :file_name, :width, :height, :has_alpha, :avg_color 20 | 21 | def initialize(id: nil, image: nil, media_type: nil, file_name: nil, width: nil, height: nil, has_alpha: nil, avg_color: nil) 22 | @id = id 23 | @image = image 24 | @media_type = media_type 25 | @file_name = file_name 26 | @width = width 27 | @height = height 28 | @has_alpha = has_alpha 29 | @avg_color = avg_color 30 | end 31 | 32 | def self.from_response(payload) 33 | Image.new( 34 | id: payload[:id], 35 | media_type: payload[:media_type], 36 | file_name: payload[:file_name], 37 | width: payload[:width], 38 | height: payload[:height], 39 | has_alpha: payload[:has_alpha], 40 | avg_color: payload[:avg_color] 41 | ) 42 | end 43 | 44 | def payload 45 | { 46 | image: image, 47 | media_type: media_type, 48 | file_name: file_name 49 | }.to_json 50 | end 51 | 52 | def same?(actual) 53 | (id.nil? || id == actual.id) && 54 | (media_type.nil? || media_type == actual.media_type) && 55 | (file_name.nil? || file_name == actual.file_name) && 56 | (width.nil? || width == actual.width) && 57 | (height.nil? || height == actual.height) && 58 | (has_alpha.nil? || has_alpha == actual.has_alpha) && 59 | (avg_color.nil? || avg_color == actual.avg_color) 60 | end 61 | 62 | def src 63 | "#{APIConfig.image_api_request_url}/images/#{id}" 64 | end 65 | 66 | def self.full_example 67 | Image.new( 68 | image: File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data', 'typeform_image.txt'))), 69 | media_type: 'image/gif', 70 | file_name: 'typeform.gif', 71 | width: 530, 72 | height: 350, 73 | has_alpha: true, 74 | avg_color: '5a6067' 75 | ) 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/create_image_from_url_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'image_request' 19 | 20 | class CreateImageFromUrlRequest < ImageRequest 21 | def initialize(image_url, token: APIConfig.token) 22 | request( 23 | method: :post, 24 | url: "#{APIConfig.api_request_url}/images", 25 | headers: { 26 | 'Content-Type' => 'application/json', 27 | 'Authorization' => "Bearer #{token}" 28 | }, 29 | payload: { 30 | url: image_url 31 | }.to_json 32 | ) 33 | end 34 | 35 | def success? 36 | @response.code == 201 && json? 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/create_image_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'image_request' 19 | 20 | class CreateImageRequest < ImageRequest 21 | def initialize(image, token: APIConfig.token) 22 | request( 23 | method: :post, 24 | url: "#{APIConfig.api_request_url}/images", 25 | headers: { 26 | 'Content-Type' => 'application/json', 27 | 'Authorization' => "Bearer #{token}" 28 | }, 29 | payload: image.payload 30 | ) 31 | end 32 | 33 | def success? 34 | @response.code == 201 && json? 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/delete_image_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'image_request' 19 | 20 | class DeleteImageRequest < ImageRequest 21 | def initialize(image, token: APIConfig.token) 22 | request( 23 | method: :delete, 24 | url: "#{APIConfig.api_request_url}/images/#{image.id}", 25 | headers: { 26 | 'Content-Type' => 'application/json', 27 | 'Authorization' => "Bearer #{token}" 28 | } 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 204 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/image_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative '../../api_request' 19 | 20 | class ImageRequest < APIRequest 21 | def image 22 | Image.from_response(json) 23 | end 24 | 25 | def src 26 | json.fetch(:src) 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/retrieve_all_images_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'image_request' 19 | 20 | class RetrieveAllImagesRequest < ImageRequest 21 | def initialize(token: APIConfig.token) 22 | request( 23 | method: :get, 24 | url: "#{APIConfig.api_request_url}/images", 25 | headers: { 26 | 'Content-Type' => 'application/json', 27 | 'Authorization' => "Bearer #{token}" 28 | } 29 | ) 30 | end 31 | 32 | def images 33 | json.map { |image| Image.from_response(image) } 34 | end 35 | 36 | def success? 37 | @response.code == 200 && json? 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/retrieve_frame_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'image_request' 19 | 20 | class RetrieveFrameRequest < ImageRequest 21 | def initialize(image, frame) 22 | request( 23 | method: :get, 24 | url: "#{APIConfig.image_api_request_url}/images/#{image.id}/image/default-#{frame}frame.png", 25 | headers: { 26 | 'Content-Type' => 'application/json' 27 | } 28 | ) 29 | end 30 | 31 | def success? 32 | @response.code == 200 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/images/requests/retrieve_image_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'image_request' 19 | 20 | class RetrieveImageRequest < ImageRequest 21 | def initialize(image, type: nil, size: nil, accept: nil) 22 | url = if type.nil? && size.nil? 23 | "#{APIConfig.api_request_url}/images/#{image.id}" 24 | else 25 | "#{APIConfig.api_request_url}/images/#{image.id}/#{type}/#{size}" 26 | end 27 | headers = { 'Content-Type' => 'application/json' } 28 | headers['Accept'] = 'application/json' if accept == 'json' 29 | request( 30 | method: :get, 31 | url: url, 32 | headers: headers 33 | ) 34 | end 35 | 36 | def success? 37 | @response.code == 200 38 | end 39 | 40 | def body 41 | @response.body 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/create_api_gem/patch_operation.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class PatchOperation 19 | attr_accessor :op, :value, :path 20 | 21 | def initialize(op: nil, path: nil, value: nil) 22 | @op = op 23 | @path = path 24 | @value = value 25 | end 26 | 27 | def payload 28 | { 29 | op: op, 30 | path: path, 31 | value: value 32 | } 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/background.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Background 19 | attr_accessor :href, :brightness, :layout 20 | 21 | def initialize(href: nil, brightness: nil, layout: nil) 22 | @href = href 23 | @brightness = brightness 24 | @layout = layout 25 | end 26 | 27 | def payload 28 | payload = { 29 | href: href 30 | } 31 | payload[:brightness] = brightness unless brightness.nil? 32 | payload[:layout] = layout unless layout.nil? 33 | payload 34 | end 35 | 36 | def self.from_response(payload) 37 | new( 38 | href: payload[:href], 39 | layout: payload[:layout], 40 | brightness: payload[:brightness] 41 | ) 42 | end 43 | 44 | def self.default 45 | Background.new( 46 | brightness: 0, 47 | layout: 'repeat' 48 | ) 49 | end 50 | 51 | def self.full_example 52 | Background.new( 53 | href: "#{APIConfig.image_api_request_url}/images/default", 54 | brightness: 0.5, 55 | layout: 'no-repeat' 56 | ) 57 | end 58 | 59 | def same?(actual) 60 | (layout.nil? ? Background.default.layout : layout) == actual.layout && 61 | (brightness.nil? ? Background.default.brightness : brightness) == actual.brightness 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/requests/create_theme_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'theme_request' 19 | 20 | class CreateThemeRequest < ThemeRequest 21 | def initialize(theme, token: APIConfig.token) 22 | request( 23 | method: :post, 24 | url: "#{APIConfig.api_request_url}/themes", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}" 27 | }, 28 | payload: theme.payload 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 201 && json? 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/requests/delete_theme_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'theme_request' 19 | 20 | class DeleteThemeRequest < ThemeRequest 21 | def initialize(theme, token: APIConfig.token) 22 | request( 23 | method: :delete, 24 | url: "#{APIConfig.api_request_url}/themes/#{theme.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}" 27 | } 28 | ) 29 | end 30 | 31 | def success? 32 | @response.code == 204 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/requests/retrieve_all_themes_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'theme_request' 19 | require 'rack' 20 | 21 | class RetrieveAllThemesRequest < APIRequest 22 | def initialize(token: APIConfig.token, page: nil, page_size: nil, visibility: nil) 23 | filters = {} 24 | filters[:page] = page unless page.nil? 25 | filters[:page_size] = page_size unless page_size.nil? 26 | filters[:visibility] = visibility unless visibility.nil? 27 | parameters = Rack::Utils.build_query(filters) 28 | request( 29 | method: :get, 30 | url: "#{APIConfig.api_request_url}/themes?" + parameters, 31 | headers: { 32 | 'Authorization' => "Bearer #{token}" 33 | }, 34 | verify_ssl: OpenSSL::SSL::VERIFY_NONE 35 | ) 36 | end 37 | 38 | def bad_request? 39 | @response.code == 400 && json? 40 | end 41 | 42 | def success? 43 | @response.code == 200 && json? 44 | end 45 | 46 | def themes 47 | json.fetch(:items) 48 | end 49 | 50 | def total_items 51 | json.fetch(:total_items) 52 | end 53 | 54 | def page_count 55 | json.fetch(:page_count) 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/requests/retrieve_theme_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'theme_request' 19 | 20 | class RetrieveThemeRequest < ThemeRequest 21 | def initialize(theme, token: APIConfig.token) 22 | headers = {} 23 | headers = { 'Authorization' => "Bearer #{token}" } unless token.nil? 24 | request( 25 | method: :get, 26 | url: "#{APIConfig.api_request_url}/themes/#{theme.id}", 27 | headers: headers 28 | ) 29 | end 30 | 31 | def success? 32 | @response.code == 200 && json? 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/requests/theme_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative '../../api_request' 19 | 20 | class ThemeRequest < APIRequest 21 | def location_header 22 | headers.fetch(:location) 23 | end 24 | 25 | def theme 26 | Theme.from_response(json) 27 | end 28 | 29 | def invalid_theme? 30 | @response.code == 400 31 | end 32 | 33 | def not_found_theme? 34 | @response.code == 404 35 | end 36 | 37 | def forbidden? 38 | @response.code == 403 39 | end 40 | 41 | def theme_id 42 | headers.fetch(:location).split('/themes/')[1] 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/requests/update_theme_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'theme_request' 19 | 20 | class UpdateThemeRequest < ThemeRequest 21 | def initialize(theme, token: APIConfig.token) 22 | request( 23 | method: :put, 24 | url: "#{APIConfig.api_request_url}/themes/#{theme.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}" 27 | }, 28 | payload: theme.payload 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 200 && json? 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/themes/theme.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Theme 19 | attr_accessor :id, :name, :font, :colors, :visibility, :has_transparent_button, :background, :screens, :fields 20 | 21 | def initialize(id: nil, name: nil, font: nil, colors: nil, visibility: nil, has_transparent_button: nil, background: nil, screens: nil, fields: nil) 22 | @id = id 23 | @name = name || DataGenerator.title 24 | @font = font || 'Arial' 25 | @colors = colors || Theme.colors 26 | @visibility = visibility || 'private' 27 | @has_transparent_button = has_transparent_button 28 | @background = background 29 | @screens = screens || Theme.screens 30 | @fields = fields || Theme.fields 31 | end 32 | 33 | def self.default 34 | Theme.new( 35 | id: 'gJ3gfQ', 36 | name: 'Default', 37 | colors: [ 38 | question: '#3D3D3D', 39 | answer: '#4FB0AE', 40 | button: '#4FB0AE', 41 | background: '#FFFFFF' 42 | ], 43 | screens: [ 44 | font_size: 'small', 45 | alignment: 'center' 46 | ], 47 | fields: [ 48 | font_size: 'medium', 49 | alignment: 'left' 50 | ], 51 | font: 'Karla', 52 | has_transparent_button: false, 53 | visibility: 'private' 54 | ) 55 | end 56 | 57 | def self.full_example 58 | Theme.new( 59 | name: DataGenerator.title, 60 | colors: colors, 61 | font: 'Nixie One', 62 | has_transparent_button: true, 63 | visibility: 'private', 64 | background: Background.full_example, 65 | screens: screens, 66 | fields: fields 67 | ) 68 | end 69 | 70 | def self.colors 71 | { 72 | question: DataGenerator.color_code, 73 | answer: DataGenerator.color_code, 74 | button: DataGenerator.color_code, 75 | background: DataGenerator.color_code 76 | } 77 | end 78 | 79 | def self.screens 80 | { 81 | font_size: 'small', 82 | alignment: 'center' 83 | } 84 | end 85 | 86 | def self.fields 87 | { 88 | font_size: 'medium', 89 | alignment: 'left' 90 | } 91 | end 92 | 93 | def payload 94 | payload = { 95 | name: name, 96 | font: font, 97 | colors: colors 98 | } 99 | payload[:has_transparent_button] = has_transparent_button unless has_transparent_button.nil? 100 | payload[:visibility] = visibility unless visibility.nil? 101 | payload[:background] = background.payload unless background.nil? 102 | payload[:screens] = screens unless screens.nil? 103 | payload[:fields] = fields unless fields.nil? 104 | payload.to_json 105 | end 106 | 107 | def self.from_response(payload) 108 | background = payload[:background].nil? ? nil : Background.from_response(payload[:background]) 109 | new( 110 | id: payload[:id], 111 | name: payload[:name], 112 | font: payload[:font], 113 | colors: payload[:colors], 114 | visibility: payload[:visibility], 115 | has_transparent_button: payload[:has_transparent_button], 116 | background: background, 117 | screens: payload[:screens], 118 | fields: payload[:fields] 119 | ) 120 | end 121 | 122 | def same?(actual) 123 | (id.nil? || id == actual.id) && 124 | name == actual.name && 125 | colors == actual.colors && 126 | colors.keys == %i[question answer button background] && 127 | font == actual.font && 128 | (visibility.nil? ? Theme.default.visibility : visibility) == actual.visibility && 129 | (has_transparent_button.nil? ? Theme.default.has_transparent_button : has_transparent_button) == actual.has_transparent_button && 130 | (background.nil? || background.same?(actual.background)) && 131 | (screens || Theme.default.screens) == actual.screens && 132 | (fields.nil? ? Theme.fields.screens : fields) == actual.fields 133 | end 134 | end 135 | -------------------------------------------------------------------------------- /lib/create_api_gem/version.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | module CreateApiGem 19 | VERSION = '0.0.1'.freeze 20 | end 21 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/create_workspace_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'workspace_request' 19 | 20 | class CreateWorkspaceRequest < WorkspaceRequest 21 | def initialize(workspace, token: APIConfig.token) 22 | request( 23 | method: :post, 24 | url: APIConfig.workspaces_api_request_url, 25 | headers: { 26 | 'Authorization' => "Bearer #{token}", 27 | 'Content-Type' => 'application/json' 28 | }, 29 | payload: workspace.payload 30 | ) 31 | end 32 | 33 | def success? 34 | @response.code == 201 && json? && json.key?(:forms) && json.key?(:self) 35 | end 36 | 37 | def location_header 38 | headers.fetch(:location) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/delete_workspace_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'workspace_request' 19 | 20 | class DeleteWorkspaceRequest < WorkspaceRequest 21 | def initialize(workspace, token: APIConfig.token) 22 | request( 23 | method: :delete, 24 | url: "#{APIConfig.workspaces_api_request_url}/#{workspace.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}", 27 | 'Content-Type' => 'application/json' 28 | } 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 204 34 | end 35 | 36 | def invalid_operation? 37 | @response.code == 400 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/retrieve_all_workspaces_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'workspace_request' 19 | require 'open-uri' 20 | 21 | class RetrieveAllWorkspacesRequest < WorkspaceRequest 22 | def initialize(token: APIConfig.token, workspaces_per_page: 10, page: nil, search: nil) 23 | url = "#{APIConfig.workspaces_api_request_url}?" 24 | url << "page_size=#{workspaces_per_page}&" unless workspaces_per_page.nil? 25 | url << "page=#{page}&" unless page.nil? 26 | url << "search=#{URI.encode_www_form_component(search)}&" unless search.nil? 27 | request( 28 | method: :get, 29 | url: url, 30 | headers: { 31 | 'Authorization' => "Bearer #{token}", 32 | 'Content-Type' => 'application/json' 33 | } 34 | ) 35 | end 36 | 37 | def success? 38 | @response.code == 200 && json? 39 | end 40 | 41 | def workspaces 42 | json.fetch(:items).map do |workspace_json| 43 | Workspace.from_response(workspace_json) 44 | end 45 | end 46 | 47 | def default_workspace 48 | workspaces.find(&:default) 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/retrieve_default_workspace_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'workspace_request' 19 | 20 | class RetrieveDefaultWorkspaceRequest < WorkspaceRequest 21 | def initialize(token: APIConfig.token) 22 | request( 23 | method: :get, 24 | url: "#{APIConfig.workspaces_api_request_url}/default", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}", 27 | 'Content-Type' => 'application/json' 28 | } 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 200 && json? && json.key?(:forms) && json.key?(:self) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/retrieve_workspace_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'workspace_request' 19 | 20 | class RetrieveWorkspaceRequest < WorkspaceRequest 21 | def initialize(workspace, token: APIConfig.token) 22 | request( 23 | method: :get, 24 | url: "#{APIConfig.workspaces_api_request_url}/#{workspace.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}", 27 | 'Content-Type' => 'application/json' 28 | } 29 | ) 30 | end 31 | 32 | def success? 33 | @response.code == 200 && json? && json.key?(:forms) && json.key?(:self) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/update_workspace_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative 'workspace_request' 19 | 20 | class UpdateWorkspaceRequest < WorkspaceRequest 21 | def initialize(workspace, operations, token: APIConfig.token) 22 | request( 23 | method: :patch, 24 | url: "#{APIConfig.workspaces_api_request_url}/#{workspace.id}", 25 | headers: { 26 | 'Authorization' => "Bearer #{token}", 27 | 'Content-Type' => 'application/json' 28 | }, 29 | payload: operations.map(&:payload).to_json 30 | ) 31 | end 32 | 33 | def success? 34 | @response.code == 204 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/requests/workspace_request.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require_relative '../../api_request' 19 | 20 | class WorkspaceRequest < APIRequest 21 | def workspace 22 | Workspace.from_response(json) 23 | end 24 | 25 | def unauthorized? 26 | @response.code == 401 27 | end 28 | 29 | def not_found? 30 | @response.code == 404 31 | end 32 | 33 | def forbidden? 34 | @response.code == 403 35 | end 36 | 37 | def bad_request? 38 | @response.code == 400 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/create_api_gem/workspaces/workspace.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class Workspace 19 | attr_accessor :name, :id, :default, :shared, :members 20 | 21 | def initialize(name: nil, id: nil, default: nil, shared: nil, members: nil) 22 | @name = name || DataGenerator.title 23 | @id = id 24 | @default = default 25 | @shared = shared 26 | @members = members 27 | end 28 | 29 | def payload 30 | { 31 | name: name 32 | }.to_json 33 | end 34 | 35 | def same?(actual) 36 | name == actual.name && 37 | id.nil? || id == actual.id && 38 | (default.nil? ? Workspace.default.default : default) == actual.default && 39 | (shared.nil? ? Workspace.default.shared : shared) == actual.shared 40 | end 41 | 42 | def self.default 43 | Workspace.new(default: false, shared: false) 44 | end 45 | 46 | def self.from_response(payload) 47 | new( 48 | name: payload[:name], 49 | id: payload[:id], 50 | default: payload[:default], 51 | shared: payload[:shared], 52 | members: payload[:members] 53 | ) 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1 3 | } 4 | -------------------------------------------------------------------------------- /test/test_base.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | require 'simplecov' 19 | SimpleCov.start do 20 | add_filter '/test/' 21 | end 22 | SimpleCov.command_name 'Gem Unit Tests' 23 | 24 | require 'minitest/autorun' 25 | require 'create_api_gem' 26 | 27 | class TestBase < Minitest::Test 28 | def token 29 | ENV['TYPEFORM_API_TOKEN'] 30 | end 31 | 32 | def email 33 | 'maria_jose@typeform.com' 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /test/test_forms.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class FormsTest < TestBase 19 | def test_all_requests 20 | form = Form.full_example 21 | 22 | create_form = CreateFormRequest.new(form) 23 | assert_equal create_form.success?, true 24 | assert_equal form.same?(create_form.form), true 25 | form = create_form.form 26 | 27 | retrieve_form = RetrieveFormRequest.new(form) 28 | assert_equal retrieve_form.success?, true 29 | assert_equal form.same?(retrieve_form.form), true 30 | form = retrieve_form.form 31 | 32 | head_form = HeadFormRequest.new(form) 33 | assert_equal head_form.success?, true 34 | 35 | retrieve_all_forms = RetrieveAllFormsRequest.new 36 | assert_equal retrieve_all_forms.success?, true 37 | 38 | update_form = UpdateFormRequest.new(form) 39 | assert_equal update_form.success?, true 40 | assert_equal form.same?(update_form.form), true 41 | form = update_form.form 42 | 43 | patch_operations = [PatchOperation.new(op: 'replace', path: '/title', value: 'new title')] 44 | update_patch_form = UpdateFormPatchRequest.new(form, patch_operations) 45 | assert_equal update_patch_form.success?, true 46 | 47 | delete_form = DeleteFormRequest.new(form) 48 | assert_equal delete_form.success?, true 49 | end 50 | 51 | def test_form_same_method 52 | form = Form.full_example 53 | same_form = form.dup 54 | assert_equal form.same?(same_form), true 55 | 56 | different_form = form.dup 57 | different_form.title = DataGenerator.title 58 | assert_equal form.same?(different_form), false 59 | end 60 | 61 | def test_block_same_method 62 | block = ShortTextBlock.full_example 63 | same_block = block.dup 64 | assert_equal block.same?(same_block), true 65 | 66 | different_block = block.dup 67 | different_block.ref = DataGenerator.field_ref 68 | assert_equal block.same?(different_block), false 69 | end 70 | 71 | def test_logic_same_method 72 | logic_jump = LogicJump.create_always_jump(Form.full_example) 73 | same_logic_jump = logic_jump.dup 74 | assert_equal logic_jump.same?(same_logic_jump), true 75 | 76 | different_logic_jump = logic_jump.dup 77 | different_logic_jump.to_ref = DataGenerator.field_ref 78 | assert_equal logic_jump.same?(different_logic_jump), false 79 | end 80 | 81 | def test_settings_same_method 82 | settings = Settings.full_example(DataGenerator.field_ref) 83 | same_settings = settings.dup 84 | assert_equal settings.same?(same_settings), true 85 | 86 | different_settings = settings.dup 87 | different_settings.is_public = false 88 | assert_equal settings.same?(different_settings), false 89 | end 90 | 91 | def test_messages 92 | form = CreateFormRequest.execute(Form.new).form 93 | 94 | retrieve_messages = RetrieveMessagesRequest.new(form) 95 | assert_equal retrieve_messages.success?, true 96 | 97 | messages = Messages.new('label.button.ok' => 'New Ok') 98 | update_messages = UpdateMessagesRequest.new(form, messages) 99 | assert_equal update_messages.success?, true 100 | assert_equal messages.same?(RetrieveMessagesRequest.execute(form).messages), true 101 | 102 | DeleteFormRequest.execute(form) 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /test/test_images.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class ImagesTest < TestBase 19 | def test_all_requests 20 | image = Image.full_example 21 | 22 | create_image = CreateImageRequest.new(image) 23 | assert_equal create_image.success?, true 24 | image = create_image.image 25 | 26 | retrieve_image = RetrieveImageRequest.new(image, accept: 'json') 27 | assert_equal retrieve_image.success?, true 28 | assert_equal image.id == retrieve_image.image.id, true 29 | assert_equal image.file_name == retrieve_image.image.file_name, true 30 | assert_equal image.media_type == retrieve_image.image.media_type, true 31 | image = retrieve_image.image 32 | 33 | retrieve_frame = RetrieveFrameRequest.new(image, 'first') 34 | assert_equal retrieve_frame.success?, true 35 | 36 | retrieve_all_images = RetrieveAllImagesRequest.new 37 | assert_equal retrieve_all_images.success?, true 38 | 39 | delete_image = DeleteImageRequest.new(image) 40 | assert_equal delete_image.success?, true 41 | end 42 | 43 | def test_same_method 44 | image = Image.full_example 45 | same_image = image.dup 46 | assert_equal image.same?(same_image), true 47 | 48 | different_image = image.dup 49 | different_image.file_name = 'different_file_name' 50 | assert_equal image.same?(different_image), false 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /test/test_themes.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class ThemesTest < TestBase 19 | def test_all_requests 20 | theme = Theme.full_example 21 | 22 | create_theme = CreateThemeRequest.new(theme) 23 | assert_equal create_theme.success?, true 24 | assert_equal theme.same?(create_theme.theme), true 25 | theme = create_theme.theme 26 | 27 | retrieve_theme = RetrieveThemeRequest.new(theme) 28 | assert_equal retrieve_theme.success?, true 29 | assert_equal theme.same?(retrieve_theme.theme), true 30 | theme = retrieve_theme.theme 31 | 32 | retrieve_all_themes = RetrieveAllThemesRequest.new(page: 1, page_size: 2, visibility: 'private') 33 | assert_equal retrieve_all_themes.success?, true 34 | 35 | update_theme = UpdateThemeRequest.new(theme) 36 | assert_equal update_theme.success?, true 37 | assert_equal theme.same?(update_theme.theme), true 38 | theme = update_theme.theme 39 | 40 | delete_theme = DeleteThemeRequest.new(theme) 41 | assert_equal delete_theme.success?, true 42 | end 43 | 44 | def test_same_method 45 | theme = Theme.full_example 46 | same_theme = theme.dup 47 | 48 | assert_equal theme.same?(same_theme), true 49 | 50 | not_same_theme = theme.dup 51 | not_same_theme.name = 'A different title' 52 | assert_equal theme.same?(not_same_theme), false 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /test/test_workspaces.rb: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | class WorkspacesTest < TestBase 19 | def test_all_requests 20 | workspace = Workspace.new 21 | 22 | create_workspace = CreateWorkspaceRequest.new(workspace) 23 | assert_equal create_workspace.success?, true 24 | assert_equal workspace.same?(create_workspace.workspace), true 25 | workspace = create_workspace.workspace 26 | 27 | retrieve_workspace = RetrieveWorkspaceRequest.new(workspace) 28 | assert_equal retrieve_workspace.success?, true 29 | assert_equal workspace.same?(retrieve_workspace.workspace), true 30 | workspace = retrieve_workspace.workspace 31 | 32 | retrieve_all_workspaces = RetrieveAllWorkspacesRequest.new 33 | assert_equal retrieve_all_workspaces.success?, true 34 | 35 | retrieve_default_workspace = RetrieveDefaultWorkspaceRequest.new 36 | assert_equal retrieve_default_workspace.success?, true 37 | 38 | form = CreateFormRequest.execute(Form.new).form 39 | operations = [ 40 | PatchOperation.new(op: 'replace', path: '/name', value: DataGenerator.title), 41 | PatchOperation.new(op: 'add', path: '/members', value: { email: email }) 42 | ] 43 | update_workspace = UpdateWorkspaceRequest.new(workspace, operations) 44 | assert_equal update_workspace.success?, true 45 | 46 | UpdateWorkspaceRequest.execute(workspace, [PatchOperation.new(op: 'remove', path: '/members', value: { email: email })]) 47 | DeleteFormRequest.execute(form) 48 | 49 | delete_workspace = DeleteWorkspaceRequest.new(workspace) 50 | assert_equal delete_workspace.success?, true 51 | end 52 | 53 | def test_same_method 54 | workspace = Workspace.new 55 | same_workspace = workspace.dup 56 | assert_equal workspace.same?(same_workspace), true 57 | 58 | different_workspace = workspace.dup 59 | different_workspace.name = DataGenerator.title 60 | assert_equal workspace.same?(different_workspace), false 61 | end 62 | end 63 | --------------------------------------------------------------------------------