Class: Waffle::Maker::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/waffle/maker/api/base.rb

Direct Known Subclasses

Alert, AlertDetail

Constant Summary collapse

FORCE_ENCODING =
"UTF-8"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



8
9
10
# File 'lib/waffle/maker/api/base.rb', line 8

def headers
  @headers
end

#urlObject

Returns the value of attribute url.

Raises:

  • (NotImplementedError)


8
9
10
# File 'lib/waffle/maker/api/base.rb', line 8

def url
  @url
end

Instance Method Details

#body_in_hash_formatObject



10
11
12
13
14
# File 'lib/waffle/maker/api/base.rb', line 10

def body_in_hash_format
  get.then do |response|
    JSON.parse(response.body.force_encoding(FORCE_ENCODING))
  end
end

#body_in_json_formatObject



16
17
18
19
20
# File 'lib/waffle/maker/api/base.rb', line 16

def body_in_json_format
  get.then do |response|
    response.body.force_encoding(FORCE_ENCODING)
  end
end

#getObject



22
23
24
# File 'lib/waffle/maker/api/base.rb', line 22

def get
  @get ||= http.get(url, headers)
end

#httpObject



26
27
28
29
30
# File 'lib/waffle/maker/api/base.rb', line 26

def http
  Net::HTTP.new(url.host, url.port).tap do |http|
    http.use_ssl = (url.scheme === "https")
  end
end