Class: Zenaton::Services::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/zenaton/services/http.rb

Overview

Wrapper class around HTTParty that:

  • handles http calls

  • sets appropriate headers for each request type

  • translates exceptions into Zenaton specific ones

Instance Method Summary collapse

Instance Method Details

#get(url) ⇒ Hash

Makes a GET request and sets the correct headers

Parameters:

  • url (String)

    the url for the request

Returns:

  • (Hash)

    the parsed json response



18
19
20
# File 'lib/zenaton/services/http.rb', line 18

def get(url)
  request(:get, url, default_options)
end

#post(url, body) ⇒ Hash

Makes a POST request with some data and sets the correct headers

Parameters:

  • url (String)

    the url for the request

  • body (Hash)

    the payload to send with the request

Returns:

  • (Hash)

    the parsed json response



27
28
29
# File 'lib/zenaton/services/http.rb', line 27

def post(url, body)
  request(:post, url, post_options(body))
end

#put(url, body) ⇒ Hash

Makes a PUT request with some data and sets the correct headers

Parameters:

  • url (String)

    the url for the request

  • body (Hash)

    the payload to send with the request

Returns:

  • (Hash)

    the parsed json response



36
37
38
# File 'lib/zenaton/services/http.rb', line 36

def put(url, body)
  request(:put, url, put_options(body))
end