-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for API version 5 #114
Open
peret
wants to merge
15
commits into
ylecuyer:master
Choose a base branch
from
playtestcloud:version-5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b061455
Add fields that were added in v5 of the API.
peret a81c3f1
Fix some API-specific fields.
peret 8bc8510
Split up resource classes for v4 and v5.
peret 690225c
Choose question class based on configuration.
peret 3a0cf71
Restore v4 fields to original state.
peret c0342de
Revert accidental changes in v4 classes.
peret 0da1e1f
Add space.
peret 1d493b1
Change accessor methods to work with the new v5 data structures.
peret a6b6ff2
Parse answers with options.
peret f849c4d
Set default API version to v5 and fix tests to v4.
d443302
Fix Response filter names for v5.
3da9f56
Preserve public class names by dynamically including the correct vers…
f515808
Re-work test setup and add tests for V5 resources.
26fd403
Add v5 time fields to the faraday middleware.
8313bd1
Revert unnecessary change in Resource class.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module SurveyGizmo::API | ||
if SurveyGizmo.configuration.v5? | ||
include SurveyGizmo::V5 | ||
else | ||
include SurveyGizmo::V4 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/survey_gizmo/api/account_teams.rb → lib/survey_gizmo/v4/account_teams.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module SurveyGizmo::API | ||
module SurveyGizmo::V4 | ||
class Answer | ||
include Virtus.model | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
lib/survey_gizmo/api/campaign.rb → lib/survey_gizmo/v4/campaign.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module SurveyGizmo::API | ||
module SurveyGizmo::V4 | ||
class Campaign | ||
include SurveyGizmo::Resource | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
lib/survey_gizmo/api/contact.rb → lib/survey_gizmo/v4/contact.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module SurveyGizmo::API | ||
module SurveyGizmo::V4 | ||
class Contact | ||
include SurveyGizmo::Resource | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
lib/survey_gizmo/api/email_message.rb → lib/survey_gizmo/v4/email_message.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module SurveyGizmo::API | ||
module SurveyGizmo::V4 | ||
class EmailMessage | ||
include SurveyGizmo::Resource | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/survey_gizmo/api/question.rb → lib/survey_gizmo/v4/question.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/survey_gizmo/api/response.rb → lib/survey_gizmo/v4/response.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module SurveyGizmo::API | ||
module SurveyGizmo::V4 | ||
class Response | ||
include SurveyGizmo::Resource | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
lib/survey_gizmo/api/survey.rb → lib/survey_gizmo/v4/survey.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This REST endpoint is only available to accounts with admin privileges | ||
# This code is untested. | ||
|
||
module SurveyGizmo::V5 | ||
class AccountTeams | ||
include SurveyGizmo::Resource | ||
|
||
attribute :id, Integer | ||
attribute :default_role, String | ||
attribute :status, String | ||
|
||
# v5 fields | ||
attribute :team_name, String | ||
attribute :description, String | ||
|
||
@route = '/accountteams' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'survey_gizmo/v5/option' | ||
|
||
module SurveyGizmo::V5 | ||
class Answer | ||
include Virtus.model | ||
|
||
attribute :key, String | ||
attribute :value, String | ||
attribute :survey_id, Integer | ||
attribute :response_id, Integer | ||
attribute :question_id, Integer | ||
attribute :question_text, String | ||
attribute :question_type, String | ||
attribute :options, Array[Option] | ||
attribute :submitted_at, DateTime | ||
attribute :answer_text, String | ||
attribute :other_text, String | ||
attribute :question_pipe, String | ||
|
||
def initialize(attrs = {}) | ||
self.attributes = attrs | ||
self.question_id = value['id'] | ||
self.question_text = value['question'] | ||
self.question_type = value['type'] | ||
|
||
if value['options'] | ||
self.answer_text = selected_options_texts.join(', ') | ||
else | ||
self.answer_text = value['answer'] | ||
end | ||
end | ||
|
||
def single_option | ||
[ | ||
Option.new(attributes.merge( | ||
id: value['answer_id'], | ||
value: value['answer'], | ||
title: value['original_answer'] || value['answer'] | ||
)) | ||
] | ||
end | ||
|
||
def selected_options_texts | ||
selected_options.map do |opt| | ||
opt['answer'] | ||
end | ||
end | ||
|
||
def selected_options | ||
value['options'].values.reject { |opt| opt['answer'].nil? }.map do |opt| | ||
Option.new(attributes.merge( | ||
id: opt['id'], | ||
value: opt['answer'], | ||
title: opt['option'] | ||
)) | ||
end | ||
end | ||
|
||
# Strips out the answer_text when there is a valid option_id | ||
def to_hash | ||
{ | ||
response_id: response_id, | ||
question_id: question_id, | ||
question_pipe: question_pipe, | ||
submitted_at: submitted_at, | ||
survey_id: survey_id, | ||
other_text: other_text, | ||
answer_text: other_text ? nil : answer_text | ||
}.reject { |k, v| v.nil? } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module SurveyGizmo::V5 | ||
class Campaign | ||
include SurveyGizmo::Resource | ||
|
||
attribute :id, Integer | ||
attribute :name, String | ||
attribute :type, String | ||
attribute :status, String | ||
attribute :uri, String | ||
attribute :SSL, Boolean | ||
attribute :language, String | ||
attribute :close_message, String | ||
attribute :limit_responses, String | ||
attribute :survey_id, Integer | ||
|
||
# v5 fields | ||
attribute :token_variables, Array | ||
attribute :invite_id, Integer | ||
attribute :subtype, String | ||
attribute :link_type, String | ||
attribute :date_created, DateTime | ||
attribute :date_modified, DateTime | ||
attribute :link_open_date, DateTime | ||
attribute :link_close_date, DateTime | ||
|
||
@route = '/survey/:survey_id/surveycampaign' | ||
|
||
def contacts(conditions = {}) | ||
Contact.all(conditions.merge(children_params).merge(all_pages: !conditions[:page])) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module SurveyGizmo::V5 | ||
class Contact | ||
include SurveyGizmo::Resource | ||
|
||
attribute :id, Integer | ||
attribute :survey_id, Integer | ||
attribute :campaign_id, Integer | ||
|
||
# v5 fields | ||
attribute :date_last_sent, DateTime | ||
attribute :division, String | ||
attribute :team, String | ||
attribute :group, String | ||
attribute :role, String | ||
attribute :status, String | ||
attribute :subscriber_status, String | ||
attribute :email_address, String | ||
attribute :first_name, String | ||
attribute :last_name, String | ||
attribute :organization, String | ||
attribute :department, String | ||
attribute :business_phone, String | ||
attribute :home_phone, String | ||
attribute :fax_phone, String | ||
attribute :mailing_address, String | ||
attribute :mailing_address2, String | ||
attribute :mailing_address_city, String | ||
attribute :mailing_address_state, String | ||
attribute :mailing_address_country, String | ||
attribute :mailing_address_postal, String | ||
attribute :title, String | ||
attribute :url, String | ||
attribute :customfield1, String | ||
attribute :customfield2, String | ||
attribute :customfield3, String | ||
attribute :customfield4, String | ||
attribute :customfield5, String | ||
attribute :customfield6, String | ||
attribute :customfield7, String | ||
attribute :customfield8, String | ||
attribute :customfield9, String | ||
attribute :customfield10, String | ||
|
||
@route = '/survey/:survey_id/surveycampaign/:campaign_id/contact' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module SurveyGizmo::V5 | ||
class EmailMessage | ||
include SurveyGizmo::Resource | ||
|
||
attribute :id, Integer | ||
attribute :survey_id, Integer | ||
attribute :campaign_id, Integer | ||
attribute :invite_identity, Integer | ||
attribute :subject, String | ||
attribute :replies, String | ||
attribute :medium, String | ||
attribute :status, String | ||
attribute :from, Hash | ||
attribute :body, Hash | ||
attribute :send, Boolean | ||
|
||
# v5 fields | ||
attribute :type, String | ||
attribute :subtype, String | ||
attribute :message_type, String | ||
attribute :footer, String | ||
attribute :embed_question, Boolean | ||
attribute :disable_styles, Boolean | ||
attribute :date_created, DateTime | ||
attribute :date_modified, DateTime | ||
|
||
@route = '/survey/:survey_id/surveycampaign/:campaign_id/emailmessage' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module SurveyGizmo::V5 | ||
class Option | ||
include SurveyGizmo::Resource | ||
include SurveyGizmo::MultilingualTitle | ||
|
||
attribute :id, Integer | ||
attribute :survey_id, Integer | ||
attribute :page_id, Integer | ||
attribute :question_id, Integer | ||
attribute :value, String | ||
attribute :properties, Hash | ||
|
||
# v5 fields | ||
attribute :title, String | ||
|
||
@route = '/survey/:survey_id/surveypage/:page_id/surveyquestion/:question_id/surveyoption' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'survey_gizmo/v5/question' | ||
|
||
module SurveyGizmo::V5 | ||
class Page | ||
include SurveyGizmo::Resource | ||
include SurveyGizmo::MultilingualTitle | ||
|
||
attribute :id, Integer | ||
attribute :description, String | ||
attribute :properties, Hash | ||
attribute :survey_id, Integer | ||
attribute :questions, Array[Question] | ||
|
||
# v5 fields | ||
attribute :title, String | ||
|
||
@route = '/survey/:survey_id/surveypage' | ||
|
||
def survey | ||
@survey ||= Survey.first(id: survey_id) | ||
end | ||
|
||
def questions | ||
@questions.each { |q| q.attributes = children_params } | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we need to keep the
**/*.rb
otherwise theSurveyGizmo::API
won't be required and you wont be able to use thing like:SurveyGizmo::API::Survey.all(all_pages: true)
You can give it a try with an new rails project:
and in the Gemfile point at your local version of the gem
Then if you do
bundle exec rails c
you'll have the following error:Instead of:
which is expected