r43 0.2.0 → 0.3.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.
- data/lib/r43.rb +366 -232
- data/lib/{city.rb → r43/city.rb} +0 -0
- data/lib/{entry.rb → r43/entry.rb} +0 -0
- data/lib/{goal.rb → r43/goal.rb} +0 -0
- data/lib/{id.rb → r43/id.rb} +1 -1
- data/lib/{person.rb → r43/person.rb} +0 -0
- data/lib/{tag.rb → r43/tag.rb} +0 -0
- data/test/es-get_persons_tags-Alvaro.xml +10 -0
- data/test/get_city-1164.xml +8 -0
- data/test/get_goal_by_id-533.xml +18 -0
- data/test/get_tags_goals-travel-offset20.xml +152 -0
- data/test/get_tags_goals-travel-offset80-max10.xml +82 -0
- data/test/get_tags_goals-travel.xml +152 -0
- data/test/get_tags_similarities-travel.xml +12 -0
- data/test/get_teams_progress-222591.xml +170 -0
- data/test/get_teams_progress-7.xml +146 -0
- data/test/idea-get_person-pate.xml +48 -0
- data/test/search_tags-lose+weight.xml +48 -0
- data/test/search_tags-travel-offset20.xml +36 -0
- data/test/search_tags-travel.xml +39 -0
- data/test/test_r43.rb +307 -38
- metadata +22 -10
- data/lib/r43.rb.~1.6.~ +0 -645
- data/test/test_r43.rb.~1.8.~ +0 -728
data/lib/r43.rb
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
|
5
5
|
require 'net/http'
|
6
6
|
require 'rexml/document'
|
7
|
-
require 'city'
|
8
|
-
require 'entry'
|
9
|
-
require 'goal'
|
10
|
-
require 'id'
|
11
|
-
require 'person'
|
12
|
-
require 'tag'
|
7
|
+
require 'r43/city'
|
8
|
+
require 'r43/entry'
|
9
|
+
require 'r43/goal'
|
10
|
+
require 'r43/id'
|
11
|
+
require 'r43/person'
|
12
|
+
require 'r43/tag'
|
13
13
|
|
14
14
|
module R43
|
15
15
|
|
@@ -19,8 +19,12 @@ module R43
|
|
19
19
|
class R43::Service
|
20
20
|
attr_reader :key, :proxy_addr
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
#
|
23
|
+
# This method is only intended to be called by R43::Connection objects
|
24
|
+
#
|
25
|
+
def initialize(key, url, proxy_addr, proxy_port, proxy_user, proxy_pass)
|
26
|
+
@url = url
|
27
|
+
@key = key.to_s
|
24
28
|
@proxy_addr = proxy_addr
|
25
29
|
@proxy_port = proxy_port
|
26
30
|
@proxy_user = proxy_user
|
@@ -29,9 +33,6 @@ module R43
|
|
29
33
|
|
30
34
|
protected
|
31
35
|
|
32
|
-
#
|
33
|
-
# a private method to add the api_key to the url
|
34
|
-
#
|
35
36
|
def _inject_key(url)
|
36
37
|
key_str = "api_key=#{@key}"
|
37
38
|
if url =~ /\?$/
|
@@ -51,11 +52,8 @@ module R43
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
54
|
-
#
|
55
|
-
# a private method for getting responses from 43 things.
|
56
|
-
#
|
57
55
|
def _get_response(url)
|
58
|
-
_get_http.start(
|
56
|
+
_get_http.start(@url) do |http|
|
59
57
|
response = _build_response(http, url)
|
60
58
|
end
|
61
59
|
end
|
@@ -75,6 +73,10 @@ module R43
|
|
75
73
|
|
76
74
|
public
|
77
75
|
|
76
|
+
#
|
77
|
+
# This method is only meant to be called by R43::Connection objects,
|
78
|
+
# it's the mechanism for getting data from the web service
|
79
|
+
#
|
78
80
|
def get_response(url)
|
79
81
|
_get_response(_inject_key(url))
|
80
82
|
end
|
@@ -83,19 +85,187 @@ module R43
|
|
83
85
|
|
84
86
|
public
|
85
87
|
|
88
|
+
class R43::Response
|
89
|
+
attr_reader :service, :query, :xml,
|
90
|
+
:object, :entry, :person, :goal, :city, :title,
|
91
|
+
:objects, :entries, :people, :goals, :cities, :tags,
|
92
|
+
:has_object, :max_in_page, :total_available, :next_offset
|
93
|
+
|
94
|
+
#
|
95
|
+
# This is only meant to be called by a R43::Connection object.
|
96
|
+
#
|
97
|
+
def initialize(service, query)
|
98
|
+
@service = service
|
99
|
+
@query = query
|
100
|
+
@has_object = false
|
101
|
+
@objects = []
|
102
|
+
@entries = []
|
103
|
+
@people = []
|
104
|
+
@goals = []
|
105
|
+
@cities = []
|
106
|
+
@tags = []
|
107
|
+
@title = ""
|
108
|
+
@max_in_page = 0
|
109
|
+
@total_available = 0
|
110
|
+
@next_offset = 0
|
111
|
+
_from_xml(service.get_response(query))
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# When a response hase been paged, the more method provides a simple
|
116
|
+
# mechanism for getting additional entries.
|
117
|
+
#
|
118
|
+
# require 'r43'
|
119
|
+
# connection = R43::Connection.new(<api_key>)
|
120
|
+
# people = connection.get_goals_people(<goal_id>)
|
121
|
+
# people += connection.more
|
122
|
+
#
|
123
|
+
def more()
|
124
|
+
clear_arrays()
|
125
|
+
_populate_collections_from_xml(service.get_response(query + "&offset=#{@next_offset}"))
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
|
131
|
+
def clear_arrays()
|
132
|
+
@objects.clear()
|
133
|
+
@entries.clear()
|
134
|
+
@people.clear()
|
135
|
+
@goals.clear()
|
136
|
+
@cities.clear()
|
137
|
+
@tags.clear()
|
138
|
+
end
|
139
|
+
|
140
|
+
def object=(object)
|
141
|
+
if @has_object
|
142
|
+
@object = nil
|
143
|
+
else
|
144
|
+
@has_object = true
|
145
|
+
@object = object
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def title=(title)
|
150
|
+
@title = title.to_s
|
151
|
+
end
|
152
|
+
|
153
|
+
def entry=(entry)
|
154
|
+
@entry = entry
|
155
|
+
self.object = entry
|
156
|
+
add_entry(entry)
|
157
|
+
end
|
158
|
+
|
159
|
+
def person=(person)
|
160
|
+
@person = person
|
161
|
+
self.object = person
|
162
|
+
add_person person
|
163
|
+
end
|
164
|
+
|
165
|
+
def goal=(goal)
|
166
|
+
@goal = goal
|
167
|
+
self.object = goal
|
168
|
+
add_goal goal
|
169
|
+
end
|
170
|
+
|
171
|
+
def city=(city)
|
172
|
+
@city = city
|
173
|
+
self.object = city
|
174
|
+
add_city city
|
175
|
+
end
|
176
|
+
|
177
|
+
def title=(title)
|
178
|
+
@title = title.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def add_entry(entry)
|
182
|
+
@entries.push entry
|
183
|
+
@objects.push entry
|
184
|
+
end
|
185
|
+
|
186
|
+
def add_person(person)
|
187
|
+
@people.push person
|
188
|
+
@objects.push person
|
189
|
+
end
|
190
|
+
|
191
|
+
def add_goal(goal)
|
192
|
+
@goals.push goal
|
193
|
+
@objects.push goal
|
194
|
+
end
|
195
|
+
|
196
|
+
def add_city(city)
|
197
|
+
@cities.push city
|
198
|
+
@objects.push city
|
199
|
+
end
|
200
|
+
|
201
|
+
def add_tag(tag)
|
202
|
+
@tags.push tag
|
203
|
+
@objects.push tag
|
204
|
+
end
|
205
|
+
|
206
|
+
def _from_xml(xml)
|
207
|
+
@xml = xml
|
208
|
+
self.entry= Entry.from_xml(xml.elements["entry"]) if xml.elements["entry"]
|
209
|
+
self.person= Person.from_xml(xml.elements["person"]) if xml.elements["person"]
|
210
|
+
self.goal= Goal.from_xml(xml.elements["goal"]) if xml.elements["goal"]
|
211
|
+
self.city= City.from_xml(xml.elements["city"]) if xml.elements["city"]
|
212
|
+
self.title= xml.elements["feed/title"] if xml.elements["feed/title"]
|
213
|
+
self.title= xml.elements["feed/title"].text.strip if
|
214
|
+
xml.elements["feed/title"]if xml.elements["feed/title"]
|
215
|
+
_populate_collections_from_xml xml
|
216
|
+
end
|
217
|
+
|
218
|
+
def _populate_collections_from_xml(xml)
|
219
|
+
if xml.elements["feed/pagination"] then
|
220
|
+
@max_per_page = xml.elements["feed/pagination/max"].text.to_i
|
221
|
+
@total_available = xml.elements["feed/pagination/total"].text.to_i
|
222
|
+
@next_offset = xml.elements["feed/pagination/next_offset"].text.to_i
|
223
|
+
end
|
224
|
+
|
225
|
+
xml.elements.each("feed/entry") do |entry_element|
|
226
|
+
add_entry(Entry.from_xml(entry_element))
|
227
|
+
end
|
228
|
+
|
229
|
+
xml.elements.each("feed/person") do |person_element|
|
230
|
+
add_person(Person.from_xml(person_element))
|
231
|
+
end
|
232
|
+
|
233
|
+
xml.elements.each("feed/members/person") do |person_element|
|
234
|
+
add_person(Person.from_xml(person_element))
|
235
|
+
end
|
236
|
+
|
237
|
+
xml.elements.each("feed/goal") do |goal_element|
|
238
|
+
add_goal(Goal.from_xml(goal_element))
|
239
|
+
end
|
240
|
+
|
241
|
+
xml.elements.each("feed/city") do |city_element|
|
242
|
+
add_city(City.from_xml(city_element))
|
243
|
+
end
|
244
|
+
|
245
|
+
xml.elements.each("feed/tags/tag") do |tag_element|
|
246
|
+
tag = Tag.from_xml(tag_element)
|
247
|
+
add_tag(tag)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
|
86
253
|
#
|
87
254
|
# Implements the 43 Things API. This is where you actually
|
88
|
-
# instantiate objects.
|
255
|
+
# instantiate objects. r43 supports multiple servers in the
|
256
|
+
# 43things family and the use of a web proxy.
|
89
257
|
#
|
90
258
|
# require 'r43'
|
91
|
-
# connection = R43::Connection.new(<api_key>
|
259
|
+
# connection = R43::Connection.new(<api_key> [, <url> [,
|
260
|
+
# <proxy_address> [, <proxy_port> [, <proxy_user> [,
|
261
|
+
# <proxy_password]]]]])
|
92
262
|
#
|
93
263
|
class R43::Connection
|
94
264
|
attr_reader :service, :response
|
95
265
|
|
96
|
-
def initialize(key, proxy_addr=nil, proxy_port=nil,
|
266
|
+
def initialize(key, url="www.43things.com", proxy_addr=nil, proxy_port=nil,
|
97
267
|
proxy_user=nil, proxy_pass=nil)
|
98
|
-
@service = R43::Service.new(key, proxy_addr, proxy_port,
|
268
|
+
@service = R43::Service.new(key, url, proxy_addr, proxy_port,
|
99
269
|
proxy_user, proxy_pass)
|
100
270
|
end
|
101
271
|
|
@@ -103,13 +273,29 @@ module R43
|
|
103
273
|
protected
|
104
274
|
attr_reader :return_reference
|
105
275
|
|
106
|
-
#
|
107
|
-
# a private method for getting responses from 43 things.
|
108
|
-
#
|
109
276
|
def _get_response(url)
|
110
277
|
@response = Response.new(@service, url)
|
111
278
|
end
|
112
279
|
|
280
|
+
def _clean_string(string)
|
281
|
+
string.gsub(/\s/, '+')
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
def _handle_optional
|
286
|
+
@string.gsub!(/\s/, "+")
|
287
|
+
if @optional[:offset] then
|
288
|
+
@string += "&offset=#{@optional[:offset]}"
|
289
|
+
end
|
290
|
+
if @optional[:max] then
|
291
|
+
@string += "&max=#{@optional[:max]}"
|
292
|
+
end
|
293
|
+
if @optional[:view] then
|
294
|
+
@string += "&view=#{@optional[:view]}"
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|
298
|
+
|
113
299
|
def return_by_value(object)
|
114
300
|
if object.kind_of? Enumerable then
|
115
301
|
object.collect{|element| element.clone}
|
@@ -128,6 +314,11 @@ module R43
|
|
128
314
|
#
|
129
315
|
# Exposes paging from the last connection.
|
130
316
|
#
|
317
|
+
# require 'r43'
|
318
|
+
# connection = R43::Connection(<api_key>)
|
319
|
+
# people = connection.get_goals_people(<goal_id>)
|
320
|
+
# people += connection.more
|
321
|
+
#
|
131
322
|
def more()
|
132
323
|
@response.more()
|
133
324
|
return_by_value(@return_reference)
|
@@ -181,7 +372,7 @@ module R43
|
|
181
372
|
# goal = connection.get_goal_by_id(255)
|
182
373
|
#
|
183
374
|
def get_goal_by_id(id)
|
184
|
-
store_and_return(_get_response("get_goal_by_id?id=#{id}").goal)
|
375
|
+
store_and_return(_get_response("get_goal_by_id?id=#{id.to_i}").goal)
|
185
376
|
end
|
186
377
|
|
187
378
|
|
@@ -194,11 +385,12 @@ module R43
|
|
194
385
|
# goal = connection.get_goal_by_name(<name>)
|
195
386
|
#
|
196
387
|
def get_goal_by_name(name)
|
197
|
-
name = name
|
388
|
+
name = _clean_string(name)
|
198
389
|
store_and_return(_get_response("get_goal_by_name?name=#{name}").goal)
|
199
390
|
end
|
200
391
|
|
201
392
|
|
393
|
+
|
202
394
|
#
|
203
395
|
# Implements the get_goals_similarities method from the Goals API and
|
204
396
|
# returns an array of Goal objects
|
@@ -208,8 +400,10 @@ module R43
|
|
208
400
|
# connection = R43::Connection.new(<api_key>)
|
209
401
|
# goals = connection.get_goals_similarities(<id>)
|
210
402
|
#
|
211
|
-
def get_goals_similarities(id)
|
212
|
-
|
403
|
+
def get_goals_similarities(id, optional={})
|
404
|
+
@string, @optional = "id=#{id.to_i}", optional
|
405
|
+
_handle_optional
|
406
|
+
store_and_return(_get_response("get_goals_similarities?#{@string}").goals)
|
213
407
|
end
|
214
408
|
|
215
409
|
#
|
@@ -220,19 +414,14 @@ module R43
|
|
220
414
|
# require 'r43'
|
221
415
|
# connection = R43::Connection.new(<api_key>)
|
222
416
|
# goals = connection.search_goals(<query string>[,
|
223
|
-
# {[
|
224
|
-
# [
|
417
|
+
# {[:offset => <offset>],
|
418
|
+
# [:max => <max>]}])
|
225
419
|
#
|
226
|
-
def search_goals(
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
if optional["max"] then
|
232
|
-
string += "&max=#{optional["max"]}"
|
233
|
-
end
|
234
|
-
|
235
|
-
store_and_return(_get_response("search_goals?q=#{string}").goals)
|
420
|
+
def search_goals(query, optional={})
|
421
|
+
query = _clean_string(query)
|
422
|
+
@string, @optional = "q=#{query}", optional
|
423
|
+
_handle_optional
|
424
|
+
store_and_return(_get_response("search_goals?#{@string}").goals)
|
236
425
|
end
|
237
426
|
|
238
427
|
#
|
@@ -242,19 +431,13 @@ module R43
|
|
242
431
|
# require 'r43'
|
243
432
|
# connection = R43::Connection.new(<api_key>)
|
244
433
|
# people = connection.get_goals_people(<id>[,
|
245
|
-
# {[
|
246
|
-
# [
|
434
|
+
# {[:offset => <offset>],
|
435
|
+
# [:max => <max>]}])
|
247
436
|
#
|
248
437
|
def get_goals_people(id, optional={})
|
249
|
-
string = "id=#{id}"
|
250
|
-
|
251
|
-
|
252
|
-
end
|
253
|
-
if optional["max"] then
|
254
|
-
string += "&max=#{optional["max"]}"
|
255
|
-
end
|
256
|
-
|
257
|
-
store_and_return(_get_response("get_goals_people?#{string}").people)
|
438
|
+
@string, @optional = "id=#{id.to_i}", optional
|
439
|
+
_handle_optional
|
440
|
+
store_and_return(_get_response("get_goals_people?#{@string}").people)
|
258
441
|
end
|
259
442
|
|
260
443
|
#
|
@@ -263,23 +446,14 @@ module R43
|
|
263
446
|
#
|
264
447
|
# require 'r43'
|
265
448
|
# connection = R43::Connection.new(<api_key>)
|
266
|
-
# entries = connection.get_goals_entries(<id>,[{[
|
267
|
-
# [
|
268
|
-
# [
|
449
|
+
# entries = connection.get_goals_entries(<id>,[{[:offset => <offset>],
|
450
|
+
# [:max => <max>],
|
451
|
+
# [:view => <view>]}])
|
269
452
|
#
|
270
453
|
def get_goals_entries(id, optional={})
|
271
|
-
string = "id=#{id}"
|
272
|
-
|
273
|
-
|
274
|
-
end
|
275
|
-
if optional["max"] then
|
276
|
-
string += "&max=#{optional["max"]}"
|
277
|
-
end
|
278
|
-
if optional["view"] then
|
279
|
-
string += "&view=#{optional["view"]}"
|
280
|
-
end
|
281
|
-
|
282
|
-
store_and_return(_get_response("get_goals_entries?#{string}").entries)
|
454
|
+
@string, @optional = "id=#{id.to_i}", optional
|
455
|
+
_handle_optional
|
456
|
+
store_and_return(_get_response("get_goals_entries?#{@string}").entries)
|
283
457
|
end
|
284
458
|
|
285
459
|
|
@@ -289,13 +463,17 @@ module R43
|
|
289
463
|
# this is a paged collection.
|
290
464
|
#
|
291
465
|
# require 'r43'
|
292
|
-
# connection = R43::Connection.new(<api_key>
|
466
|
+
# connection = R43::Connection.new(<api_key> [,
|
467
|
+
# {[:offset => <offset>],
|
468
|
+
# [:max => <max>]}])
|
293
469
|
# people = connection.search_people(<query>)
|
294
470
|
# people += connection.more
|
295
471
|
#
|
296
|
-
def search_people(query,
|
297
|
-
|
298
|
-
|
472
|
+
def search_people(query, optional={})
|
473
|
+
query = _clean_string(query)
|
474
|
+
@string, @optional = "q=#{query}", optional
|
475
|
+
_handle_optional
|
476
|
+
store_and_return(_get_response("search_people?#{@string}").people)
|
299
477
|
end
|
300
478
|
|
301
479
|
#
|
@@ -308,9 +486,11 @@ module R43
|
|
308
486
|
# people = connection.search_people_by_email(<query>)
|
309
487
|
# people += connection.more
|
310
488
|
#
|
311
|
-
def search_people_by_email(query,
|
312
|
-
|
313
|
-
|
489
|
+
def search_people_by_email(query, optional={})
|
490
|
+
query = _clean_string(query)
|
491
|
+
@string, @optional = "q=#{query}", optional
|
492
|
+
_handle_optional
|
493
|
+
store_and_return(_get_response("search_people_by_email?#{@string}").people)
|
314
494
|
end
|
315
495
|
|
316
496
|
#
|
@@ -324,13 +504,13 @@ module R43
|
|
324
504
|
# connection = R43::Connection.new(<api_key>)
|
325
505
|
# person = connection.get_person(<username>[, <true|false>])
|
326
506
|
#
|
327
|
-
def get_person(
|
507
|
+
def get_person(username,use_flickr=false)
|
328
508
|
if (use_flickr)
|
329
509
|
id_cmd = "flickr_username"
|
330
510
|
else
|
331
511
|
id_cmd = "id"
|
332
512
|
end
|
333
|
-
store_and_return(_get_response("get_person?#{id_cmd}=#{
|
513
|
+
store_and_return(_get_response("get_person?#{id_cmd}=#{username}").person)
|
334
514
|
end
|
335
515
|
|
336
516
|
#
|
@@ -342,9 +522,11 @@ module R43
|
|
342
522
|
# person = connection.get_persons_completed_things("erik")
|
343
523
|
# completed_goals = person.completed_goals
|
344
524
|
#
|
345
|
-
def get_persons_completed_things(username,
|
525
|
+
def get_persons_completed_things(username, optional={})
|
346
526
|
# TODO: add flickr_username handling
|
347
|
-
|
527
|
+
@string, @optional = "id=#{username}", optional
|
528
|
+
_handle_optional
|
529
|
+
store_and_return(_get_response("get_persons_completed_things?#{@string}").person)
|
348
530
|
end
|
349
531
|
|
350
532
|
#
|
@@ -352,16 +534,16 @@ module R43
|
|
352
534
|
# returns an array of the person's entries. This method
|
353
535
|
# sets connection.response and configures paging via connection.
|
354
536
|
#
|
355
|
-
# Currently broken. The web service never returns entries.
|
356
|
-
#
|
357
537
|
# require 'r43'
|
358
538
|
# connection = R43::Connection.new(<api_key>)
|
359
539
|
# entries = connection.get_persons_completed_things(<username>)
|
360
540
|
# entries += connection.more
|
361
541
|
#
|
362
|
-
def get_persons_entries(username,
|
542
|
+
def get_persons_entries(username, optional={})
|
363
543
|
# TODO: add flickr_username handling
|
364
|
-
|
544
|
+
@string, @optional = "id=#{username}", optional
|
545
|
+
_handle_optional
|
546
|
+
store_and_return(_get_response("get_persons_entries?#{@string}").entries)
|
365
547
|
end
|
366
548
|
|
367
549
|
#
|
@@ -375,9 +557,11 @@ module R43
|
|
375
557
|
# [, options])
|
376
558
|
# entries += connection.more
|
377
559
|
#
|
378
|
-
def get_persons_progress_on_goal(username, goal_id,
|
560
|
+
def get_persons_progress_on_goal(username, goal_id, optional={})
|
379
561
|
# TODO: add flickr_username handling
|
380
|
-
|
562
|
+
@string, @optional = "id=#{username}&goal_id=#{goal_id}", optional
|
563
|
+
_handle_optional
|
564
|
+
store_and_return(_get_response("get_persons_progress_on_goal?#{@string}").entries)
|
381
565
|
end
|
382
566
|
|
383
567
|
|
@@ -392,10 +576,11 @@ module R43
|
|
392
576
|
# [, options])
|
393
577
|
# people += connection.more
|
394
578
|
#
|
395
|
-
def get_persons_teammates(username,
|
579
|
+
def get_persons_teammates(username, optional={})
|
396
580
|
# TODO: add flickr_username handling
|
397
|
-
|
398
|
-
|
581
|
+
@string, @optional = "id=#{username}", optional
|
582
|
+
_handle_optional
|
583
|
+
store_and_return(_get_response("get_persons_teammates?#{@string}").people)
|
399
584
|
end
|
400
585
|
|
401
586
|
|
@@ -410,10 +595,11 @@ module R43
|
|
410
595
|
# [, options])
|
411
596
|
# people += connection.more
|
412
597
|
#
|
413
|
-
def get_persons_neighbors(username,
|
598
|
+
def get_persons_neighbors(username, optional={})
|
414
599
|
# TODO: add flickr_username handling
|
415
|
-
|
416
|
-
|
600
|
+
@string, @optional = "id=#{username}", optional
|
601
|
+
_handle_optional
|
602
|
+
store_and_return(_get_response("get_persons_neighbors?#{@string}").people)
|
417
603
|
end
|
418
604
|
|
419
605
|
|
@@ -426,9 +612,32 @@ module R43
|
|
426
612
|
# tags = connection.get_persons_tags(<username>
|
427
613
|
# [, options])
|
428
614
|
#
|
429
|
-
def get_persons_tags(username,
|
615
|
+
def get_persons_tags(username, optional={})
|
430
616
|
# TODO: add flickr_username handling
|
431
|
-
|
617
|
+
@string, @optional = "id=#{username}", optional
|
618
|
+
_handle_optional
|
619
|
+
store_and_return(_get_response("get_persons_tags?#{@string}").tags)
|
620
|
+
end
|
621
|
+
|
622
|
+
|
623
|
+
#
|
624
|
+
# Implements the get_teams_progress from the Team API
|
625
|
+
# it returns an array of entries. The array may
|
626
|
+
# be paginated.
|
627
|
+
#
|
628
|
+
# require 'r43'
|
629
|
+
# connection = R43::Connection(<api_key>)
|
630
|
+
# entries = connection.get_teams_progress(<team_id>)
|
631
|
+
#
|
632
|
+
# The get_teams_progress API method also returns an array
|
633
|
+
# of Person objects. This array can be accessed through the
|
634
|
+
# R43::Connection#people method
|
635
|
+
#
|
636
|
+
# people = connection.people
|
637
|
+
#
|
638
|
+
def get_teams_progress(team_id)
|
639
|
+
store_and_return(
|
640
|
+
_get_response("get_teams_progress?id=#{team_id}").entries)
|
432
641
|
end
|
433
642
|
|
434
643
|
|
@@ -441,12 +650,14 @@ module R43
|
|
441
650
|
# tags = connection.get_persons_tag_cloud(<username>
|
442
651
|
# [, options])
|
443
652
|
#
|
444
|
-
def get_persons_tag_cloud(username,
|
653
|
+
def get_persons_tag_cloud(username, optional={})
|
445
654
|
# TODO: add flickr_username handling
|
655
|
+
@string, @optional = "id=#{username}", optional
|
656
|
+
_handle_optional
|
446
657
|
store_and_return(_get_response("get_persons_tag_cloud?id=#{username}").tags)
|
447
658
|
end
|
448
659
|
|
449
|
-
|
660
|
+
|
450
661
|
#
|
451
662
|
# Implements the get_entry method of the Entries API and
|
452
663
|
# returns an Entry object.
|
@@ -456,9 +667,62 @@ module R43
|
|
456
667
|
# entry = connection.get_entry(<id>)
|
457
668
|
#
|
458
669
|
def get_entry(id)
|
459
|
-
store_and_return(_get_response("get_entry?id=#{id}").entry)
|
670
|
+
store_and_return(_get_response("get_entry?id=#{id.to_i}").entry)
|
671
|
+
end
|
672
|
+
|
673
|
+
#
|
674
|
+
# Implements the search_tags method from the Tag API. It returns an
|
675
|
+
# array of tags.
|
676
|
+
#
|
677
|
+
# require 'r43'
|
678
|
+
# connection = R43::Connection.new(<api_key>)
|
679
|
+
# tags = connection.search_tags(<query>)
|
680
|
+
#
|
681
|
+
# Once constructed, a tag can be grown by repeated calls to the
|
682
|
+
# R43::Connection#more method.
|
683
|
+
#
|
684
|
+
# tags += connection.more
|
685
|
+
#
|
686
|
+
def search_tags(query, optional={})
|
687
|
+
query = _clean_string(query)
|
688
|
+
@string, @optional = "q=#{query}", optional
|
689
|
+
_handle_optional
|
690
|
+
store_and_return(_get_response("search_tags?#{@string}").tags)
|
460
691
|
end
|
461
692
|
|
693
|
+
#
|
694
|
+
# Implements the get_tags_goals method from the Tag API. It returns an
|
695
|
+
# array of tags.
|
696
|
+
#
|
697
|
+
# require 'r43'
|
698
|
+
# connection = R43::Connection.new(<api_key>)
|
699
|
+
# tags = connection.get_tags_goals(<query>)
|
700
|
+
# tags += connection.more
|
701
|
+
#
|
702
|
+
def get_tags_goals(tag, optional={})
|
703
|
+
query = _clean_string(tag)
|
704
|
+
@string, @optional = "id=#{query}", optional
|
705
|
+
_handle_optional
|
706
|
+
store_and_return(_get_response("get_tags_goals?#{@string}").goals)
|
707
|
+
end
|
708
|
+
|
709
|
+
#
|
710
|
+
# Implements the get_tags_similarities method from the Tag API. It
|
711
|
+
# returns an array of tags.
|
712
|
+
#
|
713
|
+
# require 'r43'
|
714
|
+
# connection = R43::Connection.new(<api_key>)
|
715
|
+
# tags = connection.get_tags_similarities(<query>)
|
716
|
+
# tags += connection.more
|
717
|
+
#
|
718
|
+
def get_tags_similarities(tag, optional={})
|
719
|
+
query = _clean_string(tag)
|
720
|
+
@string, @optional = "id=#{query}", optional
|
721
|
+
_handle_optional
|
722
|
+
store_and_return(_get_response("get_tags_similarities?#{@string}").tags)
|
723
|
+
end
|
724
|
+
|
725
|
+
|
462
726
|
#
|
463
727
|
# Implements the search_cities method of the Cities API
|
464
728
|
#
|
@@ -466,7 +730,10 @@ module R43
|
|
466
730
|
# connection = R43::Connection.new(<api_key>)
|
467
731
|
# cities = connection.search_cities(<query>)
|
468
732
|
#
|
469
|
-
def search_cities(query)
|
733
|
+
def search_cities(query, optional={})
|
734
|
+
query = _clean_string(query)
|
735
|
+
@string, @optional = "q=#{query}", optional
|
736
|
+
_handle_optional
|
470
737
|
store_and_return(_get_response("search_cities?q=#{query}").cities)
|
471
738
|
end
|
472
739
|
|
@@ -479,7 +746,7 @@ module R43
|
|
479
746
|
#
|
480
747
|
|
481
748
|
def get_city(id)
|
482
|
-
store_and_return(_get_response("get_city?id=#{id}").city)
|
749
|
+
store_and_return(_get_response("get_city?id=#{id.to_i}").city)
|
483
750
|
end
|
484
751
|
|
485
752
|
#
|
@@ -491,147 +758,14 @@ module R43
|
|
491
758
|
#
|
492
759
|
|
493
760
|
def get_citys_people(id, optional={})
|
494
|
-
|
495
|
-
|
496
|
-
params += "&max=#{optional["max"]}" if optional["max"]
|
761
|
+
@string, @optional = "id=#{id.to_i}", optional
|
762
|
+
_handle_optional
|
497
763
|
|
498
|
-
store_and_return(_get_response("get_citys_people?#{
|
764
|
+
store_and_return(_get_response("get_citys_people?#{@string}").people)
|
499
765
|
end
|
500
|
-
|
501
|
-
end
|
502
766
|
|
503
|
-
|
504
|
-
attr_reader :service, :query, :xml,
|
505
|
-
:object, :entry, :person, :goal, :city,
|
506
|
-
:objects, :entries, :people, :goals, :cities, :tags,
|
507
|
-
:has_object, :max_in_page, :total_available, :next_offset
|
508
|
-
|
509
|
-
def initialize(service, query)
|
510
|
-
@service = service
|
511
|
-
@query = query
|
512
|
-
@has_object = false
|
513
|
-
@objects = []
|
514
|
-
@entries = []
|
515
|
-
@people = []
|
516
|
-
@goals = []
|
517
|
-
@cities = []
|
518
|
-
@tags = []
|
519
|
-
@max_in_page = 0
|
520
|
-
@total_available = 0
|
521
|
-
@next_offset = 0
|
522
|
-
_from_xml(service.get_response(query))
|
523
|
-
end
|
524
|
-
|
525
|
-
def more()
|
526
|
-
clear_arrays()
|
527
|
-
_populate_collections_from_xml(service.get_response(query + "&offset=#{@next_offset}"))
|
528
|
-
end
|
529
|
-
|
530
|
-
private
|
767
|
+
|
531
768
|
|
532
|
-
def clear_arrays()
|
533
|
-
@objects.clear()
|
534
|
-
@entries.clear()
|
535
|
-
@people.clear()
|
536
|
-
@goals.clear()
|
537
|
-
@cities.clear()
|
538
|
-
@tags.clear()
|
539
|
-
end
|
540
|
-
|
541
|
-
def object=(object)
|
542
|
-
if @has_object
|
543
|
-
@object = nil
|
544
|
-
else
|
545
|
-
@has_object = true
|
546
|
-
@object = object
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
|
-
def entry=(entry)
|
551
|
-
@entry = entry
|
552
|
-
self.object = @entry
|
553
|
-
add_entry(@entry)
|
554
|
-
end
|
555
|
-
|
556
|
-
def person=(person)
|
557
|
-
@person = person
|
558
|
-
self.object = @person
|
559
|
-
add_person @person
|
560
|
-
end
|
561
|
-
|
562
|
-
def goal=(goal)
|
563
|
-
@goal = goal
|
564
|
-
self.object = @goal
|
565
|
-
add_goal @goal
|
566
|
-
end
|
567
|
-
|
568
|
-
def city=(city)
|
569
|
-
@city = city
|
570
|
-
self.object = @city
|
571
|
-
add_city @city
|
572
|
-
end
|
573
|
-
|
574
|
-
def add_entry(entry)
|
575
|
-
@entries.push entry
|
576
|
-
@objects.push entry
|
577
|
-
end
|
578
|
-
|
579
|
-
def add_person(person)
|
580
|
-
@people.push person
|
581
|
-
@objects.push person
|
582
|
-
end
|
583
|
-
|
584
|
-
def add_goal(goal)
|
585
|
-
@goals.push goal
|
586
|
-
@objects.push goal
|
587
|
-
end
|
588
|
-
|
589
|
-
def add_city(city)
|
590
|
-
@cities.push city
|
591
|
-
@objects.push city
|
592
|
-
end
|
593
|
-
|
594
|
-
def add_tag(tag)
|
595
|
-
@tags.push tag
|
596
|
-
@objects.push tag
|
597
|
-
end
|
598
|
-
|
599
|
-
def _from_xml(xml)
|
600
|
-
@xml = xml
|
601
|
-
self.entry = Entry.from_xml(xml.elements["entry"]) if xml.elements["entry"]
|
602
|
-
self.person = Person.from_xml(xml.elements["person"]) if xml.elements["person"]
|
603
|
-
self.goal = Goal.from_xml(xml.elements["goal"]) if xml.elements["goal"]
|
604
|
-
self.city = City.from_xml(xml.elements["city"]) if xml.elements["city"]
|
605
|
-
_populate_collections_from_xml xml
|
606
|
-
end
|
607
|
-
|
608
|
-
def _populate_collections_from_xml(xml)
|
609
|
-
if xml.elements["feed/pagination"] then
|
610
|
-
@max_per_page = xml.elements["feed/pagination/max"].text.to_i
|
611
|
-
@total_available = xml.elements["feed/pagination/total"].text.to_i
|
612
|
-
@next_offset = xml.elements["feed/pagination/next_offset"].text.to_i
|
613
|
-
end
|
614
|
-
|
615
|
-
xml.elements.each("feed/entry") do |entry_element|
|
616
|
-
add_entry(Entry.from_xml(entry_element))
|
617
|
-
end
|
618
|
-
|
619
|
-
xml.elements.each("feed/person") do |person_element|
|
620
|
-
add_person(Person.from_xml(person_element))
|
621
|
-
end
|
622
|
-
|
623
|
-
xml.elements.each("feed/goal") do |goal_element|
|
624
|
-
add_goal(Goal.from_xml(goal_element))
|
625
|
-
end
|
626
|
-
|
627
|
-
xml.elements.each("feed/city") do |city_element|
|
628
|
-
add_city(City.from_xml(city_element))
|
629
|
-
end
|
630
|
-
|
631
|
-
xml.elements.each("feed/tags/tag") do |tag_element|
|
632
|
-
tag = Tag.from_xml(tag_element)
|
633
|
-
add_tag(tag)
|
634
|
-
end
|
635
|
-
end
|
636
769
|
end
|
770
|
+
|
637
771
|
end
|