Skip to content

Commit c172fea

Browse files
committed
Merge pull request #14 from cakejelly/identity-update
Requests with empty responses should return true to indicate success
2 parents 21ffad6 + 911ff90 commit c172fea

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

README.md

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ operations = [
112112
]
113113

114114
conv.update(operations)
115-
# => nil
115+
# => true
116116
```
117117
#### Deleting Conversations ####
118118

119119
```ruby
120120
conv = platform.conversations.find("conversation_id")
121121
conv.destroy
122-
# => nil
122+
# => true
123123

124124
```
125125

@@ -209,7 +209,7 @@ messages = conv.messages.find("message_id")
209209
```ruby
210210
conv = platform.conversations.find("conversation_id")
211211
conv.messages.find("message_id").destroy
212-
# => nil
212+
# => true
213213
```
214214

215215
#### Sending Announcements ####
@@ -248,7 +248,7 @@ operations = [
248248
]
249249

250250
user.update(operations)
251-
# => nil
251+
# => true
252252
```
253253

254254
#### Retrieving A Users Block List
@@ -283,16 +283,89 @@ owner.blocks.create(blocked)
283283
# using the blocked users id
284284
owner = platform.users.find("owner")
285285
owner.blocks.find("blocked_user").destroy
286-
# => nil
286+
# => true
287287

288288
# using a User object
289289
owner = platform.users.find("owner")
290290
blocked = platform.users.find("blocked")
291291

292292
owner.blocks.find(blocked).destroy
293-
# => nil
293+
# => true
294294
```
295295

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+
316+
```
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+
296369
#### Generating Identity Tokens ####
297370
See: [the official authentication guide](https://developer.layer.com/docs/android/guides#authentication)
298371

lib/layer/http_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def delete(url)
4141

4242
def call(method, url, options = {})
4343
response = run_request(method, url, options)
44-
response.body.empty? ? nil : JSON.parse(response.body)
44+
response.body.empty? ? true : JSON.parse(response.body)
4545
end
4646

4747
def run_request(method, url, options = {})

spec/layer/http_client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
end
8383
end
8484

85-
it "should run request & return nil if response has no body" do
85+
it "should run request & return true if response has no body" do
8686
VCR.use_cassette('conversation') do
8787
existing_conversation = @layer.conversations.create(conversation_params)
8888
existing_conversation_id = existing_conversation.uuid
@@ -93,7 +93,7 @@
9393
]
9494

9595
response = @layer.conversations.find(existing_conversation_id).update(operations)
96-
expect(response).to be(nil)
96+
expect(response).to be(true)
9797
end
9898
end
9999
end

0 commit comments

Comments
 (0)