Class: ShareASale::Request

Inherits:
Struct
  • Object
show all
Defined in:
lib/share_a_sale/request.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



2
3
4
# File 'lib/share_a_sale/request.rb', line 2

def action
  @action
end

#api_secretObject

Returns the value of attribute api_secret

Returns:

  • (Object)

    the current value of api_secret



2
3
4
# File 'lib/share_a_sale/request.rb', line 2

def api_secret
  @api_secret
end

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



2
3
4
# File 'lib/share_a_sale/request.rb', line 2

def date
  @date
end

#merchant_idObject

Returns the value of attribute merchant_id

Returns:

  • (Object)

    the current value of merchant_id



2
3
4
# File 'lib/share_a_sale/request.rb', line 2

def merchant_id
  @merchant_id
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/share_a_sale/request.rb', line 2

def options
  @options
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



2
3
4
# File 'lib/share_a_sale/request.rb', line 2

def token
  @token
end

Instance Method Details

#authentication_hashObject



12
13
14
# File 'lib/share_a_sale/request.rb', line 12

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

#custom_headersObject



32
33
34
35
36
37
# File 'lib/share_a_sale/request.rb', line 32

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

#date_stringObject



4
5
6
# File 'lib/share_a_sale/request.rb', line 4

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

#execute!Object



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

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

#string_to_hashObject



8
9
10
# File 'lib/share_a_sale/request.rb', line 8

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

#urlObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/share_a_sale/request.rb', line 16

def url
  params = [
    ['merchantId', merchant_id],
    ['token', token],
    ['version', version],
    ['action', action],
    ['date', date.strftime("%D")]
  ] + options.to_a

  URI::HTTPS.build(
    host:  host,
    path:  path,
    query: params.map{|p| p.join('=') }.join('&')
  ).to_s
end