crisp-api 1.1.2 → 1.1.7

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.
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.2'
4
+ s.name = "crisp-api"
5
+ s.version = "1.1.7"
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
 
@@ -23,7 +23,7 @@ data = client.website.send_message_in_conversation(
23
23
 
24
24
  {
25
25
  "type" => "text",
26
- "content" => "This message was sent from python-crisp-api! :)",
26
+ "content" => "This message was sent from ruby-crisp-api! :)",
27
27
  "from" => "operator",
28
28
  "origin" => "chat"
29
29
  }
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.2",
94
+ :user_agent => "ruby-crisp-api/1.1.7",
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)
86
121
  end
87
122
 
88
- def create_new_conversation(website_id, data)
89
- return @parent.post(self._url_website(website_id, "/conversation"), data: data)
123
+ def list_conversations(website_id, page_number = 1)
124
+ return self.search_conversations(website_id, page_number)
125
+ end
126
+
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,27 +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
- return @parent.get(self._url_people("profile", website_id, email, ""))
236
+ return @parent.get(self._url_people("profile", website_id, email))
198
237
  end
199
238
 
200
239
  def get_people_profile(website_id, people_id)
201
- return @parent.get(self._url_people("profile", website_id, people_id, ""))
240
+ return @parent.get(self._url_people("profile", website_id, people_id))
202
241
  end
203
242
 
204
243
  def save_people_profile(website_id, people_id, data)
205
- 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)
206
245
  end
207
246
 
208
247
  def update_people_profile(website_id, people_id, data)
209
- 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)
210
249
  end
211
250
 
212
251
  def remove_people_profile(website_id, people_id)
213
- return @parent.remove(self._url_people("profile", website_id, people_id, ""))
252
+ return @parent.remove(self._url_people("profile", website_id, people_id))
214
253
  end
215
254
 
216
255
  def list_people_conversations(website_id, people_id, page_number)
@@ -218,7 +257,7 @@ module Crisp
218
257
  end
219
258
 
220
259
  def add_people_event(website_id, people_id, data)
221
- 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)
222
261
  end
223
262
 
224
263
  def list_people_events(website_id, people_id, page_number)
@@ -226,19 +265,23 @@ module Crisp
226
265
  end
227
266
 
228
267
  def get_people_data(website_id, people_id)
229
- return @parent.get(self._url_people("data", website_id, people_id, ""))
268
+ return @parent.get(self._url_people("data", website_id, people_id))
230
269
  end
231
270
 
232
271
  def save_people_data(website_id, people_id, data)
233
- 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)
273
+ end
274
+
275
+ def update_people_data(website_id, people_id, data)
276
+ return @parent.patch(self._url_people("data", website_id, people_id), data: data)
234
277
  end
235
278
 
236
279
  def get_people_subscription_status(website_id, people_id)
237
- return @parent.get(self._url_people("subscription", website_id, people_id, ""))
280
+ return @parent.get(self._url_people("subscription", website_id, people_id))
238
281
  end
239
282
 
240
283
  def update_people_subscription_status(website_id, people_id, data)
241
- return @parent.patch(self._url_people("subscription", website_id, people_id, ""), data: data)
284
+ return @parent.patch(self._url_people("subscription", website_id, people_id), data: data)
242
285
  end
243
286
 
244
287
  def get_session_id_by_token(website_id, token)
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.2
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valerian Saliou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-06 00:00:00.000000000 Z
11
+ date: 2022-02-01 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: []
@@ -31,6 +31,7 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - ".gitignore"
34
+ - EXAMPLES.md
34
35
  - Gemfile
35
36
  - LICENSE
36
37
  - README.md
@@ -59,8 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
62
  requirements: []
62
- rubyforge_project:
63
- rubygems_version: 2.6.11
63
+ rubygems_version: 3.0.3.1
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Crisp API Ruby