layer-ruby 0.6.0 → 0.7.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/.travis.yml +1 -1
- data/lib/layer.rb +2 -0
- data/lib/layer/client.rb +0 -1
- data/lib/layer/client/platform.rb +1 -0
- data/lib/layer/client/rest.rb +1 -0
- data/lib/layer/content.rb +7 -1
- data/lib/layer/conversation.rb +22 -1
- data/lib/layer/identity.rb +21 -0
- data/lib/layer/operations.rb +1 -0
- data/lib/layer/operations/fetch.rb +33 -0
- data/lib/layer/singleton_relation_proxy.rb +29 -0
- data/lib/layer/user.rb +41 -0
- data/lib/layer/version.rb +1 -1
- data/lib/layer/webhook.rb +5 -5
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0976249289a43645badaaadd9d3a67cb684938d2
|
4
|
+
data.tar.gz: bc136906bf91e1ae79cbd6423adec89dc06304ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ad40b5dab203070617cae0a203d25f88e2944b36aba548afc0ad1ea2c5f068b66dff7145cc7c194a64227a50b487da0e2548569571853ead9852e35f72ba7af
|
7
|
+
data.tar.gz: 52d8129875fd24be068f90e60bd710a3c39734535aab61fce2c93261f2ac8a9c8ee36ac35a84fad431d0d116219037de0626b7860f995404929e35729ad2db1a
|
data/.travis.yml
CHANGED
data/lib/layer.rb
CHANGED
@@ -6,11 +6,13 @@ require 'layer/operations'
|
|
6
6
|
require 'layer/resource'
|
7
7
|
require 'layer/resource_collection'
|
8
8
|
require 'layer/relation_proxy'
|
9
|
+
require 'layer/singleton_relation_proxy'
|
9
10
|
require 'layer/conversation'
|
10
11
|
require 'layer/content'
|
11
12
|
require 'layer/message'
|
12
13
|
require 'layer/user'
|
13
14
|
require 'layer/block'
|
15
|
+
require 'layer/identity'
|
14
16
|
require 'layer/announcement'
|
15
17
|
require 'layer/webhook'
|
16
18
|
|
data/lib/layer/client.rb
CHANGED
@@ -67,7 +67,6 @@ module Layer
|
|
67
67
|
url = "https://api.layer.com#{url}" unless url.start_with?('https://api.layer.com')
|
68
68
|
|
69
69
|
headers = {
|
70
|
-
'Accept' => 'application/vnd.layer+json; version=1.0',
|
71
70
|
'Content-Type' => 'application/json',
|
72
71
|
'If-None-Match' => SecureRandom.uuid
|
73
72
|
}.merge(headers)
|
@@ -13,6 +13,7 @@ module Layer
|
|
13
13
|
|
14
14
|
def request(method, url, payload = {}, headers = {})
|
15
15
|
url = "https://api.layer.com/apps/#{app_id}#{url}" unless url.start_with?('https://api.layer.com')
|
16
|
+
headers['Accept'] ||= 'application/vnd.layer+json; version=1.1'
|
16
17
|
headers['Authorization'] ||= "Bearer #{token}"
|
17
18
|
|
18
19
|
super
|
data/lib/layer/client/rest.rb
CHANGED
@@ -25,6 +25,7 @@ module Layer
|
|
25
25
|
|
26
26
|
def request(method, url, payload = {}, headers = {})
|
27
27
|
url = "https://api.layer.com#{url}" unless url.start_with?('https://api.layer.com')
|
28
|
+
headers['Accept'] ||= 'application/vnd.layer+json; version=1.0'
|
28
29
|
headers['Authorization'] ||= "Layer session-token=\"#{token}\""
|
29
30
|
|
30
31
|
super
|
data/lib/layer/content.rb
CHANGED
@@ -9,8 +9,14 @@ module Layer
|
|
9
9
|
# ]
|
10
10
|
# })
|
11
11
|
#
|
12
|
+
# @example
|
13
|
+
# conversation = Layer::Conversation.find('layer-conversation-id-here')
|
14
|
+
# content = conversation.contents.create('image/png', File.open('photo.png'))
|
15
|
+
#
|
16
|
+
#
|
12
17
|
# @see https://developer.layer.com/docs/client/rest#rich-content Layer REST API documentation about rich content
|
13
|
-
#
|
18
|
+
# @see https://developer.layer.com/docs/platform/messages#rich-content Layer Platform API documentation about rich content
|
19
|
+
# @!macro various-apis
|
14
20
|
class Content < Resource
|
15
21
|
include Operations::Create
|
16
22
|
include Operations::Find
|
data/lib/layer/conversation.rb
CHANGED
@@ -28,7 +28,7 @@ module Layer
|
|
28
28
|
# @!parse extend Layer::Operations::Delete::ClassMethods
|
29
29
|
# @!parse extend Layer::Operations::Destroy::ClassMethods
|
30
30
|
|
31
|
-
# Returns the
|
31
|
+
# Returns the conversations messages
|
32
32
|
#
|
33
33
|
# @return [Layer::RelationProxy] the conversation's messages
|
34
34
|
# @!macro various-apis
|
@@ -36,6 +36,27 @@ module Layer
|
|
36
36
|
RelationProxy.new(self, Message, [Operations::Create, Operations::Paginate, Operations::Find, Operations::Delete, Operations::Destroy])
|
37
37
|
end
|
38
38
|
|
39
|
+
# Allows creating and finding of the conversation's rich content
|
40
|
+
#
|
41
|
+
# @return [Layer::RelationProxy] the conversation's rich content
|
42
|
+
# @!macro platform-api
|
43
|
+
def contents
|
44
|
+
RelationProxy.new(self, Content, [Operations::Create, Operations::Find]) do
|
45
|
+
def create(mime_type, file, client = self.client)
|
46
|
+
response = client.post(url, {}, {
|
47
|
+
'Upload-Content-Type' => mime_type,
|
48
|
+
'Upload-Content-Length' => file.size
|
49
|
+
})
|
50
|
+
|
51
|
+
attributes = response.merge('size' => file.size, 'mime_type' => mime_type)
|
52
|
+
|
53
|
+
Content.from_response(attributes, client).tap do |content|
|
54
|
+
content.upload(file)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
39
60
|
# Returns the conversations metadata
|
40
61
|
#
|
41
62
|
# @return [Layer::Patch::Hash] the metadata hash
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Layer
|
2
|
+
# Managing user identity is also possible:
|
3
|
+
#
|
4
|
+
# @example
|
5
|
+
# user = Layer::User.find('user_id')
|
6
|
+
# user.identity # Returns user identity
|
7
|
+
# user.identity.create({ first_name: 'Frodo', last_name: 'Baggins'}) # Creates new identity
|
8
|
+
# user.identity.delete # Removes identity
|
9
|
+
#
|
10
|
+
# @see https://developer.layer.com/docs/platform#identity Layer Platform API Documentation about identity
|
11
|
+
# @!macro platform-api
|
12
|
+
class Identity < Resource
|
13
|
+
include Operations::Fetch
|
14
|
+
include Operations::Delete
|
15
|
+
include Operations::Patch
|
16
|
+
|
17
|
+
def self.url
|
18
|
+
'/identity'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/layer/operations.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Layer
|
2
|
+
module Operations
|
3
|
+
module Fetch
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
# Fetches the singular resource
|
7
|
+
#
|
8
|
+
# @param client [Layer::Client] the client to use to make this request
|
9
|
+
# @return [Layer::Resource] the found resource
|
10
|
+
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
|
11
|
+
def fetch(client = self.client)
|
12
|
+
response = client.get(url)
|
13
|
+
from_response(response, client)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @!visibility private
|
18
|
+
def self.included(base)
|
19
|
+
base.extend(ClassMethods)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Reloads the resource
|
23
|
+
#
|
24
|
+
# @return [Layer::Resource] the resource itself
|
25
|
+
# @raise [Layer::Exceptions::Exception] a subclass of Layer::Exceptions::Exception describing the error
|
26
|
+
def reload
|
27
|
+
self.attributes = client.get(url)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Layer
|
2
|
+
class SingletonRelationProxy < RelationProxy
|
3
|
+
include Operations::Fetch::ClassMethods
|
4
|
+
include Operations::Fetch
|
5
|
+
|
6
|
+
def respond_to_missing?(method, include_private = false)
|
7
|
+
resource.respond_to?(method, include_private) || super
|
8
|
+
end
|
9
|
+
|
10
|
+
def from_response(*args)
|
11
|
+
resource_type.from_response(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def method_missing(method, *args, &block)
|
17
|
+
if resource.respond_to?(method)
|
18
|
+
resource.public_send(method, *args, &block)
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource
|
25
|
+
@resource ||= fetch
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/layer/user.rb
CHANGED
@@ -5,6 +5,10 @@ module Layer
|
|
5
5
|
from_response({ 'url' => "/users/#{id}" }, client)
|
6
6
|
end
|
7
7
|
|
8
|
+
# Returns the users blocked by this user
|
9
|
+
#
|
10
|
+
# @return [Layer::RelationProxy] the users the user blocks
|
11
|
+
# @!macro platform-api
|
8
12
|
def blocks
|
9
13
|
RelationProxy.new(self, Block, [Operations::Create, Operations::List, Operations::Delete]) do
|
10
14
|
def from_response(response, client)
|
@@ -19,5 +23,42 @@ module Layer
|
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
26
|
+
# Returns the identity object for this user
|
27
|
+
#
|
28
|
+
# @return [Layer::RelationProxy] identity object
|
29
|
+
# @!macro platform-api
|
30
|
+
def identity
|
31
|
+
SingletonRelationProxy.new(self, Layer::Identity) do
|
32
|
+
def from_response(response, client)
|
33
|
+
response['url'] ||= "#{base.url}#{resource_type.url}"
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def create(attributes, client = self.client)
|
38
|
+
client.post(url, attributes)
|
39
|
+
fetch
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(client = self.client)
|
43
|
+
client.delete(url)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the user's conversations
|
49
|
+
#
|
50
|
+
# @return [Layer::RelationProxy] the user's conversations
|
51
|
+
# @!macro platform-api
|
52
|
+
def conversations
|
53
|
+
RelationProxy.new(self, Conversation, [Operations::List, Operations::Find])
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the user's messages
|
57
|
+
#
|
58
|
+
# @return [Layer::RelationProxy] the user's messages
|
59
|
+
# @!macro platform-api
|
60
|
+
def messages
|
61
|
+
RelationProxy.new(self, Message, [Operations::Find])
|
62
|
+
end
|
22
63
|
end
|
23
64
|
end
|
data/lib/layer/version.rb
CHANGED
data/lib/layer/webhook.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Layer
|
2
2
|
# @example
|
3
3
|
# webhook = Layer::Webhook.create({
|
4
|
-
#
|
4
|
+
# version: '1.0',
|
5
|
+
# target_url: 'https://example.com/layer/webhook',
|
6
|
+
# events: ['message.sent'],
|
5
7
|
# secret: 'my-secret',
|
6
|
-
#
|
7
|
-
# target_url: 'http://example.com/layer/webhook'
|
8
|
+
# config: { foo: :bar }
|
8
9
|
# })
|
9
|
-
# @see https://
|
10
|
-
# @note This feature is still in beta at Layer. Please contact Layer to enable webhooks for your account.
|
10
|
+
# @see https://developer.layer.com/docs/webhooks/introduction
|
11
11
|
#
|
12
12
|
# @!macro platform-api
|
13
13
|
class Webhook < Resource
|
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.7.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: 2016-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -109,11 +109,13 @@ files:
|
|
109
109
|
- lib/layer/content.rb
|
110
110
|
- lib/layer/conversation.rb
|
111
111
|
- lib/layer/exceptions.rb
|
112
|
+
- lib/layer/identity.rb
|
112
113
|
- lib/layer/message.rb
|
113
114
|
- lib/layer/operations.rb
|
114
115
|
- lib/layer/operations/create.rb
|
115
116
|
- lib/layer/operations/delete.rb
|
116
117
|
- lib/layer/operations/destroy.rb
|
118
|
+
- lib/layer/operations/fetch.rb
|
117
119
|
- lib/layer/operations/find.rb
|
118
120
|
- lib/layer/operations/list.rb
|
119
121
|
- lib/layer/operations/paginate.rb
|
@@ -126,6 +128,7 @@ files:
|
|
126
128
|
- lib/layer/resource.rb
|
127
129
|
- lib/layer/resource_collection.rb
|
128
130
|
- lib/layer/ruby.rb
|
131
|
+
- lib/layer/singleton_relation_proxy.rb
|
129
132
|
- lib/layer/user.rb
|
130
133
|
- lib/layer/version.rb
|
131
134
|
- lib/layer/webhook.rb
|
@@ -149,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
152
|
version: '0'
|
150
153
|
requirements: []
|
151
154
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.5.1
|
153
156
|
signing_key:
|
154
157
|
specification_version: 4
|
155
158
|
summary: Ruby bindings for the Layer Platform API
|