Class: Jammed::User

Inherits:
Object
  • Object
show all
Defined in:
lib/jammed/user.rb

Overview

Provides User objects for interacting with user-specific data

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (User) initialize(username, api_key)

Creates a new Jammed::User object and assigns a username to @username

Attributes

  • username - Username of user to make API calls with

Examples

iftfom = Jammed::User.new('IFTFOM', '08972935872035')


17
18
19
20
# File 'lib/jammed/user.rb', line 17

def initialize(username, api_key)
  @username = username
  @api_key = api_key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(name, *args, &block)

Checks user's profile for attribute and returns value if attribute key is found.

Examples

user = Jammed::User.new('IFTFOM', '08972935872035')
user.name #returns 'IFTFOM'
user.date_joined #uses js_namify to find 'dateJoined' key and returns date


135
136
137
138
139
# File 'lib/jammed/user.rb', line 135

def method_missing(name, *args, &block)
  n = name.to_s.index('_') != nil ? js_namify(name.to_s) : name.to_s

  profile.has_key?(n) ? profile[n] : super
end

Instance Attribute Details

- (Object) followers(opts = {})

Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable



6
7
8
# File 'lib/jammed/user.rb', line 6

def followers
  @followers
end

- (Object) following(opts = {})

Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable



6
7
8
# File 'lib/jammed/user.rb', line 6

def following
  @following
end

- (Object) jams(opts = {})

Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable



6
7
8
# File 'lib/jammed/user.rb', line 6

def jams
  @jams
end

- (Object) likes(opts = {})

Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable



6
7
8
# File 'lib/jammed/user.rb', line 6

def likes
  @likes
end

- (Object) profile

Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable



6
7
8
# File 'lib/jammed/user.rb', line 6

def profile
  @profile
end

- (Object) username

Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable



6
7
8
# File 'lib/jammed/user.rb', line 6

def username
  @username
end

Instance Method Details

- (Object) followers!(opts = {})

Clears cached Followers data with a fresh call to Jammed::Followers

Attributes

  • opts - Options for ordering Followers data

Options

  • :order - A symbol determining how the data is orderd like :date, :affinity, or :alpha

Examples

user = Jammed::User.new('IFTFOM', '08972935872035')
user.followers #returns all followers of IFTFOM
user.followers(:order => :date) #reutrns IFTFOM's followers ordered by date


41
42
43
# File 'lib/jammed/user.rb', line 41

def followers!(opts={})
  @followers = Jammed::Followers.followers(@username, @api_key, opts)
end

- (Object) following!(opts = {})

Clears cached Following data with a fresh call to Jammed::Following

Attributes

  • opts - Options for ordering Following data

Options

  • :order - A symbol determining how the data is orderd like :date, :affinity, or :alpha

Examples

user = Jammed::User.new('IFTFOM', '08972935872035')
user.following #returns all followings of IFTFOM
user.following(:order => :date) #returns IFTFOM's followings ordered by date


64
65
66
# File 'lib/jammed/user.rb', line 64

def following!(opts={})
  @following = Jammed::Following.following(@username, @api_key, opts)
end

- (Object) jams!(opts = {})

Clears cached Jams data with a fresh call to Jammed::Jams

Attributes

  • opts - Options for which data is shown

Options

  • :show - A symbol determining what data is shown like :past or :current

Examples

user = Jammed::User.new('IFTFOM', '08972935872035')
user.jams #returns all jams of IFTFOM
user.jams(:show => :past) #returns IFTFOM's past jams


87
88
89
# File 'lib/jammed/user.rb', line 87

def jams!(opts={})
  @jams = Jammed::Jams.jams(@username, @api_key, opts)
end

- (Object) js_namify(name)

Converts Ruby styled method names to JavaScript's prefered style. Used by method_missing to generate dynamic attributes methods for user's profile.

Attributes

  • name - Method name to be converted

Examples

js_namify('date_joined') #returns 'dateJoined'


150
151
152
153
154
155
156
# File 'lib/jammed/user.rb', line 150

def js_namify(name)
  x = []
  name.split('_').each_with_index do |e, i|
    i == 0 ? x << e.downcase : x << e.capitalize
  end
  x.join('')
end

- (Object) likes!(opts = {})

Clears cached Likes data with a fresh call to Jammed::Likes

Attributes

  • opts - Options for which data is shown

Options

  • :show - A symbol determining what data is shown like :past or :current

Examples

user = Jammed::User.new('IFTFOM', '08972935872035')
user.likes #returns all likes of IFTFOM
user.likes(:show => :past) #returns IFTFOM's past likes


110
111
112
# File 'lib/jammed/user.rb', line 110

def likes!(opts={})
  @likes = Jammed::Likes.likes(@username, @api_key, opts)
end

- (Object) profile!

Clears cached Person data with a fresh call to Jammed::Person

Examples

user = Jammed::User.new('IFTFOM', '08972935872035')
user.profile #returns entire profile of IFTFOM


124
125
126
# File 'lib/jammed/user.rb', line 124

def profile!
  @profile = Jammed::Person.profile(@username, @api_key)
end