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.
149 150 151 |
# File 'lib/shopify_api/context.rb', line 149 def api_host @api_host end |
.api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
129 130 131 |
# File 'lib/shopify_api/context.rb', line 129 def api_key @api_key end |
.api_secret_key ⇒ Object (readonly)
Returns the value of attribute api_secret_key.
129 130 131 |
# File 'lib/shopify_api/context.rb', line 129 def api_secret_key @api_secret_key end |
.api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
129 130 131 |
# File 'lib/shopify_api/context.rb', line 129 def api_version @api_version end |
.host ⇒ Object (readonly)
Returns the value of attribute host.
149 150 151 |
# File 'lib/shopify_api/context.rb', line 149 def host @host end |
.log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
138 139 140 |
# File 'lib/shopify_api/context.rb', line 138 def log_level @log_level end |
.logger ⇒ Object (readonly)
Returns the value of attribute logger.
135 136 137 |
# File 'lib/shopify_api/context.rb', line 135 def logger @logger end |
.old_api_secret_key ⇒ Object (readonly)
Returns the value of attribute old_api_secret_key.
149 150 151 |
# File 'lib/shopify_api/context.rb', line 149 def old_api_secret_key @old_api_secret_key end |
.private_shop ⇒ Object (readonly)
Returns the value of attribute private_shop.
149 150 151 |
# File 'lib/shopify_api/context.rb', line 149 def private_shop @private_shop end |
.response_as_struct ⇒ Object (readonly)
Returns the value of attribute response_as_struct.
141 142 143 |
# File 'lib/shopify_api/context.rb', line 141 def response_as_struct @response_as_struct end |
.scope ⇒ Object (readonly)
Returns the value of attribute scope.
132 133 134 |
# File 'lib/shopify_api/context.rb', line 132 def scope @scope end |
.user_agent_prefix ⇒ Object (readonly)
Returns the value of attribute user_agent_prefix.
149 150 151 |
# File 'lib/shopify_api/context.rb', line 149 def user_agent_prefix @user_agent_prefix end |
Class Method Details
.activate_session(session) ⇒ Object
167 168 169 |
# File 'lib/shopify_api/context.rb', line 167 def activate_session(session) T.must(@active_session).value = session end |
.active_session ⇒ Object
162 163 164 |
# File 'lib/shopify_api/context.rb', line 162 def active_session @active_session&.value end |
.deactivate_session ⇒ Object
172 173 174 |
# File 'lib/shopify_api/context.rb', line 172 def deactivate_session T.must(@active_session).value = nil end |
.embedded? ⇒ Boolean
152 153 154 |
# File 'lib/shopify_api/context.rb', line 152 def @is_embedded end |
.host_name ⇒ Object
182 183 184 |
# File 'lib/shopify_api/context.rb', line 182 def host_name T.must(URI(T.must(host)).host) end |
.host_scheme ⇒ Object
177 178 179 |
# File 'lib/shopify_api/context.rb', line 177 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 126 |
# 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 or the release candidate version return if api_version == "unstable" || api_version == RELEASE_CANDIDATE_ADMIN_VERSION 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
144 145 146 |
# File 'lib/shopify_api/context.rb', line 144 def private? @is_private end |
.rest_disabled ⇒ Object
187 188 189 |
# File 'lib/shopify_api/context.rb', line 187 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
157 158 159 |
# File 'lib/shopify_api/context.rb', line 157 def setup? [api_key, api_secret_key, T.must(host)].none?(&:empty?) end |