jammed 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +44 -0
- data/examples/basics.rb +60 -0
- data/lib/jammed/base.rb +182 -0
- data/lib/jammed/followers.rb +36 -0
- data/lib/jammed/following.rb +36 -0
- data/lib/jammed/jams.rb +34 -0
- data/lib/jammed/likes.rb +32 -0
- data/lib/jammed/people_search.rb +55 -0
- data/lib/jammed/person.rb +32 -0
- data/lib/jammed/popular_jams.rb +14 -0
- data/lib/jammed/suggested_people.rb +14 -0
- data/lib/jammed/user.rb +158 -0
- data/lib/jammed/version.rb +4 -0
- data/lib/jammed.rb +28 -0
- data/spec/jammed/base_spec.rb +90 -0
- data/spec/jammed/followers_spec.rb +55 -0
- data/spec/jammed/following_spec.rb +55 -0
- data/spec/jammed/jams_spec.rb +53 -0
- data/spec/jammed/likes_spec.rb +51 -0
- data/spec/jammed/people_search_spec.rb +79 -0
- data/spec/jammed/person_spec.rb +38 -0
- data/spec/jammed/popular_jams_spec.rb +23 -0
- data/spec/jammed/suggested_people_spec.rb +18 -0
- data/spec/jammed/user_spec.rb +205 -0
- data/spec/sample_responses/followers.json +1495 -0
- data/spec/sample_responses/followers_affinity.json +1495 -0
- data/spec/sample_responses/followers_date.json +1281 -0
- data/spec/sample_responses/followers_name.json +0 -0
- data/spec/sample_responses/following.json +1495 -0
- data/spec/sample_responses/following_affinity.json +1495 -0
- data/spec/sample_responses/following_date.json +1406 -0
- data/spec/sample_responses/following_name.json +1406 -0
- data/spec/sample_responses/jams.json +620 -0
- data/spec/sample_responses/jams_past.json +602 -0
- data/spec/sample_responses/likes.json +1106 -0
- data/spec/sample_responses/likes_current.json +224 -0
- data/spec/sample_responses/likes_past.json +1106 -0
- data/spec/sample_responses/person.json +44 -0
- data/spec/sample_responses/popular.json +364 -0
- data/spec/sample_responses/search_artist.json +1377 -0
- data/spec/sample_responses/search_name.json +55 -0
- data/spec/sample_responses/search_track.json +1333 -0
- data/spec/sample_responses/suggested_people.json +1427 -0
- data/spec/spec_helper.rb +18 -0
- metadata +189 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sean S. Lerner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#Jammed [![Build Status](https://secure.travis-ci.org/seanslerner/Jammed.png?branch=master)](http://travis-ci.org/seanslerner/Jammed)
|
2
|
+
###A Ruby API wrapper for [This Is My Jam](http://www.thisismyjam.com/).
|
3
|
+
|
4
|
+
Note: The API for This Is My Jam is stil in beta, so if you'd like to use it please email the Jam team at api@thisismyjam.com to get on their mailing list.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'jammed'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install jammed
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Note: Right now, since the API is in beta, `Jammed.new` can be called without supplying an API key (it defaults to the beta key). Once individual dev keys are available this will change.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'jammed'
|
26
|
+
|
27
|
+
jammed = Jammed.new('987bcab01b929eb2c07877b224215c92')
|
28
|
+
|
29
|
+
pop_jams = jammed.popular_jams
|
30
|
+
|
31
|
+
iftfom_profile = jammed.profile('IFTFOM')
|
32
|
+
iftfom_likes = jammed.likes('IFTFOM', :show => :current)
|
33
|
+
|
34
|
+
iftfom = jammed.user('IFTFOM')
|
35
|
+
iftfom.profile # same as jammed.profile('IFTFOM')
|
36
|
+
iftfom.likes(:show => :current) # same as jammed.likes('IFTFOM', :show => :current)
|
37
|
+
iftfom.likes! #resets cached likes and return all of IFTFOM's like
|
38
|
+
```
|
39
|
+
|
40
|
+
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.
|
41
|
+
|
42
|
+
## Links
|
43
|
+
|
44
|
+
* [This Is My Jam](http://www.thisismyjam.com/)
|
45
|
+
* [This Is My Jam API Documentation](http://www.thisismyjam.com/developers/beta)
|
46
|
+
* [This Is My Jam API Google Group](https://groups.google.com/forum/?fromgroups#!forum/thisismyapi)
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require File.expand_path('../lib/jammed/version', __FILE__)
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "jammed"
|
17
|
+
gem.homepage = "https://github.com/seanslerner/Jammed"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %q{A Ruby wrapper for This Is My Jam's API}
|
20
|
+
gem.description = %q{Jammed wraps the This Is My Jam API. More information about the This Is My Jam API can be found on their website (http://www.thisismyjam.com/developers).}
|
21
|
+
gem.email = ["seanslerner@gmail.com"]
|
22
|
+
gem.authors = ["Sean Lerner", "Rob Young", "Mike Chlipala"]
|
23
|
+
gem.files = `git ls-files`.split($\)
|
24
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
25
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
26
|
+
gem.require_paths = ["lib"]
|
27
|
+
gem.version = Jammed::VERSION
|
28
|
+
# dependencies defined in Gemfile
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec)
|
34
|
+
task default: :spec
|
35
|
+
|
36
|
+
require 'rdoc/task'
|
37
|
+
Rake::RDocTask.new do |rdoc|
|
38
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
39
|
+
|
40
|
+
rdoc.rdoc_dir = 'rdoc'
|
41
|
+
rdoc.title = "Jammed #{version}"
|
42
|
+
rdoc.rdoc_files.include('README*')
|
43
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
44
|
+
end
|
data/examples/basics.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'jammed'
|
2
|
+
|
3
|
+
api_key = '987bcab01b929eb2c07877b224215c92'
|
4
|
+
|
5
|
+
jammed = Jammed.new(api_key)
|
6
|
+
|
7
|
+
# Print out a user's profile data
|
8
|
+
puts "IFTFOM's Profile:"
|
9
|
+
jammed.profile('IFTFOM').each {|k, v| puts "#{k} : #{v}"}
|
10
|
+
|
11
|
+
# Print out the names of all followers, followings, jams, and likes
|
12
|
+
puts "Followers:"
|
13
|
+
jammed.followers('IFTFOM').each { |f| puts f['name']}
|
14
|
+
|
15
|
+
puts "Followings:"
|
16
|
+
jammed.following('IFTFOM').each { |f| puts f['name']}
|
17
|
+
|
18
|
+
puts "Jams:"
|
19
|
+
jammed.jams('IFTFOM').each { |j| puts "#{j['artist']}: #{j['title']}"}
|
20
|
+
|
21
|
+
puts "Likes:"
|
22
|
+
jammed.likes('IFTFOM').each { |l| puts "#{l['artist']}: #{l['title']}"}
|
23
|
+
|
24
|
+
# Alternative way to access user-specific data:
|
25
|
+
# The Jammed::User object caches data, so each method
|
26
|
+
# has a 'dangerous' version (ie #followers!) that clears
|
27
|
+
# and resets the cached data
|
28
|
+
iftfom = jammed.user('IFTFOM')
|
29
|
+
|
30
|
+
puts "Followers:"
|
31
|
+
iftfom.followers.each { |f| puts f['name']}
|
32
|
+
|
33
|
+
puts "Followings:"
|
34
|
+
iftfom.following.each { |f| puts f['name']}
|
35
|
+
|
36
|
+
puts "Jams:"
|
37
|
+
iftfom.jams.each { |j| puts "#{j['artist']}: #{j['title']}"}
|
38
|
+
|
39
|
+
puts "Likes:"
|
40
|
+
iftfom.likes.each { |l| puts "#{l['artist']}: #{l['title']}"}
|
41
|
+
|
42
|
+
puts "IFTFOM's Profile:"
|
43
|
+
iftfom.profile.each {|k, v| puts "#{k} : #{v}"}
|
44
|
+
|
45
|
+
# Non-user specific data
|
46
|
+
puts "Popular Jams:"
|
47
|
+
jammed.popular_jams.each { |j| puts "#{j['artist']}: #{j['title']}"}
|
48
|
+
|
49
|
+
puts "Suggested People:"
|
50
|
+
jammed.suggested_people.each { |p| puts p['name']}
|
51
|
+
|
52
|
+
#Searches
|
53
|
+
puts "Search by Name:"
|
54
|
+
jammed.search_name('IFTFOM').each {|p| puts p['name']}
|
55
|
+
|
56
|
+
puts "Search by Artist:"
|
57
|
+
jammed.search_artist('Talking Heads').each {|p| puts p['name']}
|
58
|
+
|
59
|
+
puts "Search by Track:"
|
60
|
+
jammed.search_track('The The', 'This is the Day').each {|p| puts p['name']}
|
data/lib/jammed/base.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
module Jammed
|
2
|
+
# A base class for interacting with the API
|
3
|
+
class Base
|
4
|
+
|
5
|
+
#Stores the API key to be used for all method calls on the Jammed::Base object
|
6
|
+
attr_reader :api_key
|
7
|
+
|
8
|
+
#Sets the API key + any options
|
9
|
+
def initialize(api_key, opts={})
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
# Calls Jammed::Followers
|
14
|
+
#
|
15
|
+
# ==== Attributes
|
16
|
+
#
|
17
|
+
# * +username+ - Username of user whose followers you want to retrieve
|
18
|
+
# * +opts+ - Options for ordering Followers data
|
19
|
+
#
|
20
|
+
# ==== Options
|
21
|
+
#
|
22
|
+
# * +:order+ - A symbol determining how the data is orderd like :date, :affinity, or :alpha
|
23
|
+
#
|
24
|
+
# ==== Examples
|
25
|
+
#
|
26
|
+
# jammed = Jammed.new('08972935872035')
|
27
|
+
# jammed.followers('IFTFOM', :order => :date)
|
28
|
+
def followers(username, opts={})
|
29
|
+
Followers.followers(username, @api_key, opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Calls Jammed::Following
|
33
|
+
#
|
34
|
+
# ==== Attributes
|
35
|
+
#
|
36
|
+
# * +username+ - Username of user whose followings you want to retrieve
|
37
|
+
# * +opts+ - Options for ordering Following data
|
38
|
+
#
|
39
|
+
# ==== Options
|
40
|
+
#
|
41
|
+
# * +:order+ - A symbol determining how the data is orderd like :date, :affinity, or :alpha
|
42
|
+
#
|
43
|
+
# ==== Examples
|
44
|
+
#
|
45
|
+
# jammed = Jammed.new('08972935872035')
|
46
|
+
# jammed.following('IFTFOM', :order => :date)
|
47
|
+
def following(username, opts={})
|
48
|
+
Following.following(username, @api_key, opts)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Calls Jammed::Jams
|
52
|
+
#
|
53
|
+
# ==== Attributes
|
54
|
+
#
|
55
|
+
# * +username+ - Username of user whose jams you want to retrieve
|
56
|
+
# * +opts+ - Options for which jams to retrieve
|
57
|
+
#
|
58
|
+
# ==== Options
|
59
|
+
#
|
60
|
+
# * +:show+ - A symbol determining which data is shown (:past | :current)
|
61
|
+
#
|
62
|
+
# ==== Examples
|
63
|
+
#
|
64
|
+
# jammed = Jammed.new('08972935872035')
|
65
|
+
# jammed.jams('IFTFOM', :show => :current)
|
66
|
+
def jams(username, opts={})
|
67
|
+
Jams.jams(username, @api_key, opts)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Calls Jammed::Likes.likes
|
71
|
+
#
|
72
|
+
# ==== Attributes
|
73
|
+
#
|
74
|
+
# * +username+ - Username of user whose likes you want to retrieve
|
75
|
+
# * +opts+ - Options for which likes to retrieve
|
76
|
+
#
|
77
|
+
# ==== Options
|
78
|
+
#
|
79
|
+
# * +:show+ - A symbol determining which data is shown (:past | :current)
|
80
|
+
#
|
81
|
+
# ==== Examples
|
82
|
+
#
|
83
|
+
# jammed = Jammed.new('08972935872035')
|
84
|
+
# jammed.likes('IFTFOM', :show => :current)
|
85
|
+
def likes(username, opts={})
|
86
|
+
Likes.likes(username, @api_key, opts)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Calls Jammed::PopularJams.popular_jams
|
90
|
+
#
|
91
|
+
# ==== Examples
|
92
|
+
#
|
93
|
+
# jammed = Jammed.new('08972935872035')
|
94
|
+
# jammed.popular_jams
|
95
|
+
def popular_jams
|
96
|
+
PopularJams.popular_jams(@api_key)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Calls Jammed::Person.profile
|
100
|
+
#
|
101
|
+
# ==== Attributes
|
102
|
+
#
|
103
|
+
# * +username+ - Username of user profile want to retrieve
|
104
|
+
#
|
105
|
+
# ==== Examples
|
106
|
+
#
|
107
|
+
# jammed = Jammed.new('08972935872035')
|
108
|
+
# jammed.profile('IFTFOM')
|
109
|
+
def profile(username)
|
110
|
+
Person.profile(username, @api_key)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Calls Jammed::PeopleSearch.search_name
|
114
|
+
#
|
115
|
+
# ==== Attributes
|
116
|
+
#
|
117
|
+
# *+name+ - Name you want to search by
|
118
|
+
#
|
119
|
+
# ==== Examples
|
120
|
+
#
|
121
|
+
# jammed = Jammed.new('08972935872035')
|
122
|
+
# jammed.search_name('IFTFOM')
|
123
|
+
def search_name(name)
|
124
|
+
PeopleSearch.search_name(name, @api_key)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Calls Jammed::PeopleSearch.search_artist
|
128
|
+
#
|
129
|
+
# ==== Attributes
|
130
|
+
#
|
131
|
+
# *+artist+ - Artist you want to search by
|
132
|
+
#
|
133
|
+
# ==== Examples
|
134
|
+
#
|
135
|
+
# jammed = Jammed.new('08972935872035')
|
136
|
+
# jammed.search_artist('IFTFOM')
|
137
|
+
def search_artist(artist)
|
138
|
+
PeopleSearch.search_artist(artist, @api_key)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Calls Jammed::PeopleSearch.search_track
|
142
|
+
#
|
143
|
+
# ==== Attributes
|
144
|
+
#
|
145
|
+
# *+artist+ - Artist you want to search by
|
146
|
+
# *+track+ - Track you want to search by
|
147
|
+
#
|
148
|
+
# ==== Examples
|
149
|
+
#
|
150
|
+
# jammed = Jammed.new('08972935872035')
|
151
|
+
# jammed.search_track('IFTFOM')
|
152
|
+
def search_track(artist, track)
|
153
|
+
PeopleSearch.search_track(artist, track, @api_key)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Calls Jammed::SuggestedPeople.people
|
157
|
+
#
|
158
|
+
# ==== Examples
|
159
|
+
#
|
160
|
+
# jammed = Jammed.new('08972935872035')
|
161
|
+
# jammed.suggest_people
|
162
|
+
def suggested_people
|
163
|
+
SuggestedPeople.people(@api_key)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Calls Jammed::User.new and creates a new User object for interacting with user specific data. It provides methods for interacting with user-specific data.
|
167
|
+
#
|
168
|
+
# ==== Attributes
|
169
|
+
#
|
170
|
+
# * +username+ - Username of user you want the object oriented with
|
171
|
+
#
|
172
|
+
# ==== Examples
|
173
|
+
#
|
174
|
+
# jammed = Jammed.new('08972935872035')
|
175
|
+
# ift = jammed.user('IFTFOM')
|
176
|
+
# ift.profile
|
177
|
+
# ift.jams(:show => :past)
|
178
|
+
def user(username)
|
179
|
+
User.new(username, @api_key)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides methods for calling API endpoint /follower.json?
|
3
|
+
class Followers
|
4
|
+
# Calls API for user specific data concerning followers
|
5
|
+
#
|
6
|
+
# ==== Attributes
|
7
|
+
#
|
8
|
+
# * +username+ - The username of the user whose followers you want to retrieve
|
9
|
+
# * +api_key+ - The key to use with the API call
|
10
|
+
# * +opts+ - Options for ordering the data
|
11
|
+
#
|
12
|
+
# ==== Options
|
13
|
+
#
|
14
|
+
# * +:order+ - A symbol determining how the data is orderd like :date, :affinity, or :alpha
|
15
|
+
#
|
16
|
+
# ==== Examples
|
17
|
+
#
|
18
|
+
# Jammed::Followers.followers('IFTFOM', '08972935872035') #returns followers unorderd
|
19
|
+
# Jammed::Followers.followers('IFTFOM', '08972935872035', :order => :date) # returns followers ordered by date
|
20
|
+
def self.followers(username, api_key, opts={})
|
21
|
+
case(opts[:order])
|
22
|
+
when nil
|
23
|
+
followers = Search.get "/#{username}/followers.json?key=#{api_key}"
|
24
|
+
when :date
|
25
|
+
followers = Search.get "/#{username}/followers.json?order=followedDate&key=#{api_key}"
|
26
|
+
when :affinity
|
27
|
+
followers = Search.get "/#{username}/followers.json?order=affinity&key=#{api_key}"
|
28
|
+
when :alpha
|
29
|
+
followers = Search.get "/#{username}/followers.json?order=name&key=#{api_key}"
|
30
|
+
else
|
31
|
+
return "Cannot order Followers by #{opts[:order]}"
|
32
|
+
end
|
33
|
+
followers["people"] ? followers["people"] : "404 Not Found"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides methods for calling API endpoint /following.json?
|
3
|
+
class Following
|
4
|
+
# Calls API for user specific data concerning who the user is following
|
5
|
+
#
|
6
|
+
# ==== Attributes
|
7
|
+
#
|
8
|
+
# * +username+ - The username of the user whose followings you want to retrieve
|
9
|
+
# * +api_key+ - The key to use with the API call
|
10
|
+
# * +opts+ - Options for ordering the data
|
11
|
+
#
|
12
|
+
# ==== Options
|
13
|
+
#
|
14
|
+
# * +:order+ - A symbol determining how the data is orderd like :date, :affinity, or :alpha
|
15
|
+
#
|
16
|
+
# ==== Examples
|
17
|
+
#
|
18
|
+
# Jammed::Following.following('IFTFOM', '08972935872035') #returns followings unorderd
|
19
|
+
# Jammed::Following.following('IFTFOM', '08972935872035', :order => :date) # returns followings ordered by date
|
20
|
+
def self.following(username, api_key, opts={})
|
21
|
+
case(opts[:order])
|
22
|
+
when nil
|
23
|
+
followings = Search.get "/#{username}/following.json?key=#{api_key}"
|
24
|
+
when :date
|
25
|
+
followings = Search.get "/#{username}/following.json?order=followedDate&key=#{api_key}"
|
26
|
+
when :affinity
|
27
|
+
followings = Search.get "/#{username}/following.json?order=affinity&key=#{api_key}"
|
28
|
+
when :alpha
|
29
|
+
followings = Search.get "/#{username}/following.json?order=name&key=#{api_key}"
|
30
|
+
else
|
31
|
+
return "Cannot order Followings by #{opts[:order]}"
|
32
|
+
end
|
33
|
+
followings["people"] ? followings["people"] : "404 Not Found"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/jammed/jams.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides methods for calling API endpoint /jams.json?
|
3
|
+
class Jams
|
4
|
+
# Calls API for user specific data concerning jams
|
5
|
+
#
|
6
|
+
# ==== Attributes
|
7
|
+
#
|
8
|
+
# * +username+ - The username of the user whose followings you want to retrieve
|
9
|
+
# * +api_key+ - The key to use with the API call
|
10
|
+
# * +opts+ - Options for which data is shown
|
11
|
+
#
|
12
|
+
# ==== Options
|
13
|
+
#
|
14
|
+
# * +:show+ - A symbol determining what data is shown like :past or :current
|
15
|
+
#
|
16
|
+
# ==== Examples
|
17
|
+
#
|
18
|
+
# Jammed::Jams.jams('IFTFOM', '08972935872035') #returns all jams
|
19
|
+
# Jammed::Jams.jams('IFTFOM', '08972935872035', :show => :past) # returns only past jams
|
20
|
+
def self.jams(username, api_key, opts={})
|
21
|
+
case(opts[:show])
|
22
|
+
when nil
|
23
|
+
jams = Search.get "/#{username}/jams.json?key=#{api_key}"
|
24
|
+
jams["jams"] ? jams["jams"] : "404: User Not Found"
|
25
|
+
when :past
|
26
|
+
jams = Search.get "/#{username}/jams.json?show=past&key=#{api_key}"
|
27
|
+
jams["jams"] ? jams["jams"] : "404: User Not Found"
|
28
|
+
when :current
|
29
|
+
jams = Search.get "/#{username}/jams.json?key=#{api_key}"
|
30
|
+
jams["jams"][0]['current'] ? jams["jams"][0] : "No Current Jam"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/jammed/likes.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides methods for calling API endpoint /likes.json?
|
3
|
+
class Likes
|
4
|
+
# Calls API for user specific data concerning likes
|
5
|
+
#
|
6
|
+
# ==== Attributes
|
7
|
+
#
|
8
|
+
# * +username+ - The username of the user whose followings you want to retrieve
|
9
|
+
# * +api_key+ - The key to use with the API call
|
10
|
+
# * +opts+ - Options for which data is shown
|
11
|
+
#
|
12
|
+
# ==== Options
|
13
|
+
#
|
14
|
+
# * +:show+ - A symbol determining what data is shown like :past or :current
|
15
|
+
#
|
16
|
+
# ==== Examples
|
17
|
+
#
|
18
|
+
# Jammed::Likes.likes('IFTFOM', '08972935872035') #returns all likes
|
19
|
+
# Jammed::Likes.likes('IFTFOM', '08972935872035', :show => :past) # returns only past likes
|
20
|
+
def self.likes(username, api_key, opts={})
|
21
|
+
case(opts[:show])
|
22
|
+
when nil
|
23
|
+
likes = Search.get "/#{username}/likes.json?key=#{api_key}"
|
24
|
+
when :current
|
25
|
+
likes = Search.get "/#{username}/likes.json?show=current&key=#{api_key}"
|
26
|
+
when :past
|
27
|
+
likes = Search.get "/#{username}/likes.json?show=past&key=#{api_key}"
|
28
|
+
end
|
29
|
+
likes["jams"] ? likes["jams"] : "404: Not Found"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Jammed #:nodoc:
|
4
|
+
# Provides methods for calling API endpoint /person.json?by=
|
5
|
+
class PeopleSearch
|
6
|
+
|
7
|
+
# Calls API for a search by username
|
8
|
+
#
|
9
|
+
# ==== Attributes
|
10
|
+
#
|
11
|
+
# * +name+ - Username to search by
|
12
|
+
# * +api_key+ - The key to use with the API call
|
13
|
+
#
|
14
|
+
# ==== Examples
|
15
|
+
#
|
16
|
+
# Jammed::PeopleSearch.search_name('IFTFOM', '08972935872035')
|
17
|
+
def self.search_name(name, api_key)
|
18
|
+
search = Search.get "/search/person.json?by=name&q=#{name.split.join('+')}&key=#{api_key}"
|
19
|
+
search["people"][0] ? search["people"] : "No people found"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Calls API for a search by artist
|
23
|
+
#
|
24
|
+
# ==== Attributes
|
25
|
+
#
|
26
|
+
# * +artist+ - Artist to search by
|
27
|
+
# * +api_key+ - The key to use with the API call
|
28
|
+
#
|
29
|
+
# ==== Examples
|
30
|
+
#
|
31
|
+
# Jammed::PeopleSearch.search_artist('beach boys', '08972935872035')
|
32
|
+
def self.search_artist(artist, api_key)
|
33
|
+
search = Search.get "/search/person.json?by=artist&q=#{artist.split.join('+')}&key=#{api_key}"
|
34
|
+
search["people"][0] ? search["people"] : "No artists found"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Calls API for a search by track
|
38
|
+
#
|
39
|
+
# ==== Attributes
|
40
|
+
#
|
41
|
+
# * +artist+ - Artist to search by
|
42
|
+
# * +track+ - Track to search by
|
43
|
+
# * +api_key+ - The key to use with the API call
|
44
|
+
#
|
45
|
+
# ==== Examples
|
46
|
+
#
|
47
|
+
# Jammed::PeopleSearch.search_track('beach boys', 'good vibrations', '08972935872035')
|
48
|
+
def self.search_track(artist, track, api_key)
|
49
|
+
uri = URI.escape("/search/person.json?by=track&q=#{artist.split.join('+')}|#{track.split.join('+')}&key=#{api_key}", '|')
|
50
|
+
search = Search.get uri
|
51
|
+
search["people"][0] ? search["people"] : "No tracks found"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides methods for calling API endpoint /username.json? and accessing user specific data
|
3
|
+
class Person
|
4
|
+
# Calls API for a specific user's profile
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# Jammed::Person.profile('IFTFOM', '08972935872035') #returns IFTFOM's profile data
|
9
|
+
def self.profile(username, api_key)
|
10
|
+
profile = Search.get "/#{username}.json?key=#{api_key}"
|
11
|
+
profile["person"] ? profile["person"] : "404: User Not Found"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Calls API for a specific user's name
|
15
|
+
#
|
16
|
+
# ==== Examples
|
17
|
+
#
|
18
|
+
# Jammed::Person.name('IFTFOM', '08972935872035') #returns 'IFTFOM'
|
19
|
+
def self.name(username, api_key)
|
20
|
+
self.profile(username, api_key)['name']
|
21
|
+
end
|
22
|
+
|
23
|
+
# Calls API for a specific attribute of a user's profile
|
24
|
+
#
|
25
|
+
# ==== Examples
|
26
|
+
#
|
27
|
+
# Jammed::Person.joinedDate('IFTFOM', '08972935872035') #returns IFTFOM's joined date
|
28
|
+
def self.method_missing(name, *args, &block)
|
29
|
+
self.profile(args[0],args[1]).has_key?(name.to_s) ? self.profile(args[0],args[1])[name.to_s] : super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides method for calling API endpoint /popular.json?
|
3
|
+
class PopularJams
|
4
|
+
# Calls API for popular jams
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# Jammed::PopularJams.popular_jams('08972935872035') #returns a sample of popular jams
|
9
|
+
def self.popular_jams(api_key)
|
10
|
+
search = Search.get "/popular.json?key=#{api_key}"
|
11
|
+
search['jams'] ? search['jams'] : "404 Not Found"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides method for calling API endpoint /suggestedPeople.json?
|
3
|
+
class SuggestedPeople
|
4
|
+
# Calls API for suggested people
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# Jammed::SuggestedPeople.people('08972935872035') #returns a list of users with many followers/likes
|
9
|
+
def self.people(api_key)
|
10
|
+
response = Search.get "/suggestedPeople.json?key=#{api_key}"
|
11
|
+
response["people"][0] ? response["people"] : "No people found"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|