Skip to content

Commit 39a0cdc

Browse files
committed
Adds ability to create & retrieve a users identity
1 parent 861010b commit 39a0cdc

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

lib/layer/resources/user.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def conversations
1616
def messages
1717
Layer::ResourceProxy.new(client, self, Layer::Resources::Message)
1818
end
19+
20+
def create_identity(params)
21+
client.post("#{url}/identity", body: params.to_json)
22+
end
23+
24+
def identity
25+
client.get("#{url}/identity")
26+
end
1927
end
2028
end
2129
end

spec/layer/resources/rich_content_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "spec_helper"
2-
require "webmock/rspec"
32

43
describe Layer::Resources::RichContent do
54
let(:client) { Layer::Platform::Client.new.client }

spec/layer/resources/user_spec.rb

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22

33
describe Layer::Resources::User do
44
let(:client) { Layer::Platform::Client.new }
5+
let(:http_client) { instance_double("Layer::HttpClient") }
6+
let(:user) { client.users.find("some_user") }
7+
8+
before do
9+
allow(client).to receive(:client).and_return(http_client)
10+
end
511

612
describe ".find" do
713
it "should return instance of User" do
8-
user = client.users.find("jake")
914
expect(user).to be_instance_of(described_class)
1015
end
1116

1217
it "shouldn't send any request" do
1318
expect(Layer::HttpClient).to_not receive(:find)
14-
client.users.find("jake")
19+
user
1520
end
1621
end
1722

1823
describe "#blocks" do
1924
it "should instantiate new ResourceProxy for Block" do
20-
user = client.users.find("jake")
2125
blocks = user.blocks
2226
base = blocks.instance_variable_get("@base")
2327
resource = blocks.instance_variable_get("@resource")
@@ -30,7 +34,6 @@
3034

3135
describe "#conversations" do
3236
it "should instantiate new ResourceProxy for Conversation" do
33-
user = client.users.find("jake")
3437
conversations = user.conversations
3538
base = conversations.instance_variable_get("@base")
3639
resource = conversations.instance_variable_get("@resource")
@@ -43,7 +46,6 @@
4346

4447
describe "#messages" do
4548
it "should instantiate new ResourceProxy for Message" do
46-
user = client.users.find("jake")
4749
messages = user.messages
4850
base = messages.instance_variable_get("@base")
4951
resource = messages.instance_variable_get("@resource")
@@ -53,4 +55,30 @@
5355
expect(resource).to eq(Layer::Resources::Message)
5456
end
5557
end
58+
59+
describe "#create_identity" do
60+
it "should create identity for a user" do
61+
allow(http_client).to receive(:post).and_return("")
62+
expect(http_client).to receive(:post).
63+
with("users/#{user.id}/identity", body: user_identity_params.to_json)
64+
65+
user.create_identity(user_identity_params)
66+
end
67+
end
68+
69+
describe "#identity" do
70+
before do
71+
allow(http_client).to receive(:get).and_return(user_identity_params)
72+
expect(http_client).to receive(:get).with("users/#{user.id}/identity")
73+
end
74+
75+
it "should retrieve the users identity" do
76+
user.identity
77+
end
78+
79+
it "should return a hash containing the users identity" do
80+
identity = user.identity
81+
expect(identity).to be_instance_of(Hash)
82+
end
83+
end
5684
end

spec/layer_helper.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,19 @@ def webhook_params
6868
config: {:key1=>"value1", :key2=>"value2"}
6969
}
7070
end
71+
72+
def user_identity_params
73+
{
74+
display_name: "Frodo the Dodo",
75+
avatar_url: "http://sillylordoftheringspictures.com/frodo-riding-a-dodo.png",
76+
first_name: "Frodo",
77+
last_name: "Baggins",
78+
phone_number: "13791379137",
79+
email_address: "frodo@sillylordoftheringspictures.com",
80+
metadata: {
81+
level: "35",
82+
race: "Dodo"
83+
}
84+
}
85+
end
7186
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'layer/api'
33
require 'vcr'
44
require 'layer_helper'
5+
require "webmock/rspec"
56

67
VCR.configure do |c|
78
c.cassette_library_dir = "spec/cassettes"

0 commit comments

Comments
 (0)