<commit_before>onebox
----------

  - TODO: register to rubygems.org
  - [![Code Climate](https://codeclimate.com/github/dysania/onebox.png)](https://codeclimate.com/github/dysania/onebox)
  - [![Build Status](https://travis-ci.org/dysania/onebox.png)](https://travis-ci.org/dysania/onebox)
  - [![Dependency Status](https://gemnasium.com/dysania/onebox.png)](https://gemnasium.com/dysania/onebox)
  - [![Coverage Status](https://coveralls.io/repos/dysania/onebox/badge.png)](https://coveralls.io/r/dysania/onebox)


Onebox is a library for turning media URLs into previews.

Onebox currently has support for page, image, and video URLs from these sites:
- Amazon
- Android App Store
- Apple Store
- BlipTV
- Clikthrough
- College Humor
- Dailymotion
- Dotsub
- Flickr
- Funny or Die
- Gist
- Github
    - Blob
    - Commit
    - Pull Request
- Hulu
- Imgur
- Kinomap
- NFB
- Open Graph
- Qik
- Revision
- Rotten Tomatoes
- Slideshare
- Smugmug
- Soundcloud
- Stack Exchange
- TED
- Twitter
- Wikipedia
- yFrog


Using onebox
===============

``` ruby
require "onebox"
```

The `Gemfile` file would look like this:

``` ruby
# source/Gemfile
source "https://rubygems.org"

gem "onebox", "~> <%= version %>"
```

How to create a new onebox
===========================

1. Create new onebox engine

``` ruby
# in lib/onebox/engine/name_onebox.rb

module Onebox
  module Engine
    class NameOnebox
      include Engine

      private

      def extracted_data
        {
          url: @url,
          name: @body.css("h1").inner_text,
          image: @body.css("#main-image").first["src"],
          description: @body.css("#postBodyPS").inner_text
        }
      end
    end
  end
end
```

2. Create new onebox spec

3. Create new handlebars template

``` html
# in templates/name.handlebars
<div class="onebox">
  <a href="{{url}}">
    <h1>{{name}}</h1>
    <h2 class="host">name.com</h2>
    <img src="{{image}}" />
    <p>{{description}}</p>
  </a>
</div>
```

4. Create new fixture from HTML response

``` bash
curl --output spec/fixtures/name.response -L -X -GET http://yoursitename.com
```

5. Require in Engine module

``` ruby
# in lib/onebox/engine/engine.rb
require_relative "engine/name_onebox"
```


Installing onebox<commit_msg>add create new onebox spec example #40<commit_after>onebox
----------

  - TODO: register to rubygems.org
  - [![Code Climate](https://codeclimate.com/github/dysania/onebox.png)](https://codeclimate.com/github/dysania/onebox)
  - [![Build Status](https://travis-ci.org/dysania/onebox.png)](https://travis-ci.org/dysania/onebox)
  - [![Dependency Status](https://gemnasium.com/dysania/onebox.png)](https://gemnasium.com/dysania/onebox)
  - [![Coverage Status](https://coveralls.io/repos/dysania/onebox/badge.png)](https://coveralls.io/r/dysania/onebox)


Onebox is a library for turning media URLs into previews.

Onebox currently has support for page, image, and video URLs from these sites:
- Amazon
- Android App Store
- Apple Store
- BlipTV
- Clikthrough
- College Humor
- Dailymotion
- Dotsub
- Flickr
- Funny or Die
- Gist
- Github
    - Blob
    - Commit
    - Pull Request
- Hulu
- Imgur
- Kinomap
- NFB
- Open Graph
- Qik
- Revision
- Rotten Tomatoes
- Slideshare
- Smugmug
- Soundcloud
- Stack Exchange
- TED
- Twitter
- Wikipedia
- yFrog


Using onebox
===============

``` ruby
require "onebox"
```

The `Gemfile` file would look like this:

``` ruby
# source/Gemfile
source "https://rubygems.org"

gem "onebox", "~> <%= version %>"
```

How to create a new onebox
===========================

1. Create new onebox engine

``` ruby
# in lib/onebox/engine/name_onebox.rb

module Onebox
  module Engine
    class NameOnebox
      include Engine

      private

      def extracted_data
        {
          url: @url,
          name: @body.css("h1").inner_text,
          image: @body.css("#main-image").first["src"],
          description: @body.css("#postBodyPS").inner_text
        }
      end
    end
  end
end
```

2. Create new onebox spec

``` ruby
# in spec/lib/onebox/engine/name_spec.rb
require "spec_helper"

describe Onebox::Engine::NameOnebox do
  let(:link) { "http://yoursitename.com" }
  let(:html) { described_class.new(link).to_html }

  before do
    fake(link, response("name.response"))
  end

  it "returns video title" do
    expect(html).to include("title")
  end

  it "returns video photo" do
    expect(html).to include("photo.jpg")
  end

  it "returns video description" do
    expect(html).to include("description")
  end

  it "returns URL" do
    expect(html).to include(link)
  end
end
```

3. Create new handlebars template

``` html
# in templates/name.handlebars
<div class="onebox">
  <a href="{{url}}">
    <h1>{{name}}</h1>
    <h2 class="host">yoursitename.com</h2>
    <img src="{{image}}" />
    <p>{{description}}</p>
  </a>
</div>
```

4. Create new fixture from HTML response

``` bash
curl --output spec/fixtures/name.response -L -X -GET http://yoursitename.com
```

5. Require in Engine module

``` ruby
# in lib/onebox/engine/engine.rb
require_relative "engine/name_onebox"
```


Installing onebox
{'fraction_non_alphanumeric': 0.16562009419152277, 'fraction_numerical': 0.0043171114599686025, 'mean_word_length': 3.1574225122349104, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 18, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4680933', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1764, 'n_words': 424}