Class: TimesPeople::User
Constant Summary
Constants inherited from Base
Base::API_NAME, Base::API_SERVER, Base::API_VERSION
Instance Attribute Summary collapse
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#followers_count ⇒ Object
readonly
Returns the value of attribute followers_count.
-
#following_count ⇒ Object
readonly
Returns the value of attribute following_count.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#picture_url ⇒ Object
readonly
Returns the value of attribute picture_url.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
-
.find(email_addr) ⇒ Object
api.nytimes.com/svc/timespeople/api/version/user/hash/idresponse-format?api-key=your-API-key.
- .init_from_api(api_hash) ⇒ Object
Instance Method Summary collapse
-
#initialize(hash) ⇒ User
constructor
A new instance of User.
Methods inherited from Base
api_key, api_key=, build_request_url, date_field, debug=, integer_field, invoke, text_field
Constructor Details
#initialize(hash) ⇒ User
Returns a new instance of User.
7 8 9 10 11 12 13 14 |
# File 'lib/times_people/user.rb', line 7 def initialize(hash) @user_id = hash[:user_id] @display_name = hash[:display_name] @location = hash[:location] @picture_url = hash[:picture_url] @following_count = hash[:following_count] @followers_count = hash[:followers_count] end |
Instance Attribute Details
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name.
5 6 7 |
# File 'lib/times_people/user.rb', line 5 def display_name @display_name end |
#followers_count ⇒ Object (readonly)
Returns the value of attribute followers_count.
5 6 7 |
# File 'lib/times_people/user.rb', line 5 def followers_count @followers_count end |
#following_count ⇒ Object (readonly)
Returns the value of attribute following_count.
5 6 7 |
# File 'lib/times_people/user.rb', line 5 def following_count @following_count end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
5 6 7 |
# File 'lib/times_people/user.rb', line 5 def location @location end |
#picture_url ⇒ Object (readonly)
Returns the value of attribute picture_url.
5 6 7 |
# File 'lib/times_people/user.rb', line 5 def picture_url @picture_url end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/times_people/user.rb', line 5 def user_id @user_id end |
Class Method Details
.find(email_addr) ⇒ Object
api.nytimes.com/svc/timespeople/api/version/user/hash/idresponse-format?api-key=your-API-key
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/times_people/user.rb', line 17 def self.find(email_addr) digest = Digest::MD5.hexdigest(email_addr.downcase) begin reply = invoke("user/#{digest}/id") if reply.nil? raise UserNotFoundError, "No user with that email address was found in TimesPeople" end rescue ServerError raise UserNotFoundError, "No user with that email address was found in TimesPeople" end # http://api.nytimes.com/svc/timespeople/api/{version}/user/{user-id}/{data-type}{.response-format}?api-key={your-API-key} unless reply['results'].nil? || reply['results']['user_id'].nil? user_id = reply['results']['user_id'] reply = invoke("user/#{user_id}/profile") init_from_api(reply['results']) end end |
.init_from_api(api_hash) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/times_people/user.rb', line 38 def self.init_from_api(api_hash) new :user_id => api_hash['user_id'], :display_name => api_hash['user_displayname'], :location => api_hash['location'], :picture_url => api_hash['user_pic_url'], :following_count => api_hash['following_count'], :followers_count => api_hash['followers_count'] end |