Class: ShareNotify::API
- Inherits:
-
Object
- Object
- ShareNotify::API
- Includes:
- HTTParty
- Defined in:
- lib/share_notify/api.rb
Overview
Interact with the SHARE Notify API
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Uncomment this line if you want the api calls to be written to STDOUT debug_output $stdout.
-
#response ⇒ Object
readonly
Uncomment this line if you want the api calls to be written to STDOUT debug_output $stdout.
Instance Method Summary collapse
- #get ⇒ HTTParty::Response
-
#initialize(_token = nil) ⇒ API
constructor
A new instance of API.
- #post(body) ⇒ HTTParty::Response
- #search(query) ⇒ HTTParty::Response
Constructor Details
#initialize(_token = nil) ⇒ API
Returns a new instance of API.
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
#headers ⇒ Object (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 |
#response ⇒ Object (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
#get ⇒ 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
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
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 |