layer-api 0.6.1 → 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/README.md +119 -6
- data/layer-api.gemspec +1 -1
- data/lib/layer/api.rb +1 -0
- data/lib/layer/http_client.rb +6 -1
- data/lib/layer/resource_proxy.rb +6 -3
- data/lib/layer/resources/conversation.rb +10 -0
- data/lib/layer/resources/rich_content.rb +26 -0
- data/lib/layer/resources/user.rb +39 -0
- data/lib/layer/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d503cddd9b7bede59c73026f87bd04a5fad389e1
|
4
|
+
data.tar.gz: 107b52065cea9b15897c74ada0204e610714b336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29142b474b962ef13c663705333c59a399df86d68d58599e03b2a62448bfd0456f402eec6ffeff158f7c46c270798d296a0c6c07b6f9e9c9d14bf7150e2fe4cd
|
7
|
+
data.tar.gz: 19f209e30eaba1b1e610336c30b74ff4667b80d3af2b9beb26e4beaab560b019f0b274a9507ce69c5e3257a1449afbe22565173dfb5b2d2c2bdd1c327952ce21
|
data/README.md
CHANGED
@@ -112,17 +112,41 @@ operations = [
|
|
112
112
|
]
|
113
113
|
|
114
114
|
conv.update(operations)
|
115
|
-
# =>
|
115
|
+
# => true
|
116
116
|
```
|
117
117
|
#### Deleting Conversations ####
|
118
118
|
|
119
119
|
```ruby
|
120
120
|
conv = platform.conversations.find("conversation_id")
|
121
121
|
conv.destroy
|
122
|
-
# =>
|
122
|
+
# => true
|
123
123
|
|
124
124
|
```
|
125
125
|
|
126
|
+
#### Initiating a Rich Content Upload
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
conv = platform.conversations.find("conversation_id")
|
130
|
+
content = conv.content.create(mime_type: "image/png", file: File.open("image.png"))
|
131
|
+
# => #<Layer::Resources::RichContent @attributes={...}>
|
132
|
+
|
133
|
+
content.upload_url
|
134
|
+
# => "https://www.googleapis.com/upload/storage/path/to/content"
|
135
|
+
```
|
136
|
+
|
137
|
+
#### Refreshing the download URL for a Content Object
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
content = conv.content.find("content_id")
|
141
|
+
# => #<Layer::Resources::RichContent @attributes={...}>
|
142
|
+
|
143
|
+
content.download_url
|
144
|
+
# => "http://google-testbucket.storage.googleapis.com/some/download/path"
|
145
|
+
|
146
|
+
content.refresh_url
|
147
|
+
# => "https://api.layer.com/apps/<APP_ID>/conversations/<CONVERSATION_ID>/content/<CONTENT_ID>"
|
148
|
+
```
|
149
|
+
|
126
150
|
#### Sending Messages ####
|
127
151
|
|
128
152
|
```ruby
|
@@ -185,7 +209,7 @@ messages = conv.messages.find("message_id")
|
|
185
209
|
```ruby
|
186
210
|
conv = platform.conversations.find("conversation_id")
|
187
211
|
conv.messages.find("message_id").destroy
|
188
|
-
# =>
|
212
|
+
# => true
|
189
213
|
```
|
190
214
|
|
191
215
|
#### Sending Announcements ####
|
@@ -224,7 +248,7 @@ operations = [
|
|
224
248
|
]
|
225
249
|
|
226
250
|
user.update(operations)
|
227
|
-
# =>
|
251
|
+
# => true
|
228
252
|
```
|
229
253
|
|
230
254
|
#### Retrieving A Users Block List
|
@@ -259,16 +283,105 @@ owner.blocks.create(blocked)
|
|
259
283
|
# using the blocked users id
|
260
284
|
owner = platform.users.find("owner")
|
261
285
|
owner.blocks.find("blocked_user").destroy
|
262
|
-
# =>
|
286
|
+
# => true
|
263
287
|
|
264
288
|
# using a User object
|
265
289
|
owner = platform.users.find("owner")
|
266
290
|
blocked = platform.users.find("blocked")
|
267
291
|
|
268
292
|
owner.blocks.find(blocked).destroy
|
269
|
-
# =>
|
293
|
+
# => true
|
294
|
+
```
|
295
|
+
|
296
|
+
#### Creating a User Identity
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
identity = {
|
300
|
+
display_name: "Frodo the Dodo",
|
301
|
+
avatar_url: "http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png",
|
302
|
+
first_name: "Frodo",
|
303
|
+
last_name: "Baggins",
|
304
|
+
phone_number: "13791379137",
|
305
|
+
email_address: "frodo@sillylordoftheringspictures.com",
|
306
|
+
metadata: {
|
307
|
+
level: "35",
|
308
|
+
race: "Dodo"
|
309
|
+
}
|
310
|
+
}
|
311
|
+
|
312
|
+
user = platform.users.find("user_id")
|
313
|
+
user.create_identity(identity)
|
314
|
+
# => true
|
315
|
+
|
270
316
|
```
|
271
317
|
|
318
|
+
#### Retrieving a User's Identity
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
user = platform.users.find("user_id")
|
322
|
+
user.identity
|
323
|
+
# => {"first_name"=>"Frodo", "phone_number"=>"13791379137", "email_address"=>"frodo@sillylordoftheringspictures.com", "display_name"=>"Frodo the Dodo", "user_id"=>"jake", "last_name"=>"Baggins", "metadata"=>{"race"=>"Dodo", "level"=>"35"}, "avatar_url"=>"http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png"}
|
324
|
+
```
|
325
|
+
|
326
|
+
#### Updating an Identity
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
operations = [
|
330
|
+
{ operation: "set", property: "last_name", value: "Dodo" },
|
331
|
+
{ operation: "set", property: "phone_number", value: "" },
|
332
|
+
{ operation: "set", property: "metadata.level", value: "2" }
|
333
|
+
]
|
334
|
+
|
335
|
+
user.update_identity(operations)
|
336
|
+
# => true
|
337
|
+
```
|
338
|
+
|
339
|
+
#### Replacing an identity
|
340
|
+
|
341
|
+
```ruby
|
342
|
+
identity = {
|
343
|
+
display_name: "Frodo the Dodo",
|
344
|
+
avatar_url: "http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png",
|
345
|
+
first_name: "Frodo",
|
346
|
+
last_name: "Baggins",
|
347
|
+
phone_number: "13791379137",
|
348
|
+
email_address: "frodo@sillylordoftheringspictures.com",
|
349
|
+
metadata: {
|
350
|
+
level: "35",
|
351
|
+
race: "Dodo"
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
user.replace_identity(identity)
|
356
|
+
# => true
|
357
|
+
|
358
|
+
```
|
359
|
+
|
360
|
+
#### Deleting a User's Identity
|
361
|
+
|
362
|
+
```ruby
|
363
|
+
user = platform.users.find("user_id")
|
364
|
+
user.destroy_identity
|
365
|
+
# => true
|
366
|
+
```
|
367
|
+
|
368
|
+
#### Setting a Users Badge
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
user = platform.users.find("user_id")
|
372
|
+
user.set_badge(10)
|
373
|
+
# => true
|
374
|
+
```
|
375
|
+
|
376
|
+
#### Retrieving a Users Badge
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
user = platform.users.find("user_id")
|
380
|
+
user.badge
|
381
|
+
# => { "external_unread_count" => 13, "unread_conversation_count" => 10, "unread_message_count" => 50 }
|
382
|
+
```
|
383
|
+
|
384
|
+
|
272
385
|
#### Generating Identity Tokens ####
|
273
386
|
See: [the official authentication guide](https://developer.layer.com/docs/android/guides#authentication)
|
274
387
|
|
data/layer-api.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.license = "MIT"
|
12
12
|
|
13
13
|
spec.summary = "A ruby toolkit for Layer's Web API's (https://developer.layer.com/docs)"
|
14
|
-
spec.description = "Simple wrapper for
|
14
|
+
spec.description = "Simple wrapper for Layer's Web API's"
|
15
15
|
spec.homepage = "https://github.com/cakejelly/layer-api"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
data/lib/layer/api.rb
CHANGED
data/lib/layer/http_client.rb
CHANGED
@@ -13,6 +13,7 @@ module Layer
|
|
13
13
|
@connection ||= Faraday.new(url: base_url) do |faraday|
|
14
14
|
faraday.headers = default_headers
|
15
15
|
faraday.request :url_encoded
|
16
|
+
faraday.request :multipart
|
16
17
|
faraday.adapter Faraday.default_adapter
|
17
18
|
faraday.use Middleware::ApiErrors
|
18
19
|
end
|
@@ -22,6 +23,10 @@ module Layer
|
|
22
23
|
call(:get, url, options)
|
23
24
|
end
|
24
25
|
|
26
|
+
def put(url, options = {})
|
27
|
+
call(:put, url, options)
|
28
|
+
end
|
29
|
+
|
25
30
|
def post(url, options = {})
|
26
31
|
call(:post, url, options)
|
27
32
|
end
|
@@ -36,7 +41,7 @@ module Layer
|
|
36
41
|
|
37
42
|
def call(method, url, options = {})
|
38
43
|
response = run_request(method, url, options)
|
39
|
-
response.body.empty? ?
|
44
|
+
response.body.empty? ? true : JSON.parse(response.body)
|
40
45
|
end
|
41
46
|
|
42
47
|
def run_request(method, url, options = {})
|
data/lib/layer/resource_proxy.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
module Layer
|
2
2
|
class ResourceProxy
|
3
|
+
attr_accessor :url
|
4
|
+
|
3
5
|
def initialize(client, base, resource)
|
4
6
|
@client = client
|
5
7
|
@base = base
|
6
8
|
@resource = resource
|
9
|
+
@url = get_url(base, resource)
|
7
10
|
end
|
8
11
|
|
9
|
-
def
|
10
|
-
|
12
|
+
def get_url(base, resource)
|
13
|
+
base.nil? ? resource.url : "#{base.url}/#{resource.url}"
|
11
14
|
end
|
12
15
|
|
13
16
|
def method_missing(method, *args, &block)
|
14
|
-
@resource.public_send(method, *([@client, url] + args), &block)
|
17
|
+
@resource.public_send(method, *([@client, @url] + args), &block)
|
15
18
|
end
|
16
19
|
|
17
20
|
def respond_to_missing?(method, include_private = false)
|
@@ -4,6 +4,16 @@ module Layer
|
|
4
4
|
def messages
|
5
5
|
Layer::ResourceProxy.new(client, self, Message)
|
6
6
|
end
|
7
|
+
|
8
|
+
def content
|
9
|
+
proxy = Layer::ResourceProxy.new(client, self, RichContent)
|
10
|
+
proxy.url = content_url
|
11
|
+
proxy
|
12
|
+
end
|
13
|
+
|
14
|
+
def content_url
|
15
|
+
"conversations/#{uuid}/content"
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Layer
|
2
|
+
module Resources
|
3
|
+
class RichContent < Layer::Resource
|
4
|
+
def self.create(client, url, params = {})
|
5
|
+
mime_type = params[:mime_type]
|
6
|
+
file = params[:file]
|
7
|
+
|
8
|
+
headers = {
|
9
|
+
"Upload-Content-Type" => mime_type,
|
10
|
+
"Upload-Content-Length" => file.size.to_s
|
11
|
+
}
|
12
|
+
|
13
|
+
response = client.post(url, body: params.to_json, headers: headers)
|
14
|
+
response.merge!("mime_type" => mime_type)
|
15
|
+
|
16
|
+
new(response, client).upload(file)
|
17
|
+
end
|
18
|
+
|
19
|
+
def upload(file)
|
20
|
+
file_header = { "Content-Length" => file.size.to_s }
|
21
|
+
client.put(upload_url, body: file, headers: file_header)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/layer/resources/user.rb
CHANGED
@@ -16,6 +16,45 @@ module Layer
|
|
16
16
|
def messages
|
17
17
|
Layer::ResourceProxy.new(client, self, Layer::Resources::Message)
|
18
18
|
end
|
19
|
+
|
20
|
+
def create_identity(params)
|
21
|
+
client.post(identity_url, body: params.to_json)
|
22
|
+
end
|
23
|
+
|
24
|
+
def identity
|
25
|
+
client.get(identity_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def update_identity(params)
|
29
|
+
client.patch(
|
30
|
+
identity_url,
|
31
|
+
body: params.to_json,
|
32
|
+
headers: client.layer_patch_header
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_identity(params)
|
37
|
+
client.put(identity_url, body: params.to_json)
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy_identity
|
41
|
+
client.delete(identity_url)
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_badge(badge_count)
|
45
|
+
body = { external_unread_count: badge_count }
|
46
|
+
client.put("#{url}/badge", body: body.to_json)
|
47
|
+
end
|
48
|
+
|
49
|
+
def badge
|
50
|
+
client.get("#{url}/badge")
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def identity_url
|
56
|
+
"#{url}/identity"
|
57
|
+
end
|
19
58
|
end
|
20
59
|
end
|
21
60
|
end
|
data/lib/layer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: layer-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Kelly
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,7 +140,7 @@ dependencies:
|
|
140
140
|
- - "~>"
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: 1.5.1
|
143
|
-
description: Simple wrapper for
|
143
|
+
description: Simple wrapper for Layer's Web API's
|
144
144
|
email:
|
145
145
|
- jake.kelly10@gmail.com
|
146
146
|
executables: []
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/layer/resources/block.rb
|
171
171
|
- lib/layer/resources/conversation.rb
|
172
172
|
- lib/layer/resources/message.rb
|
173
|
+
- lib/layer/resources/rich_content.rb
|
173
174
|
- lib/layer/resources/user.rb
|
174
175
|
- lib/layer/resources/webhook.rb
|
175
176
|
- lib/layer/version.rb
|