Datawow-ruby

HTTP RESTFul for calling DataWow APIs

support or question [email protected]

Installation

gem 'datawow', '~> 1.5.0'

Rails

$ rails generate datawow:install

Note: Rails 4.1 or above

Usage

To call our module, use Datawow followed by any of the classes provided in our APIs

Classes explanation

These classes are instance methods we have created for you. You can use our provider or the recommended methods, here, when using our APIs

Image classes Datawow.image_*

There are 6 APIs for image class

instance method

Datawow.image_closed_question
Datawow.image_photo_tag
Datawow.image_choice
Datawow.image_message
Datawow.nanameue_human
Datawow.document_verification

Video class Datawow.video_*

There is 1 API for video class

Datawow.video_classification

Text classes Datawow.text_*

There are 4 APIs for text class

Datawow.text_closed_question
Datawow.text_category
Datawow.text_conversation
Datawow.text_ja

Prediction class Datawow.prediction

There is 1 API for prediction class

Datawow.prediction

Moderation class Datawow.moderation

There is 1 API for moderation class

Datawow.moderation

Above methods are shortcuts for calling the following classes

Datawow::ImageClosedQuestion
Datawow::PhotoTag
Datawow::ImageChoice
Datawow::ImageMessage
Datawow::NanameueHuman
Datawow::VideoClassification
Datawow::TextClosedQuestion
Datawow::TextCategory
Datawow::TextConversation
Datawow::TextJa
Datawow::Prediction
Datawow::DocumentVerification
Datawow::Moderation

Available methods in our APIs

There are 3 main functions for each class: create, find_by and all

create

Datawow.[class].create(data: {})

find_by

Datawow.[class].find_by({id: "_image_id"})

all

Datawow.[class].all()

Example

After the library has been called for the first time, the associated modules will be initialized and you could then call using the package name instead. here

Setting the project key
Datawow.project_key = '_token'
Working with the methods

create

Datawow.[class].create({data: "image URL"})

find_by

Datawow.[class].find_by({id: "_image_id"})

all

Datawow.[class].all({page: '_page', per_page: '_per_page'})

Dynamically setting the token

If you have many projects, we recommend using the following example instead of the one shown above if you would like to create an object and change its token dynamically

Datawow::[class].new('_token').create({data: "image URL"})

or

model = Datawow::[class].new
model.project_key = '_token'
model.create()

For available method, see calling APIs section

Setting default token for rails project

config/initializers/datawow.rb

Datawow.setup do |config|
  # ==> Secret key Configuration
  # You can change it below and use your own secret key.
  config.project_key = 'your token'
end

Response

Response is a module and it contains data including: data, meta-data, message, and status

Example of a response module

<Datawow::Response @status=200, @message="success" @meta={"code"=>200, "message"=>"success"}, @data={...}, />

You can call the data property to get the data, which would return in the format as shown below

{
  "data": {
    "image": {
      "id": "5a40be59fb9d7f27354c5efa",
      "answer": "approved",
      "credit_charged": 1,
      "custom_id": "custom_id",
      "data": "image_url",
      "postback_url": "postback_url",
      "processed_at": "2017-12-25T16:02:00.599+07:00",
      "project_id": "project_id",
      "status": "processed"
    }
  },
  "status": 200,
  "message": "success",
  "meta": {
    "code": 200,
    "message": "success"
  }
}

Checking status with successful?

if response.successful?
  # Do stuff
else
  log.error("Request was not successful, something went wrong.")
end

Demo and Usage

  • Image Documentation link
  • Video Documentation link
  • Text Documentation link
  • AI/Prediction Documentation link
  • Moderation Documentation link