Sha256: 7041a4400d224cf2508d08b3a82aad67d63acd793c58718e2c7d13871814d990

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require "active_support/time"
require "twimock/version"
require "twimock/database"
require "twimock/config"
require "twimock/application"
require "twimock/user"
require "twimock/access_token"
require "twimock/request_token"
require "twimock/auth_hash"
require "twimock/errors"
require "twimock/api"
require "twimock/omniauth_twitter"

module Twimock
  extend self

  def auth_hash(access_token_string=nil)
    return Twimock::AuthHash.new unless validate_access_token_string(access_token_string)

    if access_token = Twimock::AccessToken.find_by_string(access_token_string)
      if user = Twimock::User.find_by_id(access_token.user_id)
        hash = Twimock::AuthHash.new({
          provider:    "twitter",
          uid:         user.id,
          info:        { name: user.name },
          credentials: { token: access_token.string, expires_at: Time.now + 60.days },
          extra:       { raw_info: { id: user.id, name: user.name } }
        })
      end
    end
    hash || Twimock::AuthHash.new
  end

  private

  def validate_access_token_string(string)
    string.kind_of?(String) && string.size > 0
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twimock-0.0.2 lib/twimock.rb
twimock-0.0.1 lib/twimock.rb