Sha256: aec74b44cc6917785e1e1014b64d68e3699ba906123d01059d7a1c867a5b0615

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'faraday'
require 'json'
require 'search_kit/thor'
require 'thor'

module SearchKit
  module CLI
    class Subscribers < Thor
      namespace :subscribers

      no_commands do
        def client
          @client ||= SearchKit::Clients::Subscribers.new
        end

        def messages
          @messages ||= Messages.new
        end
      end

      document :create
      def create(email, password)
        subscriber = client.create(email: email, password: password)
        messages.info(subscriber.to_json)
      rescue Errors::BadRequest
        messages.bad_request
      rescue Errors::Unprocessable
        messages.unprocessable
      rescue Faraday::ConnectionFailed
        messages.no_service
      end

      document :info
      def info
        subscriber = client.info
        messages.info(subscriber.to_json)
      rescue Errors::SubscriberNotFound
        messages.not_found
      rescue Errors::Unauthorized
        messages.unauthorized
      rescue Faraday::ConnectionFailed
        messages.no_service
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
search-kit-0.0.6 lib/search_kit/cli/subscribers.rb