Coder Social home page Coder Social logo

zemanta's Introduction

Zemanta

This is a ruby client to awesome Zemanta app.

Installation

Add this line to your application's Gemfile:

gem 'zemanta_client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install zemanta_client

Api key

You need to set api_key to use the client. If you won't do that, gem will raise an error. There are 2 ways:

  1. Environment variable - Set ZEMANTA_KEY key in you environment variables and gem will use it

  2. Configuration - You can set your api_key in configuration block like this:

      Zemanta.configure { |c| c.api_key = 'your_api_key' }

Usage

Two use cases are implemented:

  1. Retrieving suggest_markup data and enhancing the text.
```ruby
Zemanta::Markup.fetch(text, opts = {})
```

It will fetch suggest_markup data for passed text from Zemanta api and wrap it in custom classes.
  1. Enhancing the text with links:
```ruby
Zemanta::Enhancer.new(text, opts = {}).enhance
```

Options:
  * `no_duplicates` (default: false) - ensures links are used once
  * `skip` (default: nil) - URL regexp of the links that should be skipped
  * `strip_query_string` - removes the query string part of the suggested links urls

It will fetch suggest_markup data for given text and for every returned link it will wrap the keyword with this link.
Then it will return the updated text.

In both relevance and confidence keys can be passes inside opts to filter any links that are below passed values.

Configuration

There are several configuration options you can set:

Zemanta.configure do |config|
  # You can pass a hash of custom options that will be passed into each request. It's empty by default.
  config.custom_request_opts = {}

  # Zemanta supports various response formats. However, this client works only with json, so changing this would be rather bad idea.
  config.format = "json"

  # This client supports caching, details below. Default is no caching.
  config.cache_store = Zemanta::Configuration::NullStorage

  # You can pass api_key to zemanta, as described above.
  config.api_key = "yourapikeyhere"
end

Caching

By default there is no caching. You can pass any cache store to config.cache_store in configuration. The only expectation is that it answers to [] and []= methods. For example, you can pass ruby hash or Cache::Disk.new object to use simple file system storage.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Changelog

0.0.5 - Added #no_duplicates option to Enhancer 0.0.4 - Fixed yajl require in gemspec 0.0.3 - Added Enhancer class, used yajl for json parsing, changed external gem api. 0.0.2 - Got rid of autoloads. 0.0.1 - Initial release. Support for suggest_markup method and caching.

zemanta's People

Contributors

pokonski avatar pzac avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.