Sha256: ac4f6f9caacb79935ba76b1eab4e1b0c10c92ae60e3704a4346785d96e1cca2f

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require 'thor'
require 'search_kit/thor'

module SearchKit
  class CLI < Thor
    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

2 entries across 2 versions & 1 rubygems

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