chronicle-zulip 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 27ed02b087bd99b0db8a702d8140add3dba7cdc9df1b3fea0cb2825b49051642
4
+ data.tar.gz: 01a4efcbf6ccc39ed9d21672684c32c71b37759b32fbaf553097b21edf4a4ce5
5
+ SHA512:
6
+ metadata.gz: 2c706f57da0de15bce5c20430edeebc9b358c55e0e5d060ebe770f91e70e40dfba3ff08edc419e704ba7901d8bae1cf65e5f16ebe033c57d680c6c8400f65b47
7
+ data.tar.gz: b02063a99a83b93e93f44926d44cd16d17e8125ac250a5300b8a3874d3eadd656e2ef9d7d91a01db5c44aee8129b1dcfe5dbdbdbcb61c6f325375b1f8e4d1730
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+ .DS_Store
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andrew@hyfen.net. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in chronicle-zulip.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Chronicle::Zulip
2
+ [![Gem Version](https://badge.fury.io/rb/chronicle-zulip.svg)](https://badge.fury.io/rb/chronicle-zulip)
3
+
4
+ Extract your Zulip messages using the command line with this plugin for [chronicle-etl](https://github.com/chronicle-app/chronicle-etl).
5
+
6
+ ## Usage
7
+
8
+ ```sh
9
+ # Install chronicle-etl and this plugin
10
+ $ gem install chronicle-etl
11
+ $ chronicle-etl plugins:install zulip
12
+ ```
13
+
14
+ You can get a personal access token by going to Settings -> Account & Privacy and pressing the "Show/change your API key".
15
+
16
+ ```sh
17
+ # Save username, access_token, and realm
18
+ $ chronicle-etl secrets:set zulip username foo@gmail.com
19
+ $ chronicle-etl secrets:set zulip access_token ACCESS_TOKEN
20
+ $ chronicle-etl secrets:set zulip realm foo
21
+
22
+ # Then, retrieve your private messages
23
+ $ chronicle-etl --extractor zulip:private-messages --loader json
24
+ ```
25
+
26
+ ## Available Connectors
27
+ ### Extractors
28
+
29
+ #### `private-message`
30
+
31
+ Extractor for importing private messages from Zulip
32
+
33
+ ##### Settings
34
+
35
+ - `username`: The email address associated with your Zulip account
36
+ - `access_token`: Your personal access token
37
+ - `realm`: ____.zulipchat.com
38
+
39
+ ### Transformers
40
+
41
+ #### `message`
42
+
43
+ Transform a Zulip message into Chronicle Schema
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "chronicle/zulip"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
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,45 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "chronicle/zulip/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chronicle-zulip"
8
+ spec.version = Chronicle::Zulip::VERSION
9
+ spec.authors = ["Andrew Louis"]
10
+ spec.email = ["andrew@hyfen.net"]
11
+
12
+ spec.summary = "Zulip importer for Chronicle"
13
+ spec.description = "Zulip importer for chronicle-etl"
14
+ spec.homepage = "https://github.com/chronicle-app/chronicle-zulip"
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"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/chronicle-app/chronicle-zulip"
24
+ spec.metadata["changelog_uri"] = "https://github.com/chronicle-app/chronicle-zulip"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "chronicle-etl", "~> 0.5.3"
40
+ spec.add_dependency "faraday", "~> 2.2"
41
+
42
+ spec.add_development_dependency "bundler", "~> 2.1"
43
+ spec.add_development_dependency "rake", "~> 13.0"
44
+ spec.add_development_dependency "rspec", "~> 3.9"
45
+ end
@@ -0,0 +1,102 @@
1
+ require 'chronicle/etl'
2
+
3
+ module Chronicle
4
+ module Zulip
5
+ class MessageTransformer < Chronicle::ETL::Transformer
6
+ register_connector do |r|
7
+ r.description = 'a zulip message'
8
+ r.provider = 'zulip'
9
+ r.identifier = 'message'
10
+ end
11
+
12
+ def transform
13
+ build_messaged
14
+ end
15
+
16
+ def id
17
+ message[:id]
18
+ end
19
+
20
+ def timestamp
21
+ Time.at(message[:timestamp])
22
+ end
23
+
24
+ private
25
+
26
+ def message
27
+ @message ||= @extraction.data
28
+ end
29
+
30
+ def participants
31
+ @participants ||= begin
32
+ message[:display_recipient].map do |recipient|
33
+ build_user(
34
+ id: recipient[:id],
35
+ email: recipient[:email],
36
+ full_name: recipient[:full_name],
37
+ realm: message[:sender_realm_str]
38
+ )
39
+ end
40
+ end
41
+ end
42
+
43
+ def build_messaged
44
+ record = ::Chronicle::ETL::Models::Activity.new
45
+ record.verb = 'messaged'
46
+ record.provider = 'zulip'
47
+ record.provider_id = id
48
+ record.provider_namespace = message[:sender_realm_str]
49
+ record.end_at = timestamp
50
+
51
+ record.dedupe_on << [:verb, :provider, :provider_id]
52
+
53
+ record.actor = build_actor
54
+ record.involved = build_message
55
+ record
56
+ end
57
+
58
+ def build_actor
59
+ participants.find { |participant| participant.provider_id == message[:sender_id]}
60
+ end
61
+
62
+ def build_user(id:, email:, full_name:, realm:)
63
+ record = ::Chronicle::ETL::Models::Entity.new
64
+ record.represents = 'identity'
65
+ record.provider = 'zulip'
66
+ record.provider_id = id
67
+ record.provider_namespace = realm
68
+ record.title = full_name
69
+
70
+ record.analogous = [ build_email_identity(email) ]
71
+
72
+ record.dedupe_on << [:represents, :provider, :provider_id, :provider_namespace]
73
+
74
+ record
75
+ end
76
+
77
+ def build_email_identity(email)
78
+ record = ::Chronicle::ETL::Models::Entity.new
79
+ record.represents = 'identity'
80
+ record.provider = 'email'
81
+ record.slug = email
82
+ record.dedupe_on << [:represents, :provider, :slug]
83
+ record
84
+ end
85
+
86
+ def build_message
87
+ record = ::Chronicle::ETL::Models::Entity.new
88
+ record.represents = 'message'
89
+ record.provider = 'zulip'
90
+ record.provider_id = id
91
+ record.provider_namespace = message[:sender_realm_str]
92
+ record.body = message[:content]
93
+
94
+ record.consumers = participants.select { |participant| participant.provider_id != message[:sender_id] }
95
+
96
+ record.dedupe_on << [:represents, :provider, :provider_id]
97
+
98
+ record
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,27 @@
1
+ require 'chronicle/etl'
2
+ require 'faraday'
3
+ module Chronicle
4
+ module Zulip
5
+ class PrivateMessageExtractor < Chronicle::ETL::Extractor
6
+ register_connector do |r|
7
+ r.provider = 'zulip'
8
+ r.description = 'zulip direct messages'
9
+ r.identifier = 'private-message'
10
+ end
11
+
12
+ setting :access_token, required: true
13
+ setting :username, required: true
14
+ setting :realm, required: true
15
+
16
+ def prepare
17
+ @proxy = Chronicle::Zulip::Proxy.new(username: @config.username, realm: @config.realm, access_token: @config.access_token)
18
+ end
19
+
20
+ def extract
21
+ @proxy.all_private_messages do |message|
22
+ yield Chronicle::ETL::Extraction.new(data: message)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ require 'faraday'
2
+
3
+ module Chronicle
4
+ module Zulip
5
+ class Proxy
6
+ def initialize(username:, access_token:, realm:)
7
+ @username = username
8
+ @access_token = access_token
9
+ @realm = realm
10
+ end
11
+
12
+ def all_private_messages(anchor: 'oldest')
13
+ narrow = '[{"negated":false,"operator":"is","operand":"private"}]'
14
+ has_more = true
15
+
16
+ while has_more
17
+ response = load_messages(anchor: anchor, narrow: narrow)
18
+ messages = response[:messages] || []
19
+
20
+ messages.each do |message|
21
+ yield message
22
+ end
23
+
24
+ has_more = !response[:found_newest]
25
+ anchor = messages.map { |message| message[:id] }.max
26
+ end
27
+ end
28
+
29
+ def load_messages(anchor:, narrow:)
30
+ params = {
31
+ narrow: narrow,
32
+ num_after: '50',
33
+ num_before: '0',
34
+ anchor: anchor,
35
+ apply_markdown: 'false'
36
+ }
37
+
38
+ make_request(endpoint: 'messages', params: params)
39
+ end
40
+
41
+ def make_request(endpoint:, params: {})
42
+ conn = Faraday.new(
43
+ url: zulip_subdomain,
44
+ params: params
45
+ ) do |conn|
46
+ conn.use Faraday::Response::RaiseError
47
+ conn.request :authorization, :basic, @username, @access_token
48
+ end
49
+
50
+ response = conn.get("api/v1/#{endpoint}")
51
+ JSON.parse(response.body, { symbolize_names: true })
52
+ end
53
+
54
+ private
55
+
56
+ def zulip_subdomain
57
+ "https://#{@realm}.zulipchat.com"
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chronicle
4
+ module Zulip
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "zulip/version"
4
+ require_relative "zulip/proxy"
5
+ require_relative "zulip/private_message_extractor"
6
+ require_relative "zulip/message_transformer"
7
+
8
+ module Chronicle
9
+ module Zulip
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronicle-zulip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Louis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chronicle-etl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ description: Zulip importer for chronicle-etl
84
+ email:
85
+ - andrew@hyfen.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - chronicle-zulip.gemspec
98
+ - lib/chronicle/zulip.rb
99
+ - lib/chronicle/zulip/message_transformer.rb
100
+ - lib/chronicle/zulip/private_message_extractor.rb
101
+ - lib/chronicle/zulip/proxy.rb
102
+ - lib/chronicle/zulip/version.rb
103
+ homepage: https://github.com/chronicle-app/chronicle-zulip
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ homepage_uri: https://github.com/chronicle-app/chronicle-zulip
108
+ source_code_uri: https://github.com/chronicle-app/chronicle-zulip
109
+ changelog_uri: https://github.com/chronicle-app/chronicle-zulip
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.3.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Zulip importer for Chronicle
129
+ test_files: []