crisp_client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -7
- data/crisp_client.gemspec +1 -1
- data/lib/crisp_client/list_websites.rb +4 -10
- data/lib/crisp_client/user_availability.rb +1 -0
- data/lib/crisp_client/version.rb +1 -1
- data/lib/crisp_client/website_people.rb +26 -3
- data/lib/crisp_client.rb +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83dadcd8697550aa3810162d39053d3c0762c726
|
4
|
+
data.tar.gz: fcb2eb0fc094f017102d0edf9afd3cb0acc88eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 976158d977afa073bbff555c5ae49c013ce5f291950fb283bc6517ded160892bdcb256c778b05b16e4409effb77e23ff41cce0980f0a6888954dcead4e8c10a4
|
7
|
+
data.tar.gz: c4f66ceb6cab3babe2578ccca3b5c2d26e99e5c6c51432bbf1d215273764ad8ef4e09303b5d93c01e0a127bac82d5b0f6822d5aebd8537175ca399068a40adde
|
data/README.md
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
# CrispClient
|
2
2
|
|
3
|
-
|
3
|
+
:small_red_triangle_down: Ruby Client for Crisp API
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
cc = CrispClient::Base.new(email: ENV['CRISP_EMAIL'], password: ENV['CRISP_PASSWORD']).authenticate
|
9
|
+
#=> {"Authorization"=>"Basic MmjjiyAjSLuMmjjiyAjSLuMmjjiyAjSLuMmjjiyAjSLuMmjjiyAiaiIyMGUyYTdjYzA="}
|
10
|
+
|
11
|
+
website_id = cc.find_website_id_by_name(website_name: "Touts")
|
12
|
+
#=> "8sajk18272-4aab-kjhh-bkjh-8e3chjk5609"
|
13
|
+
|
14
|
+
cc.get_people_statistics(website_id: website_id)
|
15
|
+
#=> {"total"=>3523}
|
16
|
+
|
17
|
+
person_id = cc.add_new_people_profile(website_id: website_id, nickname: "Flavio Wuensche", email: "flavio@touts.com.br")
|
18
|
+
#=> "cd71e876-62e4-17hs-b6c2-570f44b3d83b"
|
19
|
+
cc.add_new_people_profile(website_id: website_id, nickname: "Flavio Wuensche", email: "flavio@touts.com.br")
|
20
|
+
# RuntimeError: people_exists
|
21
|
+
|
22
|
+
cc.remove_people_profile(website_id: website_id, people_id: person_id)
|
23
|
+
#=> "deleted"
|
24
|
+
cc.remove_people_profile(website_id: website_id, people_id: person_id)
|
25
|
+
#=> "people_not_found"
|
26
|
+
```
|
6
27
|
|
7
28
|
## Installation
|
8
29
|
|
@@ -20,10 +41,6 @@ Or install it yourself as:
|
|
20
41
|
|
21
42
|
$ gem install crisp_client
|
22
43
|
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
44
|
## Development
|
28
45
|
|
29
46
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -34,8 +51,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
51
|
|
35
52
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/crisp_client.
|
36
53
|
|
54
|
+
While debugging you might need to reload edited files:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
load '/Users/fwuensche/www/crisp_client/lib/crisp_client/website_people.rb'
|
58
|
+
```
|
37
59
|
|
38
60
|
## License
|
39
61
|
|
40
62
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/crisp_client.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Flavio Wuensche"]
|
10
10
|
spec.email = ["f.wuensche@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Crisp API
|
12
|
+
spec.summary = %q{Ruby Client for Crisp API}
|
13
13
|
spec.description = %q{Use ruby syntax to manipulate your Crisp data}
|
14
14
|
spec.homepage = "https://github.com/fwuensche/crisp_client"
|
15
15
|
spec.license = "MIT"
|
@@ -1,17 +1,11 @@
|
|
1
1
|
module ListWebsites
|
2
|
+
# https://docs.crisp.im/api/v1/#user-user-account-websites-get
|
2
3
|
def list_websites
|
3
4
|
client_get("/user/account/websites")["data"]
|
4
5
|
end
|
5
6
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
# def find_website_by_name name
|
11
|
-
# list_websites.select{ |website| website["name"] == name }.first
|
12
|
-
# end
|
13
|
-
|
14
|
-
def find_website_id_by_name name
|
15
|
-
list_websites.select{ |website| website["name"] == name }.first["id"]
|
7
|
+
# custom method
|
8
|
+
def find_website_id_by_name(website_name:)
|
9
|
+
list_websites.select{ |website| website["name"] == website_name }.first["id"]
|
16
10
|
end
|
17
11
|
end
|
data/lib/crisp_client/version.rb
CHANGED
@@ -1,9 +1,32 @@
|
|
1
1
|
module WebsitePeople
|
2
|
-
|
2
|
+
# https://docs.crisp.im/api/v1/#website-website-people-get
|
3
|
+
def get_people_statistics(website_id:)
|
3
4
|
client_get("/website/#{website_id}/people/stats")["data"]
|
4
5
|
end
|
5
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: "nickname", sort_order: "ascending")
|
9
|
+
# TODO: accept params sort_field, sort_order, search_operator, search_filter
|
10
|
+
client_get("/website/#{website_id}/people/profiles/#{page_number}?sort_order=#{sort_order}")["data"]
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://docs.crisp.im/api/v1/#website-website-people-post
|
14
|
+
def add_new_people_profile(website_id:, nickname:, email:)
|
15
|
+
response = self.class.post("/website/#{website_id}/people/profile",
|
16
|
+
body: { email: email, person: { nickname: nickname } }.to_json,
|
17
|
+
headers: { 'Content-Type' => 'application/json' }.merge(@auth))
|
18
|
+
|
19
|
+
if response["error"] == false
|
20
|
+
return response["data"]["people_id"]
|
21
|
+
else
|
22
|
+
raise response["reason"]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# https://docs.crisp.im/api/v1/#website-website-people-delete
|
27
|
+
def remove_people_profile(website_id:, people_id:)
|
28
|
+
response = self.class.delete("/website/#{website_id}/people/profile/#{people_id}",
|
29
|
+
headers: { 'Content-Type' => 'application/json' }.merge(@auth))
|
30
|
+
return response["reason"]
|
8
31
|
end
|
9
32
|
end
|
data/lib/crisp_client.rb
CHANGED
@@ -3,7 +3,6 @@ require "crisp_client/user_availability"
|
|
3
3
|
require "crisp_client/list_websites"
|
4
4
|
require "crisp_client/website_people"
|
5
5
|
require "httparty"
|
6
|
-
# require "byebug"
|
7
6
|
|
8
7
|
module CrispClient
|
9
8
|
class Base
|
@@ -14,7 +13,7 @@ module CrispClient
|
|
14
13
|
|
15
14
|
base_uri "https://api.crisp.im/v1"
|
16
15
|
|
17
|
-
def initialize(email
|
16
|
+
def initialize(email:, password:)
|
18
17
|
@email = email
|
19
18
|
@password = password
|
20
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crisp_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flavio Wuensche
|
@@ -95,5 +95,5 @@ rubyforge_project:
|
|
95
95
|
rubygems_version: 2.6.8
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
|
-
summary: Crisp API
|
98
|
+
summary: Ruby Client for Crisp API
|
99
99
|
test_files: []
|