storage_room 0.3.23 → 0.3.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,6 @@
1
+ == Version 0.3.24
2
+ * Add support for Ruby 2.x
3
+
1
4
  == Version 0.3.23
2
5
  * Support the configuration of a custom connection timeout
3
6
 
@@ -84,4 +87,4 @@
84
87
 
85
88
  === Version 0.1.0
86
89
 
87
- * Initial Version
90
+ * Initial Version
@@ -1,15 +1,15 @@
1
1
  module StorageRoom
2
-
2
+
3
3
  # Module that contains attributes methods shared between StorageRoom::Resource and StorageRoom::Embedded
4
4
  module Accessors
5
5
  extend ActiveSupport::Concern
6
-
6
+
7
7
  included do
8
8
  self.send(:extend, ::ActiveModel::Callbacks)
9
9
  self.send(:define_model_callbacks, :initialize_from_response_data)
10
10
  end
11
-
12
- module ClassMethods
11
+
12
+ module ClassMethods
13
13
  # Is the passed hash of response data a real object or only an association with a URL but no actual data
14
14
  def response_data_is_association?(hash)
15
15
  hash.size == 2 && hash.include?('@type') && hash.include?('url')
@@ -62,14 +62,14 @@ module StorageRoom
62
62
  define_attribute_methods(name, options)
63
63
  end
64
64
 
65
- # Defines a to-many association for a Resource (embedded or association)
65
+ # Defines a to-many association for a Resource (embedded or association)
66
66
  def many(name, options = {})
67
67
  options.merge!(:type => :many, :default => [])
68
68
  define_attribute_methods(name, options)
69
69
  end
70
70
 
71
71
  # Creates getter and setter for an attribute
72
- def define_attribute_methods(name, options) # :nodoc:
72
+ def define_attribute_methods(name, options) # :nodoc:
73
73
  define_method name do
74
74
  attributes[name] || options[:default]
75
75
  end
@@ -85,7 +85,7 @@ module StorageRoom
85
85
  @attribute_options ||= {}
86
86
  end
87
87
 
88
- def attribute_options_including_superclasses
88
+ def attribute_options_including_superclasses
89
89
  hash = attribute_options.dup
90
90
  hash.merge!(superclass.attribute_options_including_superclasses) if superclass.respond_to?(:attribute_options_including_superclasses)
91
91
 
@@ -94,45 +94,45 @@ module StorageRoom
94
94
  end
95
95
 
96
96
  # Optionally pass attributes to set up the object
97
- def initialize(hash={})
97
+ def initialize(hash={})
98
98
  self.attributes = hash
99
99
  end
100
-
101
- # Shortcut to get an attribute.
100
+
101
+ # Shortcut to get an attribute.
102
102
  def [](name)
103
103
  self.response_data[name]
104
104
  end
105
-
105
+
106
106
  # Takes a response data hash, saves it in the record and initializes the class from the response data
107
107
  def set_from_response_data(hash)
108
108
  self.response_data = hash
109
109
  self.initialize_from_response_data
110
110
  self
111
111
  end
112
-
112
+
113
113
  # Return all of the objects attributes
114
114
  def response_data
115
115
  @_response_data ||= Hash.new.with_indifferent_access
116
116
  end
117
-
117
+
118
118
  # Set the objects attributes with a hash. Only attributes passed in the hash are changed, existing ones are not overridden.
119
119
  def response_data=(hash = {})
120
120
  response_data.merge!(hash)
121
121
  end
122
-
122
+
123
123
  # The attributes as they were defined with key, one, many
124
124
  def attributes
125
125
  @_attributes ||= Hash.new.with_indifferent_access
126
126
  end
127
-
127
+
128
128
  def attributes=(args = {})
129
129
  attributes.merge!(args)
130
130
  end
131
-
131
+
132
132
  def as_json(args = {}) # :nodoc:
133
133
  to_hash(args)
134
134
  end
135
-
135
+
136
136
  # ActiveSupport seemed to cause problems when just using as_json, so using to_hash
137
137
  def to_hash(args = {}) # :nodoc:
138
138
  args ||= {}
@@ -149,46 +149,46 @@ module StorageRoom
149
149
  value
150
150
  end
151
151
  end
152
-
152
+
153
153
  hash
154
154
  end
155
-
155
+
156
156
  def inspect # :nodoc:
157
157
  body = attributes.map{|k, v| "#{k}: #{attribute_for_inspect(v)}"}.join(', ')
158
- "#<#{self.class} #{body}>"
158
+ "#<#{self.class} #{body}>"
159
159
  end
160
-
160
+
161
161
  # Reset an object to its initial state with all attributes unset
162
162
  def reset!
163
163
  @_response_data = Hash.new.with_indifferent_access
164
164
  @_attributes = Hash.new.with_indifferent_access
165
165
  true
166
166
  end
167
-
167
+
168
168
  # Has a Resource been loaded from the API
169
169
  def loaded?
170
170
  self.response_data.present?
171
171
  end
172
-
172
+
173
173
  def proxy? # :nodoc:
174
174
  false
175
175
  end
176
-
176
+
177
177
  # Compare Resources by comparing their attributes
178
178
  def eql?(object)
179
179
  self.class.equal?(object.class) && attributes == object.attributes
180
180
  end
181
-
182
- alias == eql?
183
-
181
+
182
+ alias == eql?
183
+
184
184
  def hash
185
185
  self.class.hash ^ self.attributes.hash
186
186
  end
187
-
187
+
188
188
  protected
189
189
  # Helper to not call to_hash with the wrong number of arguments
190
190
  def call_method_with_optional_parameters(object, method_name, parameters)
191
- if object.respond_to?(method_name)
191
+ if object.respond_to?(method_name)
192
192
  if object.method(method_name).arity == -1
193
193
  object.send(method_name, parameters)
194
194
  else
@@ -196,10 +196,10 @@ module StorageRoom
196
196
  end
197
197
  end
198
198
  end
199
-
199
+
200
200
  # Iterate over the response data and initialize the attributes
201
201
  def initialize_from_response_data # :nodoc:
202
- _run_initialize_from_response_data_callbacks do
202
+ run_callbacks :initialize_from_response_data do
203
203
  self.class.attribute_options_including_superclasses.each do |name, options|
204
204
  value = if options[:type] == :key
205
205
  self[name].blank? ? options[:default] : self[name]
@@ -216,7 +216,7 @@ module StorageRoom
216
216
  end
217
217
  end
218
218
  end
219
-
219
+
220
220
  def ensure_loaded # :nodoc:
221
221
  if loaded?
222
222
  yield if block_given?
@@ -224,7 +224,7 @@ module StorageRoom
224
224
  raise StorageRoom::ResourceNotLoadedError
225
225
  end
226
226
  end
227
-
227
+
228
228
  def attribute_for_inspect(value) # :nodoc:
229
229
  if value.is_a?(String) && value.length > 50
230
230
  "#{value[0..50]}...".inspect
@@ -235,8 +235,8 @@ module StorageRoom
235
235
  end
236
236
  end
237
237
  end
238
-
239
-
240
-
241
-
238
+
239
+
240
+
241
+
242
242
  end
@@ -1,10 +1,10 @@
1
1
  module StorageRoom
2
2
  # Abstract superclass for classes that can persist to the remote servers
3
- class Model < Resource
3
+ class Model < Resource
4
4
  define_model_callbacks :create, :update, :save, :destroy
5
-
5
+
6
6
  attr_accessor :skip_webhooks
7
-
7
+
8
8
  class << self
9
9
  # Create a new model with the passed attributes
10
10
  def create(attributes={})
@@ -12,116 +12,116 @@ module StorageRoom
12
12
  entry.create
13
13
  entry
14
14
  end
15
-
15
+
16
16
  # Get all models (could be paginated)
17
17
  def all
18
18
  load(index_path)
19
19
  end
20
-
20
+
21
21
  # Find a model with the specified id
22
22
  def find(id)
23
23
  load(show_path(id))
24
24
  end
25
-
26
- #
25
+
26
+ #
27
27
  def index_path # :nodoc:
28
28
  raise StorageRoom::AbstractMethodError.new
29
29
  end
30
-
30
+
31
31
  def show_path(id) # :nodoc:
32
32
  raise StorageRoom::AbstractMethodError.new
33
33
  end
34
-
34
+
35
35
  def json_name # :nodoc:
36
36
  raise StorageRoom::AbstractMethodError.new
37
37
  end
38
38
  end
39
-
39
+
40
40
  # Create a new model and set its attributes
41
- def initialize(attributes={})
41
+ def initialize(attributes={})
42
42
  @errors = []
43
-
43
+
44
44
  super
45
45
  end
46
-
46
+
47
47
  # Reset the model to its default state
48
48
  def reset!
49
49
  super
50
50
  @errors = []
51
51
  true
52
52
  end
53
-
53
+
54
54
  # Has this model been saved to the API already?
55
55
  def new_record?
56
56
  self['@version'] ? false : true
57
57
  end
58
-
58
+
59
59
  # Create a new model or update an existing model on the server
60
60
  def save
61
61
  new_record? ? create : update
62
62
  end
63
-
63
+
64
64
  # Create a new model on the server
65
65
  def create
66
66
  return false unless new_record?
67
- _run_save_callbacks do
68
- _run_create_callbacks do
67
+ run_callbacks :save do
68
+ run_callbacks :create do
69
69
  httparty = self.class.post(self.class.index_path, request_options.merge(:body => to_json))
70
70
  handle_save_response(httparty)
71
71
  end
72
72
  end
73
73
  end
74
-
74
+
75
75
  # Update an existing model on the server
76
76
  def update
77
77
  return false if new_record?
78
- _run_save_callbacks do
79
- _run_update_callbacks do
78
+ run_callbacks :save do
79
+ run_callbacks :update do
80
80
  httparty = self.class.put(self[:@url], request_options.merge(:body => to_json))
81
81
  handle_save_response(httparty)
82
82
  end
83
83
  end
84
84
  end
85
-
85
+
86
86
  # Delete an existing model on the server
87
87
  def destroy
88
88
  return false if new_record?
89
-
90
- _run_destroy_callbacks do
89
+
90
+ run_callbacks :destroy do
91
91
  httparty = self.class.delete(self[:@url], request_options)
92
92
  self.class.handle_critical_response_errors(httparty)
93
93
  end
94
-
94
+
95
95
  true
96
96
  end
97
-
97
+
98
98
  # Is the model valid or were there validation errors on the server?
99
99
  def valid?
100
100
  self.errors.empty?
101
101
  end
102
-
102
+
103
103
  # ActiveSupport caused problems when using as_json, so using to_hash
104
104
  def to_hash(args = {}) # :nodoc:
105
105
  args ||= {}
106
-
106
+
107
107
  if args[:nested]
108
108
  {'url' => self[:@url] || self[:url]}
109
109
  else
110
110
  hash = super
111
111
  hash.merge!('@version' => self['@version']) unless new_record?
112
- {self.class.json_name => hash}
112
+ {self.class.json_name => hash}
113
113
  end
114
114
  end
115
-
115
+
116
116
  # The validation errors that were returned by the server
117
117
  def errors
118
118
  @errors ||= []
119
119
  end
120
-
120
+
121
121
  protected
122
122
  def handle_save_response(httparty) # :nodoc:
123
123
  self.class.handle_critical_response_errors(httparty)
124
-
124
+
125
125
  if httparty.response.code == '200' || httparty.response.code == '201'
126
126
  self.set_from_response_data(httparty.parsed_response.first[1])
127
127
  @errors = []
@@ -133,15 +133,15 @@ module StorageRoom
133
133
  false
134
134
  end
135
135
  end
136
-
136
+
137
137
  def query_parameters
138
138
  skip_webhooks ? {:skip_webhooks => true} : nil
139
139
  end
140
-
140
+
141
141
  def request_options
142
142
  StorageRoom.request_options.merge(:query => query_parameters)
143
143
  end
144
144
 
145
-
145
+
146
146
  end
147
147
  end
@@ -1,3 +1,3 @@
1
1
  module StorageRoom
2
- VERSION = '0.3.23'
3
- end
2
+ VERSION = '0.3.24'
3
+ end
@@ -9,14 +9,15 @@ Gem::Specification.new do |s|
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Sascha Konietzke"]
11
11
  s.email = "sascha@thriventures.com"
12
- s.homepage = "http://github.com/thriventures/storage_room_gem"
12
+ s.homepage = "http://github.com/thriventures/storage_room_gem"
13
13
  s.summary = "StorageRoom API Wrapper (ActiveModel style)"
14
14
  s.description = "StorageRoom is a CMS system for Mobile Applications (iPhone, Android, BlackBerry, ...). This library gives you an ActiveModel-like interface to your data."
15
-
15
+
16
16
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
17
17
 
18
18
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
19
19
  s.add_development_dependency(%q<webmock>, [">= 0"])
20
+ s.add_runtime_dependency(%q<rake>)
20
21
  s.add_runtime_dependency(%q<json>, [">= 0"])
21
22
  s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
22
23
  s.add_runtime_dependency(%q<activesupport>, [">= 3.1.0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storage_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.23
4
+ version: 0.3.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2014-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70271550602000 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 1.2.9
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70271550602000
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.9
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: webmock
27
- requirement: &70271550601480 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,31 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70271550601480
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
36
62
  - !ruby/object:Gem::Dependency
37
63
  name: json
38
- requirement: &70271550600900 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
39
65
  none: false
40
66
  requirements:
41
67
  - - ! '>='
@@ -43,10 +69,15 @@ dependencies:
43
69
  version: '0'
44
70
  type: :runtime
45
71
  prerelease: false
46
- version_requirements: *70271550600900
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
47
78
  - !ruby/object:Gem::Dependency
48
79
  name: httparty
49
- requirement: &70271550600240 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ! '>='
@@ -54,10 +85,15 @@ dependencies:
54
85
  version: 0.6.1
55
86
  type: :runtime
56
87
  prerelease: false
57
- version_requirements: *70271550600240
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.6.1
58
94
  - !ruby/object:Gem::Dependency
59
95
  name: activesupport
60
- requirement: &70271550599520 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ! '>='
@@ -65,10 +101,15 @@ dependencies:
65
101
  version: 3.1.0
66
102
  type: :runtime
67
103
  prerelease: false
68
- version_requirements: *70271550599520
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 3.1.0
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: activemodel
71
- requirement: &70271550598620 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
72
113
  none: false
73
114
  requirements:
74
115
  - - ! '>='
@@ -76,10 +117,15 @@ dependencies:
76
117
  version: 3.1.0
77
118
  type: :runtime
78
119
  prerelease: false
79
- version_requirements: *70271550598620
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 3.1.0
80
126
  - !ruby/object:Gem::Dependency
81
127
  name: mime-types
82
- requirement: &70271550598040 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
83
129
  none: false
84
130
  requirements:
85
131
  - - ! '>='
@@ -87,7 +133,12 @@ dependencies:
87
133
  version: '0'
88
134
  type: :runtime
89
135
  prerelease: false
90
- version_requirements: *70271550598040
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
91
142
  description: StorageRoom is a CMS system for Mobile Applications (iPhone, Android,
92
143
  BlackBerry, ...). This library gives you an ActiveModel-like interface to your data.
93
144
  email: sascha@thriventures.com
@@ -215,6 +266,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
266
  - - ! '>='
216
267
  - !ruby/object:Gem::Version
217
268
  version: '0'
269
+ segments:
270
+ - 0
271
+ hash: -4081310409651511771
218
272
  required_rubygems_version: !ruby/object:Gem::Requirement
219
273
  none: false
220
274
  requirements:
@@ -223,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
277
  version: '0'
224
278
  requirements: []
225
279
  rubyforge_project:
226
- rubygems_version: 1.8.10
280
+ rubygems_version: 1.8.24
227
281
  signing_key:
228
282
  specification_version: 3
229
283
  summary: StorageRoom API Wrapper (ActiveModel style)