Class: AppleNews::Request::Get

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, config = AppleNews.config) ⇒ Get

Returns a new instance of Get.



6
7
8
9
# File 'lib/apple-news/requests/get.rb', line 6

def initialize(url, config = AppleNews.config)
  @config = config
  @url = URI::parse(File.join(@config.api_base, url))
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/apple-news/requests/get.rb', line 4

def url
  @url
end

Instance Method Details

#call(params = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/apple-news/requests/get.rb', line 11

def call(params = {})
  http = Net::HTTP.new(@url.hostname, @url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER

  res = http.get(@url, headers)
  JSON.parse(res.body)
end