zquickblox 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +18 -0
- data/README.md +14 -2
- data/lib/zquickblox/dialog/create_dialog_request.rb +12 -0
- data/lib/zquickblox/dialog/update_dialog_request.rb +12 -0
- data/lib/zquickblox/dialog.rb +62 -0
- data/lib/zquickblox/session.rb +11 -6
- data/lib/zquickblox/user/login_user_request.rb +12 -0
- data/lib/zquickblox/version.rb +1 -1
- data/lib/zquickblox.rb +1 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeb0858b298f6e9d67fd7ddfcbfabefe0fcf37ac
|
4
|
+
data.tar.gz: 999be6edda770efcd280412f2ad5ffad0ae78660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7158981235e439d4396e7eeaab26c0a61d4e6a4ed4875916559f65e0f4219c43e912cc0cf51f76087d443fdb06e6af23b2fd3bae31ab6e311a46558365f0ef1e
|
7
|
+
data.tar.gz: 2fc11880467f73dada1a66d660882e3818d34fa5158c6cfec781cd8c57823fc8dd55575d500cef8895d396431551e1c9967286a7468611914df01581a1cf6cbe
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 2.2.2
|
6
|
+
|
7
|
+
install:
|
8
|
+
- gem install bundler
|
9
|
+
- bundle install
|
10
|
+
|
11
|
+
script: 'bundle exec rake'
|
12
|
+
|
13
|
+
notifications:
|
14
|
+
email:
|
15
|
+
recipients:
|
16
|
+
- thuongnh.uit@gmail.com
|
17
|
+
on_failure: change
|
18
|
+
on_success: never
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# ZQuickblox
|
1
|
+
# ZQuickblox [![Gem Version](https://badge.fury.io/rb/zquickblox.svg)](https://badge.fury.io/rb/zquickblox) [![Build Status](https://travis-ci.org/zelic91/zquickblox.svg?branch=master)](https://travis-ci.org/zelic91/zquickblox)
|
2
2
|
|
3
3
|
This gem is a Quickblox API client in Ruby. Normally, we will use Javascript or mobile SDK, but in some cases where server needs to control things, this gem will play its role.
|
4
4
|
|
5
|
-
Currently this gem ONLY supports creating users on Quickblox (used for signing up user).
|
5
|
+
Currently this gem ONLY supports creating users on Quickblox (used for signing up user) and creating / updating chat dialog (used for backend's need).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -63,6 +63,18 @@ ZQuickblox::User.find("abc@email.com")
|
|
63
63
|
|
64
64
|
The result will be `nil` if the user doesn't exist.
|
65
65
|
|
66
|
+
To create a new dialog, just call:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
ZQuickblox::Dialog.create("user_login", "user_password", {type: 2, name: "Some dialog", occupants_ids: "ids of occupants separated by ,"})
|
70
|
+
```
|
71
|
+
|
72
|
+
To update a dialog (name, photo, occupants_ids), just call:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
ZQuickblox::Dialog.update("user_login", "user_password", "dialog id", {name: "Some dialog", occupants_ids: "ids of occupants separated by ,"})
|
76
|
+
```
|
77
|
+
|
66
78
|
## Error handling
|
67
79
|
|
68
80
|
During the API processing, errors may occur. In such cases, `ZQuickblox::Error` (subclass of StandardError) will be thrown with `messages` as an array of string error messages.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative "dialog/create_dialog_request"
|
2
|
+
require_relative "dialog/update_dialog_request"
|
3
|
+
|
4
|
+
module ZQuickblox
|
5
|
+
module Dialog
|
6
|
+
class << self
|
7
|
+
def create(login, password, params)
|
8
|
+
dialog = Dialog.new(params)
|
9
|
+
params = dialog.build_params
|
10
|
+
request = ZQuickblox::Dialog::CreateDialogRequest.new(params)
|
11
|
+
run_request(login, password, request)
|
12
|
+
dialog = Dialog.new(ZQuickblox::Util.symbolize_keys(request.response_body))
|
13
|
+
return dialog
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(login, password, id, params)
|
17
|
+
dialog = Dialog.new(params)
|
18
|
+
params = dialog.build_params
|
19
|
+
request = ZQuickblox::Dialog::UpdateDialogRequest.new(id, params)
|
20
|
+
run_request(login, password, request)
|
21
|
+
dialog = Dialog.new(ZQuickblox::Util.symbolize_keys(request.response_body))
|
22
|
+
return dialog
|
23
|
+
end
|
24
|
+
|
25
|
+
def run_request(login, password, request)
|
26
|
+
session = ZQuickblox::Session.create(login, password)
|
27
|
+
request.header("QB-Token", session.token)
|
28
|
+
request.execute
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Dialog
|
33
|
+
attr_accessor :id, :user_id, :type,
|
34
|
+
:occupants_ids, :name, :photo,
|
35
|
+
:created_at, :last_message, :last_message_date_sent,
|
36
|
+
:last_message_user_id, :unread_messages_count
|
37
|
+
|
38
|
+
def initialize(params)
|
39
|
+
@id = params[:_id]
|
40
|
+
@user_id = params[:user_id]
|
41
|
+
@type = params[:type]
|
42
|
+
@occupants_ids = params[:occupants_ids]
|
43
|
+
@name = params[:name]
|
44
|
+
@photo = params[:photo]
|
45
|
+
@created_at = params[:created_at]
|
46
|
+
@last_message = params[:last_message]
|
47
|
+
@last_message_date_sent = params[:last_message_date_sent]
|
48
|
+
@last_message_user_id = params[:last_message_user_id]
|
49
|
+
@unread_messages_count = params[:unread_messages_count]
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_params
|
53
|
+
@params = {
|
54
|
+
"type": @type,
|
55
|
+
"occupants_ids": @occupants_ids,
|
56
|
+
"name": @name,
|
57
|
+
"photo": @photo
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/zquickblox/session.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module ZQuickblox
|
2
2
|
class Session < Request
|
3
|
+
attr_accessor :login, :password
|
3
4
|
attr_reader :token, :session
|
4
5
|
|
5
6
|
class << self
|
6
|
-
def create
|
7
|
+
def create(login=nil, password=nil)
|
7
8
|
session = ZQuickblox::Session.new
|
9
|
+
session.login = login
|
10
|
+
session.password = password
|
8
11
|
session.execute
|
9
12
|
return session
|
10
13
|
end
|
@@ -30,12 +33,14 @@ module ZQuickblox
|
|
30
33
|
|
31
34
|
def build_params
|
32
35
|
@params = {
|
33
|
-
application_id: ZQuickblox.config.app_id,
|
34
|
-
auth_key: ZQuickblox.config.auth_key,
|
35
|
-
timestamp: Time.now.to_i,
|
36
|
-
nonce: rand(2000)
|
36
|
+
"application_id": ZQuickblox.config.app_id,
|
37
|
+
"auth_key": ZQuickblox.config.auth_key,
|
38
|
+
"timestamp": Time.now.to_i,
|
39
|
+
"nonce": rand(2000)
|
37
40
|
}
|
38
|
-
@params[
|
41
|
+
@params["user[login]"] = @login if @login
|
42
|
+
@params["user[password]"] = @password if @password
|
43
|
+
@params["signature"] = ZQuickblox::Signature.generate_signature(@params, ZQuickblox.config.auth_secret)
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
data/lib/zquickblox/version.rb
CHANGED
data/lib/zquickblox.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "zquickblox/request"
|
|
4
4
|
require_relative "zquickblox/signature"
|
5
5
|
require_relative "zquickblox/session"
|
6
6
|
require_relative "zquickblox/user"
|
7
|
+
require_relative "zquickblox/dialog"
|
7
8
|
require_relative "zquickblox/util"
|
8
9
|
require "faraday"
|
9
10
|
require "json"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zquickblox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thuong Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
91
92
|
- CODE_OF_CONDUCT.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE
|
@@ -99,6 +100,9 @@ files:
|
|
99
100
|
- lib/generators/templates/zquickblox.rb
|
100
101
|
- lib/generators/zquickblox_generator.rb
|
101
102
|
- lib/zquickblox.rb
|
103
|
+
- lib/zquickblox/dialog.rb
|
104
|
+
- lib/zquickblox/dialog/create_dialog_request.rb
|
105
|
+
- lib/zquickblox/dialog/update_dialog_request.rb
|
102
106
|
- lib/zquickblox/error.rb
|
103
107
|
- lib/zquickblox/request.rb
|
104
108
|
- lib/zquickblox/session.rb
|
@@ -106,6 +110,7 @@ files:
|
|
106
110
|
- lib/zquickblox/user.rb
|
107
111
|
- lib/zquickblox/user/create_user_request.rb
|
108
112
|
- lib/zquickblox/user/find_user_request.rb
|
113
|
+
- lib/zquickblox/user/login_user_request.rb
|
109
114
|
- lib/zquickblox/util.rb
|
110
115
|
- lib/zquickblox/version.rb
|
111
116
|
- zquickblox.gemspec
|
@@ -130,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
135
|
version: '0'
|
131
136
|
requirements: []
|
132
137
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.5.1
|
134
139
|
signing_key:
|
135
140
|
specification_version: 4
|
136
141
|
summary: A good friend of Quickblox.
|