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.
-
.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) ⇒ Object
- .setup? ⇒ Boolean
Class Attribute Details
.api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
114 115 116 |
# File 'lib/shopify_api/context.rb', line 114 def api_key @api_key end |
.api_secret_key ⇒ Object (readonly)
Returns the value of attribute api_secret_key.
114 115 116 |
# File 'lib/shopify_api/context.rb', line 114 def api_secret_key @api_secret_key end |
.api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
114 115 116 |
# File 'lib/shopify_api/context.rb', line 114 def api_version @api_version end |
.host ⇒ Object (readonly)
Returns the value of attribute host.
131 132 133 |
# File 'lib/shopify_api/context.rb', line 131 def host @host end |
.log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
123 124 125 |
# File 'lib/shopify_api/context.rb', line 123 def log_level @log_level 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.
131 132 133 |
# File 'lib/shopify_api/context.rb', line 131 def old_api_secret_key @old_api_secret_key end |
.private_shop ⇒ Object (readonly)
Returns the value of attribute private_shop.
131 132 133 |
# File 'lib/shopify_api/context.rb', line 131 def private_shop @private_shop end |
.scope ⇒ Object (readonly)
Returns the value of attribute scope.
117 118 119 |
# File 'lib/shopify_api/context.rb', line 117 def scope @scope end |
.user_agent_prefix ⇒ Object (readonly)
Returns the value of attribute user_agent_prefix.
131 132 133 |
# File 'lib/shopify_api/context.rb', line 131 def user_agent_prefix @user_agent_prefix end |
Class Method Details
.activate_session(session) ⇒ Object
149 150 151 |
# File 'lib/shopify_api/context.rb', line 149 def activate_session(session) T.must(@active_session).value = session end |
.active_session ⇒ Object
144 145 146 |
# File 'lib/shopify_api/context.rb', line 144 def active_session @active_session&.value end |
.deactivate_session ⇒ Object
154 155 156 |
# File 'lib/shopify_api/context.rb', line 154 def deactivate_session T.must(@active_session).value = nil end |
.embedded? ⇒ Boolean
134 135 136 |
# File 'lib/shopify_api/context.rb', line 134 def @is_embedded end |
.host_name ⇒ Object
164 165 166 |
# File 'lib/shopify_api/context.rb', line 164 def host_name T.must(URI(T.must(host)).host) end |
.host_scheme ⇒ Object
159 160 161 |
# File 'lib/shopify_api/context.rb', line 159 def host_scheme T.must(URI.parse(T.must(host)).scheme) end |
.load_rest_resources(api_version:) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/shopify_api/context.rb', line 85 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
126 127 128 |
# File 'lib/shopify_api/context.rb', line 126 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) ⇒ Object
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/shopify_api/context.rb', line 44 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 ) 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 = 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
139 140 141 |
# File 'lib/shopify_api/context.rb', line 139 def setup? [api_key, api_secret_key, T.must(host)].none?(&:empty?) end |