matrix_sdk 0.0.1
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +23 -0
- data/Rakefile +10 -0
- data/lib/matrix_sdk/api.rb +113 -0
- data/lib/matrix_sdk/client.rb +0 -0
- data/lib/matrix_sdk/errors.rb +15 -0
- data/lib/matrix_sdk/version.rb +3 -0
- data/lib/matrix_sdk.rb +5 -0
- data/matrix-sdk.gemspec +22 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1edf23725115b5d4e4891db5baa88ff1d7850fff891921c0d5f294d74e04d4bc
|
4
|
+
data.tar.gz: 8e836ac2b7f6758ee89f43f964e6495df332db826d523456563c95c9cc3261ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c86db36a677016fb8fcdb9b56a0ba307f6d21d7fccc5fe445557258d339e7ed5a9cc29602ea75f10f3d95e2f77f16c5e9cd9ac4ec4e4314739c61d1c8054cf9
|
7
|
+
data.tar.gz: fc66623c861bc0d8bb7941330ef9d21661df4a219c872c10b988a328dac6d7d2b0fdfa5a0b5641b145ecc6badf1bbe30ad4dff4d52650aa15046843381d2c9f6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Alexander "Ace" Olofsson
|
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,23 @@
|
|
1
|
+
# Ruby Matrix SDK
|
2
|
+
|
3
|
+
A Ruby gem for easing the development of software that communicates with servers implementing the Matrix protocol.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
api = MatrixSdk::Api.new 'https://matrix.org'
|
10
|
+
|
11
|
+
api.login user: 'example', password: 'notarealpass'
|
12
|
+
api.whoami?
|
13
|
+
```
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ananace/ruby-matrix-sdk.
|
18
|
+
|
19
|
+
|
20
|
+
## License
|
21
|
+
|
22
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'openssl'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module MatrixSdk
|
7
|
+
class Api
|
8
|
+
attr_accessor :access_token, :device_id, :validate_certificate
|
9
|
+
attr_reader :homeserver
|
10
|
+
|
11
|
+
def initialize(homeserver, params = {})
|
12
|
+
@homeserver = homeserver
|
13
|
+
@homeserver = URI(@homeserver) unless @homeserver.is_a? URI
|
14
|
+
@homeserver.path.sub!('/_matrix/', '/') if @homeserver.path.start_with? '/_matrix/'
|
15
|
+
|
16
|
+
@access_token = params.fetch(:access_token, nil)
|
17
|
+
@device_id = params.fetch(:device_id, nil)
|
18
|
+
@validate_certificate = params.fetch(:validate_certificate, false)
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_versions
|
22
|
+
request(:get, :client, '/versions')
|
23
|
+
end
|
24
|
+
|
25
|
+
def sync(params = {})
|
26
|
+
options = {
|
27
|
+
timeout: 30.0,
|
28
|
+
}.merge(params).select { |k, _v|
|
29
|
+
%i[since timeout filter full_state set_presence].include? k
|
30
|
+
}
|
31
|
+
|
32
|
+
options[:timeout] = ((options[:timeout] || 30) * 1000).to_i
|
33
|
+
options[:timeout] = options.delete(:timeout_ms).to_i if options.key? :timeout_ms
|
34
|
+
|
35
|
+
request(:get, :client_r0, '/sync', query: options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def register(params = {})
|
39
|
+
raise NotImplementedError, 'Registering is not implemented yet'
|
40
|
+
end
|
41
|
+
|
42
|
+
def login(params = {})
|
43
|
+
options = {}
|
44
|
+
options[:store_token] = params.delete(:store_token) { true }
|
45
|
+
|
46
|
+
data = {
|
47
|
+
type: params.delete(:login_type) { 'm.login.password' }
|
48
|
+
}.merge params
|
49
|
+
data[:device_id] = device_id if device_id
|
50
|
+
|
51
|
+
request(:post, :client_r0, '/login', body: data).tap do |resp|
|
52
|
+
@access_token = resp[:token] if resp[:token] && options[:store_token]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def logout
|
57
|
+
request(:post, :client_r0, '/logout')
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_room(params = {})
|
61
|
+
raise NotImplementedError, 'Creating rooms is not implemented yet'
|
62
|
+
end
|
63
|
+
|
64
|
+
def join_room(id_or_alias)
|
65
|
+
request(:post, :client_r0, "/join/#{URI.escape id_or_alias}")
|
66
|
+
end
|
67
|
+
|
68
|
+
def whoami?
|
69
|
+
request(:get, :client_r0, '/account/whoami')
|
70
|
+
end
|
71
|
+
|
72
|
+
def request(method, api, path, options = {})
|
73
|
+
url = homeserver.dup.tap do |u|
|
74
|
+
u.path = api_to_path(api) + path
|
75
|
+
u.query = [u.query, options[:query]].reject(&:nil?).flatten.join('&') if options[:query]
|
76
|
+
end
|
77
|
+
request = Net::HTTP.const_get(method.to_s.capitalize.to_sym).new url.request_uri
|
78
|
+
request.body = options[:body] if options.key? :body
|
79
|
+
request.body = request.body.to_json unless request.body.is_a? String
|
80
|
+
request.body_stream = options[:body_stream] if options.key? :body_stream
|
81
|
+
|
82
|
+
request.content_type = 'application/json' if request.body || request.body_stream
|
83
|
+
|
84
|
+
request['authorization'] = "Bearer #{access_token}" if access_token
|
85
|
+
request['user-agent'] = 'Cool string goes here' if false
|
86
|
+
options[:headers].each do |h, v|
|
87
|
+
request[h.to_s.downcase] = v
|
88
|
+
end if options.key? :headers
|
89
|
+
|
90
|
+
response = http.request request
|
91
|
+
data = JSON.parse response.body, symbolize_names: true
|
92
|
+
|
93
|
+
return data if response.kind_of? Net::HTTPSuccess
|
94
|
+
raise MatrixError, data, response.code
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def api_to_path(api)
|
100
|
+
# TODO: <api>_current / <api>_latest
|
101
|
+
"/_matrix/#{api.to_s.split('_').join('/')}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def http
|
105
|
+
@http ||= (
|
106
|
+
opts = { }
|
107
|
+
opts[:use_ssl] = true if homeserver.scheme == 'https'
|
108
|
+
opts[:verify_mode] = ::OpenSSL::SSL::VERIFY_NONE unless @validate_certificate
|
109
|
+
Net::HTTP.start homeserver.host, homeserver.port, opts
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MatrixSdk
|
2
|
+
class MatrixError
|
3
|
+
attr_reader :errcode, :error, :httpstatus
|
4
|
+
|
5
|
+
def initialize(error, status)
|
6
|
+
@errcode = error[:errcode]
|
7
|
+
@error = error[:error]
|
8
|
+
@httpstatus = status
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"#{errcode}: #{error}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/matrix_sdk.rb
ADDED
data/matrix-sdk.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join File.expand_path('lib', __dir__), 'matrix_sdk/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "matrix_sdk"
|
5
|
+
spec.version = MatrixSdk::VERSION
|
6
|
+
spec.authors = ["Alexander Olofsson"]
|
7
|
+
spec.email = ["ace@haxalot.com"]
|
8
|
+
|
9
|
+
spec.summary = ''
|
10
|
+
spec.description = ''
|
11
|
+
spec.homepage = 'https://github.com/ananace/ruby_matrix_sdk'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: matrix_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Olofsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-06 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- ace@haxalot.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/matrix_sdk.rb
|
69
|
+
- lib/matrix_sdk/api.rb
|
70
|
+
- lib/matrix_sdk/client.rb
|
71
|
+
- lib/matrix_sdk/errors.rb
|
72
|
+
- lib/matrix_sdk/version.rb
|
73
|
+
- matrix-sdk.gemspec
|
74
|
+
homepage: https://github.com/ananace/ruby_matrix_sdk
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: ''
|
98
|
+
test_files: []
|