Skip to content
Browse files

profile -> get_profile + instance vars

  • Loading branch information...
1 parent f52643b commit 8da0a5b86e480bad7fde5daad6d994c478166a50 @JackCA committed Mar 24, 2012
Showing with 31 additions and 6 deletions.
  1. +1 −1 lib/hypem/request.rb
  2. +15 −2 lib/hypem/user.rb
  3. +15 −3 spec/user_spec.rb
View
2 lib/hypem/request.rb
@@ -20,7 +20,7 @@ def get
def connection
@@conn ||= Faraday.new(url: 'http://hypem.com') do |builder|
builder.request :url_encoded
- builder.response :logger
+ #builder.response :logger
builder.adapter :net_http
end
end
View
17 lib/hypem/user.rb
@@ -1,13 +1,26 @@
module Hypem
class User
+ attr_reader :full_name, :joined_at, :location, :twitter_username, :image_url,
+ :followed_users_count, :followed_items_count, :followed_sites_count,
+ :followed_queries_count
def initialize(name)
raise ArgumentError unless name.is_a? String
@name = name
end
- def profile
- Request.new("/api/get_profile?username=#{@name}").get.response.body
+ def get_profile
+ response = Request.new("/api/get_profile?username=#{@name}").get.response.body
+ @full_name = response['fullname']
+ @joined_at = Time.at response['joined_ts']
+ @location = response['location']
+ @twitter_username = response['twitter_username']
+ @image_url = response['userpic']
+ @followed_users_count = response['favorites_count']['user']
+ @followed_items_count = response['favorites_count']['item']
+ @followed_sites_count = response['favorites_count']['site']
+ @followed_queries_count = response['favorites_count']['query']
+ return self
end
#playlist requests
View
18 spec/user_spec.rb
@@ -41,10 +41,22 @@
end
end
- it "gets profile stats" do
- VCR.use_cassette('user_profile') do
- user.profile.should be_a Hash
+ describe ".get_profile" do
+ let(:user_with_profile) do
+ VCR.use_cassette('user_profile') {Hypem::User.new('jackca').get_profile}
end
+
+ subject {user_with_profile}
+
+ its(:full_name) {should == "Jack Anderson"}
+ its(:joined_at) {should == Time.parse('2009-03-29 17:06:55 -0700')}
+ its(:location) {should == 'San Francisco, CA, US'}
+ its(:twitter_username) {should == 'janderson'}
+ its(:image_url) {should == 'http://faces-s3.hypem.com/123376863051420_75.png'}
+ its(:followed_users_count) {should == 4}
+ its(:followed_items_count) {should == 430}
+ its(:followed_sites_count) {should == 32}
+ its(:followed_queries_count) {should == 15}
end
end

0 comments on commit 8da0a5b

Please sign in to comment.
Something went wrong with that request. Please try again.