Class: ShopifyAPI::Context
- Inherits:
-
Object
- Object
- ShopifyAPI::Context
- Extended by:
- T::Sig
- Defined in:
- lib/shopify_api/context.rb
Class Attribute Summary collapse
-
.api_host ⇒ Object
readonly
Returns the value of attribute api_host.
-
.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.
-
.log_level ⇒ Object
readonly
Returns the value of attribute log_level.
-
.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.
-
.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_name ⇒ Object
- .host_scheme ⇒ Object
- .load_rest_resources(api_version:) ⇒ Object
- .private? ⇒ Boolean
- .setup(api_key:, api_secret_key:, api_version:, scope:, is_private:, is_embedded:, log_level: :info, logger: ::Logger.new($stdout), host_name: nil, host: ENV["HOST"] || "https://#{host_name}", private_shop: nil, user_agent_prefix: nil, old_api_secret_key: nil, api_host: nil) ⇒ Object
- .setup? ⇒ Boolean
Class Attribute Details
.api_host ⇒ Object (readonly)
Returns the value of attribute api_host.
137 138 139 |
# File 'lib/shopify_api/context.rb', line 137 def api_host @api_host end |
.api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
120 121 122 |
# File 'lib/shopify_api/context.rb', line 120 def api_key @api_key end |
.api_secret_key ⇒ Object (readonly)
Returns the value of attribute api_secret_key.
120 121 122 |
# File 'lib/shopify_api/context.rb', line 120 def api_secret_key @api_secret_key end |
.api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
120 121 122 |
# File 'lib/shopify_api/context.rb', line 120 def api_version @api_version end |
.host ⇒ Object (readonly)
Returns the value of attribute host.
137 138 139 |
# File 'lib/shopify_api/context.rb', line 137 def host @host end |
.log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
129 130 131 |
# File 'lib/shopify_api/context.rb', line 129 def log_level @log_level end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
126 127 128 |
# File 'lib/shopify_api/context.rb', line 126 def logger @logger end |
.old_api_secret_key ⇒ Object (readonly)
Returns the value of attribute old_api_secret_key.
137 138 139 |
# File 'lib/shopify_api/context.rb', line 137 def old_api_secret_key @old_api_secret_key end |
.private_shop ⇒ Object (readonly)
Returns the value of attribute private_shop.
137 138 139 |
# File 'lib/shopify_api/context.rb', line 137 def private_shop @private_shop end |
.scope ⇒ Object (readonly)
Returns the value of attribute scope.
123 124 125 |
# File 'lib/shopify_api/context.rb', line 123 def scope @scope end |
.user_agent_prefix ⇒ Object (readonly)
Returns the value of attribute user_agent_prefix.
137 138 139 |
# File 'lib/shopify_api/context.rb', line 137 def user_agent_prefix @user_agent_prefix end |
Class Method Details
.activate_session(session) ⇒ Object
155 156 157 |
# File 'lib/shopify_api/context.rb', line 155 def activate_session(session) T.must(@active_session).value = session end |
.active_session ⇒ Object
150 151 152 |
# File 'lib/shopify_api/context.rb', line 150 def active_session @active_session&.value end |
.deactivate_session ⇒ Object
160 161 162 |
# File 'lib/shopify_api/context.rb', line 160 def deactivate_session T.must(@active_session).value = nil end |
.embedded? ⇒ Boolean
140 141 142 |
# File 'lib/shopify_api/context.rb', line 140 def @is_embedded end |
.host_name ⇒ Object
170 171 172 |
# File 'lib/shopify_api/context.rb', line 170 def host_name T.must(URI(T.must(host)).host) end |
.host_scheme ⇒ Object
165 166 167 |
# File 'lib/shopify_api/context.rb', line 165 def host_scheme T.must(URI.parse(T.must(host)).scheme) end |
.load_rest_resources(api_version:) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/shopify_api/context.rb', line 91 def load_rest_resources(api_version:) # Unload any previous instances - mostly useful for tests where we need to reset the version @rest_resource_loader&.setup @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
132 133 134 |
# File 'lib/shopify_api/context.rb', line 132 def private? @is_private end |
.setup(api_key:, api_secret_key:, api_version:, scope:, is_private:, is_embedded:, log_level: :info, logger: ::Logger.new($stdout), host_name: nil, host: ENV["HOST"] || "https://#{host_name}", private_shop: nil, user_agent_prefix: nil, old_api_secret_key: nil, api_host: nil) ⇒ Object
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 81 82 83 84 85 86 87 88 |
# File 'lib/shopify_api/context.rb', line 48 def setup( api_key:, api_secret_key:, api_version:, scope:, is_private:, is_embedded:, log_level: :info, logger: ::Logger.new($stdout), host_name: nil, host: ENV["HOST"] || "https://#{host_name}", private_shop: nil, user_agent_prefix: nil, old_api_secret_key: nil, api_host: 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 @api_host = api_host @host = T.let(host, T.nilable(String)) @is_private = is_private @scope = Auth::AuthScopes.new(scope) @is_embedded = @logger = logger @private_shop = private_shop @user_agent_prefix = user_agent_prefix @old_api_secret_key = old_api_secret_key @log_level = if valid_log_level?(log_level) log_level.to_sym else :info end load_rest_resources(api_version: api_version) end |
.setup? ⇒ Boolean
145 146 147 |
# File 'lib/shopify_api/context.rb', line 145 def setup? [api_key, api_secret_key, T.must(host)].none?(&:empty?) end |