tagcrumbs 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +79 -56
  3. data/README.rdoc +9 -1
  4. data/Rakefile +2 -1
  5. data/TODO.txt +0 -7
  6. data/config/website.yml +2 -0
  7. data/examples/filter_new.rb +7 -3
  8. data/examples/placemark_new_suggestions.rb +4 -2
  9. data/examples/request_authorization.rb +1 -1
  10. data/examples/tagcrumbs_find.rb +3 -3
  11. data/examples/user.rb +1 -1
  12. data/lib/console.rb +14 -0
  13. data/lib/tagcrumbs.rb +41 -14
  14. data/lib/tagcrumbs/cli.rb +1 -1
  15. data/lib/tagcrumbs/config_store.rb +3 -3
  16. data/lib/tagcrumbs/core_extensions.rb +19 -0
  17. data/lib/tagcrumbs/parsers/json_parser.rb +7 -3
  18. data/lib/tagcrumbs/proxy.rb +6 -3
  19. data/lib/tagcrumbs/requestor.rb +22 -5
  20. data/lib/tagcrumbs/resources/{array.rb → collection.rb} +8 -7
  21. data/lib/tagcrumbs/resources/models/access_token.rb +8 -0
  22. data/lib/tagcrumbs/resources/models/accessors.rb +17 -3
  23. data/lib/tagcrumbs/resources/models/activity.rb +1 -0
  24. data/lib/tagcrumbs/resources/models/application.rb +9 -0
  25. data/lib/tagcrumbs/resources/models/comment.rb +2 -0
  26. data/lib/tagcrumbs/resources/models/email_recommendation.rb +17 -0
  27. data/lib/tagcrumbs/resources/models/favorite.rb +2 -1
  28. data/lib/tagcrumbs/resources/models/filter.rb +2 -2
  29. data/lib/tagcrumbs/resources/models/flag.rb +3 -0
  30. data/lib/tagcrumbs/resources/models/model.rb +8 -7
  31. data/lib/tagcrumbs/resources/models/paragraph.rb +8 -0
  32. data/lib/tagcrumbs/resources/models/picture.rb +4 -4
  33. data/lib/tagcrumbs/resources/models/place.rb +3 -3
  34. data/lib/tagcrumbs/resources/models/placemark.rb +3 -2
  35. data/lib/tagcrumbs/resources/models/profile.rb +0 -1
  36. data/lib/tagcrumbs/resources/models/profile_link.rb +1 -1
  37. data/lib/tagcrumbs/resources/models/root.rb +3 -3
  38. data/lib/tagcrumbs/resources/models/settings.rb +2 -1
  39. data/lib/tagcrumbs/resources/models/tagcrumb.rb +4 -12
  40. data/lib/tagcrumbs/resources/models/user.rb +27 -6
  41. data/lib/tagcrumbs/resources/models/user_recommendation.rb +1 -1
  42. data/lib/tagcrumbs/resources/resource.rb +4 -4
  43. data/script/console +8 -3
  44. data/spec/fixtures_external/README.rdoc +15 -0
  45. data/spec/fixtures_external/json/access_token.json +11 -0
  46. data/spec/{fixtures → fixtures_external/json}/activity.json +32 -25
  47. data/spec/{fixtures → fixtures_external/json}/address.json +22 -25
  48. data/spec/fixtures_external/json/application.json +13 -0
  49. data/spec/{fixtures → fixtures_external/json}/city.json +2 -11
  50. data/spec/{fixtures → fixtures_external/json}/comment.json +51 -44
  51. data/spec/{fixtures → fixtures_external/json}/country.json +1 -4
  52. data/spec/fixtures_external/json/email_recommendation.json +286 -0
  53. data/spec/{fixtures → fixtures_external/json}/fanship.json +30 -30
  54. data/spec/{fixtures → fixtures_external/json}/favorite.json +45 -47
  55. data/spec/{fixtures → fixtures_external/json}/filter.json +30 -42
  56. data/spec/{fixtures → fixtures_external/json}/friendship.json +30 -30
  57. data/spec/fixtures_external/json/geoname.json +18 -0
  58. data/spec/{fixtures → fixtures_external/json}/link.json +41 -44
  59. data/spec/{fixtures → fixtures_external/json}/location.json +21 -31
  60. data/spec/fixtures_external/json/paragraph.json +12 -0
  61. data/spec/fixtures_external/json/picture.json +129 -0
  62. data/spec/fixtures_external/json/picture_upload.json +9 -0
  63. data/spec/{fixtures → fixtures_external/json}/placemark.json +136 -142
  64. data/spec/fixtures_external/json/placemarks.json +851 -0
  65. data/spec/{fixtures → fixtures_external/json}/profile.json +65 -94
  66. data/spec/fixtures_external/json/profile_link.json +123 -0
  67. data/spec/{fixtures → fixtures_external/json}/root.json +17 -21
  68. data/spec/{fixtures → fixtures_external/json}/settings.json +26 -19
  69. data/spec/{fixtures → fixtures_external/json}/state.json +2 -8
  70. data/spec/{fixtures → fixtures_external/json}/subscription.json +41 -44
  71. data/spec/fixtures_external/json/suggestions.json +302 -0
  72. data/spec/{fixtures → fixtures_external/json}/tag.json +0 -0
  73. data/spec/{fixtures → fixtures_external/json}/user.json +44 -20
  74. data/spec/{fixtures → fixtures_external/json}/user_recommendation.json +52 -55
  75. data/spec/fixtures_external/json/validation_errors.json +6 -0
  76. data/spec/fixtures_external/kml/network_link.kml +24 -0
  77. data/spec/fixtures_external/kml/tagcrumbs.kml +64 -0
  78. data/spec/fixtures_external/rdf/placemark.rdf +56 -0
  79. data/spec/fixtures_external/rss/tagcrumbs.rss +24 -0
  80. data/spec/fixtures_external/xml/access_token.xml +5 -0
  81. data/spec/fixtures_external/xml/activity.xml +62 -0
  82. data/spec/fixtures_external/xml/address.xml +51 -0
  83. data/spec/fixtures_external/xml/application.xml +5 -0
  84. data/spec/fixtures_external/xml/city.xml +27 -0
  85. data/spec/fixtures_external/xml/comment.xml +81 -0
  86. data/spec/fixtures_external/xml/country.xml +10 -0
  87. data/spec/fixtures_external/xml/email_recommendation.xml +78 -0
  88. data/spec/fixtures_external/xml/fanship.xml +49 -0
  89. data/spec/fixtures_external/xml/favorite.xml +97 -0
  90. data/spec/fixtures_external/xml/filter.xml +68 -0
  91. data/spec/fixtures_external/xml/friendship.xml +49 -0
  92. data/spec/fixtures_external/xml/geoname.xml +6 -0
  93. data/spec/fixtures_external/xml/link.xml +78 -0
  94. data/spec/fixtures_external/xml/location.xml +58 -0
  95. data/spec/fixtures_external/xml/paragraph.xml +8 -0
  96. data/spec/fixtures_external/xml/picture.xml +36 -0
  97. data/spec/fixtures_external/xml/picture_upload.xml +153 -0
  98. data/spec/fixtures_external/xml/placemark.xml +54 -0
  99. data/spec/fixtures_external/xml/placemarks.xml +336 -0
  100. data/spec/fixtures_external/xml/profile.xml +77 -0
  101. data/spec/fixtures_external/xml/profile_link.xml +34 -0
  102. data/spec/fixtures_external/xml/root.xml +12 -0
  103. data/spec/fixtures_external/xml/settings.xml +42 -0
  104. data/spec/fixtures_external/xml/state.xml +19 -0
  105. data/spec/fixtures_external/xml/subscription.xml +76 -0
  106. data/spec/fixtures_external/xml/suggestions.xml +106 -0
  107. data/spec/{fixtures → fixtures_external/xml}/tag.xml +2 -2
  108. data/spec/fixtures_external/xml/user.xml +37 -0
  109. data/spec/fixtures_external/xml/user_recommendation.xml +94 -0
  110. data/spec/fixtures_external/xml/validation_errors.xml +5 -0
  111. data/spec/spec_helper.rb +12 -2
  112. data/spec/tagcrumbs/requestor_spec.rb +2 -2
  113. data/spec/tagcrumbs/resources/array_spec.rb +38 -38
  114. data/spec/tagcrumbs/resources/models/access_token_spec.rb +16 -0
  115. data/spec/tagcrumbs/resources/models/accessors_spec.rb +2 -2
  116. data/spec/tagcrumbs/resources/models/activity_spec.rb +5 -1
  117. data/spec/tagcrumbs/resources/models/address_spec.rb +1 -1
  118. data/spec/tagcrumbs/resources/models/application_spec.rb +17 -0
  119. data/spec/tagcrumbs/resources/models/city_spec.rb +2 -5
  120. data/spec/tagcrumbs/resources/models/comment_spec.rb +8 -2
  121. data/spec/tagcrumbs/resources/models/country_spec.rb +2 -4
  122. data/spec/tagcrumbs/resources/models/email_recommendation_spec.rb +31 -0
  123. data/spec/tagcrumbs/resources/models/fanship_spec.rb +1 -1
  124. data/spec/tagcrumbs/resources/models/favorite_spec.rb +5 -1
  125. data/spec/tagcrumbs/resources/models/filter_spec.rb +3 -4
  126. data/spec/tagcrumbs/resources/models/friendship_spec.rb +1 -1
  127. data/spec/tagcrumbs/resources/models/geoname_spec.rb +1 -1
  128. data/spec/tagcrumbs/resources/models/link_spec.rb +1 -1
  129. data/spec/tagcrumbs/resources/models/location_spec.rb +1 -1
  130. data/spec/tagcrumbs/resources/models/model_spec.rb +20 -3
  131. data/spec/tagcrumbs/resources/models/paragraph_spec.rb +21 -0
  132. data/spec/tagcrumbs/resources/models/picture_spec.rb +13 -21
  133. data/spec/tagcrumbs/resources/models/place_spec.rb +3 -3
  134. data/spec/tagcrumbs/resources/models/placemark_spec.rb +11 -9
  135. data/spec/tagcrumbs/resources/models/profile_link_spec.rb +6 -12
  136. data/spec/tagcrumbs/resources/models/profile_spec.rb +5 -12
  137. data/spec/tagcrumbs/resources/models/root_spec.rb +15 -19
  138. data/spec/tagcrumbs/resources/models/settings_spec.rb +3 -1
  139. data/spec/tagcrumbs/resources/models/state_spec.rb +2 -5
  140. data/spec/tagcrumbs/resources/models/subscription_spec.rb +1 -1
  141. data/spec/tagcrumbs/resources/models/suggestions_spec.rb +7 -7
  142. data/spec/tagcrumbs/resources/models/tag_spec.rb +1 -1
  143. data/spec/tagcrumbs/resources/models/tagcrumb_spec.rb +3 -11
  144. data/spec/tagcrumbs/resources/models/user_recommendation_spec.rb +1 -1
  145. data/spec/tagcrumbs/resources/models/user_spec.rb +35 -27
  146. data/spec/tagcrumbs/resources/resource_spec.rb +3 -3
  147. data/spec/tagcrumbs_spec.rb +7 -7
  148. data/tagcrumbs.gemspec +2 -2
  149. metadata +82 -58
  150. data/examples/tagcrumbs_search.rb +0 -7
  151. data/lib/tagcrumbs/validations.rb +0 -301
  152. data/spec/fixtures/activity.xml +0 -66
  153. data/spec/fixtures/address.xml +0 -58
  154. data/spec/fixtures/city.xml +0 -34
  155. data/spec/fixtures/comment.xml +0 -87
  156. data/spec/fixtures/country.xml +0 -13
  157. data/spec/fixtures/fanship.xml +0 -54
  158. data/spec/fixtures/favorite.xml +0 -109
  159. data/spec/fixtures/filter.xml +0 -80
  160. data/spec/fixtures/friendship.xml +0 -54
  161. data/spec/fixtures/geoname.json +0 -18
  162. data/spec/fixtures/geoname.xml +0 -6
  163. data/spec/fixtures/link.xml +0 -88
  164. data/spec/fixtures/location.xml +0 -71
  165. data/spec/fixtures/picture.json +0 -154
  166. data/spec/fixtures/picture.xml +0 -49
  167. data/spec/fixtures/placemark.xml +0 -58
  168. data/spec/fixtures/placemarks.json +0 -887
  169. data/spec/fixtures/placemarks.xml +0 -348
  170. data/spec/fixtures/profile.xml +0 -100
  171. data/spec/fixtures/profile_link.json +0 -156
  172. data/spec/fixtures/profile_link.xml +0 -49
  173. data/spec/fixtures/root.xml +0 -14
  174. data/spec/fixtures/settings.xml +0 -45
  175. data/spec/fixtures/state.xml +0 -23
  176. data/spec/fixtures/subscription.xml +0 -86
  177. data/spec/fixtures/suggestions.json +0 -1877
  178. data/spec/fixtures/suggestions.xml +0 -724
  179. data/spec/fixtures/user.xml +0 -31
  180. data/spec/fixtures/user_recommendation.xml +0 -106
  181. data/spec/fixtures/validation_errors.json +0 -5
  182. data/spec/fixtures/validation_errors.xml +0 -5
  183. data/spec/tagcrumbs/validations_spec.rb +0 -27
@@ -32,7 +32,7 @@ describe Tagcrumbs::Resource do
32
32
  end
33
33
 
34
34
  it "should reload" do
35
- response = mock("Response", :body => '')
35
+ response = mock("Response", :plain_body => '')
36
36
 
37
37
  requestor = mock("Requestor", :response_format => :xml)
38
38
  requestor.stub!(:response).and_return(response)
@@ -46,14 +46,14 @@ describe Tagcrumbs::Resource do
46
46
  end
47
47
 
48
48
  it "should load a new resource" do
49
- stub_get('/sascha.xml', 'user.xml', [200])
49
+ stub_get('/sascha.xml', 'user', :xml, [200])
50
50
  resource = Tagcrumbs::Resource.load('/sascha.xml')
51
51
 
52
52
  resource.username.should == 'sascha'
53
53
  end
54
54
 
55
55
  it "should initialize from document" do
56
- @resource.initialize_from_document(fixture_file('user.xml'))
56
+ @resource.initialize_from_document(external_fixture_file('user', :xml))
57
57
 
58
58
  @resource.resource_url.should == 'http://www.tagcrumbs.com/sascha.xml'
59
59
  @resource.loaded.should == true
@@ -18,7 +18,7 @@ describe Tagcrumbs do
18
18
  Tagcrumbs.constants[:per_page].should be_an_instance_of(Array)
19
19
  Tagcrumbs.constants[:from].should be_an_instance_of(Array)
20
20
  Tagcrumbs.constants[:tagcrumb_type].should be_an_instance_of(Array)
21
- Tagcrumbs.constants[:within].should be_an_instance_of(Array)
21
+ Tagcrumbs.constants[:range].should be_an_instance_of(Array)
22
22
  Tagcrumbs.constants[:sort].should be_an_instance_of(Array)
23
23
  Tagcrumbs.constants[:order].should be_an_instance_of(Array)
24
24
  Tagcrumbs.constants[:w].should be_an_instance_of(Array)
@@ -44,7 +44,7 @@ describe Tagcrumbs do
44
44
  end
45
45
 
46
46
  it "should get a class by type" do
47
- Tagcrumbs.class_by_type('array').should == Tagcrumbs::Array
47
+ Tagcrumbs.class_by_type('Collection').should == Tagcrumbs::Collection
48
48
  Tagcrumbs.class_by_type('user').should == Tagcrumbs::User
49
49
 
50
50
  # irregular names
@@ -53,14 +53,14 @@ describe Tagcrumbs do
53
53
  end
54
54
 
55
55
  it "should get the current user" do
56
- stub_get('/you', 'user.xml', [200])
56
+ stub_get('/you', 'user', :xml, [200])
57
57
 
58
58
  Tagcrumbs.current_user.should be_an_instance_of(Tagcrumbs::User)
59
59
  Tagcrumbs.current_user.username.should == 'sascha'
60
60
  end
61
61
 
62
62
  it "should get the root" do
63
- stub_get('/index', 'root.xml', [200])
63
+ stub_get('/index', 'root', :xml, [200])
64
64
 
65
65
  Tagcrumbs.root.should be_an_instance_of(Tagcrumbs::Root)
66
66
  Tagcrumbs.root.tagcrumbs.resource_url.should == tagcrumbs_url('/tagcrumbs.xml')
@@ -75,7 +75,7 @@ describe Tagcrumbs do
75
75
 
76
76
  describe "should validate credentials" do
77
77
  it "with valid credentials and tokens" do
78
- stub_get('/you', 'user.xml', [200])
78
+ stub_get('/you', 'user', :xml, [200])
79
79
  Tagcrumbs.configure(:access_token => 123, :access_secret => 456)
80
80
 
81
81
  Tagcrumbs.valid_credentials?.should be_true
@@ -86,13 +86,13 @@ describe Tagcrumbs do
86
86
  end
87
87
 
88
88
  it "with invalid credentials" do
89
- stub_get('/you', '', [401])
89
+ stub_get('/you', '', nil, [401])
90
90
 
91
91
  Tagcrumbs.valid_credentials?.should be_false
92
92
  end
93
93
 
94
94
  it "with tokens and no server" do
95
- stub_get('/you', '', [503])
95
+ stub_get('/you', '', nil, [503])
96
96
  Tagcrumbs.configure(:access_token => 123, :access_secret => 456)
97
97
 
98
98
  lambda {
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tagcrumbs}
5
- s.version = "0.3.1"
5
+ s.version = "0.3.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sascha Konietzke"]
9
- s.date = %q{2009-06-14}
9
+ s.date = %q{2009-07-13}
10
10
  s.default_executable = %q{tagcrumbs}
11
11
  s.description = %q{This is a RubyGem that provides an ActiveRecord-like interface to the www.tagcrumbs.com web service.}
12
12
  s.email = ["sascha@tagcrumbs.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagcrumbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sascha Konietzke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-14 00:00:00 +02:00
12
+ date: 2009-07-13 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -116,6 +116,7 @@ extra_rdoc_files:
116
116
  - PostInstall.txt
117
117
  - README.rdoc
118
118
  - TODO.txt
119
+ - spec/fixtures_external/README.rdoc
119
120
  files:
120
121
  - History.txt
121
122
  - License.txt
@@ -125,6 +126,7 @@ files:
125
126
  - Rakefile
126
127
  - TODO.txt
127
128
  - bin/tagcrumbs
129
+ - config/website.yml
128
130
  - examples/address_update.rb
129
131
  - examples/comment_new.rb
130
132
  - examples/favorite_new.rb
@@ -141,15 +143,16 @@ files:
141
143
  - examples/settings_update.rb
142
144
  - examples/subscription_new.rb
143
145
  - examples/tagcrumbs_find.rb
144
- - examples/tagcrumbs_search.rb
145
146
  - examples/user.rb
146
147
  - examples/user_recommendation_new.rb
148
+ - lib/console.rb
147
149
  - lib/tagcrumbs.rb
148
150
  - lib/tagcrumbs/builders/builder.rb
149
151
  - lib/tagcrumbs/builders/json_builder.rb
150
152
  - lib/tagcrumbs/builders/xml_builder.rb
151
153
  - lib/tagcrumbs/cli.rb
152
154
  - lib/tagcrumbs/config_store.rb
155
+ - lib/tagcrumbs/core_extensions.rb
153
156
  - lib/tagcrumbs/exceptions.rb
154
157
  - lib/tagcrumbs/node.rb
155
158
  - lib/tagcrumbs/parsers/json_parser.rb
@@ -157,13 +160,16 @@ files:
157
160
  - lib/tagcrumbs/parsers/xml_parser.rb
158
161
  - lib/tagcrumbs/proxy.rb
159
162
  - lib/tagcrumbs/requestor.rb
160
- - lib/tagcrumbs/resources/array.rb
163
+ - lib/tagcrumbs/resources/collection.rb
164
+ - lib/tagcrumbs/resources/models/access_token.rb
161
165
  - lib/tagcrumbs/resources/models/accessors.rb
162
166
  - lib/tagcrumbs/resources/models/activity.rb
163
167
  - lib/tagcrumbs/resources/models/address.rb
168
+ - lib/tagcrumbs/resources/models/application.rb
164
169
  - lib/tagcrumbs/resources/models/city.rb
165
170
  - lib/tagcrumbs/resources/models/comment.rb
166
171
  - lib/tagcrumbs/resources/models/country.rb
172
+ - lib/tagcrumbs/resources/models/email_recommendation.rb
167
173
  - lib/tagcrumbs/resources/models/fanship.rb
168
174
  - lib/tagcrumbs/resources/models/favorite.rb
169
175
  - lib/tagcrumbs/resources/models/filter.rb
@@ -173,6 +179,7 @@ files:
173
179
  - lib/tagcrumbs/resources/models/link.rb
174
180
  - lib/tagcrumbs/resources/models/location.rb
175
181
  - lib/tagcrumbs/resources/models/model.rb
182
+ - lib/tagcrumbs/resources/models/paragraph.rb
176
183
  - lib/tagcrumbs/resources/models/picture.rb
177
184
  - lib/tagcrumbs/resources/models/place.rb
178
185
  - lib/tagcrumbs/resources/models/placemark.rb
@@ -188,65 +195,79 @@ files:
188
195
  - lib/tagcrumbs/resources/models/user.rb
189
196
  - lib/tagcrumbs/resources/models/user_recommendation.rb
190
197
  - lib/tagcrumbs/resources/resource.rb
191
- - lib/tagcrumbs/validations.rb
192
198
  - script/console
193
199
  - script/destroy
194
200
  - script/generate
195
- - spec/fixtures/activity.json
196
- - spec/fixtures/activity.xml
197
- - spec/fixtures/address.json
198
- - spec/fixtures/address.xml
199
- - spec/fixtures/city.json
200
- - spec/fixtures/city.xml
201
- - spec/fixtures/comment.json
202
- - spec/fixtures/comment.xml
203
- - spec/fixtures/country.json
204
- - spec/fixtures/country.xml
205
- - spec/fixtures/fanship.json
206
- - spec/fixtures/fanship.xml
207
- - spec/fixtures/favorite.json
208
- - spec/fixtures/favorite.xml
209
- - spec/fixtures/filter.json
210
- - spec/fixtures/filter.xml
211
- - spec/fixtures/friendship.json
212
- - spec/fixtures/friendship.xml
213
- - spec/fixtures/geoname.json
214
- - spec/fixtures/geoname.xml
215
201
  - spec/fixtures/json_parser.json
216
- - spec/fixtures/link.json
217
- - spec/fixtures/link.xml
218
- - spec/fixtures/location.json
219
- - spec/fixtures/location.xml
220
- - spec/fixtures/picture.json
221
202
  - spec/fixtures/picture.png
222
- - spec/fixtures/picture.xml
223
- - spec/fixtures/placemark.json
224
- - spec/fixtures/placemark.xml
225
- - spec/fixtures/placemarks.json
226
- - spec/fixtures/placemarks.xml
227
- - spec/fixtures/profile.json
228
- - spec/fixtures/profile.xml
229
- - spec/fixtures/profile_link.json
230
- - spec/fixtures/profile_link.xml
231
- - spec/fixtures/root.json
232
- - spec/fixtures/root.xml
233
- - spec/fixtures/settings.json
234
- - spec/fixtures/settings.xml
235
- - spec/fixtures/state.json
236
- - spec/fixtures/state.xml
237
- - spec/fixtures/subscription.json
238
- - spec/fixtures/subscription.xml
239
- - spec/fixtures/suggestions.json
240
- - spec/fixtures/suggestions.xml
241
- - spec/fixtures/tag.json
242
- - spec/fixtures/tag.xml
243
- - spec/fixtures/user.json
244
- - spec/fixtures/user.xml
245
- - spec/fixtures/user_recommendation.json
246
- - spec/fixtures/user_recommendation.xml
247
- - spec/fixtures/validation_errors.json
248
- - spec/fixtures/validation_errors.xml
249
203
  - spec/fixtures/xml_parser.xml
204
+ - spec/fixtures_external/README.rdoc
205
+ - spec/fixtures_external/json/access_token.json
206
+ - spec/fixtures_external/json/activity.json
207
+ - spec/fixtures_external/json/address.json
208
+ - spec/fixtures_external/json/application.json
209
+ - spec/fixtures_external/json/city.json
210
+ - spec/fixtures_external/json/comment.json
211
+ - spec/fixtures_external/json/country.json
212
+ - spec/fixtures_external/json/email_recommendation.json
213
+ - spec/fixtures_external/json/fanship.json
214
+ - spec/fixtures_external/json/favorite.json
215
+ - spec/fixtures_external/json/filter.json
216
+ - spec/fixtures_external/json/friendship.json
217
+ - spec/fixtures_external/json/geoname.json
218
+ - spec/fixtures_external/json/link.json
219
+ - spec/fixtures_external/json/location.json
220
+ - spec/fixtures_external/json/paragraph.json
221
+ - spec/fixtures_external/json/picture.json
222
+ - spec/fixtures_external/json/picture_upload.json
223
+ - spec/fixtures_external/json/placemark.json
224
+ - spec/fixtures_external/json/placemarks.json
225
+ - spec/fixtures_external/json/profile.json
226
+ - spec/fixtures_external/json/profile_link.json
227
+ - spec/fixtures_external/json/root.json
228
+ - spec/fixtures_external/json/settings.json
229
+ - spec/fixtures_external/json/state.json
230
+ - spec/fixtures_external/json/subscription.json
231
+ - spec/fixtures_external/json/suggestions.json
232
+ - spec/fixtures_external/json/tag.json
233
+ - spec/fixtures_external/json/user.json
234
+ - spec/fixtures_external/json/user_recommendation.json
235
+ - spec/fixtures_external/json/validation_errors.json
236
+ - spec/fixtures_external/kml/network_link.kml
237
+ - spec/fixtures_external/kml/tagcrumbs.kml
238
+ - spec/fixtures_external/rdf/placemark.rdf
239
+ - spec/fixtures_external/rss/tagcrumbs.rss
240
+ - spec/fixtures_external/xml/access_token.xml
241
+ - spec/fixtures_external/xml/activity.xml
242
+ - spec/fixtures_external/xml/address.xml
243
+ - spec/fixtures_external/xml/application.xml
244
+ - spec/fixtures_external/xml/city.xml
245
+ - spec/fixtures_external/xml/comment.xml
246
+ - spec/fixtures_external/xml/country.xml
247
+ - spec/fixtures_external/xml/email_recommendation.xml
248
+ - spec/fixtures_external/xml/fanship.xml
249
+ - spec/fixtures_external/xml/favorite.xml
250
+ - spec/fixtures_external/xml/filter.xml
251
+ - spec/fixtures_external/xml/friendship.xml
252
+ - spec/fixtures_external/xml/geoname.xml
253
+ - spec/fixtures_external/xml/link.xml
254
+ - spec/fixtures_external/xml/location.xml
255
+ - spec/fixtures_external/xml/paragraph.xml
256
+ - spec/fixtures_external/xml/picture.xml
257
+ - spec/fixtures_external/xml/picture_upload.xml
258
+ - spec/fixtures_external/xml/placemark.xml
259
+ - spec/fixtures_external/xml/placemarks.xml
260
+ - spec/fixtures_external/xml/profile.xml
261
+ - spec/fixtures_external/xml/profile_link.xml
262
+ - spec/fixtures_external/xml/root.xml
263
+ - spec/fixtures_external/xml/settings.xml
264
+ - spec/fixtures_external/xml/state.xml
265
+ - spec/fixtures_external/xml/subscription.xml
266
+ - spec/fixtures_external/xml/suggestions.xml
267
+ - spec/fixtures_external/xml/tag.xml
268
+ - spec/fixtures_external/xml/user.xml
269
+ - spec/fixtures_external/xml/user_recommendation.xml
270
+ - spec/fixtures_external/xml/validation_errors.xml
250
271
  - spec/spec.opts
251
272
  - spec/spec_helper.rb
252
273
  - spec/tagcrumbs/builders/builder_spec.rb
@@ -260,12 +281,15 @@ files:
260
281
  - spec/tagcrumbs/proxy_spec.rb
261
282
  - spec/tagcrumbs/requestor_spec.rb
262
283
  - spec/tagcrumbs/resources/array_spec.rb
284
+ - spec/tagcrumbs/resources/models/access_token_spec.rb
263
285
  - spec/tagcrumbs/resources/models/accessors_spec.rb
264
286
  - spec/tagcrumbs/resources/models/activity_spec.rb
265
287
  - spec/tagcrumbs/resources/models/address_spec.rb
288
+ - spec/tagcrumbs/resources/models/application_spec.rb
266
289
  - spec/tagcrumbs/resources/models/city_spec.rb
267
290
  - spec/tagcrumbs/resources/models/comment_spec.rb
268
291
  - spec/tagcrumbs/resources/models/country_spec.rb
292
+ - spec/tagcrumbs/resources/models/email_recommendation_spec.rb
269
293
  - spec/tagcrumbs/resources/models/fanship_spec.rb
270
294
  - spec/tagcrumbs/resources/models/favorite_spec.rb
271
295
  - spec/tagcrumbs/resources/models/filter_spec.rb
@@ -275,6 +299,7 @@ files:
275
299
  - spec/tagcrumbs/resources/models/link_spec.rb
276
300
  - spec/tagcrumbs/resources/models/location_spec.rb
277
301
  - spec/tagcrumbs/resources/models/model_spec.rb
302
+ - spec/tagcrumbs/resources/models/paragraph_spec.rb
278
303
  - spec/tagcrumbs/resources/models/picture_spec.rb
279
304
  - spec/tagcrumbs/resources/models/place_spec.rb
280
305
  - spec/tagcrumbs/resources/models/placemark_spec.rb
@@ -290,7 +315,6 @@ files:
290
315
  - spec/tagcrumbs/resources/models/user_recommendation_spec.rb
291
316
  - spec/tagcrumbs/resources/models/user_spec.rb
292
317
  - spec/tagcrumbs/resources/resource_spec.rb
293
- - spec/tagcrumbs/validations_spec.rb
294
318
  - spec/tagcrumbs_spec.rb
295
319
  - tagcrumbs.gemspec
296
320
  - tasks/rspec.rake
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env ruby -rubygems
2
-
3
- require File.dirname(__FILE__) + '/../lib/tagcrumbs' # this would not be needed if we only search for public Tagcrumbs
4
-
5
- # This is doing a fulltext search, searching name, tags, description, etc.
6
- restaurants = Tagcrumbs::Tagcrumb.search(:q => 'restaurant', :l => 'berlin', :w => 'city')
7
- puts "#{restaurants.total_entries} Placemarks that contain the word 'restaurant' in Berlin."
@@ -1,301 +0,0 @@
1
- module Tagcrumbs
2
- class ResourceInvalid# < ClientError #:nodoc:
3
- end
4
-
5
- # == Borrowed from ActiveResource
6
-
7
- # Active Resource validation is reported to and from this object, which is used by Base#save
8
- # to determine whether the object in a valid state to be saved. See usage example in Validations.
9
- class Errors
10
- include Enumerable
11
- attr_reader :errors
12
-
13
- delegate :empty?, :to => :errors
14
-
15
- def initialize(base) # :nodoc:
16
- @base, @errors = base, {}
17
- end
18
-
19
- # Add an error to the base Active Resource object rather than an attribute.
20
- #
21
- # ==== Examples
22
- # my_folder = Folder.find(1)
23
- # my_folder.errors.add_to_base("You can't edit an existing folder")
24
- # my_folder.errors.on_base
25
- # # => "You can't edit an existing folder"
26
- #
27
- # my_folder.errors.add_to_base("This folder has been tagged as frozen")
28
- # my_folder.valid?
29
- # # => false
30
- # my_folder.errors.on_base
31
- # # => ["You can't edit an existing folder", "This folder has been tagged as frozen"]
32
- #
33
- def add_to_base(msg)
34
- add(:base, msg)
35
- end
36
-
37
- # Adds an error to an Active Resource object's attribute (named for the +attribute+ parameter)
38
- # with the error message in +msg+.
39
- #
40
- # ==== Examples
41
- # my_resource = Node.find(1)
42
- # my_resource.errors.add('name', 'can not be "base"') if my_resource.name == 'base'
43
- # my_resource.errors.on('name')
44
- # # => 'can not be "base"!'
45
- #
46
- # my_resource.errors.add('desc', 'can not be blank') if my_resource.desc == ''
47
- # my_resource.valid?
48
- # # => false
49
- # my_resource.errors.on('desc')
50
- # # => 'can not be blank!'
51
- #
52
- def add(attribute, msg)
53
- @errors[attribute.to_s] = [] if @errors[attribute.to_s].nil?
54
- @errors[attribute.to_s] << msg
55
- end
56
-
57
- # Returns true if the specified +attribute+ has errors associated with it.
58
- #
59
- # ==== Examples
60
- # my_resource = Disk.find(1)
61
- # my_resource.errors.add('location', 'must be Main') unless my_resource.location == 'Main'
62
- # my_resource.errors.on('location')
63
- # # => 'must be Main!'
64
- #
65
- # my_resource.errors.invalid?('location')
66
- # # => true
67
- # my_resource.errors.invalid?('name')
68
- # # => false
69
- def invalid?(attribute)
70
- !@errors[attribute.to_s].nil?
71
- end
72
-
73
- # A method to return the errors associated with +attribute+, which returns nil, if no errors are
74
- # associated with the specified +attribute+, the error message if one error is associated with the specified +attribute+,
75
- # or an array of error messages if more than one error is associated with the specified +attribute+.
76
- #
77
- # ==== Examples
78
- # my_person = Person.new(params[:person])
79
- # my_person.errors.on('login')
80
- # # => nil
81
- #
82
- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''
83
- # my_person.errors.on('login')
84
- # # => 'can not be empty'
85
- #
86
- # my_person.errors.add('login', 'can not be longer than 10 characters') if my_person.login.length > 10
87
- # my_person.errors.on('login')
88
- # # => ['can not be empty', 'can not be longer than 10 characters']
89
- def on(attribute)
90
- errors = @errors[attribute.to_s]
91
- return nil if errors.nil?
92
- errors.size == 1 ? errors.first : errors
93
- end
94
-
95
- alias :[] :on
96
-
97
- # A method to return errors assigned to +base+ object through add_to_base, which returns nil, if no errors are
98
- # associated with the specified +attribute+, the error message if one error is associated with the specified +attribute+,
99
- # or an array of error messages if more than one error is associated with the specified +attribute+.
100
- #
101
- # ==== Examples
102
- # my_account = Account.find(1)
103
- # my_account.errors.on_base
104
- # # => nil
105
- #
106
- # my_account.errors.add_to_base("This account is frozen")
107
- # my_account.errors.on_base
108
- # # => "This account is frozen"
109
- #
110
- # my_account.errors.add_to_base("This account has been closed")
111
- # my_account.errors.on_base
112
- # # => ["This account is frozen", "This account has been closed"]
113
- #
114
- def on_base
115
- on(:base)
116
- end
117
-
118
- # Yields each attribute and associated message per error added.
119
- #
120
- # ==== Examples
121
- # my_person = Person.new(params[:person])
122
- #
123
- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''
124
- # my_person.errors.add('password', 'can not be empty') if my_person.password == ''
125
- # messages = ''
126
- # my_person.errors.each {|attr, msg| messages += attr.to_s.humanize + " " + msg + "<br />"}
127
- # messages
128
- # # => "Login can not be empty<br />Password can not be empty<br />"
129
- #
130
- def each
131
- @errors.each_key { |attr| @errors[attr].each { |msg| yield attr, msg } }
132
- end
133
-
134
- # Yields each full error message added. So Person.errors.add("first_name", "can't be empty") will be returned
135
- # through iteration as "First name can't be empty".
136
- #
137
- # ==== Examples
138
- # my_person = Person.new(params[:person])
139
- #
140
- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''
141
- # my_person.errors.add('password', 'can not be empty') if my_person.password == ''
142
- # messages = ''
143
- # my_person.errors.each_full {|msg| messages += msg + "<br/>"}
144
- # messages
145
- # # => "Login can not be empty<br />Password can not be empty<br />"
146
- #
147
- def each_full
148
- full_messages.each { |msg| yield msg }
149
- end
150
-
151
- # Returns all the full error messages in an array.
152
- #
153
- # ==== Examples
154
- # my_person = Person.new(params[:person])
155
- #
156
- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''
157
- # my_person.errors.add('password', 'can not be empty') if my_person.password == ''
158
- # messages = ''
159
- # my_person.errors.full_messages.each {|msg| messages += msg + "<br/>"}
160
- # messages
161
- # # => "Login can not be empty<br />Password can not be empty<br />"
162
- #
163
- def full_messages
164
- full_messages = []
165
-
166
- @errors.each_key do |attr|
167
- @errors[attr].each do |msg|
168
- next if msg.nil?
169
-
170
- if attr == "base"
171
- full_messages << msg
172
- else
173
- full_messages << [attr.to_s.humanize, msg].join(' ')
174
- end
175
- end
176
- end
177
- full_messages
178
- end
179
-
180
- def clear
181
- @errors = {}
182
- end
183
-
184
- # Returns the total number of errors added. Two errors added to the same attribute will be counted as such
185
- # with this as well.
186
- #
187
- # ==== Examples
188
- # my_person = Person.new(params[:person])
189
- # my_person.errors.size
190
- # # => 0
191
- #
192
- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''
193
- # my_person.errors.add('password', 'can not be empty') if my_person.password == ''
194
- # my_person.error.size
195
- # # => 2
196
- #
197
- def size
198
- @errors.values.inject(0) { |error_count, attribute| error_count + attribute.size }
199
- end
200
-
201
- alias_method :count, :size
202
- alias_method :length, :size
203
-
204
- def from_format(document, format)
205
- case format
206
- when :xml: from_xml(document)
207
- when :json: from_json(document)
208
- end
209
- end
210
-
211
- # Grabs errors from the XML response.
212
- def from_xml(xml)
213
- clear
214
- humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.to_s.humanize => attr_name) }
215
- messages = ::Array.wrap(Hash.from_xml(xml)['errors']['error']) rescue []
216
- messages.each do |message|
217
- attr_message = humanized_attributes.keys.detect do |attr_name|
218
- if message[0, attr_name.size + 1] == "#{attr_name} "
219
- add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
220
- end
221
- end
222
-
223
- add_to_base message if attr_message.nil?
224
- end
225
- end
226
-
227
- # Grabs errors from the JSON response.
228
- # Added for Tagcrumbs
229
- def from_json(json)
230
- clear
231
- humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.to_s.humanize => attr_name) }
232
-
233
- messages = JSON.parse(json)['errors']['error'] rescue []
234
- messages.each do |message|
235
- attr_message = humanized_attributes.keys.detect do |attr_name|
236
- if message[0, attr_name.size + 1] == "#{attr_name} "
237
- add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
238
- end
239
- end
240
-
241
- add_to_base message if attr_message.nil?
242
- end
243
- end
244
- end
245
-
246
- # Module to support validation and errors with Active Resource objects. The module overrides
247
- # Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned
248
- # in the web service response. The module also adds an +errors+ collection that mimics the interface
249
- # of the errors provided by ActiveRecord::Errors.
250
- #
251
- # ==== Example
252
- #
253
- # Consider a Person resource on the server requiring both a +first_name+ and a +last_name+ with a
254
- # <tt>validates_presence_of :first_name, :last_name</tt> declaration in the model:
255
- #
256
- # person = Person.new(:first_name => "Jim", :last_name => "")
257
- # person.save # => false (server returns an HTTP 422 status code and errors)
258
- # person.valid? # => false
259
- # person.errors.empty? # => false
260
- # person.errors.count # => 1
261
- # person.errors.full_messages # => ["Last name can't be empty"]
262
- # person.errors.on(:last_name) # => "can't be empty"
263
- # person.last_name = "Halpert"
264
- # person.save # => true (and person is now saved to the remote service)
265
- #
266
- module Validations
267
- # def self.included(base) # :nodoc:
268
- # base.class_eval do
269
- # alias_method_chain :save, :validation
270
- # end
271
- # end
272
- #
273
- # # Validate a resource and save (POST) it to the remote web service.
274
- # def save_with_validation
275
- # save_without_validation
276
- # true
277
- # rescue ResourceInvalid => error
278
- # errors.from_xml(error.response.body)
279
- # false
280
- # end
281
-
282
- # Checks for errors on an object (i.e., is resource.errors empty?).
283
- #
284
- # ==== Examples
285
- # my_person = Person.create(params[:person])
286
- # my_person.valid?
287
- # # => true
288
- #
289
- # my_person.errors.add('login', 'can not be empty') if my_person.login == ''
290
- # my_person.valid?
291
- # # => false
292
- def valid?
293
- errors.empty?
294
- end
295
-
296
- # Returns the Errors object that holds all information about attribute error messages.
297
- def errors
298
- @errors ||= Errors.new(self)
299
- end
300
- end
301
- end