crisp-api 1.1.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 73edc201f441670de7a0a5f19f264e9cd63dbdd2
4
- data.tar.gz: d9a70ac91e7d86a5a4e37776cadf9257ed18427c
2
+ SHA256:
3
+ metadata.gz: fe1293fc6504f10040ac4837f78ca211c437e823c6381a962d8f2fd7ffe16067
4
+ data.tar.gz: c97ef803d68d9c7d7f83c568cc81f9e90118baaff3f16c2e123636b5e14dfe2c
5
5
  SHA512:
6
- metadata.gz: 06e95d148d771c58a47908bcaf5fedbf61d658e9508b63d134eb92ec324d2efeda2eca1dbb13dff1e6214596f1a3a456683e86d64e3c6ac38fcc4a1ccdb75a5b
7
- data.tar.gz: dad99b1c1f8756531d5f6bfef3ce0684b35ac6a475763d9added5c6890829ec842abf6ad3ecbdcefd55b27ccbbff5c4f5402eb9cccfe68ebb8b4e90ecba984cd
6
+ metadata.gz: 9066fdcc6d9305de0607524f3eb720dd750ce5d517bd95e9eed49ce5101166c2af6aa336bc9d8e7785b1fd2e3e49a55a1402b4c44ac9f0b2777d538deb766c6a
7
+ data.tar.gz: f9c9ffeb9c607fff2e1888b744ee6df6a168f11f36c7ad3c489050b29c8d117df99aef8804bc9b61929543b033fcf2374450cb207d6bdff4ab83fb782314af13
data/README.md CHANGED
@@ -2,23 +2,23 @@
2
2
 
3
3
  The Crisp API Ruby wrapper. Authenticate, send messages, fetch conversations, access your agent accounts from your Ruby code.
4
4
 
5
- Copyright 2018 Crisp IM SARL. See LICENSE for copying information.
5
+ Copyright 2019 Crisp IM SARL. See LICENSE for copying information.
6
6
 
7
7
  * **📝 Implements**: [Crisp Platform - API ~ v1](https://docs.crisp.chat/api/v1/) at reference revision: 12/31/2017
8
- * **😘 Maintainer**: [@valeriansaliou](https://github.com/valeriansaliou)
8
+ * **😘 Maintainer**: [@valeriansaliou](https://github.com/valeriansaliou), [@eliottvincent](https://github.com/eliottvincent)
9
9
 
10
10
  ## Usage
11
11
 
12
12
  Add the library to your `Gemfile`:
13
13
 
14
14
  ```bash
15
- gem 'crisp-api', '~> 1.0'
15
+ gem "crisp-api", "~> 1.1.5"
16
16
  ```
17
17
 
18
18
  Then, import it:
19
19
 
20
20
  ```ruby
21
- require 'crisp-api'
21
+ require "crisp-api"
22
22
  ```
23
23
 
24
24
  Build a new authenticated Crisp client with your `identifier` and `key` tokens.
@@ -42,6 +42,10 @@ Then, add authentication parameters to your `client` instance right after you cr
42
42
  ```ruby
43
43
  client = Crisp::Client.new
44
44
 
45
+ # Make sure to use the correct tier if you are authenticating a plugin
46
+ # eg. with a permanent token generated from Crisp Marketplace
47
+ client.set_tier("plugin")
48
+
45
49
  # Authenticate to API (identifier, key)
46
50
  # eg. client.authenticate("5c0595b2-9381-4a76-a2e0-04aa00c1ede7", "3bdb0812d0f5352bf68901ddc731434dade419b98507971905acdd2f967df61c")
47
51
  client.authenticate(identifier, key)
@@ -81,6 +85,7 @@ client.website.send_message_in_conversation(
81
85
 
82
86
  * **Website Conversations**
83
87
  * **List Conversations**: `client.website.list_conversations(website_id, page_number)`
88
+ * **Search Conversations**: `client.website.search_conversations(website_id, page_number, search_query, search_type, search_operator, include_empty, filter_unread, filter_resolved, filter_not_resolved, filter_mention, filter_assigned, filter_unassigned, filter_date_start, filter_date_end, order_date_created", order_date_updated)`
84
89
 
85
90
  * **Website Conversation**
86
91
  * **Create A New Conversation**: `client.website.create_new_conversation(website_id)`
@@ -114,7 +119,7 @@ client.website.send_message_in_conversation(
114
119
  * **Check If People Profile Exists**: `client.website.check_people_profile_exists(website_id, people_id)`
115
120
  * **Get People Profile**: `client.website.get_people_profile(website_id, people_id)`
116
121
  * **Save People Profile**: `client.website.save_people_profile(website_id, people_id, data)`
117
- * **Find People Profile By Email**: `find_people_profile_by_email(website_id, email)`
122
+ * **Find People Profile By Email**: `client.website.find_people_profile_by_email(website_id, email)`
118
123
  * **Update People Profile**: `client.website.update_people_profile(website_id, people_id, data)`
119
124
  * **Remove People Profile**: `client.website.remove_people_profile(website_id, people_id)`
120
125
  * **List People Conversations**: `client.website.list_people_conversations(website_id, people_id, page_number)`
@@ -149,6 +154,7 @@ client.website.send_message_in_conversation(
149
154
  * **Website Visitors**
150
155
  * **Count Visitors**: `client.website.count_visitors(website_id)`
151
156
  * **List Visitors**: `client.website.list_visitors(website_id, page_number)`
157
+ * **Get Session ID**: `client.website.get_session_id_by_token(website_id, token)`
152
158
 
153
159
  ### Bucket
154
160
 
data/crisp-api.gemspec CHANGED
@@ -1,17 +1,17 @@
1
1
  require File.expand_path("../lib/crisp-api", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = 'crisp-api'
5
- s.version = '1.1.1'
4
+ s.name = "crisp-api"
5
+ s.version = "1.1.5"
6
6
  s.date = Date.today
7
7
  s.summary = "Crisp API Ruby"
8
8
  s.description = "Crisp API Ruby"
9
9
  s.authors = ["Valerian Saliou"]
10
- s.email = 'valerian@valeriansaliou.name'
10
+ s.email = "valerian@valeriansaliou.name"
11
11
  s.files = `git ls-files`.split($/)
12
- s.homepage = 'https://github.com/crisp-im/ruby-crisp-api'
13
- s.license = 'MIT'
14
- s.require_paths = ['lib']
12
+ s.homepage = "https://github.com/crisp-im/ruby-crisp-api"
13
+ s.license = "MIT"
14
+ s.require_paths = ["lib"]
15
15
 
16
- s.add_dependency 'rest-client', '~> 2.0.0'
16
+ s.add_dependency "rest-client", "~> 2.0"
17
17
  end
@@ -5,7 +5,7 @@
5
5
  # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
6
  ##
7
7
 
8
- require 'crisp-api'
8
+ require "crisp-api"
9
9
 
10
10
  client = Crisp::Client.new
11
11
 
data/lib/crisp-api.rb CHANGED
@@ -5,12 +5,12 @@
5
5
  # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
6
  ##
7
7
 
8
- require 'rest-client'
9
- require 'json'
8
+ require "rest-client"
9
+ require "json"
10
10
 
11
- require_relative 'errors/route'
12
- require_relative 'resources/bucket'
13
- require_relative 'resources/website'
11
+ require_relative "errors/route"
12
+ require_relative "resources/bucket"
13
+ require_relative "resources/website"
14
14
 
15
15
  module Crisp
16
16
  class Client
@@ -22,6 +22,7 @@ module Crisp
22
22
 
23
23
  def initialize()
24
24
  @auth = {}
25
+ @tier = "user"
25
26
 
26
27
  @bucket = Crisp::BucketResource.new(self)
27
28
  @website = Crisp::WebsiteResource.new(self)
@@ -34,6 +35,10 @@ module Crisp
34
35
  @auth["key"] = key
35
36
  end
36
37
 
38
+ def set_tier(tier)
39
+ @tier = tier
40
+ end
41
+
37
42
  def rest_host
38
43
  @rest_host || "https://api.crisp.chat"
39
44
  end
@@ -86,9 +91,10 @@ module Crisp
86
91
  :payload => (data ? data.to_json : nil),
87
92
 
88
93
  :headers => {
89
- :user_agent => "ruby-crisp-api/1.1.1",
94
+ :user_agent => "ruby-crisp-api/1.1.5",
90
95
  :accept => :json,
91
96
  :content_type => :json,
97
+ "X-Crisp-Tier" => @tier,
92
98
  :params => query
93
99
  }
94
100
  )
@@ -5,7 +5,7 @@
5
5
  # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
6
  ##
7
7
 
8
- require 'rest-client'
8
+ require "rest-client"
9
9
 
10
10
  module Crisp
11
11
  class BucketResource
@@ -5,25 +5,43 @@
5
5
  # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
6
  ##
7
7
 
8
- require 'rest-client'
8
+ require "rest-client"
9
9
 
10
10
  module Crisp
11
11
  class WebsiteResource
12
+ SEARCH_CONVERSATIONS_QUERY_PARAMETERS = [
13
+ "search_query",
14
+ "search_type",
15
+ "search_operator",
16
+ "include_empty",
17
+ "filter_unread",
18
+ "filter_resolved",
19
+ "filter_not_resolved",
20
+ "filter_mention",
21
+ "filter_assigned",
22
+ "filter_unassigned",
23
+ "filter_date_start",
24
+ "filter_date_end",
25
+ "filter_date_end",
26
+ "order_date_created",
27
+ "order_date_updated",
28
+ ]
29
+
12
30
  def initialize(parent)
13
31
  @parent = parent
14
32
  end
15
33
 
16
34
  protected
17
35
 
18
- def _url_website(website_id, resource)
36
+ def _url_website(website_id, resource = "")
19
37
  return "/website/%s%s" % [website_id, resource]
20
38
  end
21
39
 
22
- def _url_conversation(website_id, session_id, resource)
40
+ def _url_conversation(website_id, session_id, resource = "")
23
41
  return self._url_website(website_id, "/conversation/%s%s" % [session_id, resource])
24
42
  end
25
43
 
26
- def _url_people(kind, website_id, people_id, resource)
44
+ def _url_people(kind, website_id, people_id, resource = "")
27
45
  return self._url_website(website_id, "/people/%s/%s%s" % [kind, people_id, resource])
28
46
  end
29
47
 
@@ -34,11 +52,11 @@ module Crisp
34
52
  end
35
53
 
36
54
  def get_website(website_id)
37
- return @parent.get(self._url_website(website_id, ""))
55
+ return @parent.get(self._url_website(website_id))
38
56
  end
39
57
 
40
58
  def delete_website(website_id)
41
- return @parent.delete(self._url_website(website_id, ""))
59
+ return @parent.delete(self._url_website(website_id))
42
60
  end
43
61
 
44
62
  def batch_resolve_items(website_id, data)
@@ -81,24 +99,45 @@ module Crisp
81
99
  return @parent.get(self._url_website(website_id, "/visitors/list/%d" % page_number))
82
100
  end
83
101
 
84
- def list_conversations(website_id, page_number)
85
- return @parent.get(self._url_website(website_id, "/conversations/%d" % page_number))
102
+ def search_conversations(website_id, page_number = 1, search_query = "", search_type = "", search_operator = "", include_empty = "", filter_unread = "", filter_resolved = "", filter_not_resolved = "", filter_mention = "", filter_assigned = "", filter_unassigned = "", filter_date_start = "", filter_date_end = "", order_date_created = "", order_date_updated = "")
103
+ resource_url = ""
104
+ query_parameters = []
105
+
106
+ SEARCH_CONVERSATIONS_QUERY_PARAMETERS.each do |parameter|
107
+ parameter_value = binding.local_variable_get(parameter)
108
+
109
+ if parameter_value != ""
110
+ query_parameters.push("%s=%s" % [parameter, CGI.escape(parameter_value).gsub("+", "%20")])
111
+ end
112
+ end
113
+
114
+ if query_parameters != []
115
+ resource_url = self._url_website(website_id, "/conversations/%d?%s" % [page_number, query_parameters.join("&")])
116
+ else
117
+ resource_url = self._url_website(website_id, "/conversations/%d" % page_number)
118
+ end
119
+
120
+ return @parent.get(resource_url)
121
+ end
122
+
123
+ def list_conversations(website_id, page_number = 1)
124
+ return self.search_conversations(website_id, page_number)
86
125
  end
87
126
 
88
- def create_new_conversation(website_id, data)
89
- return @parent.post(self._url_website(website_id, "/conversation"), data: data)
127
+ def create_new_conversation(website_id)
128
+ return @parent.post(self._url_website(website_id, "/conversation"))
90
129
  end
91
130
 
92
131
  def check_conversation_exists(website_id, session_id)
93
- return @parent.head(self._url_conversation(website_id, session_id, ""))
132
+ return @parent.head(self._url_conversation(website_id, session_id))
94
133
  end
95
134
 
96
135
  def get_conversation(website_id, session_id)
97
- return @parent.get(self._url_conversation(website_id, session_id, ""))
136
+ return @parent.get(self._url_conversation(website_id, session_id))
98
137
  end
99
138
 
100
139
  def remove_conversation(website_id, session_id)
101
- return @parent.remove(self._url_conversation(website_id, session_id, ""))
140
+ return @parent.remove(self._url_conversation(website_id, session_id))
102
141
  end
103
142
 
104
143
  def initiate_conversation_with_existing_session(website_id, session_id)
@@ -190,30 +229,27 @@ module Crisp
190
229
  end
191
230
 
192
231
  def check_people_profile_exists(website_id, people_id)
193
- return @parent.head(self._url_people("profile", website_id, people_id, ""))
232
+ return @parent.head(self._url_people("profile", website_id, people_id))
194
233
  end
195
234
 
196
235
  def find_people_profile_by_email(website_id, email)
197
- filter = [{:model => "people", :criterion => "email", :operator => "eq", query: [email]}]
198
- profiles = @parent.get(self._url_website(website_id, "/people/profiles/1?search_filter=%s" % CGI.escape(filter.to_json)))
199
-
200
- return profiles[0]
236
+ return @parent.get(self._url_people("profile", website_id, email))
201
237
  end
202
238
 
203
239
  def get_people_profile(website_id, people_id)
204
- return @parent.get(self._url_people("profile", website_id, people_id, ""))
240
+ return @parent.get(self._url_people("profile", website_id, people_id))
205
241
  end
206
242
 
207
243
  def save_people_profile(website_id, people_id, data)
208
- return @parent.put(self._url_people("profile", website_id, people_id, ""), data: data)
244
+ return @parent.put(self._url_people("profile", website_id, people_id), data: data)
209
245
  end
210
246
 
211
247
  def update_people_profile(website_id, people_id, data)
212
- return @parent.patch(self._url_people("profile", website_id, people_id, ""), data: data)
248
+ return @parent.patch(self._url_people("profile", website_id, people_id), data: data)
213
249
  end
214
250
 
215
251
  def remove_people_profile(website_id, people_id)
216
- return @parent.remove(self._url_people("profile", website_id, people_id, ""))
252
+ return @parent.remove(self._url_people("profile", website_id, people_id))
217
253
  end
218
254
 
219
255
  def list_people_conversations(website_id, people_id, page_number)
@@ -221,7 +257,7 @@ module Crisp
221
257
  end
222
258
 
223
259
  def add_people_event(website_id, people_id, data)
224
- return @parent.post(self._url_people("events", website_id, people_id, ""), data: data)
260
+ return @parent.post(self._url_people("events", website_id, people_id), data: data)
225
261
  end
226
262
 
227
263
  def list_people_events(website_id, people_id, page_number)
@@ -229,19 +265,23 @@ module Crisp
229
265
  end
230
266
 
231
267
  def get_people_data(website_id, people_id)
232
- return @parent.get(self._url_people("data", website_id, people_id, ""))
268
+ return @parent.get(self._url_people("data", website_id, people_id))
233
269
  end
234
270
 
235
271
  def save_people_data(website_id, people_id, data)
236
- return @parent.put(self._url_people("data", website_id, people_id, ""), data: data)
272
+ return @parent.put(self._url_people("data", website_id, people_id), data: data)
237
273
  end
238
274
 
239
275
  def get_people_subscription_status(website_id, people_id)
240
- return @parent.get(self._url_people("subscription", website_id, people_id, ""))
276
+ return @parent.get(self._url_people("subscription", website_id, people_id))
241
277
  end
242
278
 
243
279
  def update_people_subscription_status(website_id, people_id, data)
244
- return @parent.patch(self._url_people("subscription", website_id, people_id, ""), data: data)
280
+ return @parent.patch(self._url_people("subscription", website_id, people_id), data: data)
281
+ end
282
+
283
+ def get_session_id_by_token(website_id, token)
284
+ return @parent.get(self._url_website(website_id, "/visitors/token/#{token}"))
245
285
  end
246
286
  end
247
287
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crisp-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valerian Saliou
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: '2.0'
27
27
  description: Crisp API Ruby
28
28
  email: valerian@valeriansaliou.name
29
29
  executables: []
@@ -44,7 +44,7 @@ homepage: https://github.com/crisp-im/ruby-crisp-api
44
44
  licenses:
45
45
  - MIT
46
46
  metadata: {}
47
- post_install_message:
47
+ post_install_message:
48
48
  rdoc_options: []
49
49
  require_paths:
50
50
  - lib
@@ -59,9 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.6.11
64
- signing_key:
62
+ rubygems_version: 3.0.3
63
+ signing_key:
65
64
  specification_version: 4
66
65
  summary: Crisp API Ruby
67
66
  test_files: []