Class: FullCircle::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/full_circle/connection.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

NullCache =
Class.new do
  def fetch(key)
    yield
  end

  def store(key, value)
    value
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, args = {}) ⇒ Connection

domain - domain of directory (ex. 360durango.com) args

- cache - Caching object to use


10
11
12
13
# File 'lib/full_circle/connection.rb', line 10

def initialize(domain, args={})
  @domain = domain
  @cache = args.fetch(:cache){NullCache.new}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



5
6
7
# File 'lib/full_circle/connection.rb', line 5

def cache
  @cache
end

#domainObject (readonly)

Returns the value of attribute domain.



5
6
7
# File 'lib/full_circle/connection.rb', line 5

def domain
  @domain
end

Instance Method Details

#base_uriObject



15
16
17
# File 'lib/full_circle/connection.rb', line 15

def base_uri
  "http://api.#{domain}/1.0/"
end

#call_api_method(method_name, query_params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/full_circle/connection.rb', line 19

def call_api_method(method_name, query_params={})
  uri_str = uri_string(method_name, query_params)
  uri = URI(uri_str)

  body = cache.fetch(uri_str) do
    response_text = Net::HTTP.get(uri)
    cache.store(uri_str, response_text)
  end

  Response.new body

end