class Blockstack::User

Attributes

angellist_username[R]
avatar_url[R]
bio[R]
bitcoin_address[R]
bitcoinotc_username[R]
bitmessage_address[R]
cover_url[R]
facebook_username[R]
github_username[R]
instagram_username[R]
linkedin_url[R]
location_formatted[R]
name_formatted[R]
orgs[R]
pgp_fingerprint[R]
pgp_url[R]
schema_version[R]
twitter_username[R]
username[R]
website[R]

Public Class Methods

from_json(json, username) click to toggle source
# File lib/blockstack/user.rb, line 3
def self.from_json(json, username)
  User.new(json, username)
end
new(json, username) click to toggle source
# File lib/blockstack/user.rb, line 28
def initialize(json, username)
  json = json['profile'] if json['profile']

  if json['v'] == '0.2'
    @username = username
    @name_formatted = json['name']['formatted'] if json['name']
    @avatar_url = json['avatar']['url'] if json['avatar']
    @cover_url = json['cover']['url'] if json['cover']
    @location_formatted = json['location']['formatted'] if json['location']
    @website = json['website']
    @bio = json['bio']
    @angellist_username = json['angellist']['username'] if json['angellist']
    @github_username = json['github']['username'] if json['github']
    @facebook_username = json['facebook']['username'] if json['facebook']
    @twitter_username = json['twitter']['username'] if json['twitter']
    @instagram_username = json['instagram']['username'] if json['instagram']
    @linkedin_url = json['linkedin']['url'] if json['linkedin']
    @bitcoin_address = json['bitcoin']['address'] if json['bitcoin']
    @bitmessage_address = json['bitmessage']['address'] if json['bitmessage']
    @bitcoinotc_username = json['bitcoinotc']['username'] if json['bitcoinotc']
    @pgp_fingerprint = json['pgp']['fingerprint'] if json['pgp']
    @pgp_url = json['pgp']['url'] if json['pgp']
    @schema_version = json['v']
    @orgs = parse_orgs(json['orgs'])
  else
    @username = username
    @name_formatted = json['name'] if json['name']
    @avatar_url = find_image_url(json, 'avatar')
    @cover_url = find_image_url(json, 'cover')
    @location_formatted = json['address']['addressLocality'] if json['address']
    @website = json['website'][0]['url'] if json['website'] && json['website'][0]
    @bio = json['description']
    @angellist_username = find_account_username(json, 'angellist')
    @github_username = find_account_username(json, 'github')
    @facebook_username = find_account_username(json, 'facebook')
    @twitter_username = find_account_username(json, 'twitter')
    @instagram_username = find_account_username(json, 'instagram')
    @linkedin_url = find_account_username(json, 'linkedin')
    @bitcoin_address = find_account_username(json, 'bitcoin')
    @bitmessage_address = find_account_username(json, 'bitmessage')
    @bitcoinotc_username = find_account_username(json, 'bitcoinotc')
    @pgp_fingerprint = find_account_username(json, 'pgp')
    @pgp_url = find_account(json, 'pgp')['contentUrl'] if @pgp_fingerprint
    @schema_version = '0.3'
    @orgs = parse_orgs(json['orgs'])
  end
end

Public Instance Methods

openname() click to toggle source
# File lib/blockstack/user.rb, line 76
def openname
  warn '[DEPRECATION] `openname` is deprecated.  Please use `username` instead.'
  username
end

Protected Instance Methods

find_account(json, service) click to toggle source
# File lib/blockstack/user.rb, line 93
def find_account(json, service)
  accounts = json['account']
  if accounts && accounts.is_a?(Array)
    accounts.each do |account|
      return account if account['service'] == service
    end
  end
  nil
end
find_account_username(json, service) click to toggle source
# File lib/blockstack/user.rb, line 103
def find_account_username(json, service)
  account = find_account(json, service)
  return account['identifier'] if account
  nil
end
find_image_url(json, type) click to toggle source
# File lib/blockstack/user.rb, line 83
def find_image_url(json, type)
  images = json['image']
  if images && images.is_a?(Array)
    images.each do |image|
      return image['contentUrl'] if image['name'] == type
    end
  end
  nil
end
parse_orgs(orgs_json) click to toggle source
# File lib/blockstack/user.rb, line 109
def parse_orgs(orgs_json)
  orgs = []
  if orgs_json
    orgs_json.each do |org_json|
      orgs << Org.new(org_json)
    end
  end
  orgs
end