layer-ruby 0.5.2 → 0.6.0
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/lib/layer/client.rb +1 -0
- data/lib/layer/client/webhook.rb +18 -0
- data/lib/layer/conversation.rb +5 -17
- data/lib/layer/exceptions.rb +2 -1
- data/lib/layer/message.rb +4 -0
- data/lib/layer/operations.rb +1 -0
- data/lib/layer/operations/destroy.rb +31 -0
- data/lib/layer/operations/patch.rb +1 -1
- data/lib/layer/patch.rb +4 -2
- data/lib/layer/patch/base.rb +2 -2
- data/lib/layer/patch/hash.rb +1 -1
- data/lib/layer/relation_proxy.rb +5 -0
- data/lib/layer/version.rb +1 -1
- data/lib/layer/webhook.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c88bda03f993c0830bcdfa3e2c61bd70d6513fc5
|
4
|
+
data.tar.gz: 516ec66a994540689b597f06ea01d1fcd12a0b2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96e3857ed7f52b85f5c9d7d21c1159b768b6dd94a4617ec4754ea9b0b1f7045e3127f91114a6818203e03df7d128cea744c44339cabccc583bb7e04f7b19196b
|
7
|
+
data.tar.gz: b838d08d8aa637d85f7d7f78eadff5467c7a924eea13b87cb3853e1aad00f828574e07929d0d4e5c8bc836f9b677de2481b79c2ee45504b8c87dd95f4099a5c3
|
data/lib/layer/client.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Layer
|
2
|
+
class Client
|
3
|
+
class Webhook < Platform
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def request(method, url, payload = {}, headers = {})
|
8
|
+
headers = {
|
9
|
+
'Accept' => 'application/vnd.layer.webhooks+json; version=1.0',
|
10
|
+
'Content-Type' => 'application/json'
|
11
|
+
}.merge(headers)
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/layer/conversation.rb
CHANGED
@@ -19,28 +19,21 @@ module Layer
|
|
19
19
|
include Operations::Paginate
|
20
20
|
include Operations::Create
|
21
21
|
include Operations::Delete
|
22
|
+
include Operations::Destroy
|
22
23
|
include Operations::Patch
|
23
24
|
|
24
25
|
# @!parse extend Layer::Operations::Find::ClassMethods
|
25
26
|
# @!parse extend Layer::Operations::Paginate::ClassMethods
|
26
27
|
# @!parse extend Layer::Operations::Create::ClassMethods
|
27
28
|
# @!parse extend Layer::Operations::Delete::ClassMethods
|
28
|
-
|
29
|
-
# Destroys the conversation with the given id for all participants
|
30
|
-
#
|
31
|
-
# @param [String] id of the conversation to destroy
|
32
|
-
# @!macro rest-api
|
33
|
-
def self.destroy(id, client = self.client)
|
34
|
-
id = Layer::Client.normalize_id(id)
|
35
|
-
client.delete("#{url}/#{id}", {}, { params: { destroy: true } })
|
36
|
-
end
|
29
|
+
# @!parse extend Layer::Operations::Destroy::ClassMethods
|
37
30
|
|
38
31
|
# Returns the converations messages
|
39
32
|
#
|
40
33
|
# @return [Layer::RelationProxy] the conversation's messages
|
41
34
|
# @!macro various-apis
|
42
35
|
def messages
|
43
|
-
RelationProxy.new(self, Message, [Operations::Create, Operations::Paginate, Operations::Find])
|
36
|
+
RelationProxy.new(self, Message, [Operations::Create, Operations::Paginate, Operations::Find, Operations::Delete, Operations::Destroy])
|
44
37
|
end
|
45
38
|
|
46
39
|
# Returns the conversations metadata
|
@@ -48,6 +41,7 @@ module Layer
|
|
48
41
|
# @return [Layer::Patch::Hash] the metadata hash
|
49
42
|
def metadata
|
50
43
|
attributes['metadata'] ||= {}
|
44
|
+
attributes['metadata']
|
51
45
|
end
|
52
46
|
|
53
47
|
# Returns the conversations metadata
|
@@ -55,6 +49,7 @@ module Layer
|
|
55
49
|
# @return [Layer::Patch::Array] the participants array
|
56
50
|
def participants
|
57
51
|
attributes['participants'] ||= []
|
52
|
+
attributes['participants']
|
58
53
|
end
|
59
54
|
|
60
55
|
# Whether the conversation is distinct
|
@@ -71,12 +66,5 @@ module Layer
|
|
71
66
|
Time.parse(attributes['created_at'])
|
72
67
|
end
|
73
68
|
|
74
|
-
# Destroys the conversation for all participants
|
75
|
-
#
|
76
|
-
# @!macro rest-api
|
77
|
-
def destroy
|
78
|
-
client.delete(url, {}, { params: { destroy: true } })
|
79
|
-
end
|
80
|
-
|
81
69
|
end
|
82
70
|
end
|
data/lib/layer/exceptions.rb
CHANGED
@@ -28,8 +28,9 @@ module Layer
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class ClientException < Exception; end
|
31
|
+
class InternalServerError < ClientException; end
|
31
32
|
class ServiceUnavailable < ClientException; end
|
32
|
-
class InvalidAppId< ClientException; end
|
33
|
+
class InvalidAppId < ClientException; end
|
33
34
|
class InvalidRequestId < ClientException; end
|
34
35
|
class AuthenticationRequired < ClientException; end
|
35
36
|
class AppSuspended < ClientException; end
|
data/lib/layer/message.rb
CHANGED
@@ -10,8 +10,12 @@ module Layer
|
|
10
10
|
# @!macro various-apis
|
11
11
|
class Message < Resource
|
12
12
|
include Operations::Find
|
13
|
+
include Operations::Delete
|
14
|
+
include Operations::Destroy
|
13
15
|
|
14
16
|
# @!parse extend Layer::Operations::Find::ClassMethods
|
17
|
+
# @!parse extend Layer::Operations::Delete::ClassMethods
|
18
|
+
# @!parse extend Layer::Operations::Destroy::ClassMethods
|
15
19
|
|
16
20
|
# Returns the conversation this message belongs to
|
17
21
|
#
|
data/lib/layer/operations.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Layer
|
2
|
+
module Operations
|
3
|
+
module Destroy
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
# Destroys the resource with the given id
|
7
|
+
#
|
8
|
+
# @param id [String] the resource's id
|
9
|
+
# @param client [Layer::Client] the client to use to make this request
|
10
|
+
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
|
11
|
+
def destroy(id, client = self.client)
|
12
|
+
id = Layer::Client.normalize_id(id)
|
13
|
+
client.delete("#{url}/#{id}", {}, { params: { destroy: true } })
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @!visibility private
|
18
|
+
def self.included(base)
|
19
|
+
base.extend(ClassMethods)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Destroys the resource
|
23
|
+
#
|
24
|
+
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
|
25
|
+
def destroy
|
26
|
+
client.delete(url, {}, { params: { destroy: true } })
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -7,7 +7,7 @@ module Layer
|
|
7
7
|
# @return [Boolean] whether saving was successful
|
8
8
|
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
|
9
9
|
def save
|
10
|
-
client.patch(url, patch.operations)
|
10
|
+
client.patch(url, patch.operations.dup)
|
11
11
|
patch.reset
|
12
12
|
true
|
13
13
|
end
|
data/lib/layer/patch.rb
CHANGED
@@ -46,9 +46,11 @@ module Layer
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def reset
|
49
|
-
@parent ? parent.reset :
|
49
|
+
@parent ? parent.reset : operations.clear
|
50
50
|
end
|
51
51
|
|
52
|
+
attr_reader :property
|
53
|
+
|
52
54
|
private
|
53
55
|
|
54
56
|
def operation(type, property = nil, options = {})
|
@@ -56,7 +58,7 @@ module Layer
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def expand_property(property)
|
59
|
-
[@property, property].compact.join('.')
|
61
|
+
[@parent && @parent.property, @property, property].compact.join('.')
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
data/lib/layer/patch/base.rb
CHANGED
@@ -12,9 +12,9 @@ module Layer
|
|
12
12
|
def wrap(property, object)
|
13
13
|
case object
|
14
14
|
when ::Array
|
15
|
-
Layer::Patch::Array.new(patch.nested(property), object)
|
15
|
+
return Layer::Patch::Array.new(patch.nested(property), object)
|
16
16
|
when ::Hash
|
17
|
-
Layer::Patch::Hash.new(patch.nested(property), object)
|
17
|
+
return Layer::Patch::Hash.new(patch.nested(property), object)
|
18
18
|
else
|
19
19
|
object
|
20
20
|
end
|
data/lib/layer/patch/hash.rb
CHANGED
data/lib/layer/relation_proxy.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Layer
|
2
2
|
class RelationProxy
|
3
|
+
include Enumerable
|
3
4
|
|
4
5
|
attr_reader :resource_type, :base
|
5
6
|
|
@@ -24,6 +25,10 @@ module Layer
|
|
24
25
|
base.client
|
25
26
|
end
|
26
27
|
|
28
|
+
def each(&block)
|
29
|
+
all.each(&block)
|
30
|
+
end
|
31
|
+
|
27
32
|
private
|
28
33
|
|
29
34
|
def method_missing(method, *args, &block)
|
data/lib/layer/version.rb
CHANGED
data/lib/layer/webhook.rb
CHANGED
@@ -21,6 +21,10 @@ module Layer
|
|
21
21
|
# @!parse extend Layer::Operations::Create::ClassMethods
|
22
22
|
# @!parse extend Layer::Operations::Delete::ClassMethods
|
23
23
|
|
24
|
+
def self.client
|
25
|
+
@client ||= Client::Webhook.new
|
26
|
+
end
|
27
|
+
|
24
28
|
# Activate this webhook
|
25
29
|
def activate!
|
26
30
|
client.post("#{url}/activate")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: layer-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benedikt Deicke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/layer/client.rb
|
106
106
|
- lib/layer/client/platform.rb
|
107
107
|
- lib/layer/client/rest.rb
|
108
|
+
- lib/layer/client/webhook.rb
|
108
109
|
- lib/layer/content.rb
|
109
110
|
- lib/layer/conversation.rb
|
110
111
|
- lib/layer/exceptions.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- lib/layer/operations.rb
|
113
114
|
- lib/layer/operations/create.rb
|
114
115
|
- lib/layer/operations/delete.rb
|
116
|
+
- lib/layer/operations/destroy.rb
|
115
117
|
- lib/layer/operations/find.rb
|
116
118
|
- lib/layer/operations/list.rb
|
117
119
|
- lib/layer/operations/paginate.rb
|