Sha256: b4620cecb9ba8894f49cf6f1070f931ae907ce00548bad061525c07c959e8341

Contents?: true

Size: 627 Bytes

Versions: 2

Compression:

Stored size: 627 Bytes

Contents

require "faraday"
require "faraday_middleware"
require "json"

module Datatxt

  class Base

    protected

    def call(endpoint, params)
      begin
        params = params.merge(
          :$app_id => Datatxt.config.app_id,
          :$app_key => Datatxt.config.app_key
        )
        conn = Faraday.new(url: Datatxt.config.endpoint) do |faraday|
          faraday.request  :url_encoded
          faraday.adapter  Faraday.default_adapter
        end
        response = conn.post endpoint, params
        JSON.parse response.body
      rescue Exception => e
        raise Datatxt::BadResponse
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datatxt-0.1.0 lib/datatxt/base.rb
datatxt-0.0.2 lib/datatxt/base.rb