Class: SmoothCodeAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/smoothcode/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(request_hmac, client_secret) ⇒ SmoothCodeAuth

Returns a new instance of SmoothCodeAuth.



4
5
6
7
# File 'lib/smoothcode/auth.rb', line 4

def initialize(request_hmac, client_secret)
    @request_hmac = request_hmac
    @client_secret = client_secret
end

Instance Method Details

#dashboard_request?(shop) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/smoothcode/auth.rb', line 9

def dashboard_request?(shop)
    generate_hmac(@client_secret, shop) == @request_hmac
end

#gdpr_webhook_request?(webhook_data) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/smoothcode/auth.rb', line 20

def gdpr_webhook_request?(webhook_data)
    webhook_data = webhook_data.transform_keys(&:to_sym)
    shop_id = webhook_data[:shop_id]

    generate_hmac(@client_secret, shop_id.to_s) == @request_hmac
end

#webhook_request?(webhook_data) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/smoothcode/auth.rb', line 13

def webhook_request?(webhook_data)
    webhook_data = webhook_data.transform_keys(&:to_sym)
    webhook_id = webhook_data[:shopify_webhook_uuid]

    generate_hmac(@client_secret, webhook_id.to_s) == @request_hmac
end