Class: Calais::Client
- Inherits:
-
Object
- Object
- Calais::Client
- Defined in:
- lib/calais/client.rb
Instance Attribute Summary collapse
-
#allow_distribution ⇒ Object
user directives.
-
#allow_search ⇒ Object
user directives.
-
#calculate_relevance ⇒ Object
processing directives.
-
#content ⇒ Object
base attributes of the call.
-
#content_type ⇒ Object
processing directives.
-
#external_id ⇒ Object
user directives.
-
#external_metadata ⇒ Object
Returns the value of attribute external_metadata.
-
#license_id ⇒ Object
Returns the value of attribute license_id.
-
#metadata_discards ⇒ Object
Returns the value of attribute metadata_discards.
-
#metadata_enables ⇒ Object
Returns the value of attribute metadata_enables.
-
#omit_outputting_original_text ⇒ Object
processing directives.
-
#output_format ⇒ Object
processing directives.
-
#reltag_base_url ⇒ Object
processing directives.
-
#store_rdf ⇒ Object
Returns the value of attribute store_rdf.
-
#submitter ⇒ Object
user directives.
-
#use_beta ⇒ Object
Returns the value of attribute use_beta.
Instance Method Summary collapse
- #enlighten ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #params_xml ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
18 19 20 21 |
# File 'lib/calais/client.rb', line 18 def initialize(={}, &block) .each {|k,v| send("#{k}=", v)} yield(self) if block_given? end |
Instance Attribute Details
#allow_distribution ⇒ Object
user directives
12 13 14 |
# File 'lib/calais/client.rb', line 12 def allow_distribution @allow_distribution end |
#allow_search ⇒ Object
user directives
12 13 14 |
# File 'lib/calais/client.rb', line 12 def allow_search @allow_search end |
#calculate_relevance ⇒ Object
processing directives
8 9 10 |
# File 'lib/calais/client.rb', line 8 def calculate_relevance @calculate_relevance end |
#content ⇒ Object
base attributes of the call
4 5 6 |
# File 'lib/calais/client.rb', line 4 def content @content end |
#content_type ⇒ Object
processing directives
8 9 10 |
# File 'lib/calais/client.rb', line 8 def content_type @content_type end |
#external_id ⇒ Object
user directives
12 13 14 |
# File 'lib/calais/client.rb', line 12 def external_id @external_id end |
#external_metadata ⇒ Object
Returns the value of attribute external_metadata.
14 15 16 |
# File 'lib/calais/client.rb', line 14 def @external_metadata end |
#license_id ⇒ Object
Returns the value of attribute license_id.
5 6 7 |
# File 'lib/calais/client.rb', line 5 def license_id @license_id end |
#metadata_discards ⇒ Object
Returns the value of attribute metadata_discards.
9 10 11 |
# File 'lib/calais/client.rb', line 9 def @metadata_discards end |
#metadata_enables ⇒ Object
Returns the value of attribute metadata_enables.
9 10 11 |
# File 'lib/calais/client.rb', line 9 def @metadata_enables end |
#omit_outputting_original_text ⇒ Object
processing directives
8 9 10 |
# File 'lib/calais/client.rb', line 8 def omit_outputting_original_text @omit_outputting_original_text end |
#output_format ⇒ Object
processing directives
8 9 10 |
# File 'lib/calais/client.rb', line 8 def output_format @output_format end |
#reltag_base_url ⇒ Object
processing directives
8 9 10 |
# File 'lib/calais/client.rb', line 8 def reltag_base_url @reltag_base_url end |
#store_rdf ⇒ Object
Returns the value of attribute store_rdf.
9 10 11 |
# File 'lib/calais/client.rb', line 9 def store_rdf @store_rdf end |
#submitter ⇒ Object
user directives
12 13 14 |
# File 'lib/calais/client.rb', line 12 def submitter @submitter end |
#use_beta ⇒ Object
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
#enlighten ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 } @client ||= Curl::Easy.new @client.url = @use_beta ? BETA_REST_ENDPOINT : REST_ENDPOINT @client.timeout = HTTP_TIMEOUT post_fields = post_args.map {|k,v| Curl::PostField.content(k, v) } do_request(post_fields) end |
#params_xml ⇒ Object
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 69 70 71 72 73 74 |
# File 'lib/calais/client.rb', line 39 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 |