Class: OmekaClient::Client
- Inherits:
-
Object
- Object
- OmekaClient::Client
- Defined in:
- lib/omeka_client/client.rb
Overview
A class to create clients that interact with the Omeka API
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#collections ⇒ Array
Get a list of the Omeka collections.
-
#get(resource, id = nil, query = {}) ⇒ NetHttpPersistentResponseWrapper
Generic GET request to the Omeka site.
-
#get_hash(resource, id = nil, query = {}) ⇒ Array or Hash
Parse a GET request into a useable format.
-
#initialize(endpoint, api_key = nil) ⇒ OmekaClient
constructor
Sets up a new client to interact with an Omeka site.
-
#items ⇒ Array
Get a list of the Omeka items.
-
#omeka_items(id = nil, query = {}) ⇒ OmekaItem
Get an array or a single Omeka item represented as an OmekaItem class array of all the items.
-
#resources ⇒ Hash
Get a list of the resources available from the Omeka API.
-
#site ⇒ Hash
Get the description of the Omeka site.
Constructor Details
#initialize(endpoint, api_key = nil) ⇒ OmekaClient
Sets up a new client to interact with an Omeka site
21 22 23 24 25 |
# File 'lib/omeka_client/client.rb', line 21 def initialize(endpoint, api_key = nil ) @endpoint = endpoint @api_key = api_key @connection = Rest::Client.new end |
Instance Attribute Details
#api_key ⇒ Object
10 11 12 |
# File 'lib/omeka_client/client.rb', line 10 def api_key @api_key end |
#connection ⇒ Object
10 11 12 |
# File 'lib/omeka_client/client.rb', line 10 def connection @connection end |
#endpoint ⇒ Object
10 11 12 |
# File 'lib/omeka_client/client.rb', line 10 def endpoint @endpoint end |
Instance Method Details
#collections ⇒ Array
Get a list of the Omeka collections
TODO: Check that items are available in the resources
127 128 129 |
# File 'lib/omeka_client/client.rb', line 127 def collections self.get_hash('collections') end |
#get(resource, id = nil, query = {}) ⇒ NetHttpPersistentResponseWrapper
Generic GET request to the Omeka site
39 40 41 42 43 44 |
# File 'lib/omeka_client/client.rb', line 39 def get(resource, id = nil, query = {} ) url = self.endpoint + "/" + resource url += "/" + id.to_s unless id.nil? query[:key] = self.api_key unless self.api_key.nil? self.connection.get(url, :params => query) end |
#get_hash(resource, id = nil, query = {}) ⇒ Array or Hash
Parse a GET request into a useable format
56 57 58 59 60 61 |
# File 'lib/omeka_client/client.rb', line 56 def get_hash(resource, id = nil, query = {} ) response = self.get(resource, id, query) if response.code == 200 JSON.parse(response.body) end end |
#items ⇒ Array
Get a list of the Omeka items
TODO: Check that items are available in the resources
117 118 119 |
# File 'lib/omeka_client/client.rb', line 117 def items self.get_hash('items') end |
#omeka_items(id = nil, query = {}) ⇒ OmekaItem
Get an array or a single Omeka item represented as an OmekaItem class array of all the items. or an array of OmekaItems
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/omeka_client/client.rb', line 80 def omeka_items(id = nil, query = {} ) response = self.get_hash('items', id = id, query = query) if id.nil? items = Array.new response.each do |item_hash| items.push OmekaItem.new(item_hash) end return items else OmekaItem.new(response) end end |
#resources ⇒ Hash
Get a list of the resources available from the Omeka API
107 108 109 |
# File 'lib/omeka_client/client.rb', line 107 def resources self.get_hash('resources') end |
#site ⇒ Hash
Get the description of the Omeka site
99 100 101 |
# File 'lib/omeka_client/client.rb', line 99 def site self.get_hash('site') end |