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.
-
.response_as_struct ⇒ Object
readonly
Returns the value of attribute response_as_struct.
-
.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
- .rest_disabled ⇒ Object
- .setup(api_key:, api_secret_key:, api_version:, is_private:, is_embedded:, scope: [], 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, response_as_struct: false, rest_disabled: false) ⇒ Object
- .setup? ⇒ Boolean
Class Attribute Details
.api_host ⇒ Object (readonly)
Returns the value of attribute api_host.
148 149 150 |
# File 'lib/shopify_api/context.rb', line 148 def api_host @api_host end |
.api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def api_key @api_key end |
.api_secret_key ⇒ Object (readonly)
Returns the value of attribute api_secret_key.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def api_secret_key @api_secret_key end |
.api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
128 129 130 |
# File 'lib/shopify_api/context.rb', line 128 def api_version @api_version end |
.host ⇒ Object (readonly)
Returns the value of attribute host.
148 149 150 |
# File 'lib/shopify_api/context.rb', line 148 def host @host end |
.log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
137 138 139 |
# File 'lib/shopify_api/context.rb', line 137 def log_level @log_level end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
134 135 136 |
# File 'lib/shopify_api/context.rb', line 134 def logger @logger end |
.old_api_secret_key ⇒ Object (readonly)
Returns the value of attribute old_api_secret_key.
148 149 150 |
# File 'lib/shopify_api/context.rb', line 148 def old_api_secret_key @old_api_secret_key end |
.private_shop ⇒ Object (readonly)
Returns the value of attribute private_shop.
148 149 150 |
# File 'lib/shopify_api/context.rb', line 148 def private_shop @private_shop end |
.response_as_struct ⇒ Object (readonly)
Returns the value of attribute response_as_struct.
140 141 142 |
# File 'lib/shopify_api/context.rb', line 140 def response_as_struct @response_as_struct end |
.scope ⇒ Object (readonly)
Returns the value of attribute scope.
131 132 133 |
# File 'lib/shopify_api/context.rb', line 131 def scope @scope end |
.user_agent_prefix ⇒ Object (readonly)
Returns the value of attribute user_agent_prefix.
148 149 150 |
# File 'lib/shopify_api/context.rb', line 148 def user_agent_prefix @user_agent_prefix end |
Class Method Details
.activate_session(session) ⇒ Object
166 167 168 |
# File 'lib/shopify_api/context.rb', line 166 def activate_session(session) T.must(@active_session).value = session end |
.active_session ⇒ Object
161 162 163 |
# File 'lib/shopify_api/context.rb', line 161 def active_session @active_session&.value end |
.deactivate_session ⇒ Object
171 172 173 |
# File 'lib/shopify_api/context.rb', line 171 def deactivate_session T.must(@active_session).value = nil end |
.embedded? ⇒ Boolean
151 152 153 |
# File 'lib/shopify_api/context.rb', line 151 def @is_embedded end |
.host_name ⇒ Object
181 182 183 |
# File 'lib/shopify_api/context.rb', line 181 def host_name T.must(URI(T.must(host)).host) end |
.host_scheme ⇒ Object
176 177 178 |
# File 'lib/shopify_api/context.rb', line 176 def host_scheme T.must(URI.parse(T.must(host)).scheme) end |
.load_rest_resources(api_version:) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/shopify_api/context.rb', line 99 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
143 144 145 |
# File 'lib/shopify_api/context.rb', line 143 def private? @is_private end |
.rest_disabled ⇒ Object
186 187 188 |
# File 'lib/shopify_api/context.rb', line 186 def rest_disabled T.must(@rest_disabled) end |
.setup(api_key:, api_secret_key:, api_version:, is_private:, is_embedded:, scope: [], 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, response_as_struct: false, rest_disabled: false) ⇒ Object
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 89 90 91 92 93 94 95 96 |
# File 'lib/shopify_api/context.rb', line 52 def setup( api_key:, api_secret_key:, api_version:, is_private:, is_embedded:, scope: [], 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, response_as_struct: false, rest_disabled: false ) 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 @response_as_struct = response_as_struct @rest_disabled = rest_disabled @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
156 157 158 |
# File 'lib/shopify_api/context.rb', line 156 def setup? [api_key, api_secret_key, T.must(host)].none?(&:empty?) end |