Sha256: cfe5b2df86cb1097f77587613405e8e1feb92a20e4a2ab093d13f775ed934256

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

# encoding: utf-8
module Ayadn
  class PinBoard

    def initialize
      @status = Status.new
    end

    def has_credentials_file?
      File.exist?(Ayadn::Settings.config[:paths][:auth] + '/pinboard.data')
    end

    def ask_credentials
      begin
        @status.pin_username
        pin_username = STDIN.gets.chomp()
        @status.pin_password
        pin_password = STDIN.noecho(&:gets).chomp()
      rescue Interrupt
        @status.canceled
        exit
      rescue => e
        @status.wtf
        Errors.global_error({error: e, caller: caller, data: [pin_username]})
      end
      save_credentials(encode(pin_username, pin_password))
    end

    def load_credentials
      decode(File.read(Ayadn::Settings.config[:paths][:auth] + '/pinboard.data'))
    end

    def pin(data)
      pinboard = Pinboard::Client.new(:username => data.username, :password => data.password)
      pinboard.add(:url => data.url, :tags => data.tags, :extended => data.text, :description => data.description)
    end

    private

    def decode(encoded_pinboard_credentials)
      Base64.strict_decode64(encoded_pinboard_credentials[/AyadnPinboard (.*)/, 1]).split(":")
    end

    def save_credentials(encoded_pinboard_credentials)
      File.write(Ayadn::Settings.config[:paths][:auth] + '/pinboard.data', encoded_pinboard_credentials)
    end

    def encode(username, password)
      "AyadnPinboard #{Base64.strict_encode64([username, password].join(":"))}"
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ayadn-3.0 lib/ayadn/pinboard.rb
ayadn-2.1 lib/ayadn/pinboard.rb
ayadn-2.0.12 lib/ayadn/pinboard.rb
ayadn-2.0.11 lib/ayadn/pinboard.rb
ayadn-2.0.10 lib/ayadn/pinboard.rb
ayadn-2.0.9 lib/ayadn/pinboard.rb
ayadn-2.0.8 lib/ayadn/pinboard.rb
ayadn-2.0.7 lib/ayadn/pinboard.rb
ayadn-2.0.6 lib/ayadn/pinboard.rb
ayadn-2.0.5 lib/ayadn/pinboard.rb
ayadn-2.0.4 lib/ayadn/pinboard.rb
ayadn-2.0.3 lib/ayadn/pinboard.rb
ayadn-2.0.2 lib/ayadn/pinboard.rb
ayadn-2.0.1 lib/ayadn/pinboard.rb
ayadn-2.0 lib/ayadn/pinboard.rb