Sha256: c97e78a1247c3e9f1fa9c42c0768b42855e68e4f0ccc2985dc5f73d5aad3cc66

Contents?: true

Size: 983 Bytes

Versions: 3

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true

require 'smstools_api/middleware/response/hashie_json'
require 'smstools_api/middleware/request/authorization'
require 'smstools_api/messages'
require 'smstools_api/voice_messages'

module SmstoolsApi
  class Client
    extend Forwardable

    attr_reader :config, :messages, :voice_messages

    def initialize(config = {})
      @config = Hashie::Mash.new(config)
      @messages = Messages.new(self)
      @voice_messages = VoiceMessages.new(self)
    end

    private

    delegate %i[get post put delete head patch options trace] => :connection

    def connection
      @connection ||= build_connection
    end

    def build_connection
      Faraday.new('https://api.smsgatewayapi.com/v1') do |builder|
        # Request
        builder.request :json
        builder.use SmstoolsApi::Middleware::Request::Authorization, self

        # Response
        builder.use SmstoolsApi::Middleware::Response::HashieJson, self
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smstools_api-0.1.7 lib/smstools_api/client.rb
smstools_api-0.1.4 lib/smstools_api/client.rb
smstools_api-0.1.3 lib/smstools_api/client.rb