Class: DirectedEdge::Database
Overview
A Database is an encapsulation of a database being accessed via the Directed Edge web-services API. You can request database creation by visiting www.directededge.com and will recieve a user name and password which are then used to connect to your DirectedEdge::Database instance.
Usually when getting started with a DirectedEdge database, users would like to import some pre-existing data, usually from their web application’s database. The Database class has an import method which can be used to import data using Directed Edge’s XML format. Files formatted in that way may be created with the Exporter.
A database is typically instantiated via:
database = DirectedEdge::Database.new('mydatabase', 'mypassword')
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the database.
-
#resource ⇒ Object
readonly
The REST resource used for connecting to the database.
Instance Method Summary collapse
-
#group_related(items = Set.new, tags = Set.new, params = {}) ⇒ Array
aggregate, commonly used to do recommendations for a basket of items.
-
#import(file_name) ⇒ Object
Imports a Directed Edge XML file to the database.
-
#initialize(name, password = '', protocol = 'http', options = {}) ⇒ DirectedEdge::Item
constructor
Creates a connection to a Directed Edge database.
Constructor Details
#initialize(name, password = '', protocol = 'http', options = {}) ⇒ DirectedEdge::Item
Creates a connection to a Directed Edge database. The name and password should have been provided when the account was created.
175 176 177 178 179 180 181 182 183 |
# File 'lib/directed_edge.rb', line 175 def initialize(name, password='', protocol='http', = {}) @name = name host = [:host] || ENV['DIRECTEDEDGE_HOST'] || 'webservices.directededge.com' url = "#{protocol}://#{name}:#{password}@#{host}/api/v1/#{name}" [:timeout] ||= 10 super(RestClient::Resource.new(url, )) end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the database.
157 158 159 |
# File 'lib/directed_edge.rb', line 157 def name @name end |
#resource ⇒ Object (readonly)
The REST resource used for connecting to the database.
161 162 163 |
# File 'lib/directed_edge.rb', line 161 def resource @resource end |
Instance Method Details
#group_related(items = Set.new, tags = Set.new, params = {}) ⇒ Array
aggregate, commonly used to do recommendations for a basket of items.
The tags and params parameters are equivalent to those with the normal Item#related call.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/directed_edge.rb', line 207 def (items=Set.new, =Set.new, params={}) if !items.is_a?(Array) || items.size < 1 return with_properties?(params) ? InsertOrderHash.new : [] end params['items'] = items.to_a.join(',') params['tags'] = .to_a.join(',') params['union'] = true normalize_params!(params) if params['includeProperties'] == 'true' property_hash_from_document(read_document('related', params), 'related') else list_from_document(read_document('related', params), 'related') end end |
#import(file_name) ⇒ Object
Imports a Directed Edge XML file to the database.
on the XML format.
192 193 194 |
# File 'lib/directed_edge.rb', line 192 def import(file_name) @resource.put(File.read(file_name), :content_type => 'text/xml') end |