Class: FlyingSphinx::API

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

Constant Summary collapse

APIServer =
'https://flying-sphinx.com'
APIPath =
"/api/my/app"
APIVersion =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, api_key, adapter = Faraday.default_adapter) ⇒ API

Returns a new instance of API.



12
13
14
15
16
# File 'lib/flying_sphinx/api.rb', line 12

def initialize(identifier, api_key, adapter = Faraday.default_adapter)
  @api_key    = api_key
  @identifier = identifier
  @adapter    = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



10
11
12
# File 'lib/flying_sphinx/api.rb', line 10

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



10
11
12
# File 'lib/flying_sphinx/api.rb', line 10

def api_key
  @api_key
end

#identifierObject (readonly)

Returns the value of attribute identifier.



10
11
12
# File 'lib/flying_sphinx/api.rb', line 10

def identifier
  @identifier
end

Instance Method Details

#get(path, data = {}) ⇒ Object



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

def get(path, data = {})
  log('GET', path, data) do
    connection.get do |request|
      request.url normalize_path(path), data
    end
  end
end

#post(path, data = {}) ⇒ Object



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

def post(path, data = {})
  log('POST', path, data) do
    connection.post normalize_path(path), data
  end
end

#put(path, data = {}) ⇒ Object



32
33
34
35
36
# File 'lib/flying_sphinx/api.rb', line 32

def put(path, data = {})
  log('PUT', path, data) do
    connection.put normalize_path(path), data
  end
end