Class: GuardianSearcher::Base

Inherits:
Object
  • Object
show all
Includes:
Faraday
Defined in:
lib/guardian_searcher/base.rb

Overview

Class that handles the basic functionality for the Guardian Reader gem

Direct Known Subclasses

Search

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
# File 'lib/guardian_searcher/base.rb', line 10

def initialize(api_key: nil)
  raise GuardianApyKeyError unless api_key

  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/guardian_searcher/base.rb', line 8

def api_key
  @api_key
end

Instance Method Details

#search(query, options = {}) ⇒ Object

Options needs to be passed following Guardian API docs



17
18
19
20
# File 'lib/guardian_searcher/base.rb', line 17

def search(query, options = {})
  url = search_uri + query_string(query, options)
  Faraday.get(url)
end

#search_editions(query, options = {}) ⇒ Object



32
33
34
35
# File 'lib/guardian_searcher/base.rb', line 32

def search_editions(query, options = {})
  url = editions_uri + query_string(query, options)
  Faraday.get(url)
end

#search_sections(query, options = {}) ⇒ Object



22
23
24
25
# File 'lib/guardian_searcher/base.rb', line 22

def search_sections(query, options = {})
  url = sections_uri + query_string(query, options)
  Faraday.get(url)
end

#search_tags(query, options = {}) ⇒ Object



27
28
29
30
# File 'lib/guardian_searcher/base.rb', line 27

def search_tags(query, options = {})
  url = tags_uri + query_string(query, options)
  Faraday.get(url)
end