zquickblox 0.1.7 → 0.1.8

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
2
  SHA1:
3
- metadata.gz: ae9c1f6972fdf05566146179e0ed2089934ae3dc
4
- data.tar.gz: 28098d9c341ada616d2f0a9ba2bbf0727668374e
3
+ metadata.gz: aeb0858b298f6e9d67fd7ddfcbfabefe0fcf37ac
4
+ data.tar.gz: 999be6edda770efcd280412f2ad5ffad0ae78660
5
5
  SHA512:
6
- metadata.gz: b4555c662e79d6954d3e2804012dcdfe689c4cffb1e7e492c93091c819a518eae1814cd1ddd484f14d057f5e3e4303425bfc19946aa38e9ee4b6ae199806d690
7
- data.tar.gz: fe378cf5e460844a3b5340effd6fe8aa874f83518c41347e29cc88a14a1471073a424e08b24eefe39de554749db770b56292cda8608527fd2d59a6c20f0daa15
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,12 @@
1
+ module ZQuickblox
2
+ module Dialog
3
+ class CreateDialogRequest < Request
4
+ def initialize(params)
5
+ super()
6
+ @uri = "/chat/Dialog.json"
7
+ @method = :post
8
+ @params = params
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ZQuickblox
2
+ module Dialog
3
+ class UpdateDialogRequest < Request
4
+ def initialize(id, params)
5
+ super()
6
+ @uri = "/chat/Dialog/#{id}.json"
7
+ @method = :put
8
+ @params = params
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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
@@ -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[:signature] = ZQuickblox::Signature.generate_signature(@params, ZQuickblox.config.auth_secret)
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
@@ -0,0 +1,12 @@
1
+ module ZQuickblox
2
+ module User
3
+ class LoginUserRequest < Request
4
+ def initialize(login, password)
5
+ super()
6
+ @uri = "/users/by_login.json?login=#{login}"
7
+ @method = :get
8
+ @params = params
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module ZQuickblox
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
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.7
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-09-08 00:00:00.000000000 Z
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.6.4
138
+ rubygems_version: 2.5.1
134
139
  signing_key:
135
140
  specification_version: 4
136
141
  summary: A good friend of Quickblox.