class ShareNotify::API

Interact with the SHARE Notify API @attr_reader [Hash] headers includes the authorization token needed to post data @attr_reader [HTTParty::Response] response from the service

Attributes

headers[R]

Uncomment this line if you want the api calls to be written to STDOUT debug_output $stdout

response[R]

Uncomment this line if you want the api calls to be written to STDOUT debug_output $stdout

Public Class Methods

new(_token = nil) click to toggle source

@param [String] token is optional but some actions will not be successful without it

# File lib/share_notify/api.rb, line 15
def initialize(_token = nil)
  @headers = {
    'Authorization' => "Token #{ShareNotify.config.fetch('token', nil)}",
    'Content-Type'  => 'application/json'
  }
end

Public Instance Methods

get() click to toggle source

@return [HTTParty::Response]

# File lib/share_notify/api.rb, line 23
def get
  @response = with_timeout { self.class.get(api_data_point) }
end
post(body) click to toggle source

@return [HTTParty::Response]

# File lib/share_notify/api.rb, line 28
def post(body)
  @response = with_timeout { self.class.post(api_data_point, body: body, headers: headers) }
end

Private Instance Methods

api_data_point() click to toggle source
# File lib/share_notify/api.rb, line 39
def api_data_point
  '/api/v1/share/data'
end
api_search_point() click to toggle source
# File lib/share_notify/api.rb, line 43
def api_search_point
  '/api/v1/share/search/'
end
with_timeout() { || ... } click to toggle source
# File lib/share_notify/api.rb, line 47
def with_timeout(&_block)
  Timeout.timeout(5) { yield }
end