Class: ShopifyAPI::Context
- Inherits:
-
Object
- Object
- ShopifyAPI::Context
- Extended by:
- T::Sig
- Defined in:
- lib/shopify_api/context.rb
Class Attribute Summary collapse
-
.api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
.api_secret_key ⇒ Object
readonly
Returns the value of attribute api_secret_key.
-
.api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
.host ⇒ Object
readonly
Returns the value of attribute host.
-
.host_name ⇒ Object
readonly
Returns the value of attribute host_name.
-
.logger ⇒ Object
readonly
Returns the value of attribute logger.
-
.old_api_secret_key ⇒ Object
readonly
Returns the value of attribute old_api_secret_key.
-
.private_shop ⇒ Object
readonly
Returns the value of attribute private_shop.
-
.scope ⇒ Object
readonly
Returns the value of attribute scope.
-
.session_storage ⇒ Object
readonly
Returns the value of attribute session_storage.
-
.user_agent_prefix ⇒ Object
readonly
Returns the value of attribute user_agent_prefix.
Class Method Summary collapse
- .activate_session(session) ⇒ Object
- .active_session ⇒ Object
- .deactivate_session ⇒ Object
- .embedded? ⇒ Boolean
- .host_scheme ⇒ Object
- .load_rest_resources(api_version:) ⇒ Object
- .private? ⇒ Boolean
- .setup(api_key:, api_secret_key:, api_version:, host_name:, scope:, is_private:, is_embedded:, session_storage:, logger: Logger.new($stdout), host: ENV["HOST"] || "https://#{host_name}", private_shop: nil, user_agent_prefix: nil, old_api_secret_key: nil) ⇒ Object
- .setup? ⇒ Boolean
Class Attribute Details
.api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
111 112 113 |
# File 'lib/shopify_api/context.rb', line 111 def api_key @api_key end |
.api_secret_key ⇒ Object (readonly)
Returns the value of attribute api_secret_key.
111 112 113 |
# File 'lib/shopify_api/context.rb', line 111 def api_secret_key @api_secret_key end |
.api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
111 112 113 |
# File 'lib/shopify_api/context.rb', line 111 def api_version @api_version end |
.host ⇒ Object (readonly)
Returns the value of attribute host.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def host @host end |
.host_name ⇒ Object (readonly)
Returns the value of attribute host_name.
111 112 113 |
# File 'lib/shopify_api/context.rb', line 111 def host_name @host_name end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
120 121 122 |
# File 'lib/shopify_api/context.rb', line 120 def logger @logger end |
.old_api_secret_key ⇒ Object (readonly)
Returns the value of attribute old_api_secret_key.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def old_api_secret_key @old_api_secret_key end |
.private_shop ⇒ Object (readonly)
Returns the value of attribute private_shop.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def private_shop @private_shop end |
.scope ⇒ Object (readonly)
Returns the value of attribute scope.
114 115 116 |
# File 'lib/shopify_api/context.rb', line 114 def scope @scope end |
.session_storage ⇒ Object (readonly)
Returns the value of attribute session_storage.
117 118 119 |
# File 'lib/shopify_api/context.rb', line 117 def session_storage @session_storage end |
.user_agent_prefix ⇒ Object (readonly)
Returns the value of attribute user_agent_prefix.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def user_agent_prefix @user_agent_prefix end |
Class Method Details
.activate_session(session) ⇒ Object
148 149 150 |
# File 'lib/shopify_api/context.rb', line 148 def activate_session(session) @active_session.value = session end |
.active_session ⇒ Object
141 142 143 144 145 |
# File 'lib/shopify_api/context.rb', line 141 def active_session return @active_session.value unless @active_session.value.nil? private? ? Utils::SessionUtils.load_current_session : nil end |
.deactivate_session ⇒ Object
153 154 155 |
# File 'lib/shopify_api/context.rb', line 153 def deactivate_session @active_session.value = nil end |
.embedded? ⇒ Boolean
131 132 133 |
# File 'lib/shopify_api/context.rb', line 131 def @is_embedded end |
.host_scheme ⇒ Object
158 159 160 |
# File 'lib/shopify_api/context.rb', line 158 def host_scheme T.must(URI.parse(T.must(host)).scheme) end |
.load_rest_resources(api_version:) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/shopify_api/context.rb', line 83 def load_rest_resources(api_version:) # Unload any previous instances - mostly useful for tests where we need to reset the version @rest_resource_loader&.unload # No resources for the unstable version return if api_version == "unstable" version_folder_name = api_version.gsub("-", "_") path = "#{__dir__}/rest/resources/#{version_folder_name}" unless Dir.exist?(path) unless @notified_missing_resources_folder.key?(api_version) @logger.warn("Cannot autoload REST resources for API version '#{version_folder_name}', folder is missing") @notified_missing_resources_folder[api_version] = true end return end @rest_resource_loader = T.let(Zeitwerk::Loader.new, T.nilable(Zeitwerk::Loader)) T.must(@rest_resource_loader).enable_reloading T.must(@rest_resource_loader).ignore("#{__dir__}/rest/resources") T.must(@rest_resource_loader).setup T.must(@rest_resource_loader).push_dir(path, namespace: ShopifyAPI) T.must(@rest_resource_loader).reload end |
.private? ⇒ Boolean
123 124 125 |
# File 'lib/shopify_api/context.rb', line 123 def private? @is_private end |
.setup(api_key:, api_secret_key:, api_version:, host_name:, scope:, is_private:, is_embedded:, session_storage:, logger: Logger.new($stdout), host: ENV["HOST"] || "https://#{host_name}", private_shop: nil, user_agent_prefix: nil, old_api_secret_key: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/shopify_api/context.rb', line 45 def setup( api_key:, api_secret_key:, api_version:, host_name:, scope:, is_private:, is_embedded:, session_storage:, logger: Logger.new($stdout), host: ENV["HOST"] || "https://#{host_name}", private_shop: nil, user_agent_prefix: nil, old_api_secret_key: nil ) unless ShopifyAPI::AdminVersions::SUPPORTED_ADMIN_VERSIONS.include?(api_version) raise Errors::UnsupportedVersionError, "Invalid version #{api_version}, supported versions: #{ShopifyAPI::AdminVersions::SUPPORTED_ADMIN_VERSIONS}" end @api_key = api_key @api_secret_key = api_secret_key @api_version = api_version @host_name = host_name @host = T.let(host, T.nilable(String)) @is_private = is_private @scope = Auth::AuthScopes.new(scope) @is_embedded = @session_storage = session_storage @logger = logger @private_shop = private_shop @user_agent_prefix = user_agent_prefix @old_api_secret_key = old_api_secret_key load_rest_resources(api_version: api_version) end |
.setup? ⇒ Boolean
136 137 138 |
# File 'lib/shopify_api/context.rb', line 136 def setup? [api_key, api_secret_key, host_name, T.must(host)].none?(&:empty?) end |