jammed 0.1.0

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.
Files changed (51) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +10 -0
  5. data/LICENSE +22 -0
  6. data/README.md +54 -0
  7. data/Rakefile +44 -0
  8. data/examples/basics.rb +60 -0
  9. data/lib/jammed/base.rb +182 -0
  10. data/lib/jammed/followers.rb +36 -0
  11. data/lib/jammed/following.rb +36 -0
  12. data/lib/jammed/jams.rb +34 -0
  13. data/lib/jammed/likes.rb +32 -0
  14. data/lib/jammed/people_search.rb +55 -0
  15. data/lib/jammed/person.rb +32 -0
  16. data/lib/jammed/popular_jams.rb +14 -0
  17. data/lib/jammed/suggested_people.rb +14 -0
  18. data/lib/jammed/user.rb +158 -0
  19. data/lib/jammed/version.rb +4 -0
  20. data/lib/jammed.rb +28 -0
  21. data/spec/jammed/base_spec.rb +90 -0
  22. data/spec/jammed/followers_spec.rb +55 -0
  23. data/spec/jammed/following_spec.rb +55 -0
  24. data/spec/jammed/jams_spec.rb +53 -0
  25. data/spec/jammed/likes_spec.rb +51 -0
  26. data/spec/jammed/people_search_spec.rb +79 -0
  27. data/spec/jammed/person_spec.rb +38 -0
  28. data/spec/jammed/popular_jams_spec.rb +23 -0
  29. data/spec/jammed/suggested_people_spec.rb +18 -0
  30. data/spec/jammed/user_spec.rb +205 -0
  31. data/spec/sample_responses/followers.json +1495 -0
  32. data/spec/sample_responses/followers_affinity.json +1495 -0
  33. data/spec/sample_responses/followers_date.json +1281 -0
  34. data/spec/sample_responses/followers_name.json +0 -0
  35. data/spec/sample_responses/following.json +1495 -0
  36. data/spec/sample_responses/following_affinity.json +1495 -0
  37. data/spec/sample_responses/following_date.json +1406 -0
  38. data/spec/sample_responses/following_name.json +1406 -0
  39. data/spec/sample_responses/jams.json +620 -0
  40. data/spec/sample_responses/jams_past.json +602 -0
  41. data/spec/sample_responses/likes.json +1106 -0
  42. data/spec/sample_responses/likes_current.json +224 -0
  43. data/spec/sample_responses/likes_past.json +1106 -0
  44. data/spec/sample_responses/person.json +44 -0
  45. data/spec/sample_responses/popular.json +364 -0
  46. data/spec/sample_responses/search_artist.json +1377 -0
  47. data/spec/sample_responses/search_name.json +55 -0
  48. data/spec/sample_responses/search_track.json +1333 -0
  49. data/spec/sample_responses/suggested_people.json +1427 -0
  50. data/spec/spec_helper.rb +18 -0
  51. metadata +189 -0
@@ -0,0 +1,158 @@
1
+ module Jammed #:nodoc:
2
+ # Provides User objects for interacting with user-specific data
3
+ class User
4
+
5
+ # Each attr_accessor (except for :username) caches API data on first use in corresponding instance variable
6
+ attr_accessor :username, :followers, :following, :jams, :likes, :profile
7
+
8
+ # Creates a new Jammed::User object and assigns a username to @username
9
+ #
10
+ # ==== Attributes
11
+ #
12
+ # * +username+ - Username of user to make API calls with
13
+ #
14
+ # ==== Examples
15
+ #
16
+ # iftfom = Jammed::User.new('IFTFOM', '08972935872035')
17
+ def initialize(username, api_key)
18
+ @username = username
19
+ @api_key = api_key
20
+ end
21
+
22
+ def followers(opts={})
23
+ @followers ||= Jammed::Followers.followers(@username, @api_key, opts)
24
+ end
25
+
26
+ # Clears cached Followers data with a fresh call to Jammed::Followers
27
+ #
28
+ # ==== Attributes
29
+ #
30
+ # * +opts+ - Options for ordering Followers data
31
+ #
32
+ # ==== Options
33
+ #
34
+ # * +:order+ - A symbol determining how the data is orderd like :date, :affinity, or :alpha
35
+ #
36
+ # ==== Examples
37
+ #
38
+ # user = Jammed::User.new('IFTFOM', '08972935872035')
39
+ # user.followers #returns all followers of IFTFOM
40
+ # user.followers(:order => :date) #reutrns IFTFOM's followers ordered by date
41
+ def followers!(opts={})
42
+ @followers = Jammed::Followers.followers(@username, @api_key, opts)
43
+ end
44
+
45
+ def following(opts={})
46
+ @following ||= Jammed::Following.following(@username, @api_key, opts)
47
+ end
48
+
49
+ # Clears cached Following data with a fresh call to Jammed::Following
50
+ #
51
+ # ==== Attributes
52
+ #
53
+ # * +opts+ - Options for ordering Following data
54
+ #
55
+ # ==== Options
56
+ #
57
+ # * +:order+ - A symbol determining how the data is orderd like :date, :affinity, or :alpha
58
+ #
59
+ # ==== Examples
60
+ #
61
+ # user = Jammed::User.new('IFTFOM', '08972935872035')
62
+ # user.following #returns all followings of IFTFOM
63
+ # user.following(:order => :date) #returns IFTFOM's followings ordered by date
64
+ def following!(opts={})
65
+ @following = Jammed::Following.following(@username, @api_key, opts)
66
+ end
67
+
68
+ def jams(opts={})
69
+ @jams ||= Jammed::Jams.jams(@username, @api_key, opts)
70
+ end
71
+
72
+ # Clears cached Jams data with a fresh call to Jammed::Jams
73
+ #
74
+ # ==== Attributes
75
+ #
76
+ # * +opts+ - Options for which data is shown
77
+ #
78
+ # ==== Options
79
+ #
80
+ # * +:show+ - A symbol determining what data is shown like :past or :current
81
+ #
82
+ # ==== Examples
83
+ #
84
+ # user = Jammed::User.new('IFTFOM', '08972935872035')
85
+ # user.jams #returns all jams of IFTFOM
86
+ # user.jams(:show => :past) #returns IFTFOM's past jams
87
+ def jams!(opts={})
88
+ @jams = Jammed::Jams.jams(@username, @api_key, opts)
89
+ end
90
+
91
+ def likes(opts={})
92
+ @likes ||= Jammed::Likes.likes(@username, @api_key, opts)
93
+ end
94
+
95
+ # Clears cached Likes data with a fresh call to Jammed::Likes
96
+ #
97
+ # ==== Attributes
98
+ #
99
+ # * +opts+ - Options for which data is shown
100
+ #
101
+ # ==== Options
102
+ #
103
+ # * +:show+ - A symbol determining what data is shown like :past or :current
104
+ #
105
+ # ==== Examples
106
+ #
107
+ # user = Jammed::User.new('IFTFOM', '08972935872035')
108
+ # user.likes #returns all likes of IFTFOM
109
+ # user.likes(:show => :past) #returns IFTFOM's past likes
110
+ def likes!(opts={})
111
+ @likes = Jammed::Likes.likes(@username, @api_key, opts)
112
+ end
113
+
114
+ def profile
115
+ @profile ||= Jammed::Person.profile(@username, @api_key)
116
+ end
117
+
118
+ # Clears cached Person data with a fresh call to Jammed::Person
119
+ #
120
+ # ==== Examples
121
+ #
122
+ # user = Jammed::User.new('IFTFOM', '08972935872035')
123
+ # user.profile #returns entire profile of IFTFOM
124
+ def profile!
125
+ @profile = Jammed::Person.profile(@username, @api_key)
126
+ end
127
+
128
+ # Checks user's profile for attribute and returns value if attribute key is found.
129
+ #
130
+ # ==== Examples
131
+ #
132
+ # user = Jammed::User.new('IFTFOM', '08972935872035')
133
+ # user.name #returns 'IFTFOM'
134
+ # user.date_joined #uses js_namify to find 'dateJoined' key and returns date
135
+ def method_missing(name, *args, &block)
136
+ n = name.to_s.index('_') != nil ? js_namify(name.to_s) : name.to_s
137
+
138
+ profile.has_key?(n) ? profile[n] : super
139
+ end
140
+
141
+ # Converts Ruby styled method names to JavaScript's prefered style. Used by method_missing to generate dynamic attributes methods for user's profile.
142
+ #
143
+ # ==== Attributes
144
+ #
145
+ # * +name+ - Method name to be converted
146
+ #
147
+ # ==== Examples
148
+ #
149
+ # js_namify('date_joined') #returns 'dateJoined'
150
+ def js_namify(name)
151
+ x = []
152
+ name.split('_').each_with_index do |e, i|
153
+ i == 0 ? x << e.downcase : x << e.capitalize
154
+ end
155
+ x.join('')
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,4 @@
1
+ module Jammed
2
+ #:nodoc:
3
+ VERSION = "0.1.0"
4
+ end
data/lib/jammed.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'httparty'
2
+ Dir[File.dirname(__FILE__) + '/jammed/*.rb'].each do |file|
3
+ require file
4
+ end
5
+
6
+ module Jammed
7
+
8
+ class Search #:nodoc:
9
+ include HTTParty
10
+ base_uri 'http://api.thisismyjam.com/1'
11
+ end
12
+
13
+ class << self
14
+ #Creates a Jammed::Base object for interacting with the API
15
+ #
16
+ # ==== Attributes
17
+ #
18
+ # * +api_key+ - Sets the API key to use for all calls made with object
19
+ # * +opts+ -Options hash. Does nothing at the moment.
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # jammed = Jammed.new('987bcab01b929eb2c07877b224215c92')
24
+ def new(api_key='987bcab01b929eb2c07877b224215c92', opts={})
25
+ Jammed::Base.new(api_key, opts)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe Base do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+ let(:jammed) {Jammed::Base.new(api_key)}
8
+ let(:user) {'IFTFOM'}
9
+
10
+ describe "#initialize" do
11
+ end
12
+
13
+ describe "#followers" do
14
+ it "calls Jammed::Followers.followers" do
15
+ Jammed::Followers.should_receive(:followers)
16
+ jammed.followers(user)
17
+ end
18
+ end
19
+
20
+ describe "#following" do
21
+ it "calls Jammed::Following.following" do
22
+ Jammed::Following.should_receive(:following)
23
+ jammed.following(user)
24
+ end
25
+ end
26
+
27
+ describe "#jams" do
28
+ it "calls Jammed::Jams.jams" do
29
+ Jammed::Jams.should_receive(:jams)
30
+ jammed.jams(user)
31
+ end
32
+ end
33
+
34
+ describe "#likes" do
35
+ it "calls Jammed::Like.likes" do
36
+ Jammed::Likes.should_receive(:likes)
37
+ jammed.likes(user)
38
+ end
39
+ end
40
+
41
+ describe "#popular_jams" do
42
+ it "calls Jammed::PopularJams.popular_jams" do
43
+ Jammed::PopularJams.should_receive(:popular_jams)
44
+ jammed.popular_jams
45
+ end
46
+ end
47
+
48
+ describe "#profile" do
49
+ it "calls Jammed::Person.profile" do
50
+ Jammed::Person.should_receive(:profile)
51
+ jammed.profile(user)
52
+ end
53
+ end
54
+
55
+ describe "#search_name" do
56
+ it "calls Jammed::PeopleSearch.search_name" do
57
+ Jammed::PeopleSearch.should_receive(:search_name)
58
+ jammed.search_name(user)
59
+ end
60
+ end
61
+
62
+ describe "#search_artist" do
63
+ it "calls Jammed::PeopleSearch.search_artist" do
64
+ Jammed::PeopleSearch.should_receive(:search_artist)
65
+ jammed.search_artist('track')
66
+ end
67
+ end
68
+
69
+ describe "#search_track" do
70
+ it "calls Jammed::PeopleSearch.search_track" do
71
+ Jammed::PeopleSearch.should_receive(:search_track)
72
+ jammed.search_track('artist', 'track')
73
+ end
74
+ end
75
+
76
+ describe "#suggested_people" do
77
+ it "calls Jammed::SuggestedPeople.people" do
78
+ Jammed::SuggestedPeople.should_receive(:people)
79
+ jammed.suggested_people
80
+ end
81
+ end
82
+
83
+ describe "#user" do
84
+ it "calls Jammed::User.new" do
85
+ Jammed::User.should_receive(:new).with(user, api_key)
86
+ jammed.user(user)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe Followers do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".followers" do
9
+ before do
10
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/followers.json?key=987bcab01b929eb2c07877b224215c92", :followers)
11
+ end
12
+
13
+ it "gets followers from the api" do
14
+ Jammed::Followers.followers('IFTFOM', api_key).should_not be_nil
15
+ end
16
+ end
17
+
18
+ describe ".followers(:order => :date)" do
19
+ before do
20
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/followers.json?key=987bcab01b929eb2c07877b224215c92&order=followedDate", :followers_date)
21
+ end
22
+
23
+ it "can order followers by date" do
24
+ Jammed::Followers.followers('IFTFOM', api_key, :order => :date).should_not be_nil
25
+ end
26
+ end
27
+
28
+ describe ".followers(:order => :affinity)" do
29
+ before do
30
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/followers.json?key=987bcab01b929eb2c07877b224215c92&order=affinity", :followers_affinity)
31
+ end
32
+
33
+ it "can order followers by likes" do
34
+ Jammed::Followers.followers('IFTFOM', api_key, :order => :affinity).should_not be_nil
35
+ end
36
+ end
37
+
38
+ describe ".followers(:order => :name)" do
39
+ before do
40
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/followers.json?key=987bcab01b929eb2c07877b224215c92&order=name", :followers_name)
41
+ end
42
+
43
+ it "can order followers by name" do
44
+ Jammed::Followers.followers('IFTFOM', api_key, :order => :name).should_not be_nil
45
+ end
46
+ end
47
+
48
+ context ".followers with bad :order value" do
49
+ it "complains when non-existant :order value given" do
50
+ message = "Cannot order Followers by bad"
51
+ Jammed::Followers.followers('IFTFOM', api_key, :order => :bad).should == message
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe Following do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".following" do
9
+ before do
10
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/following.json?key=987bcab01b929eb2c07877b224215c92", :following)
11
+ end
12
+
13
+ it "gets followings from the api" do
14
+ Jammed::Following.following('IFTFOM', api_key).should_not be(nil)
15
+ end
16
+ end
17
+
18
+ describe ".following(:order => :date)" do
19
+ before do
20
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/following.json?key=987bcab01b929eb2c07877b224215c92&order=followedDate", :following_date)
21
+ end
22
+
23
+ it "can order followings by date" do
24
+ Jammed::Following.following('IFTFOM', api_key, :order => :date).should_not be_nil
25
+ end
26
+ end
27
+
28
+ describe ".following(:order => :affinity)" do
29
+ before do
30
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/following.json?key=987bcab01b929eb2c07877b224215c92&order=affinity", :following_affinity)
31
+ end
32
+
33
+ it "can order followings by likes" do
34
+ Jammed::Following.following('IFTFOM', api_key, :order => :affinity).should_not be_nil
35
+ end
36
+ end
37
+
38
+ describe ".following(:order => :name)" do
39
+ before do
40
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/following.json?key=987bcab01b929eb2c07877b224215c92&order=name", :following_name)
41
+ end
42
+
43
+ it "can order followings by name" do
44
+ Jammed::Following.following('IFTFOM', api_key, :order => :name).should_not be_nil
45
+ end
46
+ end
47
+
48
+ context ".following with bad :order value" do
49
+ it "complains when non-existant :order value given" do
50
+ message = "Cannot order Followings by bad"
51
+ Jammed::Following.following('IFTFOM', api_key, :order => :bad).should == message
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe Jams do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".jams" do
9
+ before do
10
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/jams.json?key=987bcab01b929eb2c07877b224215c92", :jams)
11
+ end
12
+
13
+ it "gets jams from the api" do
14
+ Jammed::Jams.jams('IFTFOM', api_key).should_not be(nil)
15
+ end
16
+
17
+ it "gets the current jam and past jams" do
18
+ Jammed::Jams.jams('IFTFOM', api_key).to_s.should include("\"current\"=>false")
19
+ Jammed::Jams.jams('IFTFOM', api_key).to_s.should include("\"current\"=>true")
20
+ end
21
+ end
22
+
23
+ describe ".jams(:show => :past)" do
24
+ before do
25
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/jams.json?key=987bcab01b929eb2c07877b224215c92&show=past", :jams_past)
26
+ end
27
+
28
+ it "gets past jams from the api" do
29
+ Jammed::Jams.jams('IFTFOM', api_key, :show => :past).should_not be(nil)
30
+ Jammed::Jams.jams('IFTFOM', api_key, :show => :past).to_s.should include("\"current\"=>false")
31
+ end
32
+
33
+ it "doesn't get the current jam" do
34
+ Jammed::Jams.jams('IFTFOM', api_key, :show => :past).to_s.should_not include("\"current\"=>true")
35
+ end
36
+ end
37
+
38
+ describe ".jams(:show => :current)" do
39
+ before do
40
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/jams.json?key=987bcab01b929eb2c07877b224215c92", :jams)
41
+ end
42
+
43
+ it "gets the current jam from the api" do
44
+ Jammed::Jams.jams('IFTFOM', api_key, :show => :current).should_not be(nil)
45
+ Jammed::Jams.jams('IFTFOM', api_key, :show => :current).to_s.should include("\"current\"=>true")
46
+ end
47
+
48
+ it "doesn't get past jams" do
49
+ Jammed::Jams.jams('IFTFOM', api_key, :show => :current).to_s.should_not include("\"current\"=>false")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe Likes do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".likes" do
9
+ before do
10
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/likes.json?key=987bcab01b929eb2c07877b224215c92", :likes)
11
+ end
12
+
13
+ it "gets likes from the api" do
14
+ Jammed::Likes.likes('IFTFOM', api_key).should_not be(nil)
15
+ end
16
+
17
+ it "gets both current and past likes" do
18
+ Jammed::Likes.likes('IFTFOM', api_key).to_s.should include("\"current\"=>false")
19
+ Jammed::Likes.likes('IFTFOM', api_key).to_s.should include("\"current\"=>true")
20
+ end
21
+ end
22
+
23
+ describe ".likes(:show => :current)" do
24
+ before do
25
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/likes.json?show=current&key=987bcab01b929eb2c07877b224215c92", :likes_current)
26
+ end
27
+
28
+ it "gets current likes" do
29
+ Jammed::Likes.likes('IFTFOM', api_key, :show => :current).to_s.should include("\"current\"=>true")
30
+ end
31
+
32
+ it "doesn't get past likes" do
33
+ Jammed::Likes.likes('IFTFOM', api_key, :show => :current).to_s.should_not include("\"current\"=>false")
34
+ end
35
+ end
36
+
37
+ describe ".likes(:show => :past)" do
38
+ before do
39
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/likes.json?show=past&key=987bcab01b929eb2c07877b224215c92", :likes_past)
40
+ end
41
+
42
+ it "gets past likes" do
43
+ Jammed::Likes.likes('IFTFOM', api_key, :show => :past).to_s.should include("\"current\"=>false")
44
+ end
45
+
46
+ it "doesn't get current likes" do
47
+ Jammed::Likes.likes('IFTFOM', api_key, :show => :past).to_s.should_not include("\"current\"=>true")
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe PeopleSearch do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".search_name" do
9
+ let(:query) {'institute'}
10
+ let(:search) { Jammed::PeopleSearch.search_name(query, api_key) }
11
+ before do
12
+ serve_response("http://api.thisismyjam.com/1/search/person.json?by=name&q=institute&key=987bcab01b929eb2c07877b224215c92", :search_name)
13
+ end
14
+
15
+ it "returns people from the API" do
16
+ search.should_not be(nil)
17
+ end
18
+
19
+ it "returns people with the search string in their username, fullname, or Twitter name" do
20
+ successful_search = false
21
+ if search.first["fullname"].downcase.include?(query)
22
+ successful_search = true
23
+ elsif search.first["name"].downcase.include?(query)
24
+ successful_search = true
25
+ elsif search.first["twitterName"].downcase.include?(query)
26
+ successful_search = true
27
+ end
28
+ successful_search.should be true
29
+ end
30
+ end
31
+
32
+ describe ".search_artist" do
33
+ let(:query) {'beach boys'}
34
+ let(:search) { Jammed::PeopleSearch.search_artist(query, api_key) }
35
+
36
+ before do
37
+ serve_response("http://api.thisismyjam.com/1/search/person.json?by=artist&q=beach+boys&key=987bcab01b929eb2c07877b224215c92", :search_artist)
38
+ end
39
+
40
+ it "returns people from the API" do
41
+ search.should_not be(nil)
42
+ end
43
+
44
+ it "returns people who have posted tracks by the queried artist" do
45
+ successful_search = false
46
+ search.first["representativeArtists"].each do |artist|
47
+ if artist.downcase.include?(query)
48
+ successful_search = true
49
+ end
50
+ successful_search.should be true
51
+ end
52
+ end
53
+ end
54
+
55
+ describe ".search_track" do
56
+ let(:query_artist) {'Lana del Rey'}
57
+ let(:query_track) {'Video games'}
58
+ let(:search) { Jammed::PeopleSearch.search_track(query_artist, query_track, api_key)}
59
+
60
+ 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
+ end
63
+
64
+ it "returns people from the API" do
65
+ search.should_not be(nil)
66
+ end
67
+
68
+ it "returns people who have posted a particluar track" do
69
+ successful_search = false
70
+ search.first["representativeArtists"].each do |artist|
71
+ if artist.downcase.include?(query_artist.downcase)
72
+ successful_search = true
73
+ end
74
+ successful_search.should be true
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe Person do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ before do
9
+ serve_response("http://api.thisismyjam.com/1/IFTFOM.json?key=987bcab01b929eb2c07877b224215c92", :person)
10
+ end
11
+
12
+ describe ".profile" do
13
+
14
+ it "gets the data from the api" do
15
+ Jammed::Person.profile('IFTFOM', api_key)["name"].should == "IFTFOM"
16
+ end
17
+
18
+ it "parses the JSON return into a hash" do
19
+ Jammed::Person.profile('IFTFOM', api_key).should be_an_instance_of Hash
20
+ end
21
+ end
22
+
23
+ describe "dynamic attributes (.method_missing)" do
24
+
25
+ it "returns the attribute value if present in profile (name)" do
26
+ Jammed::Person.name('IFTFOM', api_key).should == "IFTFOM"
27
+ end
28
+
29
+ it "returns the attribute value if present in profile" do
30
+ Jammed::Person.fullname('IFTFOM', api_key).should match /Institute/
31
+ end
32
+
33
+ it "raises method missing if attribute is not present" do
34
+ lambda { Jammed::Person.foo_attribute('IFTFOM', api_key) }.should raise_error NoMethodError
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe PopularJams do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".popular_jams" do
9
+
10
+ before do
11
+ serve_response("http://api.thisismyjam.com/1/popular.json?key=987bcab01b929eb2c07877b224215c92", :popular)
12
+ end
13
+
14
+ it "parses the JSON return into an array of Jams" do
15
+ Jammed::PopularJams.popular_jams(api_key).should be_an_instance_of Array
16
+ end
17
+
18
+ it "gets popular jams from the api" do
19
+ Jammed::PopularJams.popular_jams(api_key).should_not be_nil
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe SuggestedPeople do
5
+
6
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
7
+
8
+ describe ".people" do
9
+ before do
10
+ serve_response("http://api.thisismyjam.com/1/suggestedPeople.json?key=987bcab01b929eb2c07877b224215c92", :suggested_people)
11
+ end
12
+
13
+ it "returns people from the API" do
14
+ Jammed::SuggestedPeople.people(api_key).should_not be_nil
15
+ end
16
+ end
17
+ end
18
+ end