Sha256: 6819a7710958827f17caabd57529daf66fdae15a33863470f1da6a6a44c8f809

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8
module Ayadn
  class PinBoard

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

    def ask_credentials status = Status.new
      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

4 entries across 4 versions & 1 rubygems

Version Path
ayadn-4.0.3 lib/ayadn/pinboard.rb
ayadn-4.0.2 lib/ayadn/pinboard.rb
ayadn-4.0.1 lib/ayadn/pinboard.rb
ayadn-4.0 lib/ayadn/pinboard.rb