Sha256: 4bec3a4f179826f7087e1d8dec5104ef07afdab72a26ecdd97da6495f431a55a

Contents?: true

Size: 997 Bytes

Versions: 1

Compression:

Stored size: 997 Bytes

Contents

require 'httparty'
require 'haml'

module MShard
  class MShard
    include HTTParty
    base_uri ENV['MSHARD_URI']

    def get(id)
      self.class.get("/v2/shards/#{id}").body
    end

    def set(params)
      self.class.post('/v2/shards', body: params)['id']
    end

    def set_safe(*args)
      3.times do
        begin
          return set(*args)
        rescue
        end
        sleep 2
      end
      nil
    end

    def error_to_html(e)
      Haml::Engine.new(<<-HAML).render(Object.new, e: e)
!!! 5
%html
  %head
    %meta{ name: 'viewport', content: 'width=device-width,initial-scale=1.0' }
    %title Error
  %body
    %p
      %pre
        &= e.inspect
    %p
      %pre
        &= e.backtrace.join("\\n")
      HAML
    end

    def set_error(e, **opt)
      set_safe({
          pushbullet: true,
          type: 'link',
          title: 'Error!',
          body: "#{e.class}\nClick here",
          contents: error_to_html(e),
        }.merge(opt)
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mshard-0.2.0 lib/mshard/mshard.rb