Sha256: f614dc3ac8104d22fe489c667aaec5d723a9f417ddedc159599c23511fa00b19

Contents?: true

Size: 1.51 KB

Versions: 26

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8
module Ayadn
  class PinBoard

    def has_credentials_file?
      File.exist?(Ayadn::Settings.config[:paths][:db] + '/ayadn_pinboard.db')
    end

    def ask_credentials
      begin
        puts "Please enter your Pinboard username (CTRL+C to cancel): ".color(:green)
        pin_username = STDIN.gets.chomp()
        puts "\nPlease enter your Pinboard password (invisible, CTRL+C to cancel): ".color(:green)
        pin_password = STDIN.noecho(&:gets).chomp()
      rescue Interrupt
        abort(Status.canceled)
      rescue => e
        puts Status.wtf
        Errors.global_error("pinboard/ask_credentials", pin_username, e)
      end
      save_credentials(encode(pin_username, pin_password))
    end

    def load_credentials
      decode(File.read(Ayadn::Settings.config[:paths][:db] + '/ayadn_pinboard.db'))
    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][:db] + '/ayadn_pinboard.db', encoded_pinboard_credentials)
    end

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

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ayadn-1.0.5 lib/ayadn/pinboard.rb
ayadn-1.0.4 lib/ayadn/pinboard.rb
ayadn-1.0.3 lib/ayadn/pinboard.rb
ayadn-1.0.2 lib/ayadn/pinboard.rb
ayadn-1.0.1 lib/ayadn/pinboard.rb
ayadn-1.0.0 lib/ayadn/pinboard.rb