storage_room 0.3.4 → 0.3.5

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/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == Version 0.3.5
2
+ * Added WebhookDefinition as an array on Collection
3
+ * Added WebhookCall Resource to parse the POST body of StorageRoom Webhooks on a server
4
+ * Added the option to skip_webhooks when creating, updating or destroying a Model
5
+ * Added trash key to Entries
6
+
1
7
  == Version 0.3.4
2
8
  * Added interface key to Fields
3
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -152,6 +152,12 @@ module StorageRoom
152
152
  new_from_response_data(httparty.parsed_response.first[1])
153
153
  end
154
154
 
155
+ # Build an object out of the POST body
156
+ def new_from_json_string(json_string)
157
+ hash = JSON.parse(json_string)
158
+ new_from_response_data(hash)
159
+ end
160
+
155
161
  # Creates a new object of the correct class and initializes it from the response data
156
162
  def new_from_response_data(response_data)
157
163
  object = StorageRoom.class_for_name(response_data['@type']).new.set_from_response_data(response_data)
@@ -0,0 +1,17 @@
1
+ module StorageRoom
2
+
3
+ class WebhookDefinition < Embedded
4
+ key :url
5
+
6
+ key :username
7
+ key :password
8
+
9
+ key :on_create
10
+ key :on_update
11
+ key :on_delete
12
+
13
+ key :api
14
+ key :web_interface
15
+
16
+ end
17
+ end
@@ -1,6 +1,8 @@
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
+ attr_accessor :skip_webhooks
5
+
4
6
  class << self
5
7
  # Create a new model with the passed attributes
6
8
  def create(attributes={})
@@ -60,14 +62,14 @@ module StorageRoom
60
62
  # Create a new model on the server
61
63
  def create
62
64
  return false unless new_record?
63
- httparty = self.class.post(self.class.index_path, :body => to_json)
65
+ httparty = self.class.post(self.class.index_path, :body => to_json, :query => query_parameters)
64
66
  handle_save_response(httparty)
65
67
  end
66
68
 
67
69
  # Update an existing model on the server
68
70
  def update
69
71
  return false if new_record?
70
- httparty = self.class.put(self[:@url], :body => to_json)
72
+ httparty = self.class.put(self[:@url], :body => to_json, :query => query_parameters)
71
73
  handle_save_response(httparty)
72
74
  end
73
75
 
@@ -75,7 +77,7 @@ module StorageRoom
75
77
  def destroy
76
78
  return false if new_record?
77
79
 
78
- httparty = self.class.delete(self[:@url])
80
+ httparty = self.class.delete(self[:@url], :query => query_parameters)
79
81
  self.class.handle_critical_response_errors(httparty)
80
82
 
81
83
  true
@@ -119,6 +121,10 @@ module StorageRoom
119
121
  false
120
122
  end
121
123
  end
124
+
125
+ def query_parameters
126
+ skip_webhooks ? {:skip_webhooks => true} : nil
127
+ end
122
128
 
123
129
 
124
130
  end
@@ -5,6 +5,7 @@ module StorageRoom
5
5
  key :primary_field_identifier
6
6
 
7
7
  many :fields
8
+ many :webhook_definitions
8
9
 
9
10
  class << self
10
11
  def index_path # :nodoc:
@@ -29,6 +29,11 @@ module StorageRoom
29
29
  def collection
30
30
  self.class.collection
31
31
  end
32
+
33
+ # Has this Entry been trashed?
34
+ def trashed?
35
+ self[:@trash]
36
+ end
32
37
 
33
38
  end
34
39
  end
@@ -11,7 +11,7 @@ module StorageRoom
11
11
  headers 'User-Agent' => "StorageRoom Ruby Gem (#{StorageRoom.version})", 'Accept' => 'application/json', 'Content-Type' => 'application/json'
12
12
  format :json
13
13
 
14
- class << self
14
+ class << self
15
15
  # Handle known server errors
16
16
  def handle_critical_response_errors(httparty) # :nodoc:
17
17
  case httparty.response.code
@@ -0,0 +1,11 @@
1
+ module StorageRoom
2
+ # Helper class for receiving Webhook Calls
3
+ class WebhookCall < Resource
4
+ one :@entry
5
+
6
+ def entry
7
+ send('@entry')
8
+ end
9
+
10
+ end
11
+ end
data/lib/storage_room.rb CHANGED
@@ -26,6 +26,7 @@ module StorageRoom
26
26
  autoload :Resource, 'storage_room/resource'
27
27
  autoload :Model, 'storage_room/model'
28
28
  autoload :Array, 'storage_room/array'
29
+ autoload :WebhookCall, 'storage_room/webhook_call'
29
30
 
30
31
  autoload :Embedded, 'storage_room/embedded'
31
32
 
@@ -58,6 +59,7 @@ module StorageRoom
58
59
  autoload :Image, 'storage_room/embeddeds/image'
59
60
  autoload :Location, 'storage_room/embeddeds/location'
60
61
  autoload :ImageVersion, 'storage_room/embeddeds/image_version'
62
+ autoload :WebhookDefinition, 'storage_room/embeddeds/webhook_definition'
61
63
 
62
64
 
63
65
  class << self
@@ -0,0 +1,18 @@
1
+ {
2
+ "@attempts": 0,
3
+ "@created_at": "2011-07-14T18:25:42Z",
4
+ "@entry": {
5
+ "@collection_url": "http:\/\/api.storageroomapp.com\/accounts\/4e1e9c234250712eba000052\/collections\/4e1e9c234250712eba000062",
6
+ "@created_at": "2011-07-14T18:15:53Z",
7
+ "@type": "Announcement",
8
+ "@trash": false,
9
+ "@updated_at": "2011-07-14T18:25:42Z",
10
+ "@url": "http:\/\/api.storageroomapp.com\/accounts\/4e1e9c234250712eba000052\/collections\/4e1e9c234250712eba000062\/entries\/4e1f3259425071435e00004a",
11
+ "@version": 2,
12
+ "text": "WEBHOOK TEST"
13
+ },
14
+ "@event": "update",
15
+ "@last_attempt_at": null,
16
+ "@last_status_code": null,
17
+ "@type": "WebhookCall"
18
+ }
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe StorageRoom::WebhookDefinition do
4
+
5
+ before(:each) do
6
+ @webhook_definition = StorageRoom::WebhookDefinition.new(:url => 'URL', :on_create => true, :on_update => true, :on_delete => true, :api => true, :web_interface => true, :username => 'username', :password => 'password')
7
+ end
8
+
9
+ context "Configuration" do
10
+ describe "#keys" do
11
+ it "should have keys" do
12
+ @webhook_definition.url.should == 'URL'
13
+
14
+ @webhook_definition.on_create.should be_true
15
+ @webhook_definition.on_update.should be_true
16
+ @webhook_definition.on_delete.should be_true
17
+
18
+ @webhook_definition.api.should be_true
19
+ @webhook_definition.web_interface.should be_true
20
+
21
+ @webhook_definition.username.should == 'username'
22
+ @webhook_definition.password.should == 'password'
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -255,6 +255,19 @@ describe StorageRoom::Model do
255
255
  collection.destroy
256
256
  end
257
257
  end
258
+
259
+ describe "#query_parameters" do
260
+ it "should return parameter if skip_webhooks" do
261
+ @model.skip_webhooks = false
262
+ @model.send(:query_parameters).should be_nil
263
+ end
264
+
265
+ it "should return nil if not skip_webhooks" do
266
+ @model.skip_webhooks = true
267
+ @model.send(:query_parameters).should include(:skip_webhooks => true)
268
+ end
269
+
270
+ end
258
271
 
259
272
  end
260
273
 
@@ -54,5 +54,17 @@ describe StorageRoom::Entry do
54
54
  @entry.collection.should == @collection
55
55
  end
56
56
  end
57
+
58
+ describe "#trashed?" do
59
+ it "should return true" do
60
+ @entry.response_data[:@trash] = true
61
+ @entry.should be_trashed
62
+ end
63
+
64
+ it "should return false" do
65
+ @entry.response_data[:@trash] = false
66
+ @entry.should_not be_trashed
67
+ end
68
+ end
57
69
  end
58
70
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ class Announcement < StorageRoom::Entry
4
+ key :text
5
+ end
6
+
7
+ describe StorageRoom::WebhookCall do
8
+ before(:each) do
9
+ @webhook_call = StorageRoom::WebhookCall.new
10
+ end
11
+
12
+ describe "#new_from_json_string" do
13
+ it "should create object" do
14
+ file = fixture_file('webhook_call.json')
15
+ webhook_call = StorageRoom::Resource.new_from_json_string(file)
16
+
17
+ webhook_call.should be_an_instance_of(StorageRoom::WebhookCall)
18
+ webhook_call[:@url].should_not be_present
19
+ webhook_call[:@event].should == 'update'
20
+ webhook_call.entry.should be_an_instance_of(Announcement)
21
+ webhook_call.entry.text.should == 'WEBHOOK TEST'
22
+ end
23
+ end
24
+ end
data/storage_room.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{storage_room}
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sascha Konietzke"]
12
- s.date = %q{2011-07-14}
12
+ s.date = %q{2011-07-18}
13
13
  s.description = %q{StorageRoom is a CMS system for Mobile Applications (iPhone, Android, BlackBerry, ...). This library gives you an ActiveModel-like interface to your data.}
14
14
  s.email = %q{sascha@thriventures.com}
15
15
  s.extra_rdoc_files = [
@@ -60,6 +60,7 @@ Gem::Specification.new do |s|
60
60
  "lib/storage_room/embeddeds/image.rb",
61
61
  "lib/storage_room/embeddeds/image_version.rb",
62
62
  "lib/storage_room/embeddeds/location.rb",
63
+ "lib/storage_room/embeddeds/webhook_definition.rb",
63
64
  "lib/storage_room/extensions/const_defined.rb",
64
65
  "lib/storage_room/identity_map.rb",
65
66
  "lib/storage_room/model.rb",
@@ -68,10 +69,12 @@ Gem::Specification.new do |s|
68
69
  "lib/storage_room/plugins.rb",
69
70
  "lib/storage_room/proxy.rb",
70
71
  "lib/storage_room/resource.rb",
72
+ "lib/storage_room/webhook_call.rb",
71
73
  "spec/fixtures/collection.json",
72
74
  "spec/fixtures/collections.json",
73
75
  "spec/fixtures/image.png",
74
76
  "spec/fixtures/validation_error.json",
77
+ "spec/fixtures/webhook_call.json",
75
78
  "spec/spec_helper.rb",
76
79
  "spec/storage_room/accessors_spec.rb",
77
80
  "spec/storage_room/array_spec.rb",
@@ -98,12 +101,14 @@ Gem::Specification.new do |s|
98
101
  "spec/storage_room/embeddeds/image_spec.rb",
99
102
  "spec/storage_room/embeddeds/image_version_spec.rb",
100
103
  "spec/storage_room/embeddeds/location_spec.rb",
104
+ "spec/storage_room/embeddeds/webhook_definition_spec.rb",
101
105
  "spec/storage_room/identity_map_spec.rb",
102
106
  "spec/storage_room/model_spec.rb",
103
107
  "spec/storage_room/models/collection_spec.rb",
104
108
  "spec/storage_room/models/entry_spec.rb",
105
109
  "spec/storage_room/proxy_spec.rb",
106
110
  "spec/storage_room/resource_spec.rb",
111
+ "spec/storage_room/webhook_call_spec.rb",
107
112
  "spec/storage_room_spec.rb",
108
113
  "storage_room.gemspec",
109
114
  "tasks/storage_room.rake"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 5
9
+ version: 0.3.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sascha Konietzke
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-14 00:00:00 +02:00
17
+ date: 2011-07-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -141,6 +141,7 @@ files:
141
141
  - lib/storage_room/embeddeds/image.rb
142
142
  - lib/storage_room/embeddeds/image_version.rb
143
143
  - lib/storage_room/embeddeds/location.rb
144
+ - lib/storage_room/embeddeds/webhook_definition.rb
144
145
  - lib/storage_room/extensions/const_defined.rb
145
146
  - lib/storage_room/identity_map.rb
146
147
  - lib/storage_room/model.rb
@@ -149,10 +150,12 @@ files:
149
150
  - lib/storage_room/plugins.rb
150
151
  - lib/storage_room/proxy.rb
151
152
  - lib/storage_room/resource.rb
153
+ - lib/storage_room/webhook_call.rb
152
154
  - spec/fixtures/collection.json
153
155
  - spec/fixtures/collections.json
154
156
  - spec/fixtures/image.png
155
157
  - spec/fixtures/validation_error.json
158
+ - spec/fixtures/webhook_call.json
156
159
  - spec/spec_helper.rb
157
160
  - spec/storage_room/accessors_spec.rb
158
161
  - spec/storage_room/array_spec.rb
@@ -179,12 +182,14 @@ files:
179
182
  - spec/storage_room/embeddeds/image_spec.rb
180
183
  - spec/storage_room/embeddeds/image_version_spec.rb
181
184
  - spec/storage_room/embeddeds/location_spec.rb
185
+ - spec/storage_room/embeddeds/webhook_definition_spec.rb
182
186
  - spec/storage_room/identity_map_spec.rb
183
187
  - spec/storage_room/model_spec.rb
184
188
  - spec/storage_room/models/collection_spec.rb
185
189
  - spec/storage_room/models/entry_spec.rb
186
190
  - spec/storage_room/proxy_spec.rb
187
191
  - spec/storage_room/resource_spec.rb
192
+ - spec/storage_room/webhook_call_spec.rb
188
193
  - spec/storage_room_spec.rb
189
194
  - storage_room.gemspec
190
195
  - tasks/storage_room.rake