web-connect 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/README.md +137 -1
- data/lib/netfira/web_connect/rack_app.rb +4 -4
- data/lib/netfira/web_connect/rack_app/actions/{version_8 → version_1}/info.rb +1 -1
- data/lib/netfira/web_connect/rack_app/actions/version_1/not_supported.rb +1 -1
- data/lib/netfira/web_connect/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e6587764f67f4e6ce9e10f6d86edb1bf89c916c4
|
|
4
|
+
data.tar.gz: 952c9040de0758ae2e546f932f04887d59e84b6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfe5853e869e8910bad896aa3eeddbdccb479bbf122160f717df5c63488abbb4d1c57e0c61d36287b9bd74db380a63a452c5668ad00bce23c12c8d47304c5981
|
|
7
|
+
data.tar.gz: e785afeea27467e52e926906b3ea2d1ee7819d9ca03d55ec25a875e95476dc7b045c0e8cd894ecd243e57e31ec9852fb5b97d6adbf4b0b0bdfdba50b85b1bcf7
|
data/README.md
CHANGED
|
@@ -1 +1,137 @@
|
|
|
1
|
-
This gem provides
|
|
1
|
+
This gem provides server-side functionality for the [Netfira WebConnect](http://netfirawebconnect.com/) protocol.
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
gem install web-connect
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
**If you're using Rails, use the [web-connect-rails](https://github.com/netfira/web-connect-rails) gem.**
|
|
10
|
+
|
|
11
|
+
To take your WebConnect-enabled app online, use the bundled Rack app and request filter middleware.
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
# config.ru
|
|
15
|
+
require 'web-connect'
|
|
16
|
+
require 'my-app'
|
|
17
|
+
|
|
18
|
+
use Netfira::WebConnect::RequestFilter
|
|
19
|
+
run Netfira::WebConnect::RackApp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> The `RequestFilter` middleware is not essential, but can provide speed and compatibility advantages for older clients.
|
|
23
|
+
|
|
24
|
+
### Configuration
|
|
25
|
+
|
|
26
|
+
This is a typical WebConnect configuration.
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
Netfira::WebConnect.configure do |c|
|
|
30
|
+
# This database configuration will be used by ActiveRecord
|
|
31
|
+
c.db = {
|
|
32
|
+
adapter: 'sqlite3',
|
|
33
|
+
database: 'test.sqlite3'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# This string will be prefixed to names of tables created by
|
|
37
|
+
# WebConnect
|
|
38
|
+
c.db_table_prefix = 'nf_'
|
|
39
|
+
|
|
40
|
+
# Enabled or disable storage of fields not included in WebConnect's
|
|
41
|
+
# default schema
|
|
42
|
+
c.custom_fields = false
|
|
43
|
+
|
|
44
|
+
# Default time zone
|
|
45
|
+
c.time_zone = 'Australia/Sydney'
|
|
46
|
+
|
|
47
|
+
# WebConnect activity will be logged here
|
|
48
|
+
c.logger = Logger.new(STDERR)
|
|
49
|
+
|
|
50
|
+
# Use any Paperclip storage configuration you like here. WebConnect
|
|
51
|
+
# provides the :shop_id and :model_type interpolations.
|
|
52
|
+
c.file_store = {
|
|
53
|
+
path: File.dirname(__FILE__) + '/uploads/shop_:shop_id/:model_type/:filename'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# This block will be passed a shop name and password whenever a client
|
|
57
|
+
# needs to authenticate
|
|
58
|
+
c.on_authenticate do |shop_name, password|
|
|
59
|
+
shop = Shop.find_by(name: shop_name)
|
|
60
|
+
shop && shop.password == password
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Session lifetime (omit to disable sessions)
|
|
64
|
+
c.session_lifetime = 5.days
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Migrations
|
|
69
|
+
|
|
70
|
+
WebConnect uses ActiveRecord migrations to manage its database. It comes with two rake tasks.
|
|
71
|
+
|
|
72
|
+
rake wc:migrate # Migrate the database
|
|
73
|
+
rake wc:rollback # Roll back a single migration
|
|
74
|
+
|
|
75
|
+
If your application uses ActiveRecord, these migrations will be managed independently of your application's migrations.
|
|
76
|
+
|
|
77
|
+
Run these migrations when you first install WebConnect, and whenever you update the WebConnect gem.
|
|
78
|
+
|
|
79
|
+
### Data
|
|
80
|
+
|
|
81
|
+
You can access WebConnect data through the `Netfira::WebConnect::Models` namespace.
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
product = Netfira::WebConnect::Models::Product.first
|
|
85
|
+
|
|
86
|
+
product.unit_price # BigDecimal
|
|
87
|
+
product.name # Netfira::WebConnect::Model::Record::TranslatedString
|
|
88
|
+
product.name[:en_AU] # String
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
You can lookup records using their original client-side identifiers using `find_by_origin_id`.
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
shop = Netfira::WebConnect::Models::Shop.first
|
|
95
|
+
|
|
96
|
+
product = Netfira::WebConnect::Models::Product.find_by_origin_id(shop, 'product123')
|
|
97
|
+
# Or
|
|
98
|
+
product = shop.products.find_by(product_id: 'product123')
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Events
|
|
102
|
+
|
|
103
|
+
Events in WebConnect are handled by delegates. Define your delegates like so:
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
class MyDelegate
|
|
107
|
+
def on_create_product(product)
|
|
108
|
+
# ...
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Then add delegates to WebConnect:
|
|
114
|
+
|
|
115
|
+
```ruby
|
|
116
|
+
Netfira::WebConnect.event_delegates << MyDelegate.new
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The `event_delegates` collection is an array. You can push, merge, delete etc as you would a normal array.
|
|
120
|
+
|
|
121
|
+
Any object can be an event delegate, and you can add as many as you like. They only need to respond any of the method signatures below.
|
|
122
|
+
|
|
123
|
+
#### Delegate Method Signatures
|
|
124
|
+
|
|
125
|
+
For |Example |Arguments |Remarks
|
|
126
|
+
------------------|------------------------------------|---------------------------|-------
|
|
127
|
+
New Records |`on_create_buyer` |`buyer` | Dispatched after record is created
|
|
128
|
+
Record Updates |`on_update_image` |`image`, `previous_values` | Second argument is a hash of changed columns as they were before they were changed
|
|
129
|
+
Deleted Records |`on_delete_category` |`category` | Dispatched before records are deleted
|
|
130
|
+
New Relations |`on_add_image_to_product` |`image`, `product` | `on_add_product_to_image` also works, causing the arguments to also be swapped
|
|
131
|
+
Deleted Relations |`on_remove_product_from_category` |`product`, `category` | Same as above
|
|
132
|
+
Change Setting |`on_change_setting` |`setting`, `old` | `setting` will have `shop`, `key`, and `value` methods. `old` is the previous value.
|
|
133
|
+
|
|
134
|
+
Except for `previous_values`, all arguments above are instances of `Netfira::WebConnect::Model::Record`.
|
|
135
|
+
|
|
136
|
+
Events are dispatched to delegates synchronously, on request threads. Create new threads if you want to prevent your handlers from blocking HTTP responses to WebConnect clients.
|
|
137
|
+
|
|
@@ -6,7 +6,7 @@ module Netfira::WebConnect
|
|
|
6
6
|
begin
|
|
7
7
|
body, headers = handle_request(env)
|
|
8
8
|
if headers['Content-Type']
|
|
9
|
-
[200, headers, body]
|
|
9
|
+
[200, headers, [body]]
|
|
10
10
|
else
|
|
11
11
|
make_response 200, body, headers
|
|
12
12
|
end
|
|
@@ -38,10 +38,10 @@ module Netfira::WebConnect
|
|
|
38
38
|
[
|
|
39
39
|
status,
|
|
40
40
|
{
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
'Content-Type' => 'application/json',
|
|
42
|
+
'Content-Length' => body_string.length.to_s
|
|
43
43
|
}.merge(headers),
|
|
44
|
-
body_string
|
|
44
|
+
[body_string]
|
|
45
45
|
]
|
|
46
46
|
end
|
|
47
47
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: web-connect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Neil E. Pearson
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-06-
|
|
12
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activerecord
|
|
@@ -205,13 +205,13 @@ files:
|
|
|
205
205
|
- lib/netfira/web_connect/rack_app/action_helpers/data_types.rb
|
|
206
206
|
- lib/netfira/web_connect/rack_app/action_helpers/env_importer.rb
|
|
207
207
|
- lib/netfira/web_connect/rack_app/action_helpers/env_methods.rb
|
|
208
|
+
- lib/netfira/web_connect/rack_app/actions/version_1/info.rb
|
|
208
209
|
- lib/netfira/web_connect/rack_app/actions/version_1/not_supported.rb
|
|
209
210
|
- lib/netfira/web_connect/rack_app/actions/version_8/checksums.rb
|
|
210
211
|
- lib/netfira/web_connect/rack_app/actions/version_8/commit.rb
|
|
211
212
|
- lib/netfira/web_connect/rack_app/actions/version_8/commit/records.rb
|
|
212
213
|
- lib/netfira/web_connect/rack_app/actions/version_8/commit/relations.rb
|
|
213
214
|
- lib/netfira/web_connect/rack_app/actions/version_8/files.rb
|
|
214
|
-
- lib/netfira/web_connect/rack_app/actions/version_8/info.rb
|
|
215
215
|
- lib/netfira/web_connect/rack_app/actions/version_8/settings.rb
|
|
216
216
|
- lib/netfira/web_connect/rack_app/exceptions.rb
|
|
217
217
|
- lib/netfira/web_connect/rack_app/exceptions/http_exception.rb
|