Class: BaconIpsum::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bacon_ipsum/http_client.rb

Overview

http client for requests to bacon ipsum api

Constant Summary collapse

BASE_ENDPOINT =
'https://baconipsum.com/api/'
REQUEST_TIMEOUT =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paras, sentences, type, start_with_lorem, format) ⇒ HttpClient



13
14
15
16
17
18
19
# File 'lib/bacon_ipsum/http_client.rb', line 13

def initialize(paras, sentences, type, start_with_lorem, format)
  @paras = paras
  @sentences = sentences
  @type = type
  @start_with_lorem = start_with_lorem
  @format = format
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



11
12
13
# File 'lib/bacon_ipsum/http_client.rb', line 11

def format
  @format
end

#parasObject

Returns the value of attribute paras.



11
12
13
# File 'lib/bacon_ipsum/http_client.rb', line 11

def paras
  @paras
end

#sentencesObject

Returns the value of attribute sentences.



11
12
13
# File 'lib/bacon_ipsum/http_client.rb', line 11

def sentences
  @sentences
end

#start_with_loremObject

Returns the value of attribute start_with_lorem.



11
12
13
# File 'lib/bacon_ipsum/http_client.rb', line 11

def start_with_lorem
  @start_with_lorem
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/bacon_ipsum/http_client.rb', line 11

def type
  @type
end

Instance Method Details

#getObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/bacon_ipsum/http_client.rb', line 21

def get
  response = Typhoeus.get(
    BASE_ENDPOINT,
    params: params,
    timeout: REQUEST_TIMEOUT
  )
  raise 'BaconFail' unless response.success?

  response.body
end