Class: Haipa::Api

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/haipa/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Api

Returns a new instance of Api.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/haipa/api.rb', line 10

def initialize(params={})
  @uri = URI(params[:url].to_s).path
  @conn = Faraday.new(defaults.deep_merge(params)) do |conn|
    if block_given?
      yield conn
    else
      conn.adapter Faraday.default_adapter
    end
  end
  @resource = Resource.new(self, @uri)
end

Instance Attribute Details

#connObject (readonly) Also known as: connection

Returns the value of attribute conn.



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

def conn
  @conn
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

Instance Method Details

#clearObject



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

def clear
  @resource.clear
  self
end

#defaultsObject



22
23
24
25
26
27
28
29
30
# File 'lib/haipa/api.rb', line 22

def defaults
  {
    :headers =>
    {
      :accept => 'application/hal+json',
      :user_agent => 'Haipa'
    }
  }
end

#descriptionObject



37
38
39
# File 'lib/haipa/api.rb', line 37

def description
  resource.get
end