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
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: r43
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2005-08-03
|
8
8
|
summary: A Ruby wrapper for the 43 Things web services API
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -28,46 +28,58 @@ authors:
|
|
28
28
|
- Pat Eyler
|
29
29
|
files:
|
30
30
|
- test/get_goal_by_name-255.xml
|
31
|
+
- test/get_tags_goals-travel.xml
|
32
|
+
- test/idea-get_person-pate.xml
|
31
33
|
- test/get_goals_entries-255-offset20.xml
|
34
|
+
- test/search_tags-travel.xml
|
32
35
|
- test/get_persons_teammates-erik.xml
|
36
|
+
- test/get_tags_goals-travel-offset80-max10.xml
|
33
37
|
- test/search_goals-ruby.xml
|
34
|
-
- test/test_r43.rb.~1.8.~
|
35
38
|
- test/get_persons_neighbors-erik.xml
|
36
39
|
- test/get_persons_progress_on_goal-erik-9.xml
|
40
|
+
- test/search_tags-lose+weight.xml
|
37
41
|
- test/search_goals-ruby-offset20-max10.xml
|
38
42
|
- test/get_goals_people-533-offset20.xml
|
39
43
|
- test/search_goals-schemer.xml
|
40
44
|
- test/get_persons_tags-erik.xml
|
41
45
|
- test/search_cities-london.xml
|
42
46
|
- test/get_city-36.xml
|
47
|
+
- test/get_city-1164.xml
|
43
48
|
- test/get_goals_entries-533.xml
|
44
49
|
- test/search_people-Sean.xml
|
45
50
|
- test/get_person-erik.xml
|
46
51
|
- test/get_goals_people-533.xml
|
47
52
|
- test/get_citys_people-1164.xml
|
53
|
+
- test/get_teams_progress-222591.xml
|
48
54
|
- test/get_persons_entries-erik.xml
|
55
|
+
- test/es-get_persons_tags-Alvaro.xml
|
49
56
|
- test/get_persons_tag_cloud-erik.xml
|
50
57
|
- test/test_r43.rb
|
51
58
|
- test/get_goal_by_id-255.xml
|
52
59
|
- test/get_persons_completed_things-erik.xml
|
60
|
+
- test/search_tags-travel-offset20.xml
|
53
61
|
- test/get_persons_neighbors-erik-20.xml
|
54
62
|
- test/get_citys_people-1164-offset20.xml
|
55
63
|
- test/authentication.xml
|
56
64
|
- test/search_people_by_email-erik@mockerybird.com.xml
|
57
65
|
- test/search_goals-ruby-offset20.xml
|
66
|
+
- test/get_tags_goals-travel-offset20.xml
|
58
67
|
- test/echo.xml
|
68
|
+
- test/get_tags_similarities-travel.xml
|
59
69
|
- test/get_person-sweeting.xml
|
60
70
|
- test/get_entry-33.xml
|
71
|
+
- test/get_teams_progress-7.xml
|
61
72
|
- test/get_person-flickr_username.xml
|
73
|
+
- test/get_goal_by_id-533.xml
|
62
74
|
- test/get_goals_similarities-255.xml
|
63
|
-
- lib/
|
64
|
-
- lib/person.rb
|
75
|
+
- lib/r43
|
65
76
|
- lib/r43.rb
|
66
|
-
- lib/
|
67
|
-
- lib/
|
68
|
-
- lib/
|
69
|
-
- lib/r43.rb
|
70
|
-
- lib/
|
77
|
+
- lib/r43/id.rb
|
78
|
+
- lib/r43/person.rb
|
79
|
+
- lib/r43/goal.rb
|
80
|
+
- lib/r43/entry.rb
|
81
|
+
- lib/r43/tag.rb
|
82
|
+
- lib/r43/city.rb
|
71
83
|
test_files: []
|
72
84
|
rdoc_options: []
|
73
85
|
extra_rdoc_files: []
|
data/lib/r43.rb.~1.6.~
DELETED
@@ -1,645 +0,0 @@
|
|
1
|
-
# copyright 2005 Pat Eyler, Sean Carley, & Edward Cho
|
2
|
-
# distributed under the same terms as Ruby
|
3
|
-
|
4
|
-
|
5
|
-
require 'net/http'
|
6
|
-
require 'rexml/document'
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
# Implements a city object from 43 things. Currently only meant
|
11
|
-
# to be contructed by an R43::Request object.
|
12
|
-
#
|
13
|
-
|
14
|
-
class City
|
15
|
-
attr_accessor :city_id, :name, :region, :country, :num_people,
|
16
|
-
:link, :goals
|
17
|
-
|
18
|
-
def initialize()
|
19
|
-
# just to initialize the object, we'll always feed the attributes
|
20
|
-
# in some other way
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
# Builds a City object from 43 things. Currently only meant to
|
26
|
-
# constructed by an R43::Request object.
|
27
|
-
#
|
28
|
-
def City.from_xml(xml)
|
29
|
-
city = City.new()
|
30
|
-
city.name= xml.elements["name"].text
|
31
|
-
city.region= xml.elements["region"].text
|
32
|
-
city.country= xml.elements["country"].text
|
33
|
-
city.num_people= xml.elements["num_people"].text.to_i
|
34
|
-
city.link= xml.elements["link"].attributes["href"]
|
35
|
-
city.city_id= xml.attributes["city_id"].to_i
|
36
|
-
|
37
|
-
city.goals = Array.new
|
38
|
-
xml.elements.each("goal") do |goal_element|
|
39
|
-
goal = Goal.from_xml(goal_element)
|
40
|
-
city.goals.push(goal)
|
41
|
-
end
|
42
|
-
|
43
|
-
city
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
# Implements an entry object from 43 things. Currently only meant
|
51
|
-
# to be constructed by an R43::Request object.
|
52
|
-
#
|
53
|
-
#
|
54
|
-
|
55
|
-
class Entry
|
56
|
-
attr_accessor :title, :author, :dc_subject, :goal, :content,
|
57
|
-
:num_comments, :issued, :link, :id
|
58
|
-
|
59
|
-
def initialize()
|
60
|
-
# just to initialize the object, we'll always feed the attributes
|
61
|
-
# in some other way
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
# Builds an Entry object from an xml object. Normally, this is
|
67
|
-
# called by the get_entry method of an R43::Request object.
|
68
|
-
#
|
69
|
-
def Entry.from_xml(xml)
|
70
|
-
entry = Entry.new
|
71
|
-
|
72
|
-
if xml.elements["title"] then
|
73
|
-
entry.title= xml.elements["title"].text
|
74
|
-
end
|
75
|
-
entry.dc_subject= xml.elements["dc:subject"].text
|
76
|
-
entry.content= xml.elements["content"].text
|
77
|
-
entry.num_comments=
|
78
|
-
xml.elements["num_comments"].text.to_i
|
79
|
-
entry.issued= xml.elements["issued"].text
|
80
|
-
entry.link= xml.elements["link"].attributes["href"]
|
81
|
-
entry.id= xml.elements["id"].text
|
82
|
-
|
83
|
-
xml.elements.each("author") do |entry_element|
|
84
|
-
entry.author= Person.from_xml(entry_element)
|
85
|
-
end
|
86
|
-
|
87
|
-
goal = Goal.new
|
88
|
-
xml.elements.each("goal") do |goal_entry|
|
89
|
-
goal = Goal.from_xml(goal_entry)
|
90
|
-
end
|
91
|
-
entry.goal= goal
|
92
|
-
|
93
|
-
entry
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
#
|
99
|
-
# Implements a person object from 43 things. Currently only meant to
|
100
|
-
# be constructed by a R43::Request object:
|
101
|
-
#
|
102
|
-
# require 'r43'
|
103
|
-
# connect = R43::Request.new(<api_key>)
|
104
|
-
# person = connect.get_person('<username>')
|
105
|
-
#
|
106
|
-
class Person
|
107
|
-
attr_accessor :username, :name, :url, :profile_image_url,
|
108
|
-
:num_open_goals, :link, :city, :goals, :flickr_username
|
109
|
-
|
110
|
-
def initialize()
|
111
|
-
# just to create the object, we'll always feed the attributes in
|
112
|
-
# some other way
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
# Builds a Person object from an xml object. Normally, this is
|
118
|
-
# called by the get_person method of an R43::Request object.
|
119
|
-
#
|
120
|
-
def Person.from_xml(xml)
|
121
|
-
person = Person.new
|
122
|
-
|
123
|
-
person.username= xml.elements["username"].text
|
124
|
-
person.name= xml.elements["name"].text
|
125
|
-
person.url= xml.elements["url"].text
|
126
|
-
person.num_open_goals=
|
127
|
-
xml.elements["num_open_goals"].text.to_i
|
128
|
-
person.link= xml.elements["link"].attributes["href"]
|
129
|
-
|
130
|
-
person.flickr_username=xml.elements["flickr_username"].text if xml.elements["flickr_username"]
|
131
|
-
|
132
|
-
if xml.elements["profile_image_url"] then
|
133
|
-
person.profile_image_url=
|
134
|
-
xml.elements["profile_image_url"].text
|
135
|
-
else
|
136
|
-
person.profile_image_url= "none"
|
137
|
-
end
|
138
|
-
|
139
|
-
if xml.elements["city"] then
|
140
|
-
xml.elements.each("city") do |element|
|
141
|
-
person.city = City.from_xml(element)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
person.goals = Array.new
|
146
|
-
xml.elements.each("open_goals/goal") do |goal_element|
|
147
|
-
goal = Goal.from_xml(goal_element)
|
148
|
-
person.goals.push(goal)
|
149
|
-
end
|
150
|
-
|
151
|
-
person
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
# Implements a goal object from 43 things. Currently only meant to be
|
158
|
-
# constructed by an R43::Request object
|
159
|
-
#
|
160
|
-
# require 'r43'
|
161
|
-
# connect = R43::Request.new(<api_key>)
|
162
|
-
# goal = get_goal_by_id(<goal_id>)
|
163
|
-
#
|
164
|
-
class Goal
|
165
|
-
attr_accessor :goal_id, :name, :link, :num_registered_people,
|
166
|
-
:num_unregistered_people, :num_say_worth_it,
|
167
|
-
:num_say_not_worth_it, :percentage_worth_it,
|
168
|
-
:tags, :id, :progress_link, :team_link
|
169
|
-
|
170
|
-
def initialize()
|
171
|
-
# just to initialize the object, we'll always feed the attributes in
|
172
|
-
# some other way
|
173
|
-
end
|
174
|
-
|
175
|
-
#
|
176
|
-
# Builds a Goal object from an xml object. Normally, this is
|
177
|
-
# called by the get_goal_by_id or get_goal_by_name methods of
|
178
|
-
# an R43::Request object.
|
179
|
-
#
|
180
|
-
def Goal.from_xml(xml)
|
181
|
-
goal = Goal.new()
|
182
|
-
|
183
|
-
goal.goal_id= xml.attributes["goal_id"].to_i
|
184
|
-
goal.name= xml.elements["name"].text
|
185
|
-
goal.link= xml.elements["link"].attributes["href"]
|
186
|
-
|
187
|
-
if xml.elements["num_registered_people"] then
|
188
|
-
goal.num_registered_people=
|
189
|
-
xml.elements["num_registered_people"].text.to_i
|
190
|
-
end
|
191
|
-
|
192
|
-
if xml.elements["num_unregistered_people"] then
|
193
|
-
goal.num_unregistered_people=
|
194
|
-
xml.elements["num_unregistered_people"].text.to_i
|
195
|
-
end
|
196
|
-
|
197
|
-
if xml.elements["worth_it_data"] then
|
198
|
-
goal.num_say_worth_it=
|
199
|
-
xml.elements["worth_it_data"].elements["num_say_worth_it"].text.to_i
|
200
|
-
goal.num_say_not_worth_it=
|
201
|
-
xml.elements["worth_it_data"].elements["num_say_not_worth_it"].text.to_i
|
202
|
-
goal.percentage_worth_it=
|
203
|
-
xml.elements["worth_it_data"].elements["percentage_worth_it"].text.to_i
|
204
|
-
end
|
205
|
-
goal.id= xml.elements["id"].text
|
206
|
-
|
207
|
-
tags = []
|
208
|
-
xml.elements.each("tags/tag") do |tag_element|
|
209
|
-
tags.push(tag_element.text)
|
210
|
-
end
|
211
|
-
goal.tags= tags
|
212
|
-
|
213
|
-
goal
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
module R43
|
218
|
-
|
219
|
-
|
220
|
-
private
|
221
|
-
|
222
|
-
class R43::Service
|
223
|
-
attr_reader :key
|
224
|
-
|
225
|
-
def initialize(key)
|
226
|
-
@key = key.to_s
|
227
|
-
end
|
228
|
-
|
229
|
-
protected
|
230
|
-
|
231
|
-
#
|
232
|
-
# a private method to add the api_key to the request url
|
233
|
-
#
|
234
|
-
def _inject_key(url)
|
235
|
-
key_str = "api_key=#{@key}"
|
236
|
-
if url =~ /\?$/
|
237
|
-
url + key_str
|
238
|
-
elsif url =~ /\?/
|
239
|
-
url.sub /\?/, "?#{key_str}&"
|
240
|
-
else
|
241
|
-
url + "?" + key_str
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
#
|
246
|
-
# a private method for getting responses from 43 things.
|
247
|
-
#
|
248
|
-
def _get_response(url)
|
249
|
-
full_url = _inject_key url
|
250
|
-
Net::HTTP.start('www.43things.com') do |http|
|
251
|
-
response = http.get("/service/#{full_url}")
|
252
|
-
if response.code == "200" then
|
253
|
-
xml = REXML::Document.new(response.body)
|
254
|
-
else
|
255
|
-
return response.code
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
public
|
261
|
-
|
262
|
-
def get_response(url)
|
263
|
-
_get_response(_inject_key(url))
|
264
|
-
end
|
265
|
-
|
266
|
-
end
|
267
|
-
|
268
|
-
public
|
269
|
-
|
270
|
-
#
|
271
|
-
# Implements the 43 Things API. This is where you actually
|
272
|
-
# instantiate objects.
|
273
|
-
#
|
274
|
-
# require 'r43'
|
275
|
-
# connection = R43::Request.new(<api_key>)
|
276
|
-
#
|
277
|
-
class R43::Request
|
278
|
-
attr_reader :service
|
279
|
-
|
280
|
-
def initialize(key)
|
281
|
-
@service = R43::Service.new key
|
282
|
-
end
|
283
|
-
|
284
|
-
|
285
|
-
private
|
286
|
-
|
287
|
-
#
|
288
|
-
# a private method for getting responses from 43 things.
|
289
|
-
#
|
290
|
-
def _get_response(url)
|
291
|
-
Response.new(@service, url)
|
292
|
-
end
|
293
|
-
|
294
|
-
public
|
295
|
-
|
296
|
-
#
|
297
|
-
# Implements the echo method from the General API. Returns a hash
|
298
|
-
# with the keys; <em>api_key</em>, <em>action</em>,
|
299
|
-
# <em>controller</em>
|
300
|
-
#
|
301
|
-
# require 'r43'
|
302
|
-
# connection = R43::Request.new(<api_key>)
|
303
|
-
# response = connection.echo
|
304
|
-
#
|
305
|
-
def echo()
|
306
|
-
xml = _get_response("echo").xml
|
307
|
-
response = {
|
308
|
-
"api_key" =>
|
309
|
-
xml.elements["parameters"].elements["api_key"].text,
|
310
|
-
"action" =>
|
311
|
-
xml.elements["parameters"].elements["action"].text,
|
312
|
-
"controller" =>
|
313
|
-
xml.elements["parameters"].elements["controller"].text
|
314
|
-
}
|
315
|
-
end
|
316
|
-
|
317
|
-
|
318
|
-
#
|
319
|
-
# Implements the authentication_test method from the General API.
|
320
|
-
# returns "true" if the connection works. Only uses the cleartext
|
321
|
-
# username and password at this point
|
322
|
-
#
|
323
|
-
# require 'r43'
|
324
|
-
# connection = R43::Request.new(<api_key>)
|
325
|
-
# response = connection.echo(<username>,<password>)
|
326
|
-
#--
|
327
|
-
# This really needs ATOM style authentication to work properly
|
328
|
-
#++
|
329
|
-
#
|
330
|
-
def authentication_test(username, password)
|
331
|
-
xml = _get_response("authentication_test?username=#{username}&password=#{password}").xml
|
332
|
-
xml.elements["authentication_test"].text
|
333
|
-
end
|
334
|
-
|
335
|
-
#
|
336
|
-
# Implements the get_goal_by_id method from the Goals API. Returns a
|
337
|
-
# Goal object.
|
338
|
-
#
|
339
|
-
# require 'r43'
|
340
|
-
# connection = R43::Request.new(<api_key>)
|
341
|
-
# goal = connection.get_goal_by_id(255)
|
342
|
-
#
|
343
|
-
def get_goal_by_id(id)
|
344
|
-
_get_response("get_goal_by_id?id=#{id}").goal
|
345
|
-
end
|
346
|
-
|
347
|
-
|
348
|
-
#
|
349
|
-
# Implements the get_goal_by_name method from the Goals API. Returns
|
350
|
-
# a Goal object
|
351
|
-
#
|
352
|
-
# require 'r43'
|
353
|
-
# connection = R43::Request.new(<api_key>)
|
354
|
-
# goal = connection.get_goal_by_name(<name>)
|
355
|
-
#
|
356
|
-
def get_goal_by_name(name)
|
357
|
-
name = name.gsub!(/\s/, '+')
|
358
|
-
_get_response("get_goal_by_name?name=#{name}").goal
|
359
|
-
end
|
360
|
-
|
361
|
-
|
362
|
-
#
|
363
|
-
# Implements the get_goals_similarities method from the Goals API and
|
364
|
-
# returns an R43::Response containing an array of Goal objects
|
365
|
-
#
|
366
|
-
#
|
367
|
-
# require 'r43'
|
368
|
-
# connection = R43::Request.new(<api_key>)
|
369
|
-
# goals = connection.get_goals_similarities(<id>).goals
|
370
|
-
#
|
371
|
-
def get_goals_similarities(id)
|
372
|
-
_get_response("get_goals_similarities?id=#{id}")
|
373
|
-
end
|
374
|
-
|
375
|
-
#
|
376
|
-
# Implements the search_goals method from the Goals API and
|
377
|
-
# returns an R43::Response containing an array of Goal objects
|
378
|
-
#
|
379
|
-
#
|
380
|
-
# require 'r43'
|
381
|
-
# connection = R43::Request.new(<api_key>)
|
382
|
-
# response = connection.search_goals(<query string>[,
|
383
|
-
# {["offset" => <offset>],
|
384
|
-
# ["max" => <max>]}])
|
385
|
-
# goals = response.goals
|
386
|
-
#
|
387
|
-
def search_goals(string, optional={})
|
388
|
-
string.gsub!(/\s/, "+")
|
389
|
-
if optional["offset"] then
|
390
|
-
string += "&offset=#{optional["offset"]}"
|
391
|
-
end
|
392
|
-
if optional["max"] then
|
393
|
-
string += "&max=#{optional["max"]}"
|
394
|
-
end
|
395
|
-
|
396
|
-
_get_response("search_goals?q=#{string}")
|
397
|
-
end
|
398
|
-
|
399
|
-
#
|
400
|
-
# Implements the get_goals_people method from the Goals API and
|
401
|
-
# returns an R43:Response containging an array of Person objects
|
402
|
-
#
|
403
|
-
#
|
404
|
-
# require 'r43'
|
405
|
-
# connection = R43::Request.new(<api_key>)
|
406
|
-
# response = connection.get_goals_people(<id>[,
|
407
|
-
# {["offset" => <offset>],
|
408
|
-
# ["max" => <max>]}])
|
409
|
-
# people = response.people
|
410
|
-
#
|
411
|
-
def get_goals_people(id, optional={})
|
412
|
-
string = "id=#{id}"
|
413
|
-
if optional["offset"] then
|
414
|
-
string += "&offset=#{optional["offset"]}"
|
415
|
-
end
|
416
|
-
if optional["max"] then
|
417
|
-
string += "&max=#{optional["max"]}"
|
418
|
-
end
|
419
|
-
|
420
|
-
_get_response("get_goals_people?#{string}")
|
421
|
-
end
|
422
|
-
|
423
|
-
#
|
424
|
-
# Implements the get_goals_entries method from the Goals API and
|
425
|
-
# returns an array of Entry objects
|
426
|
-
#
|
427
|
-
#
|
428
|
-
# require 'r43'
|
429
|
-
# connection = R43::Request.new(<api_key>)
|
430
|
-
# entries = connection.get_goals_entries(<id>,[{["offset" => <offset>],
|
431
|
-
# ["max" => <max>],
|
432
|
-
# ["view" => <view>]}])
|
433
|
-
#
|
434
|
-
def get_goals_entries(id, optional={})
|
435
|
-
string = "id=#{id}"
|
436
|
-
if optional["offset"] then
|
437
|
-
string += "&offset=#{optional["offset"]}"
|
438
|
-
end
|
439
|
-
if optional["max"] then
|
440
|
-
string += "&max=#{optional["max"]}"
|
441
|
-
end
|
442
|
-
if optional["view"] then
|
443
|
-
string += "&view=#{optional["view"]}"
|
444
|
-
end
|
445
|
-
|
446
|
-
_get_response("get_goals_entries?#{string}")
|
447
|
-
end
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
#
|
452
|
-
# Implements the get_person method from the People API and returns a
|
453
|
-
# Person object. If the optional true or false value is set to true,
|
454
|
-
# the username is treated as a flickr username instead of a 43 Things
|
455
|
-
# username. If the value is false or not set, the username is treated
|
456
|
-
# as a 43 Things username.
|
457
|
-
#
|
458
|
-
# require 'r43'
|
459
|
-
# connection = R43::Request.new(<api_key>)
|
460
|
-
# person = connection.get_person(<username>[, <true|false>])
|
461
|
-
#
|
462
|
-
def get_person(id,use_flickr=false)
|
463
|
-
if (use_flickr)
|
464
|
-
id_cmd = "flickr_username"
|
465
|
-
else
|
466
|
-
id_cmd = "id"
|
467
|
-
end
|
468
|
-
_get_response("get_person?#{id_cmd}=#{id}").person
|
469
|
-
end
|
470
|
-
|
471
|
-
|
472
|
-
#
|
473
|
-
# Implements the get_entry method of the Entries API
|
474
|
-
#
|
475
|
-
# require 'r43'
|
476
|
-
# connection = R43::Request.new(<api_key>)
|
477
|
-
# connection.get_entry(<id>)
|
478
|
-
#
|
479
|
-
|
480
|
-
def get_entry(id)
|
481
|
-
_get_response("get_entry?id=#{id}").entry
|
482
|
-
end
|
483
|
-
|
484
|
-
#
|
485
|
-
# Implements the search_cities method of the Cities API
|
486
|
-
#
|
487
|
-
# require 'r43'
|
488
|
-
# connection = R43::Request.new(<api_key>)
|
489
|
-
# connection.search_cities(<query>)
|
490
|
-
#
|
491
|
-
|
492
|
-
def search_cities(query)
|
493
|
-
_get_response("search_cities?q=#{query}").cities
|
494
|
-
end
|
495
|
-
|
496
|
-
#
|
497
|
-
# Implements the get_city method of the Cities API
|
498
|
-
#
|
499
|
-
# require 'r43'
|
500
|
-
# connection = R43::Request.new(<api_key>)
|
501
|
-
# connection.get_city(<id>)
|
502
|
-
#
|
503
|
-
|
504
|
-
def get_city(id)
|
505
|
-
_get_response("get_city?id=#{id}").city
|
506
|
-
end
|
507
|
-
|
508
|
-
#
|
509
|
-
# Implements the get_citys_people method of the Cities API
|
510
|
-
#
|
511
|
-
# require 'r43'
|
512
|
-
# connection = R43::Request.new(<api_key>)
|
513
|
-
# connection.get_citys_people(<id>)
|
514
|
-
#
|
515
|
-
|
516
|
-
def get_citys_people(id, optional={})
|
517
|
-
params = "id=#{id}"
|
518
|
-
params += "&offset=#{optional["offset"]}" if optional["offset"]
|
519
|
-
params += "&max=#{optional["max"]}" if optional["max"]
|
520
|
-
|
521
|
-
_get_response("get_citys_people?#{params}").people
|
522
|
-
end
|
523
|
-
|
524
|
-
end
|
525
|
-
|
526
|
-
class R43::Response
|
527
|
-
attr_reader :service, :query, :xml,
|
528
|
-
:object, :entry, :person, :goal, :city,
|
529
|
-
:objects, :entries, :people, :goals, :cities, :tags,
|
530
|
-
:has_object, :max_in_page, :total_available, :next_offset
|
531
|
-
|
532
|
-
def initialize(service, query)
|
533
|
-
@service = service
|
534
|
-
@query = query
|
535
|
-
@has_object = false
|
536
|
-
@objects = []
|
537
|
-
@entries = []
|
538
|
-
@people = []
|
539
|
-
@goals = []
|
540
|
-
@cities = []
|
541
|
-
@tags = []
|
542
|
-
@max_in_page = 0
|
543
|
-
@total_available = 0
|
544
|
-
@next_offset = 0
|
545
|
-
_from_xml(service.get_response(query))
|
546
|
-
end
|
547
|
-
|
548
|
-
def more()
|
549
|
-
_populate_collections_from_xml(service.get_response(query + "&offset=#{@next_offset}"))
|
550
|
-
end
|
551
|
-
|
552
|
-
private
|
553
|
-
|
554
|
-
def object=(object)
|
555
|
-
if @has_object
|
556
|
-
@object = nil
|
557
|
-
else
|
558
|
-
@has_object = true
|
559
|
-
@object = object
|
560
|
-
end
|
561
|
-
end
|
562
|
-
|
563
|
-
def entry=(entry)
|
564
|
-
@entry = entry
|
565
|
-
self.object = @entry
|
566
|
-
add_entry(@entry)
|
567
|
-
end
|
568
|
-
|
569
|
-
def person=(person)
|
570
|
-
@person = person
|
571
|
-
self.object = @person
|
572
|
-
add_person @person
|
573
|
-
end
|
574
|
-
|
575
|
-
def goal=(goal)
|
576
|
-
@goal = goal
|
577
|
-
self.object = @goal
|
578
|
-
add_goal @goal
|
579
|
-
end
|
580
|
-
|
581
|
-
def city=(city)
|
582
|
-
@city = city
|
583
|
-
self.object = @city
|
584
|
-
add_city @city
|
585
|
-
end
|
586
|
-
|
587
|
-
def add_entry(entry)
|
588
|
-
@entries.push entry
|
589
|
-
@objects.push entry
|
590
|
-
end
|
591
|
-
|
592
|
-
def add_person(person)
|
593
|
-
@people.push person
|
594
|
-
@objects.push person
|
595
|
-
end
|
596
|
-
|
597
|
-
def add_goal(goal)
|
598
|
-
@goals.push goal
|
599
|
-
@objects.push goal
|
600
|
-
end
|
601
|
-
|
602
|
-
def add_city(city)
|
603
|
-
@cities.push city
|
604
|
-
@objects.push city
|
605
|
-
end
|
606
|
-
|
607
|
-
def add_tag(tag)
|
608
|
-
@tags.push tag
|
609
|
-
@objects.push tag
|
610
|
-
end
|
611
|
-
|
612
|
-
def _from_xml(xml)
|
613
|
-
@xml = xml
|
614
|
-
self.entry = Entry.from_xml(xml.elements["entry"]) if xml.elements["entry"]
|
615
|
-
self.person = Person.from_xml(xml.elements["person"]) if xml.elements["person"]
|
616
|
-
self.goal = Goal.from_xml(xml.elements["goal"]) if xml.elements["goal"]
|
617
|
-
self.city = City.from_xml(xml.elements["city"]) if xml.elements["city"]
|
618
|
-
_populate_collections_from_xml xml
|
619
|
-
end
|
620
|
-
|
621
|
-
def _populate_collections_from_xml(xml)
|
622
|
-
if xml.elements["feed/pagination"] then
|
623
|
-
@max_per_page = xml.elements["feed/pagination/max"].text.to_i
|
624
|
-
@total_available = xml.elements["feed/pagination/total"].text.to_i
|
625
|
-
@next_offset = xml.elements["feed/pagination/next_offset"].text.to_i
|
626
|
-
end
|
627
|
-
|
628
|
-
xml.elements.each("feed/entry") do |entry_element|
|
629
|
-
add_entry(Entry.from_xml(entry_element))
|
630
|
-
end
|
631
|
-
|
632
|
-
xml.elements.each("feed/person") do |person_element|
|
633
|
-
add_person(Person.from_xml(person_element))
|
634
|
-
end
|
635
|
-
|
636
|
-
xml.elements.each("feed/goal") do |goal_element|
|
637
|
-
add_goal(Goal.from_xml(goal_element))
|
638
|
-
end
|
639
|
-
|
640
|
-
xml.elements.each("feed/city") do |city_element|
|
641
|
-
add_city(City.from_xml(city_element))
|
642
|
-
end
|
643
|
-
end
|
644
|
-
end
|
645
|
-
end
|