crisp_client 0.2.1 → 0.2.5
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/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/README.md +18 -1
- data/lib/crisp_client.rb +3 -0
- data/lib/crisp_client/version.rb +1 -1
- data/lib/crisp_client/website_conversation.rb +26 -0
- data/lib/crisp_client/website_people.rb +42 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7324c527da45bbaa55dd5e8a5671d9bf314c6ee
|
4
|
+
data.tar.gz: 13b01632fc5e79bc8b4834e60e3e8a4f5bba85b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 216d6562b683178df0e60f1b7c8d67f2be2d2a6ea8e62032d6352739b6d256a3d7a2d986f093c67a121825a506a9f141106168a57dfe9e9a5068e40e26264877
|
7
|
+
data.tar.gz: 874868efdf1fc092f613e15a99549ccb664df377fe9d7f6276971582bae817dc4447f5a126edbf64111286b45936cf8f2535a24c2fb3a07c2234332a4b38b95f
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/README.md
CHANGED
@@ -27,9 +27,26 @@ cc.remove_people_profile(website_id: website_id, people_id: person_id)
|
|
27
27
|
|
28
28
|
cc.list_people_profiles(website_id: website_id)
|
29
29
|
#=> will return the first 20 users by default
|
30
|
-
cc.list_people_profiles(website_id: website_id, page_number: 2)
|
30
|
+
cc.list_people_profiles(website_id: website_id, page_number: 2, search_filter: "test@email.com")
|
31
31
|
#=> will return the next 20 users
|
32
32
|
# Other parameters you can use include: sort_field, sort_order, search_operator, search_filter
|
33
|
+
# The search_filter parameter is to be used exactly as in the dashboard, as in: "&search_filter="parameter"
|
34
|
+
|
35
|
+
cc.update_conversation_metas website_id: website_id, session_id: session_id,
|
36
|
+
meta: { nickname: "test nickname", email: "test@email.com", phone: "9999-9999",
|
37
|
+
address: "rua teste 99t", segments: ["segmento 1", "segmento 2"],
|
38
|
+
data: { teste_data: "data_teste_3", valorArbitrario: "teste arbitrário 3" } }
|
39
|
+
# Updates the metadata from a specific conversation, given a session_id
|
40
|
+
# Remember that conversation metadata is not equal to profile metadata. Each conversation has their own parameters.
|
41
|
+
|
42
|
+
cc.update_people_profile website_id: website_id, people_id: people_id,
|
43
|
+
profile_data: { person: { phone: "9999-9999", nickname: "test nickname 2",
|
44
|
+
address: "rua teste 99t", website: "http://teste.com"},
|
45
|
+
segments: ["segmento 4", "segmento 3"],
|
46
|
+
company: { name: "Empresa teste" },
|
47
|
+
geolocation: { city: "Cidade teste" } }
|
48
|
+
# Updates a user's profile data. This is what you see when you click in a specific profile.
|
49
|
+
|
33
50
|
```
|
34
51
|
|
35
52
|
## Installation
|
data/lib/crisp_client.rb
CHANGED
@@ -2,7 +2,9 @@ require "crisp_client/version"
|
|
2
2
|
require "crisp_client/user_availability"
|
3
3
|
require "crisp_client/list_websites"
|
4
4
|
require "crisp_client/website_people"
|
5
|
+
require "crisp_client/website_conversation.rb"
|
5
6
|
require "httparty"
|
7
|
+
require "uri"
|
6
8
|
|
7
9
|
module CrispClient
|
8
10
|
class Base
|
@@ -10,6 +12,7 @@ module CrispClient
|
|
10
12
|
include UserAvailability
|
11
13
|
include ListWebsites
|
12
14
|
include WebsitePeople
|
15
|
+
include WebsiteConversation
|
13
16
|
|
14
17
|
base_uri "https://api.crisp.im/v1"
|
15
18
|
|
data/lib/crisp_client/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module WebsiteConversation
|
2
|
+
# https://docs.crisp.chat/api/v1/#website-website-conversation-post
|
3
|
+
def create_a_new_conversation(website_id:)
|
4
|
+
response = self.class.post("/website/#{website_id}/conversation",
|
5
|
+
headers: { 'Content-Type' => 'application/json' }.merge(@auth))
|
6
|
+
|
7
|
+
if response["error"] == false
|
8
|
+
return response["data"]
|
9
|
+
else
|
10
|
+
raise response["reason"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# https://docs.crisp.chat/api/v1/#website-website-conversation-patch-4
|
15
|
+
def update_conversation_metas(website_id:, session_id:, meta:)
|
16
|
+
response = self.class.patch("/website/#{website_id}/conversation/#{session_id}/meta",
|
17
|
+
body: meta.to_json,
|
18
|
+
headers: { 'Content-Type' => 'application/json' }.merge(@auth))
|
19
|
+
|
20
|
+
unless response.nil? && response["error"] == true
|
21
|
+
return response["data"]
|
22
|
+
else
|
23
|
+
raise response["reason"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -5,9 +5,34 @@ module WebsitePeople
|
|
5
5
|
end
|
6
6
|
|
7
7
|
# https://docs.crisp.im/api/v1/#website-website-people-get-2
|
8
|
-
def list_people_profiles(website_id:, page_number: 1, sort_field: "
|
9
|
-
#
|
10
|
-
|
8
|
+
def list_people_profiles(website_id:, page_number: 1, sort_field: "active", sort_order: "descending", search_operator: "or", search_filter: "")
|
9
|
+
#The way to use the "search_filter" parameter isn't documented in the CRISP docs
|
10
|
+
#i've obtained this information by intercepting the HTTP request made when you use the dashboard to search for profiles
|
11
|
+
#You can view this information by using the "network" section in your devtools of choice.
|
12
|
+
#The "list_people_profiles" is what's used when you search for something in the dashboard, thus, it makes several requests using your parameter.
|
13
|
+
|
14
|
+
filter = [{"model":"people","criterion":"email","operator":"has","query":["#{search_filter}"]},
|
15
|
+
{"model":"people","criterion":"segments","operator":"has","query":["#{search_filter}"]},
|
16
|
+
{"model":"people","criterion":"company.name","operator":"has","query":["#{search_filter}"]},
|
17
|
+
{"model":"people","criterion":"company.legal_name","operator":"has","query":["#{search_filter}"]},
|
18
|
+
{"model":"people","criterion":"person.nickname","operator":"has","query":["#{search_filter}"]},
|
19
|
+
{"model":"people","criterion":"person.address","operator":"has","query":["#{search_filter}"]},
|
20
|
+
{"model":"people","criterion":"person.employment.name","operator":"has","query":["#{search_filter}"]},
|
21
|
+
{"model":"people","criterion":"person.geolocation.city","operator":"has","query":["#{search_filter}"]},
|
22
|
+
{"model":"people","criterion":"person.geolocation.country","operator":"has","query":["#{search_filter}"]}]
|
23
|
+
|
24
|
+
filter = filter.to_json
|
25
|
+
filter = URI.encode(filter.to_s)
|
26
|
+
filter = filter.gsub(/\[/, "%5B").gsub(/\]/, "%5D")
|
27
|
+
|
28
|
+
response = client_get("/website/#{website_id}/people/profiles/#{page_number}?search_filter=#{filter}&search_operator=#{search_operator}&sort_field=#{sort_field}&sort_order=#{sort_order}")
|
29
|
+
if response["data"].empty?
|
30
|
+
return nil
|
31
|
+
elsif response["error"] == false
|
32
|
+
return response["data"]
|
33
|
+
else
|
34
|
+
raise response["reason"]
|
35
|
+
end
|
11
36
|
end
|
12
37
|
|
13
38
|
# https://docs.crisp.im/api/v1/#website-website-people-post
|
@@ -29,4 +54,18 @@ module WebsitePeople
|
|
29
54
|
headers: { 'Content-Type' => 'application/json' }.merge(@auth))
|
30
55
|
return response["reason"]
|
31
56
|
end
|
57
|
+
|
58
|
+
#https://docs.crisp.chat/api/v1/#website-website-people-patch
|
59
|
+
def update_people_profile(website_id:, people_id:, profile_data:)
|
60
|
+
response = self.class.patch("/website/#{website_id}/people/profile/#{people_id}",
|
61
|
+
body: profile_data.to_json,
|
62
|
+
headers: { 'Content-Type' => 'application/json' }.merge(@auth))
|
63
|
+
|
64
|
+
unless response.nil? && response["error"] == true
|
65
|
+
return response["data"]
|
66
|
+
else
|
67
|
+
raise response["reason"]
|
68
|
+
end
|
69
|
+
end
|
32
70
|
end
|
71
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crisp_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flavio Wuensche
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- lib/crisp_client/list_websites.rb
|
72
73
|
- lib/crisp_client/user_availability.rb
|
73
74
|
- lib/crisp_client/version.rb
|
75
|
+
- lib/crisp_client/website_conversation.rb
|
74
76
|
- lib/crisp_client/website_people.rb
|
75
77
|
homepage: https://github.com/fwuensche/crisp_client
|
76
78
|
licenses:
|
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
94
|
version: '0'
|
93
95
|
requirements: []
|
94
96
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.4.5.1
|
96
98
|
signing_key:
|
97
99
|
specification_version: 4
|
98
100
|
summary: Ruby Client for Crisp API
|