Sha256: 4dfffd5297002aef10e0a2cc0ed1dc2651257df1d2070fe45ac8b5d08d87f33a

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

require "evil/client"
require "dry-types"

# HTTP(s) client to the "SMS Aero" online service
class SmsAero
  extend Evil::Client::DSL

  # Collection of dry-types with gem-specific additions
  Types = Module.new { |types| types.include Dry::Types.module }

  # Definitions for types, models, and API operations
  %w(types models operations).each do |folder|
    path = File.expand_path("../sms_aero/#{folder}/*.rb", __FILE__)
    Dir[path].each { |file| require(file) }
  end

  settings do
    option :user,     Types::FilledString
    option :password, Types::Password
    option :use_ssl,  Types::Form::Bool, default: proc { true }
    option :use_post, Types::Form::Bool, default: proc { true }
    option :test,     Types::Form::Bool, default: proc { false }
  end

  base_url do |settings|
    "http#{'s' if settings.use_ssl}://gate.smsaero.ru/"
  end

  operation do |settings|
    documentation "https://smsaero.ru/api/description/"

    http_method(settings.use_post ? :post : :get)

    security do
      key_auth :user,     settings.user,     using: :query
      key_auth :password, settings.password, using: :query
      key_auth :answer,   "json",            using: :query
    end

    responses format: :json do
      response :success, 200, model: Answer
      response :failure, 200, model: Answer
    end
  end

  private

  def method_missing(name, *args)
    op = operations[name.to_sym]
    op ? op.call(*args) : super
  end

  def respond_to_missing?(name, *)
    operations.key? name.to_sym
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sms_aero-0.0.11 lib/sms_aero.rb
sms_aero-0.0.10 lib/sms_aero.rb
sms_aero-0.0.9 lib/sms_aero.rb
sms_aero-0.0.8 lib/sms_aero.rb
sms_aero-0.0.7 lib/sms_aero.rb
sms_aero-0.0.6 lib/sms_aero.rb