teachstreet 0.0.4 → 0.0.5

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.
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'httparty'
2
3
  require 'facets/string'
3
4
  require 'facets/memoizable'
@@ -97,6 +98,19 @@ module Teachstreet
97
98
  class Answer < Result
98
99
  end
99
100
 
101
+ class Teacher < Result
102
+ end
103
+
104
+ class Review < Result
105
+ end
106
+
107
+ class Image < Result
108
+ end
109
+
110
+ class Article < Result
111
+ has_many :images
112
+ end
113
+
100
114
  class Client
101
115
  include HTTParty
102
116
 
@@ -110,26 +124,26 @@ module Teachstreet
110
124
 
111
125
  # search listings local & online classes
112
126
  def search_listings(options={})
113
- process(self.class.get("/search/listings", :query => options)).map do |l|
127
+ process(self.class.get("/search/listings.json", :query => options)).map do |l|
114
128
  Listing.new(l)
115
129
  end
116
130
  end
117
131
 
118
132
  # look up a listing by id
119
133
  def listing(id, options={})
120
- Listing.new(process(self.class.get("/listing", :query => {:id => id}.merge(options))))
134
+ Listing.new(process(self.class.get("/listing/#{id}.json", options)))
121
135
  end
122
136
 
123
137
  # find all categories
124
138
  def categories
125
- process(self.class.get("/categories")).map do |c|
139
+ process(self.class.get("/categories.json")).map do |c|
126
140
  Category.new(c)
127
141
  end
128
142
  end
129
143
 
130
144
  # find all subscategories, or substring search by name
131
145
  def subcategories(options = {})
132
- process(self.class.get("/subcategories", :query => options)).map do |c|
146
+ process(self.class.get("/subcategories.json", :query => options)).map do |c|
133
147
  Subcategory.new(c)
134
148
  end
135
149
  end
@@ -160,8 +174,52 @@ module Teachstreet
160
174
  end
161
175
  end
162
176
 
177
+ # find articles
178
+ def articles(options={})
179
+ process(self.class.get("/articles.json", :query => options)).map do |r|
180
+ Article.new(r)
181
+ end
182
+ end
183
+
184
+ # find teachers
185
+ def teachers(options={})
186
+ process(self.class.get("/teachers.json", :query => options)).map do |r|
187
+ Teacher.new(r)
188
+ end
189
+ end
190
+
191
+ # look up a teacher by id or screen_name
192
+ def teacher(id, options={})
193
+ Teacher.new(process(self.class.get(uri("/teacher/#{id}.json"), options))["teacher"])
194
+ end
195
+
196
+ # find teacher listings
197
+ def teacher_listings(id, options={})
198
+ process(self.class.get(uri("/teacher/#{id}/listings.json"), :query => options)).map do |r|
199
+ Listing.new(r)
200
+ end
201
+ end
202
+
203
+ # find teacher reviews
204
+ def teacher_reviews(id, options={})
205
+ process(self.class.get(uri("/teacher/#{id}/reviews.json"), :query => options)).map do |r|
206
+ Review.new(r)
207
+ end
208
+ end
209
+
210
+ # find teacher articles
211
+ def teacher_articles(id, options={})
212
+ process(self.class.get(uri("/teacher/#{id}/articles.json"), :query => options)).map do |r|
213
+ Article.new(r)
214
+ end
215
+ end
216
+
163
217
  private
164
218
 
219
+ def uri(u)
220
+ URI.escape(u)
221
+ end
222
+
165
223
  def process(result)
166
224
  if result.response.code == "200"
167
225
  result.parsed_response
@@ -1,3 +1,3 @@
1
1
  module Teachstreet
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -214,4 +214,68 @@ describe Teachstreet do
214
214
  answer.answered_at.should_not be_nil
215
215
  end
216
216
 
217
+ it "browse articles" do
218
+ articles = @client.articles
219
+ articles.should_not be_nil
220
+ articles.should_not be_empty
221
+ article = articles.first
222
+ article.should be_a_kind_of(Teachstreet::Article)
223
+ article.id.should_not be_nil
224
+ article.url.should_not be_nil
225
+ article.title.should_not be_nil
226
+ article.body.should_not be_nil
227
+ end
228
+
229
+ it "find teacher by id" do
230
+ teacher = @client.teacher("us-74iuao3o0")
231
+ teacher.should_not be_nil
232
+ teacher.id.should_not be_nil
233
+ teacher.screen_name.should_not be_nil
234
+ teacher.should be_a_kind_of(Teachstreet::Teacher)
235
+ end
236
+
237
+ it "find teacher by screen_name" do
238
+ teacher = @client.teacher("Scott Windsor")
239
+ teacher.should_not be_nil
240
+ teacher.id.should_not be_nil
241
+ teacher.screen_name.should_not be_nil
242
+ teacher.should be_a_kind_of(Teachstreet::Teacher)
243
+ end
244
+
245
+ it "find teacher listings" do
246
+ listings = @client.teacher_listings("us-74iuao3o0")
247
+ listings.should_not be_nil
248
+ listings.should_not be_empty
249
+ listing = listings.first
250
+ listing.should be_a_kind_of(Teachstreet::Listing)
251
+ listing.id.should_not be_nil
252
+ listing.title.should_not be_nil
253
+ end
254
+
255
+ it "find teacher reviews" do
256
+ reviews = @client.teacher_reviews("us-74iuao3o0")
257
+ reviews.should_not be_nil
258
+ reviews.should_not be_empty
259
+ review = reviews.first
260
+ review.should be_a_kind_of(Teachstreet::Review)
261
+ review.id.should_not be_nil
262
+ end
263
+
264
+ it "find teacher articles" do
265
+ articles = @client.teacher_articles("us-74iuao3o0")
266
+ articles.should_not be_nil
267
+ articles.should_not be_empty
268
+ article = articles.first
269
+ article.should be_a_kind_of(Teachstreet::Article)
270
+ article.id.should_not be_nil
271
+ article.title.should_not be_nil
272
+ article.body.should_not be_nil
273
+ article.images.should_not be_nil
274
+ article.images.should_not be_empty
275
+ image = article.images.first
276
+ image.mediumImageUrl.should_not be_nil
277
+ image.smallImageUrl.should_not be_nil
278
+ image.largeImageUrl.should_not be_nil
279
+ end
280
+
217
281
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teachstreet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Windsor
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-21 00:00:00 -07:00
18
+ date: 2011-06-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -143,9 +143,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  requirements: []
144
144
 
145
145
  rubyforge_project:
146
- rubygems_version: 1.4.1
146
+ rubygems_version: 1.4.2
147
147
  signing_key:
148
148
  specification_version: 3
149
149
  summary: Client library for accessing TeachStreet's APIs
150
- test_files: []
151
-
150
+ test_files:
151
+ - spec/api_key.rb
152
+ - spec/spec_helper.rb
153
+ - spec/teachstreet_spec.rb