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,205 @@
1
+ require 'spec_helper'
2
+
3
+ module Jammed
4
+ describe User do
5
+ let(:api_key) {'987bcab01b929eb2c07877b224215c92'}
6
+ let(:user) { Jammed::User.new('IFTFOM', api_key) }
7
+
8
+ describe "#initialize" do
9
+ it "sets the username" do
10
+ user.username.should == 'IFTFOM'
11
+ end
12
+ end
13
+
14
+ context "Followers" do
15
+ before do
16
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/followers.json?key=987bcab01b929eb2c07877b224215c92", :followers)
17
+ end
18
+
19
+ describe "#followers" do
20
+ it "calls Jammed::Followers.followers" do
21
+ Jammed::Followers.should_receive(:followers)
22
+ user.followers
23
+ end
24
+ it "sends @username + :order options to Jammed::Followers" do
25
+ Jammed::Followers.should_receive(:followers).with('IFTFOM', api_key, {:order => :date})
26
+ user.followers(:order => :date)
27
+ end
28
+ it "saves followers in @followers" do
29
+ user.followers.should be_an_instance_of Array
30
+ end
31
+ it "returns @followers if set" do
32
+ cached = user.followers
33
+ cached.should equal(user.followers)
34
+ end
35
+ end
36
+
37
+ describe "#followers!" do
38
+ it "calls Jammed::Followers.follower" do
39
+ Jammed::Followers.should_receive(:followers)
40
+ user.followers!
41
+ end
42
+ it "reassigns @followers" do
43
+ cached = user.followers
44
+ cached.should_not equal(user.followers!)
45
+ end
46
+ end
47
+ end
48
+
49
+ context "Followings" do
50
+ before do
51
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/following.json?key=987bcab01b929eb2c07877b224215c92", :following)
52
+ end
53
+ describe "#following" do
54
+ it "calls Jammed::Following.following" do
55
+ Jammed::Following.should_receive(:following)
56
+ user.following
57
+ end
58
+ it "sends @username + :order options to Jammed::Following" do
59
+ Jammed::Following.should_receive(:following).with('IFTFOM', api_key, {:order => :date})
60
+ user.following(:order => :date)
61
+ end
62
+ it "saves followers in @following" do
63
+ user.following.should be_an_instance_of Array
64
+ end
65
+ it "returns @following if set" do
66
+ cached = user.following
67
+ cached.should equal(user.following)
68
+ end
69
+ end
70
+ describe "#following!" do
71
+ it "calls Jammed::Following.following" do
72
+ Jammed::Following.should_receive(:following)
73
+ user.following
74
+ end
75
+ it "reassigns @following" do
76
+ cached = user.following
77
+ cached.should_not equal(user.following!)
78
+ end
79
+ end
80
+ end
81
+
82
+ context "Jams" do
83
+ before do
84
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/jams.json?key=987bcab01b929eb2c07877b224215c92", :jams)
85
+ end
86
+ describe "#jams" do
87
+ it "calls Jammed::Jams.jams" do
88
+ Jammed::Jams.should_receive(:jams)
89
+ user.jams
90
+ end
91
+ it "sends @username + :show options to Jammed::Jams" do
92
+ Jammed::Jams.should_receive(:jams).with('IFTFOM', api_key, {:show => :past})
93
+ user.jams(:show => :past)
94
+ end
95
+ it "saves jams in @jams" do
96
+ user.jams.should be_an_instance_of Array
97
+ end
98
+ it "returns @jams if set" do
99
+ cached = user.jams
100
+ cached.should equal(user.jams)
101
+ end
102
+ end
103
+ describe "#jams!" do
104
+ it "calls Jammed::Jams.jams" do
105
+ Jammed::Jams.should_receive(:jams)
106
+ user.jams
107
+ end
108
+ it "reassigns @jams" do
109
+ cached = user.jams
110
+ cached.should_not equal(user.jams!)
111
+ end
112
+ end
113
+ end
114
+
115
+ context "Likes" do
116
+ before do
117
+ serve_response("http://api.thisismyjam.com/1/IFTFOM/likes.json?key=987bcab01b929eb2c07877b224215c92", :likes)
118
+ end
119
+ describe "#likes" do
120
+ it "calls Jammed::Likes.likes" do
121
+ Jammed::Likes.should_receive(:likes)
122
+ user.likes
123
+ end
124
+ it "sends @username + :show options to Jammed::Likes" do
125
+ Jammed::Likes.should_receive(:likes).with('IFTFOM', api_key, {:show => :past})
126
+ user.likes(:show => :past)
127
+ end
128
+ it "saves likes in @likes" do
129
+ user.likes.should be_an_instance_of Array
130
+ end
131
+ it "returns @likes if set" do
132
+ cached = user.likes
133
+ cached.should equal(user.likes)
134
+ end
135
+ end
136
+ describe "#likes!" do
137
+ it "calls Jammed::Likes.likes" do
138
+ Jammed::Likes.should_receive(:likes)
139
+ user.likes
140
+ end
141
+ it "reassigns @likes" do
142
+ cached = user.likes
143
+ cached.should_not equal(user.likes!)
144
+ end
145
+ end
146
+ end
147
+
148
+ context "Profile + Profile Attributes" do
149
+ describe "#profile" do
150
+ before do
151
+ serve_response("http://api.thisismyjam.com/1/IFTFOM.json?key=987bcab01b929eb2c07877b224215c92", :person)
152
+ end
153
+
154
+ it "calls Jammed::Person.profile" do
155
+ Jammed::Person.should_receive(:profile)
156
+ user.profile
157
+ end
158
+
159
+ it "saves API data in @profile" do
160
+ user.profile.should be_an_instance_of Hash
161
+ end
162
+
163
+ it "returns @profile if set" do
164
+ cached = user.profile
165
+ cached.should equal(user.profile)
166
+ end
167
+ end
168
+
169
+ describe "#profile!" do
170
+ before do
171
+ serve_response("http://api.thisismyjam.com/1/IFTFOM.json?key=987bcab01b929eb2c07877b224215c92", :person)
172
+ end
173
+ it "calls Jammed::Person.profile" do
174
+ Jammed::Person.should_receive(:profile)
175
+ user.profile!
176
+ end
177
+
178
+ it "reassigns @profile" do
179
+ cached = user.profile
180
+ cached.should_not equal(user.profile!)
181
+ end
182
+ end
183
+
184
+ describe "dynamic attributes (#method_missing)" do
185
+ before do
186
+ serve_response("http://api.thisismyjam.com/1/IFTFOM.json?key=987bcab01b929eb2c07877b224215c92", :person)
187
+ end
188
+
189
+ it "returns the attribute value if present in profile" do
190
+ user.name.should == "IFTFOM"
191
+ end
192
+
193
+ it "raises method missing if attribute is not present" do
194
+ lambda { user.foo_attribute }.should raise_error NoMethodError
195
+ end
196
+ end
197
+
198
+ describe "#js_namify" do
199
+ it "turns a snake_case string into a javaScriptStyled string" do
200
+ user.js_namify('joined_date').should == 'joinedDate'
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end