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
@@ -146,7 +146,7 @@ module Tagcrumbs
146
146
  @stdout.print "Please authorize the application in your browser: #{authorize_url}.\nPress Enter after you authorized the application to continue..."
147
147
  @stdin.gets
148
148
 
149
- if Tagcrumbs.exchange_request_token!
149
+ if Tagcrumbs.access_token_from_request_token
150
150
  @stdout.puts "The application is now authorized. You won't have to do this again the next time you run the application."
151
151
  @config_store.update(Tagcrumbs.options.slice(:access_token, :access_secret))
152
152
  else
@@ -1,5 +1,5 @@
1
1
  module Tagcrumbs
2
- # Use the ConfigStore to save configuration options to a yaml file (tokens)
2
+ # Use the ConfigStore to save configuration options to a yaml file
3
3
  class ConfigStore
4
4
  attr_accessor :filename, :options
5
5
 
@@ -22,8 +22,8 @@ module Tagcrumbs
22
22
  end
23
23
 
24
24
  # Save the current options into the file in YAML format
25
- def save
26
- File.open(filename, 'w') { |f| f.write(YAML.dump(@options)) }
25
+ def save(file = filename)
26
+ File.open(file, 'w') { |f| f.write(YAML.dump(@options.stringify_keys)) }
27
27
  self
28
28
  end
29
29
  end
@@ -0,0 +1,19 @@
1
+ require 'zlib'
2
+ require 'stringio'
3
+
4
+ class Net::HTTPResponse
5
+ # uncompress the body if compression was used
6
+ def plain_body
7
+ encoding = self['content-encoding']
8
+
9
+ case encoding
10
+ when 'gzip'
11
+ Zlib::GzipReader.new(StringIO.new(self.body)).read
12
+ when 'deflate'
13
+ Zlib::Inflate.new.inflate(self.body)
14
+ else
15
+ raise "Unknown encoding - #{encoding}" if encoding.present?
16
+ self.body
17
+ end
18
+ end
19
+ end
@@ -5,9 +5,13 @@ module Tagcrumbs
5
5
 
6
6
  def initialize(parser_or_document)
7
7
  if parser_or_document.is_a?(String)
8
- tmp = JSON.parse(parser_or_document)
9
- self._name = tmp.keys.first
10
- self.document = tmp[self._name]
8
+ begin
9
+ tmp = JSON.parse(parser_or_document)
10
+ self._name = tmp.keys.first
11
+ self.document = tmp[self._name]
12
+ rescue JSON::ParserError # just a string (lowest level node in array)
13
+ self.document = {'$' => parser_or_document }
14
+ end
11
15
  elsif(parser_or_document.is_a?(Tagcrumbs::JsonParser))
12
16
  self.document = parser_or_document.document
13
17
  else
@@ -8,8 +8,9 @@ module Tagcrumbs
8
8
 
9
9
  instance_methods.each { |m| undef_method m unless m =~ /^__/ } # http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc
10
10
 
11
- def initialize(object)
11
+ def initialize(object, parameters={})
12
12
  @object = object
13
+ @parameters = parameters
13
14
  end
14
15
 
15
16
 
@@ -17,11 +18,13 @@ module Tagcrumbs
17
18
  def method_missing(method_name, *args, &block)
18
19
  #puts "** Proxying #{method_name}. Loaded: #{@object.loaded?}"
19
20
 
20
- if @object.loaded? || UNPROXIED_METHODS.include?(method_name) #|| !@object.respond_to?(method_name) # having this doesn't allow first etc on arrays
21
+ if @object.loaded? || UNPROXIED_METHODS.include?(method_name) #|| !@object.respond_to?(method_name) # having this doesn't allow first etc on collections
21
22
  @object.send(method_name, *args, &block)
23
+ elsif method_name == :total_entries && @object.respond_to?(method_name) && @object.total_entries.present? # let total_entries go through if present
24
+ @object.total_entries
22
25
  else
23
26
  #puts "** Reloading"
24
- @object.reload if @object.resource_url.present?
27
+ @object.reload(nil, @parameters) if @object.resource_url.present?
25
28
  @object.send(method_name, *args, &block)
26
29
  end
27
30
 
@@ -48,6 +48,17 @@ module Tagcrumbs
48
48
  nil
49
49
  end
50
50
  end
51
+
52
+ # Don't do a token dance, use the Credentials to OAuth Proxy
53
+ # Only works after requesting permission from Tagcrumbs
54
+ # This makes developing clients for mobile devices etc. easier
55
+ def access_token_from_credentials(username, password)
56
+ url = path_with_query_string(options[:consumer_options][:access_token_from_credentials_path], :username => username, :password => password)
57
+
58
+ response = consumer.token_request(:post, url, nil, {}, '', {}) # send a regular post request, no json or xml, makes it easier to parse
59
+ OAuth::AccessToken.from_hash(consumer, response)
60
+ end
61
+
51
62
 
52
63
  # ========
53
64
  # = HTTP =
@@ -62,8 +73,8 @@ module Tagcrumbs
62
73
 
63
74
  if access_token # 3-legged request with access token
64
75
  response = self.access_token.request(http_method, url, *arguments)
65
- elsif http_method == :get && consumer # 2-legged consumer only request
66
- response = self.consumer.request(:get, url, nil, {}, *arguments)
76
+ elsif consumer # 2-legged consumer only request
77
+ response = self.consumer.request(http_method, url, nil, {}, *arguments)
67
78
  else
68
79
  raise InvalidRequest.new("Setup the Access Token first or only make get requests with a valid consumer.")
69
80
  end
@@ -102,6 +113,7 @@ module Tagcrumbs
102
113
 
103
114
  :xml
104
115
  end
116
+
105
117
 
106
118
  private
107
119
  # Build a URL from a path and a hash of query string parameters
@@ -124,17 +136,22 @@ module Tagcrumbs
124
136
  end
125
137
  end
126
138
 
127
- # Set the Content-Type and Accept HTTP Headers to the correct values depending on format
139
+ # Set the Content-Type and Accept HTTP Headers to the correct values depending on format.
140
+ # Add Accept-Encoding if compression is enabled.
128
141
  def default_headers(format = nil)
129
142
  format ||= self.options[:format]
130
143
 
131
144
  raise UnsupportedFormat unless Tagcrumbs.supported_formats[format]
132
145
 
133
- {
146
+ hash = {
134
147
  "Content-Type" => Tagcrumbs.supported_formats[format].first,
135
148
  "Accept" => Tagcrumbs.supported_formats[format].join(', ')
136
149
  }
150
+
151
+ hash.merge!("Accept-Encoding" => 'gzip, deflate') if options[:compression]
152
+
153
+ hash
137
154
  end
138
-
155
+
139
156
  end
140
157
  end
@@ -1,7 +1,7 @@
1
1
  module Tagcrumbs
2
2
  # Basically a regular Array that holds many Resources.
3
3
  # Used to get collections from the webservice.
4
- class Array < Resource
4
+ class Collection < Resource
5
5
  ATTRIBUTES = [:total_entries, :pages, :per_page, :page, :sort, :order, :next_page, :previous_page]
6
6
 
7
7
  attr_accessor :array
@@ -32,12 +32,12 @@ module Tagcrumbs
32
32
  true
33
33
  end
34
34
 
35
- # Replace the Array with the next page of elements if there is one
35
+ # Replace the Collection with the next page of elements if there is one
36
36
  def next_page!
37
37
  reload(next_page) if next_page.present?
38
38
  end
39
39
 
40
- # Replace the Array with the privious page of elements if there is one
40
+ # Replace the Collection with the privious page of elements if there is one
41
41
  def previous_page!
42
42
  reload(previous_page) if previous_page.present?
43
43
  end
@@ -51,8 +51,8 @@ module Tagcrumbs
51
51
 
52
52
  # Iterate over all items with pagination
53
53
  def each_page_each_item(args={})
54
- self.each_page(args) do |array|
55
- array.each do |item|
54
+ self.each_page(args) do |collection|
55
+ collection.each do |item|
56
56
  yield item
57
57
  end
58
58
  end
@@ -84,15 +84,16 @@ module Tagcrumbs
84
84
  # Load data into the object from a document
85
85
  def initialize_from_document(parser, format = Tagcrumbs.options[:format])
86
86
  parser = super
87
-
87
+
88
88
  if self.loaded?
89
89
  nodes = parser.nodes_with_name(parser.name.singularize)
90
90
  return if nodes.blank?
91
91
 
92
+
92
93
  nodes.each do |node|
93
94
  node_parser = Parser.new_for_format(node, parser.format)
94
95
  node_type = node_parser.get_attribute('type')
95
-
96
+
96
97
  if node_type # a nested model
97
98
  @array << Tagcrumbs.class_by_type(node_type).new_from_document(node, parser.format)
98
99
  else # a nested node
@@ -0,0 +1,8 @@
1
+ module Tagcrumbs
2
+ # Access Tokens can be received when a new User is created with the web service.
3
+ # Special access must be granted for this from Tagcrumbs.
4
+ class AccessToken < Model
5
+ readable_attributes :token, :secret
6
+
7
+ end
8
+ end
@@ -39,7 +39,7 @@ module Tagcrumbs
39
39
  @has_one_associations_updates ||= {}
40
40
  end
41
41
 
42
- # has_many_associations contains Arrays of further objects
42
+ # has_many_associations contains Collection of further objects
43
43
  def has_many_associations
44
44
  @has_many_associations ||= {}
45
45
  end
@@ -115,6 +115,20 @@ module Tagcrumbs
115
115
  self.class.can_be_options.include?(method.to_sym)
116
116
  end
117
117
 
118
+ def valid?
119
+ errors.empty?
120
+ end
121
+
122
+ # Returns the Errors object that holds all information about attribute error messages.
123
+ def errors
124
+ @errors ||= []
125
+ end
126
+
127
+ def errors_from_document(body, format)
128
+ @errors = Tagcrumbs::Collection.new_from_document(body, format)
129
+ end
130
+
131
+
118
132
 
119
133
  module ClassMethods
120
134
  # Configure if objects of this class can be :created, :updated or :destroyed
@@ -216,11 +230,11 @@ module Tagcrumbs
216
230
 
217
231
  self.has_many_associations_options[name] = options
218
232
 
219
- define_method name do # define a reader that loads the association if not done already
233
+ define_method name do |*parameters| # define a reader that loads the association if not done already
220
234
  if !has_many_associations.has_key?(name)
221
235
  nil
222
236
  else
223
- Proxy.new(has_many_associations[name]) # use a proxy to load objects as late as possible
237
+ Proxy.new(has_many_associations[name], *parameters) # use a proxy to load objects as late as possible
224
238
  end
225
239
  end
226
240
 
@@ -14,6 +14,7 @@ module Tagcrumbs
14
14
  has_one :user
15
15
  has_one :subject
16
16
  has_one :secondary_subject
17
+ has_one :application
17
18
 
18
19
  end
19
20
  end
@@ -0,0 +1,9 @@
1
+ module Tagcrumbs
2
+ # An Application represents the program that was used to create something in the Tagcrumbs API.
3
+ # It is currently available for Comments, Placemarks, Favorites and Activities.
4
+ # If no Application is set the object was created on the Tagcrumbs website.
5
+ class Application < Model
6
+ readable_attributes :name, :url
7
+
8
+ end
9
+ end
@@ -8,5 +8,7 @@ module Tagcrumbs
8
8
  writeable_attributes :text
9
9
 
10
10
  has_one :tagcrumb, :modifiable => true
11
+ has_one :application
12
+
11
13
  end
12
14
  end
@@ -0,0 +1,17 @@
1
+ module Tagcrumbs
2
+ # A Recommendation of a Placemark between two Users
3
+ class EmailRecommendation < Model
4
+ can_be :created, :destroyed
5
+
6
+ readable_attributes :created_at, :updated_at
7
+ writeable_attributes :recipient_email, :message
8
+
9
+ has_one :user
10
+ has_one :tagcrumb, :modifiable => true
11
+
12
+
13
+ def create_url
14
+ Tagcrumbs.current_user.recommendations_url # has to be overwritten
15
+ end
16
+ end
17
+ end
@@ -10,7 +10,8 @@ module Tagcrumbs
10
10
  readable_attributes :created_at, :updated_at
11
11
 
12
12
  has_one :user
13
-
13
+ has_one :application
14
+
14
15
  has_one :tagcrumb, :modifiable => true
15
16
 
16
17
  # Find favorites and pass in additional filter options. The options are documented in Tagcrumb.
@@ -17,8 +17,8 @@ module Tagcrumbs
17
17
  class Filter < Model
18
18
  can_be :created, :updated, :destroyed
19
19
 
20
- readable_attributes :created_at, :updated_at, :permalink
21
- writeable_attributes :name, :private, :tagcrumb_type, :tag_list, :middle_of_nowhere, :from, :within, :since, :until
20
+ readable_attributes :created_at, :updated_at
21
+ writeable_attributes :name, :private, :tagcrumb_type, :tag_list, :middle_of_nowhere, :from, :range, :since, :until
22
22
 
23
23
  has_one :user
24
24
 
@@ -6,5 +6,8 @@ module Tagcrumbs
6
6
 
7
7
  writeable_attributes :reason
8
8
 
9
+ has_one :tagcrumb, :modifiable => true
10
+ has_one :user
11
+
9
12
  end
10
13
  end
@@ -3,7 +3,7 @@ module Tagcrumbs
3
3
 
4
4
  class Model < Resource
5
5
  include Tagcrumbs::Accessors
6
- include Validations
6
+ # include Validations
7
7
 
8
8
  attr_accessor :new_record
9
9
 
@@ -19,7 +19,7 @@ module Tagcrumbs
19
19
  super
20
20
  self.new_record = true
21
21
  @nodes = @nodes_updates = {}
22
- @errors = Errors.new(self) # reset errors from server
22
+ @errors = [] # reset errors from server
23
23
  restore!
24
24
 
25
25
  true
@@ -104,7 +104,7 @@ module Tagcrumbs
104
104
 
105
105
  self.class.has_one_associations_options.keys.each do |name| # load all has_one associations
106
106
  has_one_element = parser.get_node(self.class.has_one_associations_options[name][:node_name])
107
-
107
+
108
108
  if has_one_element
109
109
  has_one_parser = Parser.new_for_format(has_one_element, parser.format)
110
110
 
@@ -116,7 +116,7 @@ module Tagcrumbs
116
116
  has_many_element = parser.get_node(self.class.has_many_associations_options[name][:node_name])
117
117
 
118
118
  if has_many_element
119
- self.has_many_associations[name] = Tagcrumbs::Array.new_from_document(has_many_element, parser.format)
119
+ self.has_many_associations[name] = Tagcrumbs::Collection.new_from_document(has_many_element, parser.format)
120
120
  end
121
121
  end
122
122
  end
@@ -135,11 +135,12 @@ module Tagcrumbs
135
135
  private
136
136
  # Handle the response after a create or update and set the errors if needed.
137
137
  def handle_save_response
138
- if requestor.response.code == '422'
139
- errors.from_format(requestor.response.body, requestor.response_format)
138
+ if requestor.response.code == '422'
139
+ self.errors_from_document(requestor.response.plain_body, requestor.response_format)
140
+
140
141
  false
141
142
  else
142
- initialize_from_document(requestor.response.body)
143
+ initialize_from_document(requestor.response.plain_body)
143
144
  true
144
145
  end
145
146
  end
@@ -0,0 +1,8 @@
1
+ module Tagcrumbs
2
+ # Used to represent the Tagcrumbs Terms and Conditions and the Privacy Policy
3
+ class Paragraph < Model
4
+ readable_attributes :heading
5
+
6
+ has_many :subparagraphs
7
+ end
8
+ end
@@ -6,17 +6,17 @@ module Tagcrumbs
6
6
  class Picture < Model
7
7
  can_be :updated, :destroyed
8
8
 
9
- writeable_attributes :picture_file
10
- readable_attributes :url, :small_thumbnail_url, :medium_thumbnail_url, :content_type, :created_at, :updated_at
9
+ writeable_attributes :file
10
+ readable_attributes :large_thumbnail_url, :small_thumbnail_url, :medium_thumbnail_url, :content_type, :created_at, :updated_at
11
11
 
12
- has_one :profile
12
+ has_one :user
13
13
 
14
14
  # Load a file from the local filesystem and set the attributes.
15
15
  # Save the object to upload a new profile picture to the server.
16
16
  def get_file(filename)
17
17
  return if filename.blank?
18
18
 
19
- self.picture_file = {
19
+ self.file = {
20
20
  :filename => File.basename(filename),
21
21
  :mime_type => MIME::Types.type_for(filename).first.content_type,
22
22
  :content => Base64.encode64(File.read(filename))
@@ -1,17 +1,17 @@
1
1
  module Tagcrumbs
2
2
  # The superclass for City, State and Country
3
- # All of them contain a name and a permalink.
3
+ # All of them have a name
4
4
  # The name is automatically translated into the locale that was set by the user
5
5
  # in the settings.
6
6
  class Place < Model
7
- readable_attributes :name, :permalink
7
+ readable_attributes :name
8
8
 
9
9
  has_one :geoname
10
10
 
11
11
  def self.search(q, args={})
12
12
  args.assert_valid_keys(:page, :per_page, :for)
13
13
 
14
- Array.load(Tagcrumbs.root.place_search_url, args.merge(:q => q))
14
+ Collection.load(Tagcrumbs.root.place_search_url, args.merge(:q => q))
15
15
  end
16
16
  end
17
17
  end
@@ -6,15 +6,16 @@ module Tagcrumbs
6
6
 
7
7
 
8
8
  writeable_attributes :name, :notes, :private, :latitude, :longitude, :tag_list, :guess_city, :address_attributes
9
- readable_attributes :created_at, :updated_at, :short_url, :permalink, :favorites_count
9
+ readable_attributes :created_at, :updated_at, :short_url, :favorites_count
10
10
 
11
11
  has_one :user
12
12
  has_one :city, :modifiable => true
13
13
  has_one :address
14
+ has_one :application
15
+ has_one :tagcrumb # only if favorite of current user
14
16
 
15
17
  has_many :links
16
18
  has_many :comments
17
- has_many :recommendations
18
19
 
19
20
  # Find Placemarks by specifying find criteria.
20
21
  def self.find(args={})