mobile_workflow 0.6.18 → 0.6.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69f4d60c4068a0db15965d051763cb213bc13e38356ee3f21c35eed0d2838040
4
- data.tar.gz: 02cbe2239db1f6239cf5f4271aade224bd1ce69eabf27f9fffd65bf0faa41102
3
+ metadata.gz: '090b3070564f994192df8405b3e82cffe5e7898d1ff5a5d7d74b6f82894356a0'
4
+ data.tar.gz: 17733e78cf3e0b6f180a3db9f6e4baf41e6d5616d805f91bc8af0a0053dfa9bd
5
5
  SHA512:
6
- metadata.gz: 4f07e17e68915f0f1e1c598ff540850763f3c6871283da49e306002c8a02381ab35cf622747e82e48b5f71ed0151cbbf03816b92cc84540275c83ae3b85d4911
7
- data.tar.gz: e64d1632de882fcbde5d8f2ff6b94729d251453892001d39a0de9a7f1d9a96c7c169bcb36a8939b4f39002e5d5fd8f629c5ab3bf6af535ea50228984173ad2c2
6
+ metadata.gz: 62098f3fa6656bc4f5e29034fbade9f0087cfcb4462a161cf70549a272d94cc98bd2055a71b734a1089a0ebba80e9c309d36e5a51c4c1cb1cdeb4e39f7de3208
7
+ data.tar.gz: 31facdd89a123b1682d2bf6f5ea5fc72370c3e08462c16c614d6225f03cc1b939c8b8e8952c5d7051ab0154d9cd4c9533e2e9de2ad285e5a477f3fd08b76d9d4
@@ -6,12 +6,13 @@ module MobileWorkflow
6
6
  def binary_urls(object)
7
7
  return unless params["binaries"]
8
8
 
9
- params["binaries"].collect do |binary|
10
- extension = binary["mimetype"].split('/')[1] # i.e. image/jpg --> image, video/mp4 --> video
9
+ params["binaries"].map do |binary|
10
+ object_attribute = binary["identifier"]
11
+ extension = binary["mimetype"].split('/')[1] # i.e. image/jpg --> jpg, video/mp4 --> mp4
11
12
 
12
13
  {
13
14
  "identifier" => binary["identifier"],
14
- "url" => presigned_url("#{object.class.name.underscore}/#{object.id}/#{binary["identifier"]}.#{extension}"),
15
+ "url" => presigned_url("#{object.class.name.underscore}/#{object.id}/#{object_attribute}.#{extension}"),
15
16
  "method" => "PUT"
16
17
  }
17
18
  end
@@ -10,17 +10,27 @@ module MobileWorkflow
10
10
  when 'SubscriptionConfirmation'
11
11
  confirm_subscription ? (head :ok) : (head :bad_request)
12
12
  else
13
+ add_attachment
14
+ end
15
+ end
16
+
17
+ private
18
+ def add_attachment
19
+ begin
13
20
  @object = find_object
14
21
  @object.send("#{attribute_name}=",active_record_blob)
15
22
  if @object.save
16
23
  head :ok
17
24
  else
18
25
  Rails.logger.warn "Error saving object: #{@object} #{object.errors.full_messages}"
26
+ head :unprocessable_entity
19
27
  end
28
+ rescue NameError => e
29
+ Rails.logger.warn "Error attaching object: #{e.message}"
30
+ head :unprocessable_entity
20
31
  end
21
32
  end
22
-
23
- private
33
+
24
34
  def verify_request_authenticity
25
35
  head :unauthorized if raw_post.blank?
26
36
 
@@ -5,7 +5,8 @@ module MobileWorkflow
5
5
 
6
6
  ON_SUCCESS_OPTIONS = [:none, :reload, :backward, :forward]
7
7
  BUTTON_STYLES = [:primary, :outline, :danger]
8
- CONTENT_MODE_OPTIONS = [:scale_aspect_fill, :scale_aspect_fit]
8
+ CONTENT_MODE_OPTIONS = [:scale_aspect_fill, :scale_aspect_fit]
9
+ QUESTION_STYLES = [:single_choice, :multiple_choice]
9
10
 
10
11
  def mw_list_item(id: self.id, text:, detail_text: nil, sf_symbol_name: nil, image_attachment: nil)
11
12
  mw_list_item = {id: id, text: text, detailText: detail_text, sfSymbolName: sf_symbol_name}
@@ -37,7 +38,7 @@ module MobileWorkflow
37
38
  image_url = "https://source.unsplash.com/#{unsplash_id}/800x600"
38
39
  end
39
40
 
40
- {type: :image, previewURL: image_url, url: image_url}
41
+ {type: :image, previewURL: image_url, url: image_url}.compact
41
42
  end
42
43
 
43
44
  def mw_display_video(attachment, preview_options: { resize_to_fill: [600, 1200] })
@@ -48,35 +49,47 @@ module MobileWorkflow
48
49
  validate_on_success!(on_success)
49
50
  validate_button_style!(style)
50
51
 
51
- {type: :button, label: label, style: style, onSuccess: on_success}
52
+ {type: :button, label: label, style: style, onSuccess: on_success}.compact
52
53
  end
53
54
 
54
55
  def mw_display_delete_button(url:, label: "Delete", method: :delete, style: :danger, on_success: :backward)
55
56
  validate_on_success!(on_success)
56
57
  validate_button_style!(style)
57
58
 
58
- {type: :button, label: label, url: url, method: method, style: style, onSuccess: on_success}
59
+ {type: :button, label: label, url: url, method: method, style: style, onSuccess: on_success}.compact
59
60
  end
60
-
61
- def mw_display_button_for_url(label:, url:, method: :put, style: :primary, on_success: :reload)
61
+
62
+ def mw_display_url_button(label:, url:, method: :put, style: :primary, confirm_title: nil, confirm_text: nil, on_success: :reload)
62
63
  validate_on_success!(on_success)
63
64
  validate_button_style!(style)
64
65
 
65
- {type: :button, label: label, url: url, method: method, style: style, onSuccess: on_success}
66
+ {type: :button, label: label, url: url, method: method, style: style, confirmTitle: confirm_title, confirmText: confirm_text, onSuccess: on_success}.compact
66
67
  end
68
+ alias_method :mw_display_button_for_url, :mw_display_url_button
67
69
 
68
- def mw_display_button_for_system_url(label:, apple_system_url: nil, android_deep_link: nil, style: :primary)
70
+ def mw_display_system_url_button(label:, apple_system_url: nil, android_deep_link: nil, style: :primary)
69
71
  validate_button_style!(style)
70
72
  raise 'Invalid android_deep_link' unless android_deep_link.start_with?('http')
71
73
 
72
74
  {type: :button, label: label, appleSystemURL: apple_system_url, androidDeepLink: android_deep_link, style: style}.compact
73
75
  end
76
+ alias_method :mw_display_button_for_system_url, :mw_display_system_url_button
74
77
 
75
- def mw_display_button_for_modal_workflow(label:, modal_workflow_name:, style: :primary, on_success: :none)
78
+ def mw_display_modal_workflow_button(label:, modal_workflow_name:, style: :primary, on_success: :none)
76
79
  validate_on_success!(on_success)
77
80
  validate_button_style!(style)
78
81
 
79
- {type: :button, label: label, modalWorkflow: modal_workflow_name, style: style, onSuccess: on_success}
82
+ {type: :button, label: label, modalWorkflow: modal_workflow_name, style: style, onSuccess: on_success}.compact
83
+ end
84
+ alias_method :mw_display_button_for_modal_workflow, :mw_display_modal_workflow_button
85
+
86
+ def mw_text_choice_question(question:, style:, text_choices:)
87
+ raise 'Missing question' if question.blank?
88
+ raise 'Text Choices should be a hash' unless text_choices.is_a?(Hash)
89
+ validate_question_style!(style)
90
+
91
+ text_choices_a = text_choices.map{|k, v| {_class: "ORKTextChoice", exclusive: false, text: k, value: v} }.to_a
92
+ { question: question, answerFormat: { _class: "ORKTextChoiceAnswerFormat", style: style.to_s.camelize(:lower), textChoices: text_choices_a}}
80
93
  end
81
94
 
82
95
  private
@@ -92,6 +105,10 @@ module MobileWorkflow
92
105
  raise 'Unknown style' unless BUTTON_STYLES.include?(style)
93
106
  end
94
107
 
108
+ def validate_question_style!(style)
109
+ raise 'Unknown style' unless QUESTION_STYLES.include?(style)
110
+ end
111
+
95
112
  def preview_url(attachment, options:)
96
113
  return nil unless attachment.attached?
97
114
 
@@ -52,6 +52,9 @@ module MobileWorkflow
52
52
  def generate_models
53
53
  say "Loading OpenAPI Spec: #{open_api_spec_path}"
54
54
  say "Generating models"
55
+
56
+ copy_file("app/models/application_record.rb")
57
+
55
58
  model_name_to_properties.each_pair do |model_name, model_properties|
56
59
 
57
60
  if doorkeeper_oauth?
@@ -1,5 +1,5 @@
1
1
  require "mobile_workflow/engine"
2
2
 
3
3
  module MobileWorkflow
4
- # Your code goes here...
4
+ require 'mobile_workflow/railtie' if defined?(Rails)
5
5
  end
@@ -0,0 +1,13 @@
1
+ require 'mobile_workflow'
2
+ require 'rails'
3
+
4
+ module MobileWorkflow
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :mobile_workflow
7
+
8
+ rake_tasks do
9
+ path = File.expand_path(__dir__)
10
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+
3
+ def each_step(json, type)
4
+ json['workflows'].map{|w| w["steps"].select {|s| s["type"] == type.to_s}}.flatten.each do |step|
5
+ yield(step)
6
+ end
7
+ end
8
+
9
+ def replace_oauth(app_json)
10
+ client_id = ENV["CLIENT_ID"]
11
+ client_secret = ENV["CLIENT_SECRET"]
12
+ redirect_scheme = ENV["SCHEME"]
13
+
14
+ each_step(app_json, :networkOAuth2) do |step|
15
+ step["items"].each do |item|
16
+ if item["oAuth2ClientId"]
17
+ item["oAuth2ClientId"] = client_id
18
+ item["oAuth2ClientSecret"] = client_secret
19
+ item["oAuth2RedirectScheme"] = redirect_scheme
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def replace_servers(app_json)
26
+ server_url = ENV["SERVER_URL"]
27
+ base_url = ENV["PREVIOUS_SERVER_URL"]
28
+
29
+ app_json["servers"].each do |server|
30
+ server["url"] = server_url
31
+ end
32
+
33
+ each_step(app_json, :display) do |step|
34
+ step["items"].each do |item|
35
+ ["appleSystemURL", "androidDeepLink"].each{|key| item[key] = item[key].gsub(base_url, server_url) }
36
+ end
37
+ end
38
+ end
39
+
40
+ def env_set(path)
41
+ app_json = JSON.parse(File.read(app_json_path))
42
+ replace_oauth(app_json)
43
+ replace_servers(app_json)
44
+ File.write(app_json_path, app_json.to_json)
45
+ end
46
+
47
+ namespace :env_set do
48
+ desc 'Update Android app.json to use new env'
49
+ task :android do
50
+ env_set(File.join('app', 'src', 'main', 'res', 'raw', 'app.json'))
51
+ end
52
+
53
+ desc 'Update iOS app.json to use new env'
54
+ task :ios do
55
+ project_name = ENV["PROJECT_NAME"]
56
+ env_set(File.join(project_name, project_name, "Resources", "app.json"))
57
+ end
58
+ end
@@ -1,5 +1,5 @@
1
1
  module MobileWorkflow
2
- VERSION = '0.6.18'
2
+ VERSION = '0.6.23'
3
3
  RUBY_VERSION = '2.7.2'
4
4
  RAILS_VERSION = '6.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile_workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.18
4
+ version: 0.6.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brooke-Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -137,6 +137,8 @@ files:
137
137
  - lib/mobile_workflow/cli/heroku_backend.rb
138
138
  - lib/mobile_workflow/engine.rb
139
139
  - lib/mobile_workflow/open_api_spec/parser.rb
140
+ - lib/mobile_workflow/railtie.rb
141
+ - lib/mobile_workflow/tasks/env_set.rake
140
142
  - lib/mobile_workflow/version.rb
141
143
  homepage: https://github.com/futureworkshops/mobile_workflow
142
144
  licenses: