Class: Calais::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
# File 'lib/calais/client.rb', line 18

def initialize(options={}, &block)
  options.each {|k,v| send("#{k}=", v)}
  yield(self) if block_given?
end

Instance Attribute Details

#allow_distributionObject

user directives



12
13
14
# File 'lib/calais/client.rb', line 12

def allow_distribution
  @allow_distribution
end

#allow_searchObject

user directives



12
13
14
# File 'lib/calais/client.rb', line 12

def allow_search
  @allow_search
end

#calculate_relevanceObject

processing directives



8
9
10
# File 'lib/calais/client.rb', line 8

def calculate_relevance
  @calculate_relevance
end

#contentObject

base attributes of the call



4
5
6
# File 'lib/calais/client.rb', line 4

def content
  @content
end

#content_typeObject

processing directives



8
9
10
# File 'lib/calais/client.rb', line 8

def content_type
  @content_type
end

#external_idObject

user directives



12
13
14
# File 'lib/calais/client.rb', line 12

def external_id
  @external_id
end

#external_metadataObject

Returns the value of attribute external_metadata.



14
15
16
# File 'lib/calais/client.rb', line 14

def 
  @external_metadata
end

#license_idObject

Returns the value of attribute license_id.



5
6
7
# File 'lib/calais/client.rb', line 5

def license_id
  @license_id
end

#metadata_discardsObject

Returns the value of attribute metadata_discards.



9
10
11
# File 'lib/calais/client.rb', line 9

def 
  @metadata_discards
end

#metadata_enablesObject

Returns the value of attribute metadata_enables.



9
10
11
# File 'lib/calais/client.rb', line 9

def 
  @metadata_enables
end

#omit_outputting_original_textObject

processing directives



8
9
10
# File 'lib/calais/client.rb', line 8

def omit_outputting_original_text
  @omit_outputting_original_text
end

#output_formatObject

processing directives



8
9
10
# File 'lib/calais/client.rb', line 8

def output_format
  @output_format
end

#reltag_base_urlObject

processing directives



8
9
10
# File 'lib/calais/client.rb', line 8

def reltag_base_url
  @reltag_base_url
end

#store_rdfObject

Returns the value of attribute store_rdf.



9
10
11
# File 'lib/calais/client.rb', line 9

def store_rdf
  @store_rdf
end

#submitterObject

user directives



12
13
14
# File 'lib/calais/client.rb', line 12

def submitter
  @submitter
end

#use_betaObject

Returns the value of attribute use_beta.



16
17
18
# File 'lib/calais/client.rb', line 16

def use_beta
  @use_beta
end

Instance Method Details

#enlightenObject



23
24
25
26
27
28
29
30
31
# File 'lib/calais/client.rb', line 23

def enlighten
  post_args = {
    "licenseID" => @license_id,
    "content" => Iconv.iconv('UTF-8//IGNORE', 'UTF-8',  "#{@content} ").first[0..-2],
    "paramsXML" => params_xml
  }

  do_request(post_args)
end

#params_xmlObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/calais/client.rb', line 33

def params_xml
  check_params
  document = Nokogiri::XML::Document.new
  
  params_node = Nokogiri::XML::Node.new('c:params', document)
  params_node['xmlns:c'] = 'http://s.opencalais.com/1/pred/'
  params_node['xmlns:rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
  
  processing_node = Nokogiri::XML::Node.new('c:processingDirectives', document)
  processing_node['c:contentType'] = AVAILABLE_CONTENT_TYPES[@content_type] if @content_type
  processing_node['c:outputFormat'] = AVAILABLE_OUTPUT_FORMATS[@output_format] if @output_format
  processing_node['c:calculateRelevanceScore'] = 'false' if @calculate_relevance == false
  processing_node['c:reltagBaseURL'] = @reltag_base_url.to_s if @reltag_base_url
  
  processing_node['c:enableMetadataType'] = @metadata_enables.join(',') unless @metadata_enables.empty?
  processing_node['c:docRDFaccessible'] = @store_rdf if @store_rdf
  processing_node['c:discardMetadata'] = @metadata_discards.join(';') unless @metadata_discards.empty?
  processing_node['c:omitOutputtingOriginalText'] = 'true' if @omit_outputting_original_text
  
  user_node = Nokogiri::XML::Node.new('c:userDirectives', document)
  user_node['c:allowDistribution'] = @allow_distribution.to_s unless @allow_distribution.nil?
  user_node['c:allowSearch'] = @allow_search.to_s unless @allow_search.nil?
  user_node['c:externalID'] = @external_id.to_s if @external_id
  user_node['c:submitter'] = @submitter.to_s if @submitter
  
  params_node << processing_node
  params_node << user_node
  
  if @external_metadata
    external_node = Nokogiri::XML::Node.new('c:externalMetadata', document)
    external_node << @external_metadata
    params_node << external_node
  end
  
  params_node.to_xml(:indent => 2)
end

#urlObject



70
71
72
# File 'lib/calais/client.rb', line 70

def url
  @url ||= URI.parse(calais_endpoint)
end