Module: Smtpcom::Sendapi::Request::ClassMethods

Includes:
HTTParty
Defined in:
lib/smtpcom/sendapi/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/smtpcom/sendapi/request.rb', line 7

def response
  @response
end

Instance Method Details

#_auth_keyObject



51
52
53
# File 'lib/smtpcom/sendapi/request.rb', line 51

def _auth_key
  { apiKey: Smtpcom::Sendapi.api_key }
end

#_get(path, params = {}, formatted = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/smtpcom/sendapi/request.rb', line 9

def _get(path, params = {}, formatted = false)
  @response = HTTParty.get \
    _url(path),
    headers: _json_headers,
    query: params.merge(_auth_key),
    format: :json
  if formatted
    Utils.format_response_row @response.parsed_response
  else
    @response.parsed_response
  end
end

#_get_raw(path, params = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/smtpcom/sendapi/request.rb', line 22

def _get_raw(path, params = {})
  @response = HTTParty.get \
    _url(path),
    headers: (params.delete(:headers) || _json_headers),
    query: params.merge(_auth_key)
  @response.body
end

#_json_headersObject



47
48
49
# File 'lib/smtpcom/sendapi/request.rb', line 47

def _json_headers
  { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
end

#_post(path, params = {}, formatted = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/smtpcom/sendapi/request.rb', line 30

def _post(path, params = {}, formatted = false)
  @response = HTTParty.post \
    _url(path),
    headers: _json_headers,
    body: params.merge(_auth_key).to_json,
    format: :json
  if formatted
    Utils.format_response_row @response.parsed_response
  else
    @response.parsed_response
  end
end

#_url(path) ⇒ Object



43
44
45
# File 'lib/smtpcom/sendapi/request.rb', line 43

def _url(path)
  File.join Smtpcom::Sendapi.api_host, Smtpcom::Sendapi.api_base, path
end