Class: Script::Layers::Infrastructure::ScriptService
- Inherits:
-
Object
- Object
- Script::Layers::Infrastructure::ScriptService
- Includes:
- SmartProperties
- Defined in:
- lib/project_types/script/layers/infrastructure/script_service.rb
Instance Method Summary collapse
- #disable(api_key:, shop_domain:, extension_point_type:) ⇒ Object
- #enable(api_key:, shop_domain:, configuration:, extension_point_type:, title:) ⇒ Object
- #push(extension_point_type:, script_name:, script_content:, compiled_type:, api_key: nil, force: false) ⇒ Object
Instance Method Details
#disable(api_key:, shop_domain:, extension_point_type:) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/project_types/script/layers/infrastructure/script_service.rb', line 70 def disable(api_key:, shop_domain:, extension_point_type:) query_name = "shop_script_delete" variables = { extensionPointName: extension_point_type.upcase, } resp_hash = script_service_request( query_name: query_name, api_key: api_key, shop_domain: format_shop_domain(shop_domain), variables: variables, ) user_errors = resp_hash["data"]["shopScriptDelete"]["userErrors"] return resp_hash if user_errors.empty? if user_errors.any? { |e| e['tag'] == 'shop_script_not_found' } raise Errors::ShopScriptUndefinedError, api_key else raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s) end end |
#enable(api_key:, shop_domain:, configuration:, extension_point_type:, title:) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/project_types/script/layers/infrastructure/script_service.rb', line 41 def enable(api_key:, shop_domain:, configuration:, extension_point_type:, title:) query_name = "shop_script_update_or_create" variables = { extensionPointName: extension_point_type.upcase, configuration: configuration, title: title, } resp_hash = script_service_request( query_name: query_name, api_key: api_key, shop_domain: format_shop_domain(shop_domain), variables: variables, ) user_errors = resp_hash["data"]["shopScriptUpdateOrCreate"]["userErrors"] return resp_hash if user_errors.empty? if user_errors.any? { |e| e['tag'] == 'app_script_not_found' } raise Errors::AppScriptUndefinedError, api_key elsif user_errors.any? { |e| e['tag'] == 'shop_script_conflict' } raise Errors::ShopScriptConflictError elsif user_errors.any? { |e| e['tag'] == 'app_script_not_pushed' } raise Errors::AppScriptNotPushedError else raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s) end end |
#push(extension_point_type:, script_name:, script_content:, compiled_type:, api_key: nil, force: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/project_types/script/layers/infrastructure/script_service.rb', line 13 def push( extension_point_type:, script_name:, script_content:, compiled_type:, api_key: nil, force: false ) query_name = "app_script_update_or_create" variables = { extensionPointName: extension_point_type.upcase, title: script_name, sourceCode: Base64.encode64(script_content), language: compiled_type, force: force, } resp_hash = script_service_request(query_name: query_name, api_key: api_key, variables: variables) user_errors = resp_hash["data"]["appScriptUpdateOrCreate"]["userErrors"] return resp_hash if user_errors.empty? if user_errors.any? { |e| e['tag'] == 'already_exists_error' } raise Errors::ScriptRepushError, api_key else raise Errors::ScriptServiceUserError.new(query_name, user_errors.to_s) end end |