Class: ShareNotify::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/share_notify/api.rb

Overview

Interact with the SHARE Notify API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_token = nil) ⇒ API

Returns a new instance of API.

Parameters:

  • token (String)

    is optional but some actions will not be successful without it



15
16
17
18
19
20
# 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

Instance Attribute Details

#headersObject (readonly)

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



4
5
6
# File 'lib/share_notify/api.rb', line 4

def headers
  @headers
end

#responseObject (readonly)

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



4
5
6
# File 'lib/share_notify/api.rb', line 4

def response
  @response
end

Instance Method Details

#getHTTParty::Response

Returns:

  • (HTTParty::Response)


23
24
25
# File 'lib/share_notify/api.rb', line 23

def get
  @response = with_timeout { self.class.get(api_data_point) }
end

#post(body) ⇒ HTTParty::Response

Returns:

  • (HTTParty::Response)


28
29
30
# 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

#search(query) ⇒ HTTParty::Response

Returns:

  • (HTTParty::Response)


33
34
35
# File 'lib/share_notify/api.rb', line 33

def search(query)
  @response = with_timeout { self.class.get(api_search_point, query: { q: query }) }
end