Class: ShareASale::Request

Inherits:
Struct
  • Object
show all
Defined in:
lib/share_a_sale.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



25
26
27
# File 'lib/share_a_sale.rb', line 25

def action
  @action
end

#api_secretObject

Returns the value of attribute api_secret

Returns:

  • (Object)

    the current value of api_secret



25
26
27
# File 'lib/share_a_sale.rb', line 25

def api_secret
  @api_secret
end

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



25
26
27
# File 'lib/share_a_sale.rb', line 25

def date
  @date
end

#merchant_idObject

Returns the value of attribute merchant_id

Returns:

  • (Object)

    the current value of merchant_id



25
26
27
# File 'lib/share_a_sale.rb', line 25

def merchant_id
  @merchant_id
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



25
26
27
# File 'lib/share_a_sale.rb', line 25

def options
  @options
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



25
26
27
# File 'lib/share_a_sale.rb', line 25

def token
  @token
end

Instance Method Details

#authentication_hashObject



34
35
36
# File 'lib/share_a_sale.rb', line 34

def authentication_hash
  Digest::SHA256.hexdigest(string_to_hash).upcase
end

#custom_headersObject



43
44
45
46
47
48
# File 'lib/share_a_sale.rb', line 43

def custom_headers
  {
    "x-ShareASale-Date" => date_string,
    "x-ShareASale-Authentication" => authentication_hash
  }
end

#date_stringObject



26
27
28
# File 'lib/share_a_sale.rb', line 26

def date_string
  date.strftime("%a, %d %b %Y %H:%M:%S GMT")
end

#execute!Object



50
51
52
# File 'lib/share_a_sale.rb', line 50

def execute!
  RestClient.get(url, custom_headers)
end

#string_to_hashObject



30
31
32
# File 'lib/share_a_sale.rb', line 30

def string_to_hash
  "#{token}:#{date_string}:#{action}:#{api_secret}"
end

#urlObject



38
39
40
41
# File 'lib/share_a_sale.rb', line 38

def url
  params = [['merchantId', merchant_id], ['token', token], ['version', SHARE_A_SALE_VERSION], ['action', action], ['date', date.strftime("%D")]] + options.to_a
  URI::HTTPS.build(host: SHARE_A_SALE_HOST, path: SHARE_A_SALE_PATH, query: URI.encode_www_form(params)).to_s
end