chatrix 1.0.0 → 1.1.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: d46105489cd9f2748b15ea3a650893af40baad6d
4
- data.tar.gz: 03d5bc731429c298f6e1d3367efab623c3d34549
3
+ metadata.gz: 9c4ccf55e9b611ac9df88a62fbc8e1924815abf3
4
+ data.tar.gz: cb828784148992194d31f5771a7a653c07b9fa24
5
5
  SHA512:
6
- metadata.gz: 6bd7b7098a58b632bf67e48cd5d4b7ae4685bcbb53c8876a7a210a3450980221f247b931803f434198c111d943f42cdd9d1b5d5aca7ee2b1ac88048277e9b619
7
- data.tar.gz: 5a26a6d99f8d66905a50de48062eddd6880b176c7ca3ac61fbc574964651980d847ac25f9457d4c4775b7e04ff20832d31904bd7ef86d789b9310080db580723
6
+ metadata.gz: 3ce6a0c0835155c222cebaf4f4621f544f343c067fd60db25b250f1210fa2cf09082f7916a6de15e3fe47ab78987020f5037462f74747c45bd177c4bccad0cd0
7
+ data.tar.gz: f0d9572000576c1085f211807e3eac8063fa4f4f88e5fadc936230b5b454440a416bd0f8f8b24ae1205506d9e0694baa06cc20fce745654dd19a89c80f3dc0cb
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.0
3
+
4
+ Style/Encoding:
5
+ EnforcedStyle: always
6
+ Enabled: true
7
+
8
+ Style/FrozenStringLiteralComment:
9
+ EnforcedStyle: always
@@ -3,6 +3,10 @@ sudo: false
3
3
  language: ruby
4
4
 
5
5
  rvm:
6
+ - 2.0.0
7
+ - 2.1
8
+ - 2.2
9
+ - 2.3.0
6
10
  - 2.3.1
7
11
 
8
12
  bundler_args: --without development doc
data/Gemfile CHANGED
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  source 'https://rubygems.org'
2
5
 
3
6
  # Specify your gem's dependencies in ratrix.gemspec
@@ -14,7 +17,7 @@ group :test do
14
17
  end
15
18
 
16
19
  group :development, :test do
17
- gem 'rubocop', '~> 0.40.0'
20
+ gem 'rubocop', '~> 0.41.0'
18
21
  end
19
22
 
20
23
  group :doc do
data/Rakefile CHANGED
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'bundler/gem_tasks'
2
5
  require 'rspec/core/rake_task'
3
6
 
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # frozen_string_literal: true
2
4
 
3
5
  require 'bundler/setup'
4
6
  require 'chatrix'
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path('../lib', __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require 'chatrix/version'
@@ -22,6 +24,8 @@ Gem::Specification.new do |spec|
22
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
25
  spec.require_paths = ['lib']
24
26
 
27
+ spec.required_ruby_version = '>= 2.0.0'
28
+
25
29
  spec.add_runtime_dependency 'httparty', '~> 0.13'
26
30
  spec.add_runtime_dependency 'wisper', '~> 1.6'
27
31
 
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/version'
2
5
  require 'chatrix/errors'
3
6
  require 'chatrix/matrix'
@@ -1,8 +1,12 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  module Api
3
6
  # Wraps a matrix instance for use in calling API endpoints.
4
7
  class ApiComponent
5
8
  # Initializes a new ApiComponent instance.
9
+ # @param matrix [Matrix] The matrix API instance.
6
10
  def initialize(matrix)
7
11
  @matrix = matrix
8
12
  end
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  module Api
3
6
  # Contains methods for accessing the media endpoints of a server.
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  module Api
3
6
  # Contains methods for accessing the "push" endpoints on the server.
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  module Api
3
6
  # Contains methods for performing actions on rooms.
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/api/api_component'
2
5
  require 'chatrix/api/room_actions'
3
6
 
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/api/api_component'
2
5
 
3
6
  module Chatrix
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/api/api_component'
2
5
 
3
6
  module Chatrix
@@ -49,6 +52,7 @@ module Chatrix
49
52
  #
50
53
  # @param (see #get_user)
51
54
  # @raise (see #get_user)
55
+ # @return [String] The user's display name.
52
56
  def get_displayname(user)
53
57
  make_request(:get, "/profile/#{user}/displayname")['displayname']
54
58
  rescue NotFoundError => e
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/matrix'
2
5
  require 'chatrix/users'
3
6
  require 'chatrix/rooms'
@@ -9,8 +12,7 @@ module Chatrix
9
12
  class Client
10
13
  include Wisper::Publisher
11
14
 
12
- # @!attribute [r] me
13
- # @return [User] The user associated with the access token.
15
+ # @return [User] The user associated with the access token.
14
16
  attr_reader :me
15
17
 
16
18
  # Initializes a new Client instance.
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/user'
2
5
 
3
6
  module Chatrix
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  module Components
3
6
  # Class to handle messaging actions for a room.
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'wisper'
2
5
 
3
6
  module Chatrix
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/events'
2
5
 
3
6
  require 'chatrix/components/permissions'
@@ -11,26 +14,31 @@ module Chatrix
11
14
  class State
12
15
  include Wisper::Publisher
13
16
 
14
- # @!attribute [r] canonical_alias
15
- # @return [String,nil] The canonical alias, or `nil` if none has
16
- # been set.
17
- # @!attribute [r] name
18
- # @return [String,nil] The name, or `nil` if none has been set.
19
- # @!attribute [r] topic
20
- # @return [String,nil] The topic, or `nil` if none has been set.
21
- # @!attribute [r] creator
22
- # @return [User] The user who created the room.
23
- # @!attribute [r] guest_access
24
- # @return [Boolean] `true` if guests are allowed in the room,
25
- # otherwise `false`.
26
- # @!attribute [r] history_visibility
27
- # @return [String] The room's history visibility.
28
- # @!attribute [r] join_rule
29
- # @return [String] Join rules for the room.
30
- # @!attribute [r] permissions
31
- # @return [Permissions] Check room permissions.
32
- attr_reader :canonical_alias, :name, :topic, :creator, :guest_access,
33
- :join_rule, :history_visibility, :permissions
17
+ # @return [String,nil] The canonical alias, or `nil` if none has
18
+ # been set.
19
+ attr_reader :canonical_alias
20
+
21
+ # @return [String,nil] The name, or `nil` if none has been set.
22
+ attr_reader :name
23
+
24
+ # @return [String,nil] The topic, or `nil` if none has been set.
25
+ attr_reader :topic
26
+
27
+ # @return [User] The user who created the room.
28
+ attr_reader :creator
29
+
30
+ # @return [Boolean] `true` if guests are allowed in the room,
31
+ # otherwise `false`.
32
+ attr_reader :guest_access
33
+
34
+ # @return [String] Join rules for the room.
35
+ attr_reader :join_rule
36
+
37
+ # @return [String] The room's history visibility.
38
+ attr_reader :history_visibility
39
+
40
+ # @return [Permissions] Check room permissions.
41
+ attr_reader :permissions
34
42
 
35
43
  # Initializes a new State instance.
36
44
  #
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/message'
2
5
  require 'chatrix/events'
3
6
 
@@ -41,7 +44,10 @@ module Chatrix
41
44
  # Process a message event.
42
45
  # @param event [Hash] Event data.
43
46
  def handle_message(event)
44
- message = Message.new @users[event['sender']], event['content']
47
+ sender = @users[event['sender']]
48
+ timestamp = event['origin_server_ts'] || Time.now.to_i
49
+ content = event['content']
50
+ message = Message.new sender, timestamp, content
45
51
  broadcast(:message, @room, message)
46
52
  Events.processed event
47
53
  end
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  # Generic faults from the library.
3
6
  class ChatrixError < StandardError
@@ -116,7 +119,7 @@ module Chatrix
116
119
  # Set data to be the error response hash WITHOUT the error code and
117
120
  # error values. This will leave it with only the data relevant for
118
121
  # handling authentication.
119
- @data = error.select { |key| !%w{(errcode), (error)}.include? key }
122
+ @data = error.select { |key| !%w(errcode error).include? key }
120
123
  end
121
124
  end
122
125
  end
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  # Keeps track of what events have already been processed.
3
6
  module Events
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/errors'
2
5
 
3
6
  require 'chatrix/api/session'
@@ -230,7 +233,7 @@ module Chatrix
230
233
  # and value.
231
234
  def make_body(content)
232
235
  key = content.respond_to?(:read) ? :body_stream : :body
233
- value = content.is_a? Hash ? content.to_json : content
236
+ value = content.is_a?(Hash) ? content.to_json : content
234
237
  { key => value }
235
238
  end
236
239
 
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  # Describes a message sent in a room.
3
6
  class Message
@@ -10,29 +13,37 @@ module Chatrix
10
13
  'm.notice' => :notice
11
14
  }.freeze
12
15
 
13
- # @!attribute [r] raw
14
- # @return [Hash] The raw message data (the `content` field).
15
- # @!attribute [r] type
16
- # @return [Symbol,nil] The type of message. Will be nil if the type
17
- # failed to parse.
18
- # @!attribute [r] sender
19
- # @return [User] The user who sent this message.
20
- # @!attribute [r] body
21
- # @return [String] The text content of the message. If the message is
22
- # of `:html` type, this will contain HTML format. To get the raw
23
- # message text, use the `'body'` field of the {#raw} hash.
24
- attr_reader :raw, :type, :sender, :body
16
+ # @return [Hash] The raw message data (the `content` field).
17
+ attr_reader :raw
18
+
19
+ # @return [Symbol,nil] The type of message. Will be nil if the type
20
+ # failed to parse.
21
+ attr_reader :type
22
+
23
+ # @return [User] The user who sent this message.
24
+ attr_reader :sender
25
+
26
+ # @return [String] The text content of the message. If the message is
27
+ # of `:html` type, this will contain HTML format. To get the raw
28
+ # message text, use the `'body'` field of the {#raw} hash.
29
+ attr_reader :body
30
+
31
+ # @return [Integer] The timestamp of the message, indicating when
32
+ # it was sent, according to the origin server.
33
+ attr_reader :timestamp
25
34
 
26
35
  # Initializes a new Message instance.
27
36
  #
28
37
  # @param sender [User] The user who sent the message.
38
+ # @param timestamp [Integer] The timestamp of the message.
29
39
  # @param content [Hash] The message content.
30
- def initialize(sender, content)
40
+ def initialize(sender, timestamp, content)
31
41
  @raw = content
32
42
 
33
43
  @type = TYPES[@raw['msgtype']]
34
44
  @body = @raw['body']
35
45
  @sender = sender
46
+ @timestamp = timestamp
36
47
 
37
48
  parse_body!
38
49
  end
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/components/state'
2
5
  require 'chatrix/components/timeline'
3
6
  require 'chatrix/components/messaging'
@@ -9,14 +12,21 @@ module Chatrix
9
12
  class Room
10
13
  include Wisper::Publisher
11
14
 
12
- # @!attribute [r] id
13
- # @return [String] The ID of this room.
14
- # @!attribute [r] admin
15
- # @return [Admin] Administration object for carrying out administrative
16
- # actions like kicking and banning of users.
17
- # @!attribute [r] messaging
18
- # @return [Messaging] Handle various message actions through this object.
19
- attr_reader :id, :state, :timeline, :admin, :messaging
15
+ # @return [String] The ID of this room.
16
+ attr_reader :id
17
+
18
+ # @return [State] The state object for this room.
19
+ attr_reader :state
20
+
21
+ # @return [Timeline] The timeline object for this room.
22
+ attr_reader :timeline
23
+
24
+ # @return [Admin] Administration object for carrying out administrative
25
+ # actions like kicking and banning of users.
26
+ attr_reader :admin
27
+
28
+ # @return [Messaging] Handle various message actions through this object.
29
+ attr_reader :messaging
20
30
 
21
31
  # Initializes a new Room instance.
22
32
  #
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/room'
2
5
 
3
6
  require 'wisper'
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/events'
2
5
 
3
6
  require 'wisper'
@@ -7,14 +10,15 @@ module Chatrix
7
10
  class User
8
11
  include Wisper::Publisher
9
12
 
10
- # @!attribute [r] id
11
- # @return [String] The user ID of this user.
12
- # @!attribute [r] displayname
13
- # @return [String,nil] The display name of this user, if one has
14
- # been set.
15
- # @!attribute [r] avatar
16
- # @return [String,nil] This user's avatar URL, if one has been set.
17
- attr_reader :id, :displayname, :avatar
13
+ # @return [String] The user ID of this user.
14
+ attr_reader :id
15
+
16
+ # @return [String,nil] The display name of this user, if one has
17
+ # been set.
18
+ attr_reader :displayname
19
+
20
+ # @return [String,nil] This user's avatar URL, if one has been set.
21
+ attr_reader :avatar
18
22
 
19
23
  # Initializes a new User instance.
20
24
  # @param id [String] The user ID.
@@ -1,3 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'chatrix/user'
2
5
  require 'chatrix/events'
3
6
 
@@ -1,4 +1,7 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Chatrix
2
5
  # The current version of this gem.
3
- VERSION = '1.0.0'.freeze
6
+ VERSION = '1.1.0'.freeze
4
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hellberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -62,6 +62,7 @@ files:
62
62
  - ".editorconfig"
63
63
  - ".gitignore"
64
64
  - ".rspec"
65
+ - ".rubocop.yml"
65
66
  - ".travis.yml"
66
67
  - ".yardopts"
67
68
  - Gemfile
@@ -106,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
107
  requirements:
107
108
  - - ">="
108
109
  - !ruby/object:Gem::Version
109
- version: '0'
110
+ version: 2.0.0
110
111
  required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  requirements:
112
113
  - - ">="