Class: TextRazor::Client

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

Constant Summary collapse

EmptyApiKey =
Class.new(StandardError)
EmptyText =
Class.new(StandardError)
TextTooLong =
Class.new(StandardError)
UnsupportedExtractor =
Class.new(StandardError)
UnsupportedCleanupMode =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, options = {}) ⇒ Client

Returns a new instance of Client.



26
27
28
29
# File 'lib/textrazor/client.rb', line 26

def initialize(api_key, options = {})
  assign_api_key(api_key)
  assign_request_options(options)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



22
23
24
# File 'lib/textrazor/client.rb', line 22

def api_key
  @api_key
end

#request_optionsObject (readonly)

Returns the value of attribute request_options.



22
23
24
# File 'lib/textrazor/client.rb', line 22

def request_options
  @request_options
end

#responseObject (readonly)

Returns the value of attribute response.



22
23
24
# File 'lib/textrazor/client.rb', line 22

def response
  @response
end

Class Method Details

.categories(api_key, text, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/textrazor/client.rb', line 46

def self.categories(api_key, text, options = {})
  new(api_key, options.merge(classifiers: ['textrazor_iab'])).
    analyse(text).
    categories
end

.coarse_topics(api_key, text, options = {}) ⇒ Object



52
53
54
55
56
# File 'lib/textrazor/client.rb', line 52

def self.coarse_topics(api_key, text, options = {})
  new(api_key, options.merge(extractors: ['topics'])).
    analyse(text).
    coarse_topics
end

.entities(api_key, text, options = {}) ⇒ Object



58
59
60
61
62
# File 'lib/textrazor/client.rb', line 58

def self.entities(api_key, text, options = {})
  new(api_key, options.merge(extractors: ['entities'])).
    analyse(text).
    entities
end

.phrases(api_key, text, options = {}) ⇒ Object



70
71
72
73
74
# File 'lib/textrazor/client.rb', line 70

def self.phrases(api_key, text, options = {})
  new(api_key, options.merge(extractors: ['phrases', 'words'])).
    analyse(text).
    phrases
end

.topics(api_key, text, options = {}) ⇒ Object



40
41
42
43
44
# File 'lib/textrazor/client.rb', line 40

def self.topics(api_key, text, options = {})
  new(api_key, options.merge(extractors: ['topics'])).
    analyse(text).
    topics
end

.words(api_key, text, options = {}) ⇒ Object



64
65
66
67
68
# File 'lib/textrazor/client.rb', line 64

def self.words(api_key, text, options = {})
  new(api_key, options.merge(extractors: ['words'])).
    analyse(text).
    entities
end

Instance Method Details

#analyse(text) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/textrazor/client.rb', line 31

def analyse(text)
  assert_text(text)
  options = {
    api_key: api_key
  }.merge(request_options)

  Response.new(Request.post(text, options))
end