Class: ReferenceClient

Inherits:
Client
  • Object
show all
Defined in:
lib/client/reference_client.rb

Overview

Class ReferenceClient represents server request of reference API (provides a mechanism for accessing the standard “reference information” used by the 3taps system, including locations, categories, and sources).

Its methods are used to query API with appropriate requests:

client = ReferenceClient.new
client.get_categories     # => returns array of Category objects
client.get_category(code) # => returns Category object
client.get_locations      # => returns array of Location objects
client.get_sources        # => returns array of Source objects

Constant Summary

Constants inherited from Client

Client::DEFAULT_API_PORT, Client::DEFAULT_URL, Client::TIMEOUT

Instance Method Summary collapse

Methods inherited from Client

#execute_get, #execute_post, #initialize

Constructor Details

This class inherits a constructor from Client

Instance Method Details

#get_categoriesObject

Method get_categories returns the 3taps categories.

Example:

client = ReferenceClient.new
client.get_categories # => Array of Category


21
22
23
24
25
# File 'lib/client/reference_client.rb', line 21

def get_categories
  response = execute_get("/reference/category")
  File.new("newfile",  "w+") << response
  Category.from_array(decode(response))
end

#get_category(code) ⇒ Object

Method get_category returns a single category by passing in the category code. Takes value of code objects as String parameter.

Example:

client.get_category('NYC') # => Categoty


34
35
36
37
# File 'lib/client/reference_client.rb', line 34

def get_category(code)
  response = execute_get("/reference/category/" + code)
  Category.from_hash(decode(response)[0])
end

#get_locationsObject

Method get_locations returns the 3taps locations.

Example:

client.get_locations # => Array of Location


45
46
47
48
# File 'lib/client/reference_client.rb', line 45

def get_locations
  response = execute_get("/reference/location")
  Location.from_array(decode(response))
end

#get_sourcesObject

Method get_sources returns the 3taps sources.

Example:

client.get_sources # => Array of Source


56
57
58
59
# File 'lib/client/reference_client.rb', line 56

def get_sources
  response = execute_get("/reference/source")
  Source.from_array(decode(response))
end