Class: GatherContent::Api::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gather_content/api/base.rb

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.

Raises:

  • (RuntimeError)


5
6
7
# File 'lib/gather_content/api/base.rb', line 5

def initialize
  raise RuntimeError, "Cannot initialize this interface!"
end

Instance Method Details

#fetchObject



32
33
34
# File 'lib/gather_content/api/base.rb', line 32

def fetch
  @data ||= parse(get.body)
end

#get(path_override = nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/gather_content/api/base.rb', line 9

def get(path_override = nil)
  connection.get do |request|
    request.url(path_override || path)
    request.params = params unless params.nil?
    request.headers['Accept'] = "application/vnd.gathercontent.v0.5+json"
  end
end

#post(data = {}, path_override = nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/gather_content/api/base.rb', line 17

def post(data = {}, path_override = nil)
  connection.post do |request|
    request.url(path_override || path)
    request.body = data
    request.headers['Accept'] = "application/vnd.gathercontent.v0.5+json"
    yield request if block_given?
  end
end

#post_json(data = {}, path_override = nil) ⇒ Object



26
27
28
29
30
# File 'lib/gather_content/api/base.rb', line 26

def post_json(data = {}, path_override = nil)
  post(data.to_json, path_override) do |request|
    request.headers['Content-type'] = "application/json"
  end
end

#resetObject



36
37
38
# File 'lib/gather_content/api/base.rb', line 36

def reset
  @data = nil
end