Sha256: bfc6c8f0dec7db7a796da0315b9af3b822a7f231c7c2f850bcddd93220f09cc2

Contents?: true

Size: 695 Bytes

Versions: 2

Compression:

Stored size: 695 Bytes

Contents

module SentimentAl
  class HttpRequest
    attr_accessor :uri, :protocol, :request

    def initialize(params)
      @uri = build_uri
      @protocol = ::Net::HTTP.new(uri.host, uri.port)
      @request = ::Net::HTTP::Post.new(uri.path, headers)

      request.body = params.to_json
      yield self if block_given?
    end

    def start
      protocol.use_ssl = true
      protocol.start{ |http| http.request(request) }
    end

    private

    def build_uri
      URI("#{sentim_api_url}/api/v1/")
    end

    def headers
      { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
    end

    def sentim_api_url
      'https://sentim-api.herokuapp.com'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sentiment-all-1.2.1beta lib/sentiment_al/http_request.rb
sentiment-all-1.2.0beta lib/sentiment_al/http_request.rb