Class: Zemanta
- Inherits:
-
Object
- Object
- Zemanta
- Includes:
- HTTParty
- Defined in:
- lib/zemanta.rb,
lib/zemanta/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
- @@api_key =
api_key for Zemanta
nil
Class Method Summary collapse
Instance Method Summary collapse
- #api_key ⇒ Object
-
#get(method, options) ⇒ Object
Get REST service with JSON response.
-
#handle_response(response, options = {}) ⇒ Object
Handle response from service.
-
#initialize(api_key = nil) ⇒ Zemanta
constructor
Initialize the client.
-
#preferences(options = {}) ⇒ Object
Get preferences of specific user.
-
#suggest(text, options = {}) ⇒ Object
Provide contextual metadata about text See: developer.zemanta.com/docs/suggest/.
-
#suggest_markup(text, options = {}) ⇒ Object
Suggest method allows developers to query Zemanta for contextual metadata on a given text.
Constructor Details
#initialize(api_key = nil) ⇒ Zemanta
Initialize the client
15 16 17 18 |
# File 'lib/zemanta.rb', line 15 def initialize(api_key=nil) @@api_key = api_key unless api_key.nil? @@api_key = ENV["ZEMANTA_KEY"] if @@api_key.nil? and not(ENV["ZEMANTA_KEY"].nil?) end |
Class Method Details
.api_key ⇒ Object
11 |
# File 'lib/zemanta.rb', line 11 def self.api_key; @@api_key end |
.api_key=(key) ⇒ Object
10 |
# File 'lib/zemanta.rb', line 10 def self.api_key=(key); @@api_key=key end |
Instance Method Details
#get(method, options) ⇒ Object
Get REST service with JSON response
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/zemanta.rb', line 44 def get(method,) .merge!({ method: "zemanta.#{method}", api_key: @@api_key, format: "json"}) handle_response( self.class.get('/services/rest/0.0/',query:), ) end |
#handle_response(response, options = {}) ⇒ Object
Handle response from service
56 57 58 59 60 61 62 63 64 |
# File 'lib/zemanta.rb', line 56 def handle_response response, ={} unless response['status'] =~ /ok/ msg = response.parsed_response.match("<h1>(.+?)</h1>")[1] msg = "Error." if msg.nil? throw "Zemanta: %s" % msg end response end |
#preferences(options = {}) ⇒ Object
Get preferences of specific user.
39 40 41 |
# File 'lib/zemanta.rb', line 39 def preferences ={} get("preferences",) end |
#suggest(text, options = {}) ⇒ Object
Provide contextual metadata about text See: developer.zemanta.com/docs/suggest/
22 23 24 25 26 |
# File 'lib/zemanta.rb', line 22 def suggest text, ={} get("suggest",.merge!({ text: text })) end |
#suggest_markup(text, options = {}) ⇒ Object
Suggest method allows developers to query Zemanta for contextual metadata on a given text. In comparison to zemanta.suggest, this method returns only links to semantical entities.
32 33 34 35 36 |
# File 'lib/zemanta.rb', line 32 def suggest_markup text, ={} get("suggest_markup",.merge!({ text: text })) end |