chronicle-pinboard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 15ed0e19604895789980662542a77832a594dbb136d54509c616c0f223f90037
4
+ data.tar.gz: 75d25beb023c48b299e32cd781b34c9a4b0ca7be9e89ec85fd7ba7ca748317b2
5
+ SHA512:
6
+ metadata.gz: c66d22e21d7be71ccdfa621b545643594bf99ebdac32e49aede6a0ca0d7e34e2b95288dad866849e80dd00eb520fa18e67a2795e0c5e12926de13b9936a9330d
7
+ data.tar.gz: 6f95497832293120d18462bf587e4bc0003bdaeddb137389601ac32976b8586a878f5fd0fe45915a34094ebe1d3376dd73108914b24477177d7586300757f846
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ .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-pinboard.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Chronicle::Pinboard
2
+
3
+ Pinboard plugin for [chronicle-etl](https://github.com/chronicle-app/chronicle-etl)
4
+
5
+ ## Available Connectors
6
+ ### Extractors
7
+ - `pinboard` - Extractor for importing bookmarks
8
+
9
+ ### Transformers
10
+ - `pinboard` - Transforms bookmarks into Chronicle Schema
11
+
12
+ ## Usage
13
+
14
+ ```sh
15
+ gem install chronicle-etl
16
+ chronicle-etl connectors:install pinboard
17
+
18
+ # get PINBOARD_ACCESS_TOKEN from https://pinboard.in/settings/password
19
+ chronicle-etl --extractor pinboard --extractor-opts access_token:$PINBOARD_ACCESS_TOKEN --since 2022-02-07
20
+ ```
21
+
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/pinboard"
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
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "chronicle/pinboard/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "chronicle-pinboard"
9
+ spec.version = Chronicle::Pinboard::VERSION
10
+ spec.authors = ["Andrew Louis"]
11
+ spec.email = ["andrew@hyfen.net"]
12
+
13
+ spec.summary = "Pinboard importer for Chronicle"
14
+ spec.description = "Import your Pinboard bookmarks"
15
+ spec.homepage = "https://github.com/chronicle-app/chronicle-pinboard"
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
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/chronicle-app/chronicle-pinboard"
24
+ spec.metadata["changelog_uri"] = "https://github.com/chronicle-app/chronicle-pinboard"
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.4"
40
+ spec.add_dependency "faraday", "~> 2.2"
41
+
42
+ spec.add_development_dependency "bundler", "~> 2.3"
43
+ spec.add_development_dependency "rake", "~> 13.0.6"
44
+ spec.add_development_dependency "pry-byebug", "~> 3.9"
45
+ end
@@ -0,0 +1,51 @@
1
+ require 'chronicle/etl'
2
+ require 'faraday'
3
+
4
+ module Chronicle
5
+ module Pinboard
6
+ class PinboardExtractor < Chronicle::ETL::Extractor
7
+ register_connector do |r|
8
+ r.provider = 'pinboard'
9
+ r.description = 'bookmarks'
10
+ end
11
+
12
+ setting :access_token, required: true
13
+
14
+ def prepare
15
+ @bookmarks = load_bookmarks
16
+ @username = @config.access_token.split(":").first
17
+ end
18
+
19
+ def extract
20
+ @bookmarks.each do |bookmark|
21
+ yield Chronicle::ETL::Extraction.new(data: bookmark, meta: { username: @username })
22
+ end
23
+ end
24
+
25
+ def results_count
26
+ @bookmarks.count
27
+ end
28
+
29
+ private
30
+
31
+ def load_bookmarks
32
+ params = {
33
+ auth_token: @config.access_token,
34
+ format: 'json',
35
+ meta: true,
36
+ }
37
+ params[:fromdt] = @config.since.utc.iso8601 if @config.since
38
+
39
+ conn = Faraday.new(
40
+ url: 'https://api.pinboard.in/',
41
+ params: params
42
+ )
43
+
44
+ response = conn.get('/v1/posts/all')
45
+ bookmarks = JSON.parse(response.body, { symbolize_names: true })
46
+ bookmarks = bookmarks.keep_if { |bookmark| Time.parse(bookmark[:time]) < @config.until } if @config.until
47
+ bookmarks
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,99 @@
1
+ require 'chronicle/etl'
2
+
3
+ module Chronicle
4
+ module Pinboard
5
+ class PinboardTransformer < Chronicle::ETL::Transformer
6
+ register_connector do |r|
7
+ r.provider = 'pinboard'
8
+ r.description = 'bookmark from pinboard'
9
+ end
10
+
11
+ def transform
12
+ @bookmark = @extraction.data
13
+ build_liked
14
+ end
15
+
16
+ def timestamp
17
+ Time.parse(@bookmark[:time])
18
+ end
19
+
20
+ def id
21
+ @bookmark[:hash]
22
+ end
23
+
24
+ private
25
+
26
+ def build_liked
27
+ record = ::Chronicle::ETL::Models::Activity.new
28
+ record.end_at = timestamp
29
+ record.verb = 'liked'
30
+ record.provider_id = id
31
+ record.provider = 'pinboard'
32
+ record.dedupe_on = [[:provider, :verb, :provider_id]]
33
+
34
+ record.involved = build_bookmark
35
+ record.actor = build_actor
36
+
37
+ record
38
+ end
39
+
40
+ def build_bookmark
41
+ record = ::Chronicle::ETL::Models::Entity.new
42
+ record.title = @bookmark[:description]
43
+ record.provider_url = @bookmark[:href]
44
+ record.dedupe_on << [:provider_url]
45
+
46
+ record.abouts = build_tags
47
+
48
+ record.aboutables = build_note
49
+ record
50
+ end
51
+
52
+ def build_note
53
+ note = @bookmark[:extended]
54
+ return unless note.size.positive?
55
+
56
+ record = ::Chronicle::ETL::Models::Entity.new
57
+ record.provider_id = id
58
+ record.represents = "thought"
59
+ record.body = note
60
+ record.provider = "pinboard"
61
+ record.dedupe_on << [:represents, :provider, :provider_id]
62
+
63
+ involvement = ::Chronicle::ETL::Models::Activity.new
64
+ involvement.end_at = timestamp
65
+ involvement.verb = 'noted'
66
+ involvement.provider_id = id
67
+ involvement.provider = 'pinboard'
68
+ involvement.dedupe_on << [:provider, :verb, :provider_id]
69
+ involvement.actor = build_actor
70
+
71
+ record.involvements = [involvement]
72
+
73
+ record
74
+ end
75
+
76
+ def build_tags
77
+ @bookmark[:tags].split(" ").map do |tag|
78
+ record = ::Chronicle::ETL::Models::Entity.new
79
+ record.represents = 'topic'
80
+ record.provider = 'pinboard'
81
+ record.slug = tag.downcase
82
+ record.dedupe_on << [:provider, :slug, :represents]
83
+ record
84
+ end
85
+ end
86
+
87
+ def build_actor
88
+ record = ::Chronicle::ETL::Models::Entity.new
89
+ record.represents = 'identity'
90
+ record.slug = @extraction.meta[:username]
91
+ record.provider = 'pinboard'
92
+ record.provider_url = "https://pinboard.in/u:#{record.slug}"
93
+ record.dedupe_on << [:provider_url]
94
+ record.dedupe_on << [:provider, :represents, :slug]
95
+ record
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chronicle
4
+ module Pinboard
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pinboard/version"
4
+ require_relative "pinboard/pinboard_extractor"
5
+ require_relative "pinboard/pinboard_transformer"
6
+
7
+ module Chronicle
8
+ module Pinboard
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chronicle-pinboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Louis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-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.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
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.6
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.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
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: Import your Pinboard bookmarks
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-pinboard.gemspec
98
+ - lib/chronicle/pinboard.rb
99
+ - lib/chronicle/pinboard/pinboard_extractor.rb
100
+ - lib/chronicle/pinboard/pinboard_transformer.rb
101
+ - lib/chronicle/pinboard/version.rb
102
+ homepage: https://github.com/chronicle-app/chronicle-pinboard
103
+ licenses: []
104
+ metadata:
105
+ allowed_push_host: https://rubygems.org
106
+ homepage_uri: https://github.com/chronicle-app/chronicle-pinboard
107
+ source_code_uri: https://github.com/chronicle-app/chronicle-pinboard
108
+ changelog_uri: https://github.com/chronicle-app/chronicle-pinboard
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.1.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Pinboard importer for Chronicle
128
+ test_files: []