Class: AppleNews::Request::Post

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Post.



7
8
9
10
11
# File 'lib/apple-news/requests/post.rb', line 7

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

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/apple-news/requests/post.rb', line 5

def fields
  @fields
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apple-news/requests/post.rb', line 13

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

  # The API can be really slow, sometimes.
  http.read_timeout = 120
  

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