tinysky 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 375aa645511e39e02ec043ebdbe42bc4e2fab07827dc997206574f8a84287f94
4
+ data.tar.gz: 50f88050793b6672d4373e3279b8b702cf0b22f92f51bcad79afcd6240973214
5
+ SHA512:
6
+ metadata.gz: d97c862e81a5f6dd94bb66f69149375736c21bc87994bee829c369481b580471d7dbe6a508dc3c673f612dcff86289e32ec2ef942b2e7c86796504d67f3fbf21
7
+ data.tar.gz: 8ca244b6d7e384a7157734aec616d870fe89e96f21469f53e1e6e394170678831648e91c16e1e01d015273353d84b7e7ecc63e2f37ab4f7b7d887fe45e195177
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ format: progress
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Jon Allured
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,47 @@
1
+ # Tinysky [![CI][badge]][actions]
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/tinysky`. 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
+ ```
24
+ credentials = {
25
+ app_password: "REDACTED",
26
+ handle: "tinyskygem.bsky.social"
27
+ }
28
+ client = Tinysky::Client.new(credentials)
29
+ client.create_record("hello world!")
30
+ ```
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ 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).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jonallured/tinysky.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ [actions]: https://github.com/jonallured/tinysky/actions
47
+ [badge]: https://github.com/jonallured/tinysky/actions/workflows/main.yml/badge.svg
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: %i[standard spec]
@@ -0,0 +1,57 @@
1
+ module Tinysky
2
+ class Client
3
+ attr_reader :access_jwt, :expires_at
4
+
5
+ def initialize(credentials)
6
+ @credentials = credentials
7
+ @connection = Tinysky.generate_connection
8
+
9
+ @access_jwt = nil
10
+ @expires_at = nil
11
+ end
12
+
13
+ def create_session
14
+ body = {
15
+ identifier: @credentials[:handle],
16
+ password: @credentials[:app_password]
17
+ }
18
+
19
+ response = @connection.post(CREATE_SESSION_PATH, body)
20
+
21
+ @access_jwt = response.body["accessJwt"]
22
+ payload, _header = JWT.decode(@access_jwt, nil, false)
23
+ @expires_at = Time.at(payload["exp"])
24
+
25
+ response
26
+ end
27
+
28
+ def create_record(text)
29
+ create_session if expired_token?
30
+
31
+ record = {
32
+ "$type" => POST_LEXICON_TYPE,
33
+ "createdAt" => DateTime.now.iso8601,
34
+ "langs" => ["en-US"],
35
+ "text" => text
36
+ }
37
+
38
+ body = {
39
+ collection: POST_LEXICON_TYPE,
40
+ record: record,
41
+ repo: @credentials[:handle]
42
+ }
43
+
44
+ headers = {"Authorization" => "Bearer #{@access_jwt}"}
45
+
46
+ @connection.post(CREATE_RECORD_PATH, body, headers)
47
+ end
48
+
49
+ private
50
+
51
+ def expired_token?
52
+ return true unless @expires_at
53
+
54
+ @expires_at < Time.now
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Tinysky
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tinysky.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "faraday"
2
+ require "jwt"
3
+
4
+ require_relative "tinysky/version"
5
+ require_relative "tinysky/client"
6
+
7
+ module Tinysky
8
+ ROOT_URL = "https://bsky.social"
9
+
10
+ CREATE_RECORD_PATH = "/xrpc/com.atproto.repo.createRecord"
11
+ CREATE_SESSION_PATH = "/xrpc/com.atproto.server.createSession"
12
+
13
+ POST_LEXICON_TYPE = "app.bsky.feed.post"
14
+
15
+ def self.generate_connection
16
+ Faraday.new(url: ROOT_URL) do |f|
17
+ f.request :json
18
+ f.response :json
19
+ end
20
+ end
21
+ end
data/sig/tinysky.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Tinysky
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/tinysky.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ require_relative "lib/tinysky/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "tinysky"
5
+ spec.version = Tinysky::VERSION
6
+ spec.authors = ["Jon Allured"]
7
+ spec.email = ["jon@jonallured.com"]
8
+
9
+ spec.summary = "Tiny client for the Bluesky API."
10
+ spec.description = "A tiny client gem for the Bluesky API that focuses on creating posts."
11
+ spec.homepage = "https://github.com/jonallured/tinysky"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = ">= 2.6.0"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+
17
+ spec.files = Dir.chdir(__dir__) do
18
+ `git ls-files -z`.split("\x0").reject do |f|
19
+ (File.expand_path(f) == __FILE__) ||
20
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
21
+ end
22
+ end
23
+
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "faraday", "~> 2"
29
+ spec.add_dependency "jwt", "~> 2"
30
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinysky
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Allured
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
41
+ description: A tiny client gem for the Bluesky API that focuses on creating posts.
42
+ email:
43
+ - jon@jonallured.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".standard.yml"
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/tinysky.rb
54
+ - lib/tinysky/client.rb
55
+ - lib/tinysky/version.rb
56
+ - sig/tinysky.rbs
57
+ - tinysky.gemspec
58
+ homepage: https://github.com/jonallured/tinysky
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ homepage_uri: https://github.com/jonallured/tinysky
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.6.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.5.4
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Tiny client for the Bluesky API.
82
+ test_files: []