Class: Jammed::User
- Inherits:
-
Object
- Object
- Jammed::User
- Defined in:
- lib/jammed/user.rb
Overview
Provides User objects for interacting with user-specific data
Instance Attribute Summary collapse
-
#followers(opts = {}) ⇒ Object
Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable.
-
#following(opts = {}) ⇒ Object
Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable.
-
#jams(opts = {}) ⇒ Object
Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable.
-
#likes(opts = {}) ⇒ Object
Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable.
-
#profile ⇒ Object
Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable.
-
#username ⇒ Object
Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable.
Instance Method Summary collapse
-
#followers!(opts = {}) ⇒ Object
Clears cached Followers data with a fresh call to Jammed::Followers.
-
#following!(opts = {}) ⇒ Object
Clears cached Following data with a fresh call to Jammed::Following.
-
#initialize(username, api_key, https = false) ⇒ User
constructor
Creates a new Jammed::User object and assigns a username to @username.
-
#jams!(opts = {}) ⇒ Object
Clears cached Jams data with a fresh call to Jammed::Jams.
-
#js_namify(name) ⇒ Object
Converts Ruby styled method names to JavaScript’s prefered style.
-
#likes!(opts = {}) ⇒ Object
Clears cached Likes data with a fresh call to Jammed::Likes.
-
#method_missing(name, *args, &block) ⇒ Object
Checks user’s profile for attribute and returns value if attribute key is found.
-
#profile! ⇒ Object
Clears cached Person data with a fresh call to Jammed::Person.
Constructor Details
#initialize(username, api_key, https = false) ⇒ User
17 18 19 20 21 |
# File 'lib/jammed/user.rb', line 17 def initialize(username, api_key, https=false) @username = username @api_key = api_key @https = https end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
144 145 146 147 148 |
# File 'lib/jammed/user.rb', line 144 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
#followers(opts = {}) ⇒ Object
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 |
#following(opts = {}) ⇒ Object
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 |
#jams(opts = {}) ⇒ Object
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 |
#likes(opts = {}) ⇒ Object
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 |
#profile ⇒ Object
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 |
#username ⇒ Object
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
#followers!(opts = {}) ⇒ Object
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
43 44 45 46 |
# File 'lib/jammed/user.rb', line 43 def followers!(opts={}) opts = opts.merge({:https => @https}) @followers = Jammed::Followers.followers(@username, @api_key, opts) end |
#following!(opts = {}) ⇒ Object
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
68 69 70 71 |
# File 'lib/jammed/user.rb', line 68 def following!(opts={}) opts = opts.merge({:https => @https}) @following = Jammed::Following.following(@username, @api_key, opts) end |
#jams!(opts = {}) ⇒ Object
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
93 94 95 96 |
# File 'lib/jammed/user.rb', line 93 def jams!(opts={}) opts = opts.merge({:https => @https}) @jams = Jammed::Jams.jams(@username, @api_key, opts) end |
#js_namify(name) ⇒ Object
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'
159 160 161 162 163 164 165 |
# File 'lib/jammed/user.rb', line 159 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 |
#likes!(opts = {}) ⇒ Object
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
118 119 120 121 |
# File 'lib/jammed/user.rb', line 118 def likes!(opts={}) opts = opts.merge({:https => @https}) @likes = Jammed::Likes.likes(@username, @api_key, opts) end |