Sha256: e2d29116f0a284e888e77391b930e9d8500f2ba7d6af51aea09f2e9f9e04f3c8

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 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 ||= SearchKit::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

4 entries across 4 versions & 1 rubygems

Version Path
search-kit-0.0.10 lib/search_kit/cli/subscribers.rb
search-kit-0.0.9 lib/search_kit/cli/subscribers.rb
search-kit-0.0.8 lib/search_kit/cli/subscribers.rb
search-kit-0.0.7 lib/search_kit/cli/subscribers.rb