Sha256: 0a48a803e7d71dc00f999e1b847054bc71346002b1b0758a3db747f18938ce7e

Contents?: true

Size: 1023 Bytes

Versions: 2

Compression:

Stored size: 1023 Bytes

Contents

module Fastbill
  module Automatic
    module Request
      class Connection
        attr_reader :https

        def initialize(request_info)
          @info = request_info
        end

        def setup_https
          @https             = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
          @https.use_ssl     = true
          @https.verify_mode = OpenSSL::SSL::VERIFY_PEER
          @https.ca_file     = File.join(ROOT_PATH, "data/fastbill.crt")
        end

        def request
          https.start do |connection|
            https.request(https_request)
          end
        end

        protected

        def https_request
          https_request = Net::HTTP::Post.new(@info.url)
          https_request.basic_auth(Fastbill::Automatic.email, Fastbill::Automatic.api_key)
          body = {service: @info.service}
          body[(@info.service.include?('.get') ? :filter : :data)] = @info.data
          https_request.body = body.to_json
          https_request
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fastbill-automatic-0.0.4 lib/fastbill-automatic/request/connection.rb
fastbill-automatic-0.0.3 lib/fastbill-automatic/request/connection.rb