Socket
Book a DemoInstallSign in
Socket

sema_api_ruby

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sema_api_ruby

0.1.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

SemaApiRuby

Ruby client for Sema Media Data's image OCR API. Used for getting an estimated text to image ratio for validating images before being submitted to Facebook Ads.

Installation

Add this line to your application's Gemfile:

gem 'sema_api_ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sema_api_ruby

Usage

Configure the client by providing an API token. Also tweak the configuration for any of the OCR settings.

SemaApiRuby.configure do |config|
  config.access_token = 'myaccesstokenhere'

  #optional - below are the defaults
  config.ocr_settings = {
    lang: 'en',      # english language
    outform: 'json', # output as json
    sp: 'True',      # perform spellcheck
    mh: 'True',      # multi-hypothesis... increases accuracy at slight performance cost
    df: 'True',      # dictionary based word filtering
    noempty: 'True'  # only return detected objects that are not empty
  }
end

Post a request to the ocr endpoint with the path to an image to get back a raw response from the api (post made using Faraday gem)

client = SemaApiRuby.new
file_path = '/path/to/your/image.jpg'

client.post_ocr_image(file_path)
# => #<Faraday::Response:0x007fcb641591e0 ...

Use this method to both post to the ocr endpoint and return an text to image ratio

client = SemaApiRuby.new
file_path = '/path/to/your/image.jpg'

client.text_to_image_ratio(file_path)
# => 0.2123

Testing

Copy the sample dotenv file to .env

$> cp .env.sample .env

Update it with a testing API token if you want to run specs against the live API rather than against the network stubs

Run the specs

$> bundle exec rspec spec

This gem uses a testing gem called VCR to record and replay HTTP requests. If the actual API has changed you will need to delete all "casettes" located in spec/cassettes/ so that requests will run against the live API

Contributing

  • Fork it ( https://github.com/[my-github-username]/sema_api_ruby/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 18 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.