minisky 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/lib/minisky/minisky.rb +102 -0
- data/lib/minisky/version.rb +5 -0
- data/lib/minisky.rb +2 -0
- data/sig/minisky.rbs +4 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: afde2461017bd9cc0127a64921329a07f884377d5e434dd9b81f15e42493f5b2
|
4
|
+
data.tar.gz: 29c86293b904fa973cdc2c2a74e17a7f8096ac02c97377d39c9daef9a1cdc194
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23f5239dddeed66c6ad1a4195d53adea8d7b35d8dbc2a0680d39351a7ca9b5aeb42ef8ccdb38d4d2cd589406e93cc90ae9b5cea9f3ad4f91d3586e3b3e7fc85f
|
7
|
+
data.tar.gz: fdfce69b885db91ca2efbe19a92cdfc2e11e7fd5ac363be71e47f1e7c4186ba160f9dd2f99ae55950f3404b33a5a72014e3f14e917ceb76cbca7657cce09ddf6
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
## [Unreleased]
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The zlib License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Jakub Suder
|
4
|
+
|
5
|
+
This software is provided 'as-is', without any express or implied
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
7
|
+
arising from the use of this software.
|
8
|
+
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
11
|
+
freely, subject to the following restrictions:
|
12
|
+
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
14
|
+
claim that you wrote the original software. If you use this software
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
16
|
+
appreciated but is not required.
|
17
|
+
|
18
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
19
|
+
misrepresented as being the original software.
|
20
|
+
|
21
|
+
3. This notice may not be removed or altered from any source distribution.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Minisky
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/minisky`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/minisky.
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
class Minisky
|
7
|
+
CONFIG_FILE = 'bluesky.yml'
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@config = YAML.load(File.read(CONFIG_FILE))
|
11
|
+
@base_url = "https://#{@config['host']}/xrpc"
|
12
|
+
end
|
13
|
+
|
14
|
+
def my_id
|
15
|
+
@config['ident']
|
16
|
+
end
|
17
|
+
|
18
|
+
def my_did
|
19
|
+
@config['did']
|
20
|
+
end
|
21
|
+
|
22
|
+
def access_token
|
23
|
+
@config['access_token']
|
24
|
+
end
|
25
|
+
|
26
|
+
def refresh_token
|
27
|
+
@config['refresh_token']
|
28
|
+
end
|
29
|
+
|
30
|
+
def save_config
|
31
|
+
File.write(CONFIG_FILE, YAML.dump(@config))
|
32
|
+
end
|
33
|
+
|
34
|
+
def log_in
|
35
|
+
json = post_request('com.atproto.server.createSession', {
|
36
|
+
identifier: @config['ident'],
|
37
|
+
password: @config['pass']
|
38
|
+
})
|
39
|
+
|
40
|
+
@config['did'] = json['did']
|
41
|
+
@config['access_token'] = json['accessJwt']
|
42
|
+
@config['refresh_token'] = json['refreshJwt']
|
43
|
+
save_config
|
44
|
+
end
|
45
|
+
|
46
|
+
def perform_token_refresh
|
47
|
+
json = post_request('com.atproto.server.refreshSession', nil, refresh_token)
|
48
|
+
@config['access_token'] = json['accessJwt']
|
49
|
+
@config['refresh_token'] = json['refreshJwt']
|
50
|
+
save_config
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_all(method, params, auth = nil, field:, break_when: ->(x) { false }, progress: true)
|
54
|
+
data = []
|
55
|
+
|
56
|
+
loop do
|
57
|
+
print '.' if progress
|
58
|
+
|
59
|
+
response = get_request(method, params, auth)
|
60
|
+
records = response[field]
|
61
|
+
cursor = response['cursor']
|
62
|
+
|
63
|
+
data.concat(records)
|
64
|
+
params[:cursor] = cursor
|
65
|
+
|
66
|
+
break if cursor.nil? || records.empty? || records.any? { |x| break_when.call(x) }
|
67
|
+
end
|
68
|
+
|
69
|
+
data.reject { |x| break_when.call(x) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_request(method, params = nil, auth = nil)
|
73
|
+
headers = {}
|
74
|
+
headers['Authorization'] = "Bearer #{auth}" if auth
|
75
|
+
|
76
|
+
url = "#{@base_url}/#{method}"
|
77
|
+
|
78
|
+
if params && !params.empty?
|
79
|
+
url += "?" + params.map { |k, v|
|
80
|
+
if v.is_a?(Array)
|
81
|
+
v.map { |x| "#{k}=#{x}" }.join('&')
|
82
|
+
else
|
83
|
+
"#{k}=#{v}"
|
84
|
+
end
|
85
|
+
}.join('&')
|
86
|
+
end
|
87
|
+
|
88
|
+
JSON.parse(URI.open(url, headers).read)
|
89
|
+
end
|
90
|
+
|
91
|
+
def post_request(method, params, auth = nil)
|
92
|
+
headers = { "Content-Type" => "application/json" }
|
93
|
+
headers['Authorization'] = "Bearer #{auth}" if auth
|
94
|
+
|
95
|
+
body = params ? params.to_json : ''
|
96
|
+
|
97
|
+
response = Net::HTTP.post(URI("#{@base_url}/#{method}"), body, headers)
|
98
|
+
raise "Invalid response: #{response.code} #{response.body}" if response.code.to_i / 100 != 2
|
99
|
+
|
100
|
+
JSON.parse(response.body)
|
101
|
+
end
|
102
|
+
end
|
data/lib/minisky.rb
ADDED
data/sig/minisky.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minisky
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kuba Suder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A very simple client class that lets you log in to the Bluesky API and
|
14
|
+
make any requests there.
|
15
|
+
email:
|
16
|
+
- jakub.suder@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- CHANGELOG.md
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- lib/minisky.rb
|
25
|
+
- lib/minisky/minisky.rb
|
26
|
+
- lib/minisky/version.rb
|
27
|
+
- sig/minisky.rbs
|
28
|
+
homepage: https://github.com/mackuba/minisky
|
29
|
+
licenses:
|
30
|
+
- Zlib
|
31
|
+
metadata:
|
32
|
+
bug_tracker_uri: https://github.com/mackuba/minisky/issues
|
33
|
+
changelog_uri: https://github.com/mackuba/minisky/blob/master/CHANGELOG.md
|
34
|
+
source_code_uri: https://github.com/mackuba/minisky
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.6.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.4.10
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: A minimal client of Bluesky/AtProto API
|
54
|
+
test_files: []
|