Class: AppleNews::Security

Inherits:
Object
  • Object
show all
Defined in:
lib/apple-news/security.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url) ⇒ Security

Returns a new instance of Security.



5
6
7
8
9
10
11
12
13
# File 'lib/apple-news/security.rb', line 5

def initialize(method, url)
  @config = AppleNews.config

  @method = method.upcase
  @url = url
  @date = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
  @content_type = nil
  @content_body = nil
end

Instance Attribute Details

#content_bodyObject

Returns the value of attribute content_body.



3
4
5
# File 'lib/apple-news/security.rb', line 3

def content_body
  @content_body
end

#content_typeObject

Returns the value of attribute content_type.



3
4
5
# File 'lib/apple-news/security.rb', line 3

def content_type
  @content_type
end

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/apple-news/security.rb', line 3

def method
  @method
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/apple-news/security.rb', line 3

def url
  @url
end

Instance Method Details

#authorizationObject



15
16
17
18
19
20
21
# File 'lib/apple-news/security.rb', line 15

def authorization
  if @method == 'POST' && (@content_type.nil? || @content_body.nil?)
    raise "POST requests require the content type and body to be included in the signature generation"
  end

  "HHMAC; key=#{@config.api_key_id}; signature=#{signature}; date=#{@date}"
end