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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed7a3eb065cee30e1639308b0918f14434fafc4b
4
- data.tar.gz: 25ba674f8e1184293320313c3f86b309f8241cac
3
+ metadata.gz: 83dadcd8697550aa3810162d39053d3c0762c726
4
+ data.tar.gz: fcb2eb0fc094f017102d0edf9afd3cb0acc88eba
5
5
  SHA512:
6
- metadata.gz: bd0c8e590b9f14fc160dc115e0356c5b64cf2b9a8ab5bbde6f9dfc380f59e3f0b88b1446429fd0663deddb7323b9cb27417d2d78372b06ea664159320cb2b6f8
7
- data.tar.gz: f9be35a161b1d313efec22adef35bd7c38b92043766f4dbe21e13da8312ad76d6690442d9fd0f93dc73a443cec554fe794971eff7cffc033c6f269fe7fb620ef
6
+ metadata.gz: 976158d977afa073bbff555c5ae49c013ce5f291950fb283bc6517ded160892bdcb256c778b05b16e4409effb77e23ff41cce0980f0a6888954dcead4e8c10a4
7
+ data.tar.gz: c4f66ceb6cab3babe2578ccca3b5c2d26e99e5c6c51432bbf1d215273764ad8ef4e09303b5d93c01e0a127bac82d5b0f6822d5aebd8537175ca399068a40adde
data/README.md CHANGED
@@ -1,8 +1,29 @@
1
1
  # CrispClient
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/crisp_client`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ :small_red_triangle_down: Ruby Client for Crisp API
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
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 Ruby Wrapper}
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
- # def list_websites_ids
7
- # list_websites.map{ |website| website["id"] }
8
- # end
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
@@ -1,4 +1,5 @@
1
1
  module UserAvailability
2
+ # https://docs.crisp.im/api/v1/#user-user-availability-get
2
3
  def get_user_availability
3
4
  client_get("/user/availability")["data"]["type"]
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module CrispClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,9 +1,32 @@
1
1
  module WebsitePeople
2
- def get_people_statistics(website_id)
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
- def list_people_profiles(website_id, page_number = 1)
7
- client_get("/website/#{website_id}/people/profiles/#{page_number}")["data"]
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, password)
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.1.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 Ruby Wrapper
98
+ summary: Ruby Client for Crisp API
99
99
  test_files: []