zquickblox 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dcaf9cf04e084b207a4263b090224e1a11d7f709
4
+ data.tar.gz: 4c9ed23995354ae230db4328229dfc1b08542560
5
+ SHA512:
6
+ metadata.gz: f128d1c6cae4757bc255c5cd1a8c89c380ddae31f0529f1c6170f019c644c363f8e5ae0ed4ae69e2ddb1288b4e8a0aa273e8650deca5124f2dd43ba7098897d7
7
+ data.tar.gz: 9e49cb0b7ed112e5acde9b389f4bc405afb75af2ce04caab0b446cad26c27394d6458e35559347d39f744b46aa3401c8467e88bbb7b638c4082f6a3513bfc6eb
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at thuongnh.uit@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zquickblox.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Thuong Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Thuong Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Zquickblox
2
+
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
+
5
+ Currently this gem ONLY supports creating users on Quickblox (used for signing up user).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'zquickblox'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install zquickblox
22
+
23
+ ## Usage
24
+
25
+ You need to generate an initializer for ZQuickblox in order to config your Quickblox app:
26
+
27
+ ```ruby
28
+ rails generate zquickblox:config
29
+ ```
30
+
31
+ To create a new user, just call:
32
+
33
+ ```ruby
34
+ ZQuickblox::User.create({email: "abc@email.com", password: "a_password"})
35
+ ```
36
+
37
+ There are more params for you to set:
38
+
39
+ ```ruby
40
+ login, password, email, blob_id, external_user_id, facebook_id, twitter_id, full_name, phone, website
41
+ ```
42
+
43
+ ## Error handling
44
+
45
+ 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.
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zelic91/zquickblox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
50
+
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "lib/zquickblox"
6
+ t.test_files = FileList['test/lib/zquickblox/**']
7
+ t.verbose = true
8
+ end
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "zquickblox"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ class InitializerGenerator < Rails::Generators::Base
2
+ def create_config
3
+ template "zquickblox", "config/initializers/zquickblox.rb"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ ZQuickblox.configure do |config|
2
+ config.app_id = ENV['QB_APP_ID'],
3
+ config.auth_key = ENV['QB_AUTH_KEY'],
4
+ config.auth_secret = ENV['QB_AUTH_SECRET']
5
+ end
@@ -0,0 +1,3 @@
1
+ module ZQuickblox
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,79 @@
1
+ module ZQuickblox
2
+ class Request
3
+ API_ENDPOINT = "https://api.quickblox.com"
4
+
5
+ attr_accessor :params, :headers, :method, :response, :response_body, :errors
6
+ attr_reader :connection
7
+ attr_reader :uri
8
+
9
+ def initialize
10
+ @connection = Faraday.new(url: Request::API_ENDPOINT) do |faraday|
11
+ faraday.request :url_encoded
12
+ faraday.response :logger
13
+ faraday.adapter Faraday.default_adapter
14
+ end
15
+
16
+ @headers = {}
17
+ end
18
+
19
+ def header(key, value)
20
+ headers[key] = value
21
+ end
22
+
23
+ def before_request
24
+ end
25
+
26
+ def after_request
27
+ end
28
+
29
+ def execute
30
+ before_request
31
+
32
+ get if @method == :get
33
+ post if @method == :post
34
+ put if @method == :put
35
+ delete if @method == :delete
36
+
37
+ @response_body = JSON.parse(@response.body)
38
+
39
+ @errors = @response_body["errors"]
40
+ if @errors
41
+ raise ZQuickblox::Error.new(messages: @errors["base"])
42
+ end
43
+
44
+ after_request
45
+ end
46
+
47
+ private
48
+
49
+ def handle_request(request)
50
+ request.url @uri
51
+ request.headers = @headers
52
+ request.body = @params
53
+ end
54
+
55
+ def get
56
+ @response = @connection.get do |request|
57
+ handle_request(request)
58
+ end
59
+ end
60
+
61
+ def post
62
+ @response = @connection.post do |request|
63
+ handle_request(request)
64
+ end
65
+ end
66
+
67
+ def put
68
+ @response = @connection.put do |request|
69
+ handle_request(request)
70
+ end
71
+ end
72
+
73
+ def delete
74
+ @response = @connection.delete do |request|
75
+ handle_request(request)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,41 @@
1
+ module ZQuickblox
2
+ class Session < Request
3
+ attr_reader :token, :session
4
+
5
+ class << self
6
+ def create
7
+ session = ZQuickblox::Session.new
8
+ session.execute
9
+ return session
10
+ end
11
+ end
12
+
13
+ def initialize
14
+ super
15
+ @uri = "/session.json"
16
+ @method = :post
17
+ end
18
+
19
+ def before_request
20
+ build_params
21
+ end
22
+
23
+ def execute
24
+ super
25
+ @session = @response_body["session"]
26
+ @token = @session["token"]
27
+ end
28
+
29
+ private
30
+
31
+ def build_params
32
+ @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)
37
+ }
38
+ @params[:signature] = ZQuickblox::Signature.generate_signature(@params, ZQuickblox.config.auth_secret)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ module ZQuickblox
2
+ module Signature
3
+ class << self
4
+ def generate_signature(params, secret)
5
+ pairs = params.map { |key, value| "#{key}=#{value}" }
6
+ pairs.sort!
7
+ body = pairs.join("&")
8
+ return hmac_sha(body, secret)
9
+ end
10
+
11
+ private
12
+
13
+ def hmac_sha(data, secret)
14
+ require "base64"
15
+ require "cgi"
16
+ require "openssl"
17
+ hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), secret.encode("ASCII"), data.encode("ASCII"))
18
+ return hmac
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module ZQuickblox
2
+ module User
3
+ class CreateUserRequest < Request
4
+ def initialize(params)
5
+ super()
6
+ @uri = "/users.json"
7
+ @method = :post
8
+ @params = params
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ require_relative "user/create_user_request"
2
+
3
+ module ZQuickblox
4
+ module User
5
+ class << self
6
+ def create(params)
7
+ user = User.new(params)
8
+ params = user.build_params
9
+ request = ZQuickblox::User::CreateUserRequest.new(params)
10
+ run_request(request)
11
+ user = User.new(ZQuickblox::Util.symbolize_keys(request.response_body["user"]))
12
+ return user
13
+ end
14
+
15
+ def run_request(request)
16
+ session = ZQuickblox::Session.create
17
+ request.header("QB-Token", session.token)
18
+ request.execute
19
+ end
20
+ end
21
+
22
+ class User
23
+ attr_accessor :id, :login, :password, :email, :blob_id, :external_user_id
24
+ attr_accessor :facebook_id, :twitter_id, :full_name, :phone, :website
25
+
26
+ def initialize(params)
27
+ @id = params[:id]
28
+ @login = params[:login]
29
+ @password = params[:password]
30
+ @email = params[:email]
31
+ @blob_id = params[:blob_id]
32
+ @external_user_id = params[:external_user_id]
33
+ @facebook_id = params[:facebook_id]
34
+ @twitter_id = params[:twitter_id]
35
+ @full_name = params[:full_name]
36
+ @phone = params[:phone]
37
+ @website = params[:website]
38
+ end
39
+
40
+ def build_params
41
+ @params = {
42
+ "user[login]": @login,
43
+ "user[password]": @password,
44
+ "user[email]": @email,
45
+ "user[blob_id]": @blob_id,
46
+ "user[external_user_id]": @external_user_id,
47
+ "user[facebook_id]": @facebook_id,
48
+ "user[twitter_id]": @twitter_id,
49
+ "user[full_name]": @full_name,
50
+ "user[phone]": @phone,
51
+ "user[website]": @website
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module ZQuickblox
2
+ module Util
3
+ class << self
4
+ def symbolize_keys(hash)
5
+ new_hash = Hash.new
6
+ hash.each { |key, value| new_hash[key.to_sym] = value }
7
+ return new_hash
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ZQuickblox
2
+ VERSION = "0.1.0"
3
+ end
data/lib/zquickblox.rb ADDED
@@ -0,0 +1,24 @@
1
+ require_relative "zquickblox/version"
2
+ require_relative "zquickblox/error"
3
+ require_relative "zquickblox/request"
4
+ require_relative "zquickblox/signature"
5
+ require_relative "zquickblox/session"
6
+ require_relative "zquickblox/user"
7
+ require_relative "zquickblox/util"
8
+ require "faraday"
9
+ require "json"
10
+
11
+ module ZQuickblox
12
+ class << self
13
+ attr_accessor :config
14
+ end
15
+
16
+ def self.configure
17
+ self.config ||= Config.new
18
+ yield(self.config)
19
+ end
20
+
21
+ class Config
22
+ attr_accessor :app_id, :auth_key, :auth_secret
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zquickblox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zquickblox"
8
+ spec.version = ZQuickblox::VERSION
9
+ spec.authors = ["Thuong Nguyen"]
10
+ spec.email = ["thuongnh.uit@gmail.com"]
11
+
12
+ spec.summary = %q{A good friend of Quickblox.}
13
+ spec.description = %q{A simple API client for Quickblox in Ruby.}
14
+ spec.homepage = "https://github.com/zelic91/zquickblox"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|generators)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rails", ">= 3.0.0"
33
+ spec.add_runtime_dependency "faraday", ">= 0.9.2"
34
+ spec.add_runtime_dependency "json", ">= 1.8.3"
35
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zquickblox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thuong Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.3
83
+ description: A simple API client for Quickblox in Ruby.
84
+ email:
85
+ - thuongnh.uit@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/generators/initializer_generator.rb
100
+ - lib/generators/templates/zquickblox.rb
101
+ - lib/zquickblox.rb
102
+ - lib/zquickblox/error.rb
103
+ - lib/zquickblox/request.rb
104
+ - lib/zquickblox/session.rb
105
+ - lib/zquickblox/signature.rb
106
+ - lib/zquickblox/user.rb
107
+ - lib/zquickblox/user/create_user_request.rb
108
+ - lib/zquickblox/util.rb
109
+ - lib/zquickblox/version.rb
110
+ - zquickblox.gemspec
111
+ homepage: https://github.com/zelic91/zquickblox
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.4
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: A good friend of Quickblox.
136
+ test_files: []
137
+ has_rdoc: