5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/generators/shopify_app/rotate_shopify_token_job/templates/rotate_shopify_token_job.rb', line 5
def perform(params)
@shop = Shop.find_by(shopify_domain: params[:shop_domain])
return unless @shop
config = ShopifyApp.configuration
uri = URI("https://#{@shop.shopify_domain}/admin/oauth/access_token")
post_data = {
client_id: config.api_key,
client_secret: config.secret,
refresh_token: params[:refresh_token],
access_token: @shop.shopify_token,
}
@response = Net::HTTP.post_form(uri, post_data)
return log_error(response_exception_error_message) unless @response.is_a?(Net::HTTPSuccess)
access_token = JSON.parse(@response.body)["access_token"]
return log_error(no_access_token_error_message) unless access_token
@shop.update(shopify_token: access_token)
end
|