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, config = AppleNews.config) ⇒ Security

Returns a new instance of Security.



8
9
10
11
12
13
14
15
# File 'lib/apple-news/security.rb', line 8

def initialize(method, url, config = AppleNews.config)
  @method = method.upcase
  @url = url
  @config = config
  @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.



6
7
8
# File 'lib/apple-news/security.rb', line 6

def content_body
  @content_body
end

#content_typeObject

Returns the value of attribute content_type.



6
7
8
# File 'lib/apple-news/security.rb', line 6

def content_type
  @content_type
end

#methodObject

Returns the value of attribute method.



6
7
8
# File 'lib/apple-news/security.rb', line 6

def method
  @method
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/apple-news/security.rb', line 6

def url
  @url
end

Instance Method Details

#authorizationObject



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

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