Sha256: c12dd85b8198d3ca2fdc5b5d7f8ebb9e8a001a9adfda945b45127f491757b59d

Contents?: true

Size: 893 Bytes

Versions: 1

Compression:

Stored size: 893 Bytes

Contents

require 'rest-client'
require 'json'

module Ltp
  module Cloud
    module Sdk
      class Client
        attr_accessor :api_key

        END_POINT = 'https://api.ltp-cloud.com/'.freeze

        def initialize(api_key)
          self.api_key = api_key
        end

        def self.with(api_key)
          new(api_key)
        end

        def request_payload(data)
          {
            api_key: api_key,
            format:  'plain'
          }.merge data
        end

        def request(service, payload)
          res = RestClient.get(uri(service), params: payload)
          res.body
        end

        def uri(service)
          "#{END_POINT}#{service}"
        end

        def analysis(text)
          payload = request_payload({ text: URI::encode(text), pattern: 'ws' })
          res = request 'analysis', payload
          res.split(' ')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ltp-cloud-sdk-0.1.0 lib/ltp/cloud/sdk/client.rb