Permalink
Browse files

basic examples + fix return for PopularJams

  • Loading branch information...
1 parent d8275ea commit 4f52b14abfdc6f108990067db047da5b8dcf42fe @seanslerner committed Apr 20, 2012
Showing with 69 additions and 5 deletions.
  1. +4 −1 README.md
  2. +60 −0 examples/basics.rb
  3. +2 −1 lib/jammed/popular_jams.rb
  4. +3 −3 spec/jammed/popular_jams_spec.rb
View
@@ -29,13 +29,16 @@ jammed = Jammed.new('987bcab01b929eb2c07877b224215c92')
pop_jams = jammed.popular_jams
iftfom_profile = jammed.profile('IFTFOM')
-iftfom_liks = jammed.likes('IFTFOM', :show => :current)
+iftfom_likes = jammed.likes('IFTFOM', :show => :current)
iftfom = jammed.user('IFTFOM')
iftfom.profile # same as jammed.profile('IFTFOM')
iftfom.likes(:show => :current) # same as jammed.likes('IFTFOM', :show => :current)
+iftfom.likes! #resets cached likes and return all of IFTFOM's like
```
+Also, pagination is not supported at the moment. So, at most you will get the first 60 results for any API call that returns a list. Automatically handling pagination is a first priority for the next release.
+
## Links
* [This Is My Jam](http://www.thisismyjam.com/)
View
@@ -0,0 +1,60 @@
+require 'jammed'
+
+api_key = '987bcab01b929eb2c07877b224215c92'
+
+jammed = Jammed.new(api_key)
+
+# Print out a user's profile data
+puts "IFTFOM's Profile:"
+jammed.profile('IFTFOM').each {|k, v| puts "#{k} : #{v}"}
+
+# Print out the names of all followers, followings, jams, and likes
+puts "Followers:"
+jammed.followers('IFTFOM').each { |f| puts f['name']}
+
+puts "Followings:"
+jammed.following('IFTFOM').each { |f| puts f['name']}
+
+puts "Jams:"
+jammed.jams('IFTFOM').each { |j| puts "#{j['artist']}: #{j['title']}"}
+
+puts "Likes:"
+jammed.likes('IFTFOM').each { |l| puts "#{l['artist']}: #{l['title']}"}
+
+# Alternative way to access user-specific data:
+# The Jammed::User object caches data, so each method
+# has a 'dangerous' version (ie #followers!) that clears
+# and resets the cached data
+iftfom = jammed.user('IFTFOM')
+
+puts "Followers:"
+iftfom.followers.each { |f| puts f['name']}
+
+puts "Followings:"
+iftfom.following.each { |f| puts f['name']}
+
+puts "Jams:"
+iftfom.jams.each { |j| puts "#{j['artist']}: #{j['title']}"}
+
+puts "Likes:"
+iftfom.likes.each { |l| puts "#{l['artist']}: #{l['title']}"}
+
+puts "IFTFOM's Profile:"
+iftfom.profile.each {|k, v| puts "#{k} : #{v}"}
+
+# Non-user specific data
+puts "Popular Jams:"
+jammed.popular_jams.each { |j| puts "#{j['artist']}: #{j['title']}"}
+
+puts "Suggested People:"
+jammed.suggested_people.each { |p| puts p['name']}
+
+#Searches
+puts "Search by Name:"
+jammed.search_name('IFTFOM').each {|p| puts p['name']}
+
+puts "Search by Artist:"
+jammed.search_artist('Talking Heads').each {|p| puts p['name']}
+
+puts "Search by Track:"
+jammed.search_track('The The', 'This is the Day').each {|p| puts p['name']}
@@ -13,7 +13,8 @@ class Search #:nodoc:
#
# Jammed::PopularJams.popular_jams('08972935872035') #returns a sample of popular jams
def self.popular_jams(api_key)
- Search.get "/popular.json?key=#{api_key}"
+ search = Search.get "/popular.json?key=#{api_key}"
+ search['jams'] ? search['jams'] : "404 Not Found"
end
end
end
@@ -11,12 +11,12 @@ module Jammed
serve_response("http://api.thisismyjam.com/1/popular.json?key=987bcab01b929eb2c07877b224215c92", :popular)
end
- it "parses the JSON return into a hash" do
- Jammed::PopularJams.popular_jams(api_key).should be_an_instance_of Hash
+ it "parses the JSON return into an array of Jams" do
+ Jammed::PopularJams.popular_jams(api_key).should be_an_instance_of Array
end
it "gets popular jams from the api" do
- Jammed::PopularJams.popular_jams(api_key)["jams"].should_not be_nil
+ Jammed::PopularJams.popular_jams(api_key).should_not be_nil
end
end
end

0 comments on commit 4f52b14

Please sign in to comment.