layer-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/lib/layer.rb +3 -0
- data/lib/layer/announcement.rb +11 -0
- data/lib/layer/block.rb +5 -0
- data/lib/layer/client.rb +1 -1
- data/lib/layer/operations.rb +2 -0
- data/lib/layer/operations/create.rb +1 -1
- data/lib/layer/operations/delete.rb +21 -0
- data/lib/layer/operations/find.rb +6 -1
- data/lib/layer/operations/list.rb +18 -0
- data/lib/layer/relation_proxy.rb +7 -1
- data/lib/layer/resource.rb +10 -2
- data/lib/layer/user.rb +23 -0
- data/lib/layer/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7272a2505f0eeb66b69d0420d6f3a69ffc85edc
|
4
|
+
data.tar.gz: 699b31ddf54ee940cf8889e3242b1b8d13833471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f2a3055d5272da8e7661868593f713cfc8d261ae789d3897714a9c5efcbed3c8191482183492c134284aa26d7eb1e063db57b22b49530554ad2d702e824879f
|
7
|
+
data.tar.gz: c1bbc99b6ebcc2f81ac374284859d434709708ec584f9229f20a6d1855d32d011647e56d4b84c43c99131eec348d74be134fa23e9a0fd02181095bef6a171716
|
data/README.md
CHANGED
@@ -59,6 +59,26 @@ conversation = Layer::Conversation.find('CONVERSATION_ID_HERE')
|
|
59
59
|
conversation.messages.create({ sender: { name: 'Server' }, parts: [{ body: 'Hello!', mime_type: 'text/plain' }])
|
60
60
|
```
|
61
61
|
|
62
|
+
### Sending Messages
|
63
|
+
|
64
|
+
You can send a announcements like this:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
Layer::Announcement.create({ recipients: 'everyone', sender: { name: 'Server' }, parts: [{ body: 'Hello!', mime_type: 'text/plain' }])
|
68
|
+
```
|
69
|
+
|
70
|
+
### Managing block lists
|
71
|
+
|
72
|
+
Managing block lists is also possible:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
user = Layer::User.find('user_id')
|
76
|
+
user.blocks.all # Returns a list of blocks
|
77
|
+
user.blocks.create({ user_id: 'other_user' }) # Adds the other user to the block list
|
78
|
+
user.blocks.delete('other_user') # Removes the other user from the block list
|
79
|
+
user.blocks.all.first.delete # Removes the first entry from the block list
|
80
|
+
```
|
81
|
+
|
62
82
|
### Using the gem with multiple applications at once
|
63
83
|
|
64
84
|
It's possible to create a new instance of `Layer::Client` and passing both the app id and the token to the initializer:
|
data/lib/layer.rb
CHANGED
data/lib/layer/block.rb
ADDED
data/lib/layer/client.rb
CHANGED
data/lib/layer/operations.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Layer
|
2
|
+
module Operations
|
3
|
+
module Delete
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def delete(id, client = self.client)
|
7
|
+
client.delete("#{url}/#{id}")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete
|
16
|
+
client.delete(url)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,7 +3,7 @@ module Layer
|
|
3
3
|
module Find
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
def find(id, client =
|
6
|
+
def find(id, client = self.client)
|
7
7
|
response = client.get("#{url}/#{id}")
|
8
8
|
from_response(response, client)
|
9
9
|
end
|
@@ -13,6 +13,11 @@ module Layer
|
|
13
13
|
base.extend(ClassMethods)
|
14
14
|
end
|
15
15
|
|
16
|
+
def reload
|
17
|
+
@attributes = client.get(url)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Layer
|
2
|
+
module Operations
|
3
|
+
module List
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def all(client = self.client)
|
7
|
+
response = client.get(url)
|
8
|
+
response.map { |attributes| from_response(attributes, client) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/layer/relation_proxy.rb
CHANGED
@@ -3,11 +3,13 @@ module Layer
|
|
3
3
|
|
4
4
|
attr_reader :resource_type, :base
|
5
5
|
|
6
|
-
def initialize(base, resource_type, operations = [])
|
6
|
+
def initialize(base, resource_type, operations = [], &block)
|
7
7
|
@resource_type = resource_type
|
8
8
|
@base = base
|
9
9
|
|
10
10
|
operations.each { |operation| singleton_class.include(operation::ClassMethods) }
|
11
|
+
|
12
|
+
instance_eval(&block) if block_given?
|
11
13
|
end
|
12
14
|
|
13
15
|
def url
|
@@ -18,6 +20,10 @@ module Layer
|
|
18
20
|
resource_type.respond_to?(method, include_private) || super
|
19
21
|
end
|
20
22
|
|
23
|
+
def client
|
24
|
+
base.client
|
25
|
+
end
|
26
|
+
|
21
27
|
private
|
22
28
|
|
23
29
|
def method_missing(method, *args, &block)
|
data/lib/layer/resource.rb
CHANGED
@@ -2,6 +2,8 @@ module Layer
|
|
2
2
|
class Resource
|
3
3
|
|
4
4
|
class << self
|
5
|
+
attr_writer :client
|
6
|
+
|
5
7
|
def class_name
|
6
8
|
name.split('::')[-1]
|
7
9
|
end
|
@@ -13,9 +15,15 @@ module Layer
|
|
13
15
|
def from_response(attributes, client)
|
14
16
|
new(attributes, client)
|
15
17
|
end
|
18
|
+
|
19
|
+
def client
|
20
|
+
@client ||= Client.new
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
|
-
|
24
|
+
attr_reader :client
|
25
|
+
|
26
|
+
def initialize(attributes = {}, client = self.class.client)
|
19
27
|
@attributes = attributes
|
20
28
|
@client = client
|
21
29
|
end
|
@@ -34,7 +42,7 @@ module Layer
|
|
34
42
|
|
35
43
|
private
|
36
44
|
|
37
|
-
attr_reader :attributes
|
45
|
+
attr_reader :attributes
|
38
46
|
|
39
47
|
def method_missing(method, *args, &block)
|
40
48
|
if attributes.has_key?(method.to_s)
|
data/lib/layer/user.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Layer
|
2
|
+
class User < Resource
|
3
|
+
|
4
|
+
def self.find(id, client = self.client)
|
5
|
+
from_response({ 'url' => "/users/#{id}" }, client)
|
6
|
+
end
|
7
|
+
|
8
|
+
def blocks
|
9
|
+
RelationProxy.new(self, Block, [Operations::Create, Operations::List, Operations::Delete]) do
|
10
|
+
def from_response(response, client)
|
11
|
+
response['url'] ||= "#{base.url}#{resource_type.url}/#{response['user_id']}"
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(attributes, client = self.client)
|
16
|
+
response = client.post(url, attributes)
|
17
|
+
from_response({ 'user_id' => attributes['user_id'] }, client)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/layer/version.rb
CHANGED
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.2.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: 2015-06-
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -100,15 +100,20 @@ files:
|
|
100
100
|
- bin/setup
|
101
101
|
- layer-ruby.gemspec
|
102
102
|
- lib/layer.rb
|
103
|
+
- lib/layer/announcement.rb
|
104
|
+
- lib/layer/block.rb
|
103
105
|
- lib/layer/client.rb
|
104
106
|
- lib/layer/conversation.rb
|
105
107
|
- lib/layer/message.rb
|
106
108
|
- lib/layer/operations.rb
|
107
109
|
- lib/layer/operations/create.rb
|
110
|
+
- lib/layer/operations/delete.rb
|
108
111
|
- lib/layer/operations/find.rb
|
112
|
+
- lib/layer/operations/list.rb
|
109
113
|
- lib/layer/relation_proxy.rb
|
110
114
|
- lib/layer/resource.rb
|
111
115
|
- lib/layer/ruby.rb
|
116
|
+
- lib/layer/user.rb
|
112
117
|
- lib/layer/version.rb
|
113
118
|
homepage: https://github.com/benedikt/layer-ruby
|
114
119
|
licenses:
|
@@ -135,4 +140,3 @@ signing_key:
|
|
135
140
|
specification_version: 4
|
136
141
|
summary: Ruby bindings for the Layer Platform API
|
137
142
|
test_files: []
|
138
|
-
has_rdoc:
|