Sha256: e90b050f4eb8f6d5eb475e83a4762ee915869d9f0c9ccbcb157ab182f787111a

Contents?: true

Size: 973 Bytes

Versions: 10

Compression:

Stored size: 973 Bytes

Contents

module Flydata
  module Command
    class Login < Base
      LOGIN_TRIAL_TIMES=3
      def run
        ret = login(LOGIN_TRIAL_TIMES)
        raise "Login failed #{LOGIN_TRIAL_TIMES} times." unless ret
        ret
      end

      private
      def login(times=3)
        1.upto(times) do |i|
          begin
            return true if login_once
          rescue Exception => e
            puts e
          end
        end
        false
      end
      def login_once
        # Ask login info
        email = ask("FlyData Email:  ")
        password = ask("FlyData password:  ") {|q| q.echo = false}
        flydata.credentials = Flydata::Credentials.new(email, password)
        # Auth request
        flydata.post('/users/sign_in')
        if flydata.response.code == 201 # 201: Created
          say("Login succeeded!")
          flydata.credentials.authenticate!
          return true
        end
        say("Login failed!")
        false
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flydata-0.0.2.3 lib/flydata/command/login.rb
flydata-0.0.2.2 lib/flydata/command/login.rb
flydata-0.0.2.1 lib/flydata/command/login.rb
flydata-0.0.2 lib/flydata/command/login.rb
flydata-0.0.2.rc1 lib/flydata/command/login.rb
flydata-0.0.1.2011102901 lib/flydata/command/login.rb
flydata-0.0.1.nc2 lib/flydata/command/login.rb
flydata-0.0.1.nc1 lib/flydata/command/login.rb
flydata-0.0.1.2011102602 lib/flydata/command/login.rb
flydata-0.0.1.2011102601 lib/flydata/command/login.rb