jammed 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -0
- data/README.md +7 -1
- data/jammed.gemspec +115 -0
- data/lib/jammed/api.rb +55 -0
- data/lib/jammed/base.rb +10 -0
- data/lib/jammed/errors.rb +29 -0
- data/lib/jammed/followers.rb +10 -6
- data/lib/jammed/following.rb +10 -6
- data/lib/jammed/jams.rb +11 -7
- data/lib/jammed/likes.rb +8 -5
- data/lib/jammed/people_search.rb +12 -8
- data/lib/jammed/person.rb +4 -4
- data/lib/jammed/popular_jams.rb +3 -3
- data/lib/jammed/random.rb +14 -0
- data/lib/jammed/suggested_people.rb +3 -3
- data/lib/jammed/version.rb +1 -1
- data/lib/jammed.rb +2 -7
- data/spec/jammed/api_spec.rb +19 -0
- data/spec/jammed/base_spec.rb +7 -0
- data/spec/jammed/error_spec.rb +35 -0
- data/spec/jammed/people_search_spec.rb +4 -2
- data/spec/jammed/person_spec.rb +1 -1
- data/spec/jammed/random_spec.rb +23 -0
- data/spec/jammed/user_spec.rb +1 -1
- data/spec/sample_responses/bad_request.json +6 -0
- data/spec/sample_responses/not_found.json +6 -0
- data/spec/sample_responses/random.json +44 -0
- data/spec/spec_helper.rb +2 -2
- metadata +40 -13
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#Jammed [![Build Status]
|
1
|
+
#Jammed [![Build History][2]][1] [![Dependency Status][4]][3]
|
2
|
+
|
2
3
|
###A Ruby API wrapper for [This Is My Jam](http://www.thisismyjam.com/).
|
3
4
|
|
4
5
|
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.
|
@@ -52,3 +53,8 @@ Also, pagination is not supported at the moment. So, at most you will get the fi
|
|
52
53
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
54
|
4. Push to the branch (`git push origin my-new-feature`)
|
54
55
|
5. Create new Pull Request
|
56
|
+
|
57
|
+
[1]: http://travis-ci.org/seanslerner/Jammed
|
58
|
+
[2]: https://secure.travis-ci.org/seanslerner/Jammed.png?branch=master
|
59
|
+
[3]: https://gemnasium.com/seanslerner/jammed
|
60
|
+
[4]: https://gemnasium.com/seanslerner/Jammed.png
|
data/jammed.gemspec
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "jammed"
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Sean Lerner", "Rob Young", "Mike Chlipala"]
|
12
|
+
s.date = "2012-05-07"
|
13
|
+
s.description = "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)."
|
14
|
+
s.email = ["seanslerner@gmail.com"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
".rspec",
|
22
|
+
".travis.yml",
|
23
|
+
"Gemfile",
|
24
|
+
"LICENSE",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"examples/basics.rb",
|
28
|
+
"jammed.gemspec",
|
29
|
+
"lib/jammed.rb",
|
30
|
+
"lib/jammed/api.rb",
|
31
|
+
"lib/jammed/base.rb",
|
32
|
+
"lib/jammed/errors.rb",
|
33
|
+
"lib/jammed/followers.rb",
|
34
|
+
"lib/jammed/following.rb",
|
35
|
+
"lib/jammed/jams.rb",
|
36
|
+
"lib/jammed/likes.rb",
|
37
|
+
"lib/jammed/people_search.rb",
|
38
|
+
"lib/jammed/person.rb",
|
39
|
+
"lib/jammed/popular_jams.rb",
|
40
|
+
"lib/jammed/random.rb",
|
41
|
+
"lib/jammed/suggested_people.rb",
|
42
|
+
"lib/jammed/user.rb",
|
43
|
+
"lib/jammed/version.rb",
|
44
|
+
"spec/jammed/api_spec.rb",
|
45
|
+
"spec/jammed/base_spec.rb",
|
46
|
+
"spec/jammed/error_spec.rb",
|
47
|
+
"spec/jammed/followers_spec.rb",
|
48
|
+
"spec/jammed/following_spec.rb",
|
49
|
+
"spec/jammed/jams_spec.rb",
|
50
|
+
"spec/jammed/likes_spec.rb",
|
51
|
+
"spec/jammed/people_search_spec.rb",
|
52
|
+
"spec/jammed/person_spec.rb",
|
53
|
+
"spec/jammed/popular_jams_spec.rb",
|
54
|
+
"spec/jammed/random_spec.rb",
|
55
|
+
"spec/jammed/suggested_people_spec.rb",
|
56
|
+
"spec/jammed/user_spec.rb",
|
57
|
+
"spec/sample_responses/bad_request.json",
|
58
|
+
"spec/sample_responses/followers.json",
|
59
|
+
"spec/sample_responses/followers_affinity.json",
|
60
|
+
"spec/sample_responses/followers_date.json",
|
61
|
+
"spec/sample_responses/followers_name.json",
|
62
|
+
"spec/sample_responses/following.json",
|
63
|
+
"spec/sample_responses/following_affinity.json",
|
64
|
+
"spec/sample_responses/following_date.json",
|
65
|
+
"spec/sample_responses/following_name.json",
|
66
|
+
"spec/sample_responses/jams.json",
|
67
|
+
"spec/sample_responses/jams_past.json",
|
68
|
+
"spec/sample_responses/likes.json",
|
69
|
+
"spec/sample_responses/likes_current.json",
|
70
|
+
"spec/sample_responses/likes_past.json",
|
71
|
+
"spec/sample_responses/not_found.json",
|
72
|
+
"spec/sample_responses/person.json",
|
73
|
+
"spec/sample_responses/popular.json",
|
74
|
+
"spec/sample_responses/random.json",
|
75
|
+
"spec/sample_responses/search_artist.json",
|
76
|
+
"spec/sample_responses/search_name.json",
|
77
|
+
"spec/sample_responses/search_track.json",
|
78
|
+
"spec/sample_responses/suggested_people.json",
|
79
|
+
"spec/spec_helper.rb"
|
80
|
+
]
|
81
|
+
s.homepage = "https://github.com/seanslerner/Jammed"
|
82
|
+
s.licenses = ["MIT"]
|
83
|
+
s.require_paths = ["lib"]
|
84
|
+
s.rubygems_version = "1.8.10"
|
85
|
+
s.summary = "A Ruby wrapper for This Is My Jam's API"
|
86
|
+
s.test_files = ["spec/jammed/api_spec.rb", "spec/jammed/base_spec.rb", "spec/jammed/error_spec.rb", "spec/jammed/followers_spec.rb", "spec/jammed/following_spec.rb", "spec/jammed/jams_spec.rb", "spec/jammed/likes_spec.rb", "spec/jammed/people_search_spec.rb", "spec/jammed/person_spec.rb", "spec/jammed/popular_jams_spec.rb", "spec/jammed/random_spec.rb", "spec/jammed/suggested_people_spec.rb", "spec/jammed/user_spec.rb", "spec/sample_responses/bad_request.json", "spec/sample_responses/followers.json", "spec/sample_responses/followers_affinity.json", "spec/sample_responses/followers_date.json", "spec/sample_responses/followers_name.json", "spec/sample_responses/following.json", "spec/sample_responses/following_affinity.json", "spec/sample_responses/following_date.json", "spec/sample_responses/following_name.json", "spec/sample_responses/jams.json", "spec/sample_responses/jams_past.json", "spec/sample_responses/likes.json", "spec/sample_responses/likes_current.json", "spec/sample_responses/likes_past.json", "spec/sample_responses/not_found.json", "spec/sample_responses/person.json", "spec/sample_responses/popular.json", "spec/sample_responses/random.json", "spec/sample_responses/search_artist.json", "spec/sample_responses/search_name.json", "spec/sample_responses/search_track.json", "spec/sample_responses/suggested_people.json", "spec/spec_helper.rb"]
|
87
|
+
|
88
|
+
if s.respond_to? :specification_version then
|
89
|
+
s.specification_version = 3
|
90
|
+
|
91
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
92
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.8.2"])
|
93
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
94
|
+
s.add_development_dependency(%q<rake>, [">= 0.8.7"])
|
95
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
|
96
|
+
s.add_development_dependency(%q<rspec>, [">= 2.9.0"])
|
97
|
+
s.add_development_dependency(%q<webmock>, [">= 1.8.6"])
|
98
|
+
else
|
99
|
+
s.add_dependency(%q<httparty>, [">= 0.8.2"])
|
100
|
+
s.add_dependency(%q<json>, [">= 0"])
|
101
|
+
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
102
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
103
|
+
s.add_dependency(%q<rspec>, [">= 2.9.0"])
|
104
|
+
s.add_dependency(%q<webmock>, [">= 1.8.6"])
|
105
|
+
end
|
106
|
+
else
|
107
|
+
s.add_dependency(%q<httparty>, [">= 0.8.2"])
|
108
|
+
s.add_dependency(%q<json>, [">= 0"])
|
109
|
+
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
110
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
111
|
+
s.add_dependency(%q<rspec>, [">= 2.9.0"])
|
112
|
+
s.add_dependency(%q<webmock>, [">= 1.8.6"])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
data/lib/jammed/api.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Jammed
|
2
|
+
# A base class for API calling classes to inherit from which provides a method for making HTTP requests
|
3
|
+
class API
|
4
|
+
|
5
|
+
# Call the API through HTTParty and returns the correct error if error raised
|
6
|
+
#
|
7
|
+
# ==== Attributes
|
8
|
+
#
|
9
|
+
# * +method+ - HTTP method for making hte request (:get, :post, etc.)
|
10
|
+
# * +path+ - Path to API endpoint (/IFTFOM.json)
|
11
|
+
# * +opts+ - Query options (API key!) (:show => :past)
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
#
|
15
|
+
# Jammed::API.request(:get, /IFTFOM/followers.json, :query => {:key => 'api_key', :order => 'affinity'})
|
16
|
+
def self.request(method, path, opts={})
|
17
|
+
base_uri = 'http://api.thisismyjam.com/1'
|
18
|
+
|
19
|
+
params = {}
|
20
|
+
params[:path] = path
|
21
|
+
params[:options] = opts
|
22
|
+
params[:method] = method
|
23
|
+
|
24
|
+
response = HTTParty.send(method, "#{base_uri}#{path}",
|
25
|
+
:query => opts[:query],
|
26
|
+
:body => opts[:body],
|
27
|
+
:format => :plain,
|
28
|
+
:headers => {
|
29
|
+
"Accept" => "application/json",
|
30
|
+
"Content-Type" => "application/json; charset=utf-8",
|
31
|
+
"User-Agent" => "Jammed/#{Jammed::VERSION}"
|
32
|
+
}
|
33
|
+
)
|
34
|
+
|
35
|
+
params[:response] = response.inspect.to_s
|
36
|
+
|
37
|
+
case response.code
|
38
|
+
when 200..201
|
39
|
+
response
|
40
|
+
when 400
|
41
|
+
raise Jammed::BadRequest.new(response, params)
|
42
|
+
when 404
|
43
|
+
raise Jammed::NotFound.new(response, params)
|
44
|
+
when 500
|
45
|
+
raise Jammed::ServerError.new(response, params)
|
46
|
+
when 502
|
47
|
+
raise Jammed::Unavailable.new(response, params)
|
48
|
+
when 503
|
49
|
+
raise Jammed::RateLimited.new(response, params)
|
50
|
+
else
|
51
|
+
raise Jammed::InformJammed.new(response, params)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/jammed/base.rb
CHANGED
@@ -110,6 +110,16 @@ module Jammed
|
|
110
110
|
Person.profile(username, @api_key)
|
111
111
|
end
|
112
112
|
|
113
|
+
# Calls Jammed::RandomJam.jam
|
114
|
+
#
|
115
|
+
# ==== Examples
|
116
|
+
#
|
117
|
+
# jammed = Jammed.new('08972935872035')
|
118
|
+
# jammed.random
|
119
|
+
def random
|
120
|
+
RandomJam.jam(@api_key)
|
121
|
+
end
|
122
|
+
|
113
123
|
# Calls Jammed::PeopleSearch.search_name
|
114
124
|
#
|
115
125
|
# ==== Attributes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Jammed
|
2
|
+
class HTTPError < StandardError #:nodoc:
|
3
|
+
attr_reader :response
|
4
|
+
attr_reader :params
|
5
|
+
|
6
|
+
def initialize(response, params = {})
|
7
|
+
@response = response
|
8
|
+
@params = params
|
9
|
+
super(response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{self.class.to_s} : #{response.code} #{response.body}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class RateLimited < HTTPError#:nodoc:
|
18
|
+
end
|
19
|
+
class NotFound < HTTPError#:nodoc:
|
20
|
+
end
|
21
|
+
class Unavailable < HTTPError#:nodoc:
|
22
|
+
end
|
23
|
+
class InformJammed < HTTPError#:nodoc:
|
24
|
+
end
|
25
|
+
class BadRequest < HTTPError#:nodoc:
|
26
|
+
end
|
27
|
+
class ServerError < HTTPError#:nodoc:
|
28
|
+
end
|
29
|
+
end
|
data/lib/jammed/followers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides methods for calling API endpoint /follower.json?
|
3
|
-
class Followers
|
3
|
+
class Followers < API
|
4
4
|
# Calls API for user specific data concerning followers
|
5
5
|
#
|
6
6
|
# ==== Attributes
|
@@ -20,17 +20,21 @@ module Jammed #:nodoc:
|
|
20
20
|
def self.followers(username, api_key, opts={})
|
21
21
|
case(opts[:order])
|
22
22
|
when nil
|
23
|
-
|
23
|
+
response = request(:get, "/#{username}/followers.json",
|
24
|
+
:query => {:key => api_key})
|
24
25
|
when :date
|
25
|
-
|
26
|
+
response = request(:get, "/#{username}/followers.json",
|
27
|
+
:query => {:order => 'followedDate', :key => api_key})
|
26
28
|
when :affinity
|
27
|
-
|
29
|
+
response = request(:get, "/#{username}/followers.json",
|
30
|
+
:query => {:order => 'affinity', :key => api_key})
|
28
31
|
when :alpha
|
29
|
-
|
32
|
+
response = request(:get, "/#{username}/followers.json",
|
33
|
+
:query => {:order => 'name', :key => api_key})
|
30
34
|
else
|
31
35
|
return "Cannot order Followers by #{opts[:order]}"
|
32
36
|
end
|
33
|
-
|
37
|
+
JSON.parse(response.body)['people']
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
data/lib/jammed/following.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides methods for calling API endpoint /following.json?
|
3
|
-
class Following
|
3
|
+
class Following < API
|
4
4
|
# Calls API for user specific data concerning who the user is following
|
5
5
|
#
|
6
6
|
# ==== Attributes
|
@@ -20,17 +20,21 @@ module Jammed #:nodoc:
|
|
20
20
|
def self.following(username, api_key, opts={})
|
21
21
|
case(opts[:order])
|
22
22
|
when nil
|
23
|
-
|
23
|
+
response = request(:get, "/#{username}/following.json",
|
24
|
+
:query => {:key => api_key})
|
24
25
|
when :date
|
25
|
-
|
26
|
+
response = request(:get, "/#{username}/following.json",
|
27
|
+
:query => {:order => 'followedDate', :key => api_key})
|
26
28
|
when :affinity
|
27
|
-
|
29
|
+
response = request(:get, "/#{username}/following.json",
|
30
|
+
:query => {:order => 'affinity', :key => api_key})
|
28
31
|
when :alpha
|
29
|
-
|
32
|
+
response = request(:get, "/#{username}/following.json",
|
33
|
+
:query => {:order => 'name', :key => api_key})
|
30
34
|
else
|
31
35
|
return "Cannot order Followings by #{opts[:order]}"
|
32
36
|
end
|
33
|
-
|
37
|
+
JSON.parse(response.body)['people']
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
data/lib/jammed/jams.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides methods for calling API endpoint /jams.json?
|
3
|
-
class Jams
|
3
|
+
class Jams < API
|
4
4
|
# Calls API for user specific data concerning jams
|
5
5
|
#
|
6
6
|
# ==== Attributes
|
@@ -20,14 +20,18 @@ module Jammed #:nodoc:
|
|
20
20
|
def self.jams(username, api_key, opts={})
|
21
21
|
case(opts[:show])
|
22
22
|
when nil
|
23
|
-
|
24
|
-
|
23
|
+
response = request(:get, "/#{username}/jams.json",
|
24
|
+
:query => {:key => api_key})
|
25
|
+
JSON.parse(response.body)['jams']
|
25
26
|
when :past
|
26
|
-
|
27
|
-
|
27
|
+
response = request(:get, "/#{username}/jams.json",
|
28
|
+
:query => {:show => 'past', :key => api_key})
|
29
|
+
JSON.parse(response.body)['jams']
|
28
30
|
when :current
|
29
|
-
|
30
|
-
|
31
|
+
response = request(:get, "/#{username}/jams.json",
|
32
|
+
:query => {:key => api_key})
|
33
|
+
jams = JSON.parse(response.body)['jams'][0]
|
34
|
+
jams['current'] ? jams : "No Current Jam"
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
data/lib/jammed/likes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides methods for calling API endpoint /likes.json?
|
3
|
-
class Likes
|
3
|
+
class Likes < API
|
4
4
|
# Calls API for user specific data concerning likes
|
5
5
|
#
|
6
6
|
# ==== Attributes
|
@@ -20,13 +20,16 @@ module Jammed #:nodoc:
|
|
20
20
|
def self.likes(username, api_key, opts={})
|
21
21
|
case(opts[:show])
|
22
22
|
when nil
|
23
|
-
|
23
|
+
response = request(:get, "/#{username}/likes.json",
|
24
|
+
:query => {:key => api_key})
|
24
25
|
when :current
|
25
|
-
|
26
|
+
response = request(:get, "/#{username}/likes.json",
|
27
|
+
:query => {:show => 'current', :key => api_key})
|
26
28
|
when :past
|
27
|
-
|
29
|
+
response = request(:get, "/#{username}/likes.json",
|
30
|
+
:query => {:show => 'past', :key => api_key})
|
28
31
|
end
|
29
|
-
|
32
|
+
JSON.parse(response.body)['jams']
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
data/lib/jammed/people_search.rb
CHANGED
@@ -2,7 +2,7 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module Jammed #:nodoc:
|
4
4
|
# Provides methods for calling API endpoint /person.json?by=
|
5
|
-
class PeopleSearch
|
5
|
+
class PeopleSearch < API
|
6
6
|
|
7
7
|
# Calls API for a search by username
|
8
8
|
#
|
@@ -15,8 +15,9 @@ module Jammed #:nodoc:
|
|
15
15
|
#
|
16
16
|
# Jammed::PeopleSearch.search_name('IFTFOM', '08972935872035')
|
17
17
|
def self.search_name(name, api_key)
|
18
|
-
|
19
|
-
|
18
|
+
response = request(:get, "/search/person.json",
|
19
|
+
:query => {:by => 'name', :q => "#{name.split.join('+')}", :key => api_key})
|
20
|
+
JSON.parse(response.body)['people']
|
20
21
|
end
|
21
22
|
|
22
23
|
# Calls API for a search by artist
|
@@ -30,8 +31,9 @@ module Jammed #:nodoc:
|
|
30
31
|
#
|
31
32
|
# Jammed::PeopleSearch.search_artist('beach boys', '08972935872035')
|
32
33
|
def self.search_artist(artist, api_key)
|
33
|
-
|
34
|
-
|
34
|
+
response = request(:get, "/search/person.json",
|
35
|
+
:query => {:by => 'artist', :q => "#{artist.split.join('+')}", :key => api_key})
|
36
|
+
JSON.parse(response.body)['people']
|
35
37
|
end
|
36
38
|
|
37
39
|
# Calls API for a search by track
|
@@ -46,9 +48,11 @@ module Jammed #:nodoc:
|
|
46
48
|
#
|
47
49
|
# Jammed::PeopleSearch.search_track('beach boys', 'good vibrations', '08972935872035')
|
48
50
|
def self.search_track(artist, track, api_key)
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
response = request(:get, "/search/person.json",
|
52
|
+
:query => {:by => 'track',
|
53
|
+
:q => "#{artist.split.join('+')}|#{track.split.join('+')}",
|
54
|
+
:key => api_key})
|
55
|
+
JSON.parse(response.body)['people']
|
52
56
|
end
|
53
57
|
|
54
58
|
end
|
data/lib/jammed/person.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides methods for calling API endpoint /username.json? and accessing user specific data
|
3
|
-
class Person
|
3
|
+
class Person < API
|
4
4
|
# Calls API for a specific user's profile
|
5
5
|
#
|
6
6
|
# ==== Examples
|
7
7
|
#
|
8
8
|
# Jammed::Person.profile('IFTFOM', '08972935872035') #returns IFTFOM's profile data
|
9
9
|
def self.profile(username, api_key)
|
10
|
-
|
11
|
-
|
10
|
+
response = request(:get, "/#{username}.json", :query => {:key => api_key})
|
11
|
+
JSON.parse(response.body)["person"]
|
12
12
|
end
|
13
13
|
|
14
14
|
# Calls API for a specific user's name
|
@@ -26,7 +26,7 @@ module Jammed #:nodoc:
|
|
26
26
|
#
|
27
27
|
# Jammed::Person.joinedDate('IFTFOM', '08972935872035') #returns IFTFOM's joined date
|
28
28
|
def self.method_missing(name, *args, &block)
|
29
|
-
|
29
|
+
Jammed::Person.profile(args[0],args[1]).has_key?(name.to_s) ? self.profile(args[0],args[1])[name.to_s] : super
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/jammed/popular_jams.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides method for calling API endpoint /popular.json?
|
3
|
-
class PopularJams
|
3
|
+
class PopularJams < API
|
4
4
|
# Calls API for popular jams
|
5
5
|
#
|
6
6
|
# ==== Examples
|
7
7
|
#
|
8
8
|
# Jammed::PopularJams.popular_jams('08972935872035') #returns a sample of popular jams
|
9
9
|
def self.popular_jams(api_key)
|
10
|
-
|
11
|
-
|
10
|
+
response = request(:get, "/popular.json", :query => {:key => api_key})
|
11
|
+
JSON.parse(response.body)['jams']
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Jammed #:nodoc:
|
2
|
+
# Provides method for calling API endpoint /random.json?
|
3
|
+
class RandomJam < API
|
4
|
+
# Calls API for a random jam
|
5
|
+
#
|
6
|
+
# ==== Examples
|
7
|
+
#
|
8
|
+
# Jammed::RandomJam.jam('08972935872035') #returns a random jam + the profile of the user
|
9
|
+
def self.jam(api_key)
|
10
|
+
response = request(:get, "/random.json", :query => {:key => api_key})
|
11
|
+
JSON.parse(response.body)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module Jammed #:nodoc:
|
2
2
|
# Provides method for calling API endpoint /suggestedPeople.json?
|
3
|
-
class SuggestedPeople
|
3
|
+
class SuggestedPeople < API
|
4
4
|
# Calls API for suggested people
|
5
5
|
#
|
6
6
|
# ==== Examples
|
7
7
|
#
|
8
8
|
# Jammed::SuggestedPeople.people('08972935872035') #returns a list of users with many followers/likes
|
9
9
|
def self.people(api_key)
|
10
|
-
response =
|
11
|
-
response[
|
10
|
+
response = request(:get, "/suggestedPeople.json", :query => {:key => api_key})
|
11
|
+
JSON.parse(response.body)['people']
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/jammed/version.rb
CHANGED
data/lib/jammed.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
require 'httparty'
|
2
|
+
require 'json'
|
2
3
|
Dir[File.dirname(__FILE__) + '/jammed/*.rb'].each do |file|
|
3
4
|
require file
|
4
5
|
end
|
5
6
|
|
6
|
-
module Jammed
|
7
|
-
|
8
|
-
class Search #:nodoc:
|
9
|
-
include HTTParty
|
10
|
-
base_uri 'http://api.thisismyjam.com/1'
|
11
|
-
end
|
12
|
-
|
7
|
+
module Jammed
|
13
8
|
class << self
|
14
9
|
#Creates a Jammed::Base object for interacting with the API
|
15
10
|
#
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FakeResponse
|
4
|
+
attr_accessor :code, :body
|
5
|
+
def initialize code, body
|
6
|
+
@code, @body = code, body
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Jammed
|
11
|
+
describe API do
|
12
|
+
describe "#request" do
|
13
|
+
it "sends a request to HTTParty" do
|
14
|
+
HTTParty.should_receive(:get).and_return(FakeResponse.new(200, 'this'))
|
15
|
+
Jammed::API.request(:get, '/path')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/jammed/base_spec.rb
CHANGED
@@ -52,6 +52,13 @@ module Jammed
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
describe "#random" do
|
56
|
+
it "calls Jammed::RandomJam.jam" do
|
57
|
+
Jammed::RandomJam.should_receive(:jam)
|
58
|
+
jammed.random
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
55
62
|
describe "#search_name" do
|
56
63
|
it "calls Jammed::PeopleSearch.search_name" do
|
57
64
|
Jammed::PeopleSearch.should_receive(:search_name)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Jammed
|
4
|
+
describe "Errors" do
|
5
|
+
let(:jammed) {Jammed.new('987bcab01b929eb2c07877b224215c92')}
|
6
|
+
describe NotFound do
|
7
|
+
before do
|
8
|
+
serve_response("http://api.thisismyjam.com/1/szkjhfkgsufaiuh.json?key=987bcab01b929eb2c07877b224215c92", :not_found, 404)
|
9
|
+
end
|
10
|
+
it "is raised when unknown username is used" do
|
11
|
+
lambda { jammed.profile('szkjhfkgsufaiuh') }.should raise_error NotFound
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe BadRequest do
|
16
|
+
before do
|
17
|
+
serve_response('http://api.thisismyjam.com/1/IFTFOM.json?badparam=woo&key=987bcab01b929eb2c07877b224215c92', :bad_request, 400)
|
18
|
+
end
|
19
|
+
it "is raised when bad parameters are used" do
|
20
|
+
lambda { API.request(:get, '/IFTFOM.json',
|
21
|
+
:query => {:key => '987bcab01b929eb2c07877b224215c92',
|
22
|
+
:badparam => :woo}) }.should raise_error BadRequest
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ServerError do
|
27
|
+
before do
|
28
|
+
serve_response("http://api.thisismyjam.com/1/szkjhfkgsufaiuh.json?key=987bcab01b929eb2c07877b224215c92", :not_found, 500)
|
29
|
+
end
|
30
|
+
it "is raised when the server errors" do
|
31
|
+
lambda { jammed.profile('szkjhfkgsufaiuh') }.should raise_error ServerError
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -34,7 +34,8 @@ module Jammed
|
|
34
34
|
let(:search) { Jammed::PeopleSearch.search_artist(query, api_key) }
|
35
35
|
|
36
36
|
before do
|
37
|
-
serve_response("http://api.thisismyjam.com/1/search/person.json?by=artist&q=beach+boys&key=987bcab01b929eb2c07877b224215c92", :search_artist)
|
37
|
+
#serve_response("http://api.thisismyjam.com/1/search/person.json?by=artist&q=beach+boys&key=987bcab01b929eb2c07877b224215c92", :search_artist)
|
38
|
+
serve_response(/by=artist/, :search_artist)
|
38
39
|
end
|
39
40
|
|
40
41
|
it "returns people from the API" do
|
@@ -58,7 +59,8 @@ module Jammed
|
|
58
59
|
let(:search) { Jammed::PeopleSearch.search_track(query_artist, query_track, api_key)}
|
59
60
|
|
60
61
|
before do
|
61
|
-
serve_response("http://api.thisismyjam.com/1/search/person.json?by=track&q=Lana+del+Rey|Video+games&key=987bcab01b929eb2c07877b224215c92", :search_track)
|
62
|
+
#serve_response("http://api.thisismyjam.com/1/search/person.json?by=track&q=Lana+del+Rey|Video+games&key=987bcab01b929eb2c07877b224215c92", :search_track)
|
63
|
+
serve_response(/by=track/, :search_track)
|
62
64
|
end
|
63
65
|
|
64
66
|
it "returns people from the API" do
|
data/spec/jammed/person_spec.rb
CHANGED
@@ -31,7 +31,7 @@ module Jammed
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "raises method missing if attribute is not present" do
|
34
|
-
lambda { Jammed::Person.foo_attribute('IFTFOM', api_key) }.should raise_error
|
34
|
+
lambda { Jammed::Person.foo_attribute('IFTFOM', api_key) }.should raise_error
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Jammed
|
4
|
+
describe RandomJam do
|
5
|
+
|
6
|
+
let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
|
7
|
+
|
8
|
+
describe ".jam" do
|
9
|
+
|
10
|
+
before do
|
11
|
+
serve_response("http://api.thisismyjam.com/1/random.json?key=987bcab01b929eb2c07877b224215c92", :random)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "parses the JSON return into a hash" do
|
15
|
+
Jammed::RandomJam.jam(api_key).should be_an_instance_of Hash
|
16
|
+
end
|
17
|
+
|
18
|
+
it "gets popular jams from the api" do
|
19
|
+
Jammed::RandomJam.jam(api_key).should_not be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/jammed/user_spec.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
{
|
2
|
+
"jam": {
|
3
|
+
"artist": "B.W. Stevenson",
|
4
|
+
"caption": "The Institute needs an AM radio, and soon.",
|
5
|
+
"creationDate": "Tue, 17 Apr 2012 22:53:03 +0000",
|
6
|
+
"current": true,
|
7
|
+
"endDate": "Tue, 24 Apr 2012 22:53:03 +0000",
|
8
|
+
"from": "IFTFOM",
|
9
|
+
"id": "18ahqel",
|
10
|
+
"jamvatarLarge": "http://static01.thisismyjam.com/i/0af5ee0aebf3ed7ddd44e2a91df7f612_395.jpg",
|
11
|
+
"jamvatarMedium": "http://static02.thisismyjam.com/i/0af5ee0aebf3ed7ddd44e2a91df7f612_185.jpg",
|
12
|
+
"jamvatarSmall": "http://static01.thisismyjam.com/i/0af5ee0aebf3ed7ddd44e2a91df7f612_80.jpg",
|
13
|
+
"likes": "http://api.thisismyjam.com/1/jams/18ahqel/likes.json?key=987bcab01b929eb2c07877b224215c92",
|
14
|
+
"likesCount": 23,
|
15
|
+
"playCount": 105,
|
16
|
+
"title": "My Maria",
|
17
|
+
"via": "youtube",
|
18
|
+
"viaUrl": "http://www.youtube.com/watch?v=JdBvTvxHy7E"
|
19
|
+
},
|
20
|
+
"person": {
|
21
|
+
"apiUrl": "http://api.thisismyjam.com/1/IFTFOM.json?key=987bcab01b929eb2c07877b224215c92",
|
22
|
+
"avatarNormal": "http://static01.thisismyjam.com/i/avtr_ffb74c754f2e74d43ba3e77aa46c3e1a_128.jpg",
|
23
|
+
"avatarSmall": "http://static03.thisismyjam.com/i/avtr_ffb74c754f2e74d43ba3e77aa46c3e1a_small.jpg",
|
24
|
+
"bio": "Between the park and the canal. Improving your music life with science and heart. We like coldwave, yacht rock, the future, and you.",
|
25
|
+
"followers": "http://api.thisismyjam.com/1/IFTFOM/followers.json?key=987bcab01b929eb2c07877b224215c92",
|
26
|
+
"followersCount": 1547,
|
27
|
+
"following": "http://api.thisismyjam.com/1/IFTFOM/following.json?key=987bcab01b929eb2c07877b224215c92",
|
28
|
+
"followingCount": 718,
|
29
|
+
"fullname": "Institute for the Future of Music",
|
30
|
+
"hasCurrentJam": true,
|
31
|
+
"jamCount": 34,
|
32
|
+
"joinedDate": "Fri, 26 Aug 2011 16:15:19 +0000",
|
33
|
+
"lastfmName": "IFTFOM",
|
34
|
+
"name": "IFTFOM",
|
35
|
+
"representativeArtists": [
|
36
|
+
"Orchestral Manoeuvres in the Dark",
|
37
|
+
"Christopher Cross",
|
38
|
+
"Steely Dan",
|
39
|
+
"Robert Palmer"
|
40
|
+
],
|
41
|
+
"twitterName": "IFTFOM",
|
42
|
+
"url": "http://www.thisismyjam.com/IFTFOM"
|
43
|
+
}
|
44
|
+
}
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require 'webmock/rspec'
|
|
3
3
|
|
4
4
|
SAMPLE_RESPONSES_DIR = "sample_responses"
|
5
5
|
|
6
|
-
def serve_response(path, file_name)
|
6
|
+
def serve_response(path, file_name, status=200)
|
7
7
|
begin
|
8
8
|
response_body = File.binread(
|
9
9
|
File.dirname(__FILE__) +
|
@@ -13,6 +13,6 @@ def serve_response(path, file_name)
|
|
13
13
|
end
|
14
14
|
|
15
15
|
stub_request(:get, path)
|
16
|
-
.to_return(:status =>
|
16
|
+
.to_return(:status => status, :body => response_body,
|
17
17
|
:headers => {:content_type => 'application/json'})
|
18
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jammed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-05-07 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: httparty
|
18
|
-
requirement: &
|
18
|
+
requirement: &70115760365280 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,21 @@ dependencies:
|
|
23
23
|
version: 0.8.2
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70115760365280
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: &70115760364640 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *70115760364640
|
27
38
|
- !ruby/object:Gem::Dependency
|
28
39
|
name: rake
|
29
|
-
requirement: &
|
40
|
+
requirement: &70115760363900 !ruby/object:Gem::Requirement
|
30
41
|
none: false
|
31
42
|
requirements:
|
32
43
|
- - ! '>='
|
@@ -34,10 +45,10 @@ dependencies:
|
|
34
45
|
version: 0.8.7
|
35
46
|
type: :development
|
36
47
|
prerelease: false
|
37
|
-
version_requirements: *
|
48
|
+
version_requirements: *70115760363900
|
38
49
|
- !ruby/object:Gem::Dependency
|
39
50
|
name: jeweler
|
40
|
-
requirement: &
|
51
|
+
requirement: &70115760363120 !ruby/object:Gem::Requirement
|
41
52
|
none: false
|
42
53
|
requirements:
|
43
54
|
- - ! '>='
|
@@ -45,10 +56,10 @@ dependencies:
|
|
45
56
|
version: 1.8.3
|
46
57
|
type: :development
|
47
58
|
prerelease: false
|
48
|
-
version_requirements: *
|
59
|
+
version_requirements: *70115760363120
|
49
60
|
- !ruby/object:Gem::Dependency
|
50
61
|
name: rspec
|
51
|
-
requirement: &
|
62
|
+
requirement: &70115760350480 !ruby/object:Gem::Requirement
|
52
63
|
none: false
|
53
64
|
requirements:
|
54
65
|
- - ! '>='
|
@@ -56,10 +67,10 @@ dependencies:
|
|
56
67
|
version: 2.9.0
|
57
68
|
type: :development
|
58
69
|
prerelease: false
|
59
|
-
version_requirements: *
|
70
|
+
version_requirements: *70115760350480
|
60
71
|
- !ruby/object:Gem::Dependency
|
61
72
|
name: webmock
|
62
|
-
requirement: &
|
73
|
+
requirement: &70115760349000 !ruby/object:Gem::Requirement
|
63
74
|
none: false
|
64
75
|
requirements:
|
65
76
|
- - ! '>='
|
@@ -67,7 +78,7 @@ dependencies:
|
|
67
78
|
version: 1.8.6
|
68
79
|
type: :development
|
69
80
|
prerelease: false
|
70
|
-
version_requirements: *
|
81
|
+
version_requirements: *70115760349000
|
71
82
|
description: Jammed wraps the This Is My Jam API. More information about the This
|
72
83
|
Is My Jam API can be found on their website (http://www.thisismyjam.com/developers).
|
73
84
|
email:
|
@@ -86,8 +97,11 @@ files:
|
|
86
97
|
- README.md
|
87
98
|
- Rakefile
|
88
99
|
- examples/basics.rb
|
100
|
+
- jammed.gemspec
|
89
101
|
- lib/jammed.rb
|
102
|
+
- lib/jammed/api.rb
|
90
103
|
- lib/jammed/base.rb
|
104
|
+
- lib/jammed/errors.rb
|
91
105
|
- lib/jammed/followers.rb
|
92
106
|
- lib/jammed/following.rb
|
93
107
|
- lib/jammed/jams.rb
|
@@ -95,10 +109,13 @@ files:
|
|
95
109
|
- lib/jammed/people_search.rb
|
96
110
|
- lib/jammed/person.rb
|
97
111
|
- lib/jammed/popular_jams.rb
|
112
|
+
- lib/jammed/random.rb
|
98
113
|
- lib/jammed/suggested_people.rb
|
99
114
|
- lib/jammed/user.rb
|
100
115
|
- lib/jammed/version.rb
|
116
|
+
- spec/jammed/api_spec.rb
|
101
117
|
- spec/jammed/base_spec.rb
|
118
|
+
- spec/jammed/error_spec.rb
|
102
119
|
- spec/jammed/followers_spec.rb
|
103
120
|
- spec/jammed/following_spec.rb
|
104
121
|
- spec/jammed/jams_spec.rb
|
@@ -106,8 +123,10 @@ files:
|
|
106
123
|
- spec/jammed/people_search_spec.rb
|
107
124
|
- spec/jammed/person_spec.rb
|
108
125
|
- spec/jammed/popular_jams_spec.rb
|
126
|
+
- spec/jammed/random_spec.rb
|
109
127
|
- spec/jammed/suggested_people_spec.rb
|
110
128
|
- spec/jammed/user_spec.rb
|
129
|
+
- spec/sample_responses/bad_request.json
|
111
130
|
- spec/sample_responses/followers.json
|
112
131
|
- spec/sample_responses/followers_affinity.json
|
113
132
|
- spec/sample_responses/followers_date.json
|
@@ -121,8 +140,10 @@ files:
|
|
121
140
|
- spec/sample_responses/likes.json
|
122
141
|
- spec/sample_responses/likes_current.json
|
123
142
|
- spec/sample_responses/likes_past.json
|
143
|
+
- spec/sample_responses/not_found.json
|
124
144
|
- spec/sample_responses/person.json
|
125
145
|
- spec/sample_responses/popular.json
|
146
|
+
- spec/sample_responses/random.json
|
126
147
|
- spec/sample_responses/search_artist.json
|
127
148
|
- spec/sample_responses/search_name.json
|
128
149
|
- spec/sample_responses/search_track.json
|
@@ -143,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
164
|
version: '0'
|
144
165
|
segments:
|
145
166
|
- 0
|
146
|
-
hash:
|
167
|
+
hash: 756853401178736676
|
147
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
169
|
none: false
|
149
170
|
requirements:
|
@@ -157,7 +178,9 @@ signing_key:
|
|
157
178
|
specification_version: 3
|
158
179
|
summary: A Ruby wrapper for This Is My Jam's API
|
159
180
|
test_files:
|
181
|
+
- spec/jammed/api_spec.rb
|
160
182
|
- spec/jammed/base_spec.rb
|
183
|
+
- spec/jammed/error_spec.rb
|
161
184
|
- spec/jammed/followers_spec.rb
|
162
185
|
- spec/jammed/following_spec.rb
|
163
186
|
- spec/jammed/jams_spec.rb
|
@@ -165,8 +188,10 @@ test_files:
|
|
165
188
|
- spec/jammed/people_search_spec.rb
|
166
189
|
- spec/jammed/person_spec.rb
|
167
190
|
- spec/jammed/popular_jams_spec.rb
|
191
|
+
- spec/jammed/random_spec.rb
|
168
192
|
- spec/jammed/suggested_people_spec.rb
|
169
193
|
- spec/jammed/user_spec.rb
|
194
|
+
- spec/sample_responses/bad_request.json
|
170
195
|
- spec/sample_responses/followers.json
|
171
196
|
- spec/sample_responses/followers_affinity.json
|
172
197
|
- spec/sample_responses/followers_date.json
|
@@ -180,8 +205,10 @@ test_files:
|
|
180
205
|
- spec/sample_responses/likes.json
|
181
206
|
- spec/sample_responses/likes_current.json
|
182
207
|
- spec/sample_responses/likes_past.json
|
208
|
+
- spec/sample_responses/not_found.json
|
183
209
|
- spec/sample_responses/person.json
|
184
210
|
- spec/sample_responses/popular.json
|
211
|
+
- spec/sample_responses/random.json
|
185
212
|
- spec/sample_responses/search_artist.json
|
186
213
|
- spec/sample_responses/search_name.json
|
187
214
|
- spec/sample_responses/search_track.json
|