Commit 0ccb6aa0 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Separate GitlabSubscriptions module from class name

To be consistent with other module definitions
parent effa7178
# frozen_string_literal: true
class GitlabSubscriptions::FetchSubscriptionPlansService
URL = "#{EE::SUBSCRIPTIONS_URL}/gitlab_plans".freeze
module GitlabSubscriptions
class FetchSubscriptionPlansService
URL = "#{EE::SUBSCRIPTIONS_URL}/gitlab_plans".freeze
def initialize(plan:, namespace_id: nil)
@plan = plan
@namespace_id = namespace_id
end
def execute
cached { send_request }
end
def initialize(plan:, namespace_id: nil)
@plan = plan
@namespace_id = namespace_id
end
private
def execute
cached { send_request }
end
def send_request
response = Gitlab::HTTP.get(
URL,
allow_local_requests: true,
query: { plan: @plan, namespace_id: @namespace_id },
headers: { 'Accept' => 'application/json' }
)
private
Gitlab::Json.parse(response.body).map { |plan| Hashie::Mash.new(plan) }
rescue => e
Gitlab::AppLogger.info "Unable to connect to GitLab Customers App #{e}"
def send_request
response = Gitlab::HTTP.get(
URL,
allow_local_requests: true,
query: { plan: @plan, namespace_id: @namespace_id },
headers: { 'Accept' => 'application/json' }
)
nil
end
Gitlab::Json.parse(response.body).map { |plan| Hashie::Mash.new(plan) }
rescue => e
Gitlab::AppLogger.info "Unable to connect to GitLab Customers App #{e}"
def cached
if plans_data = cache.read(cache_key)
plans_data
else
cache.fetch(cache_key, force: true, expires_in: 1.day) { yield }
nil
end
end
def cache
Rails.cache
end
def cache_key
if Feature.enabled?(:pnp_subscription_plan_cache_key)
if @namespace_id.present?
"pnp-subscription-plan-#{@plan}-#{@namespace_id}"
else
"pnp-subscription-plan-#{@plan}"
end
elsif Feature.enabled?(:subscription_plan_cache_key)
if @namespace_id.present?
"subscription-plan-#{@plan}-#{@namespace_id}"
def cached
if plans_data = cache.read(cache_key)
plans_data
else
"subscription-plan-#{@plan}"
cache.fetch(cache_key, force: true, expires_in: 1.day) { yield }
end
else
if @namespace_id.present?
"subscription-plans-#{@plan}-#{@namespace_id}"
end
def cache
Rails.cache
end
def cache_key
if Feature.enabled?(:pnp_subscription_plan_cache_key)
if @namespace_id.present?
"pnp-subscription-plan-#{@plan}-#{@namespace_id}"
else
"pnp-subscription-plan-#{@plan}"
end
elsif Feature.enabled?(:subscription_plan_cache_key)
if @namespace_id.present?
"subscription-plan-#{@plan}-#{@namespace_id}"
else
"subscription-plan-#{@plan}"
end
else
"subscription-plans-#{@plan}"
if @namespace_id.present?
"subscription-plans-#{@plan}-#{@namespace_id}"
else
"subscription-plans-#{@plan}"
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment