From 9a3043e83222271bf0309a97145286191db7c833 Mon Sep 17 00:00:00 2001 From: Miguel Michelson Martinez Date: Tue, 12 Sep 2023 01:53:35 -0300 Subject: [PATCH] pass rubocop --- .rubocop.yml | 2 +- app.rb | 4 +--- lib/activitypub.rb | 1 + lib/activitypub/activity.rb | 29 +++++++++++++---------------- lib/activitypub/actor.rb | 14 +++++++------- lib/activitypub/object.rb | 3 +-- lib/activitypub/signature.rb | 4 ++-- spec/activity_spec.rb | 2 +- spec/actor_spec.rb | 2 +- spec/object_spec.rb | 1 - spec/outbox_spec.rb | 8 ++++---- spec/signature_spec.rb | 7 +++---- 12 files changed, 35 insertions(+), 42 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 00a72e3..01f4f98 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,4 +7,4 @@ Style/StringLiteralsInInterpolation: EnforcedStyle: double_quotes Layout/LineLength: - Max: 120 + Max: 190 diff --git a/app.rb b/app.rb index ca3ae4f..4a3fbfa 100644 --- a/app.rb +++ b/app.rb @@ -25,8 +25,6 @@ [200, "Activity received"] end - - get '/' do %( "ActivityPub Sinatra Example" @@ -49,4 +47,4 @@ ) -end \ No newline at end of file +end diff --git a/lib/activitypub.rb b/lib/activitypub.rb index d953fa7..e2ffa96 100644 --- a/lib/activitypub.rb +++ b/lib/activitypub.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "json" require 'time' require 'base64' diff --git a/lib/activitypub/activity.rb b/lib/activitypub/activity.rb index cfbebc8..0adfa75 100644 --- a/lib/activitypub/activity.rb +++ b/lib/activitypub/activity.rb @@ -2,13 +2,13 @@ module ActivityPub class Activity # The type of the activity, e.g., 'Create', 'Like', 'Follow', etc. attr_accessor :type - + # The actor performing the activity. attr_accessor :actor - + # The object of the activity, e.g., a post, a comment, etc. attr_accessor :object - + # Any additional properties can go here. # ... @@ -53,18 +53,15 @@ def self.from_h(hash) end end -#Usage example: - -#ruby -#Copy code -#activity = ActivityPub::Activity.new(type: 'Like', actor: 'https://example.com/users/alice', object: 'https://example.com/posts/1') -#puts activity.to_json - -#loaded_activity = ActivityPub::Activity.from_h(JSON.parse(activity.to_json)) -#puts loaded_activity.type # => "Like" -#Note that this is a basic and illustrative implementation. In a real-world scenario, you would need to handle more attributes, validations, and scenarios specified by the ActivityStreams and ActivityPub specifications. - - - +# Usage example: +# ruby +# Copy code +# activity = ActivityPub::Activity.new(type: 'Like', actor: 'https://example.com/users/alice', object: 'https://example.com/posts/1') +# puts activity.to_json +# loaded_activity = ActivityPub::Activity.from_h(JSON.parse(activity.to_json)) +# puts loaded_activity.type # => "Like" +# Note that this is a basic and illustrative implementation. +# In a real-world scenario, you would need to handle more attributes, validations, +# and scenarios specified by the ActivityStreams and ActivityPub specifications. diff --git a/lib/activitypub/actor.rb b/lib/activitypub/actor.rb index 02c0f3a..16df718 100644 --- a/lib/activitypub/actor.rb +++ b/lib/activitypub/actor.rb @@ -1,7 +1,7 @@ -# The ActivityPub::Actor represents individual and +# The ActivityPub::Actor represents individual and # collective entities which perform activities. -# Commonly used actor types include Person, Organization, -# Service, etc. For simplicity, we will focus on the Person +# Commonly used actor types include Person, Organization, +# Service, etc. For simplicity, we will focus on the Person # actor type. # Here's a basic representation for the ActivityPub::Actor: @@ -15,10 +15,10 @@ def initialize(id:, type: 'Person', name:, preferred_username:, inbox:, outbox:, @type = type @name = name @preferred_username = preferred_username - @inbox = inbox - @outbox = outbox - @followers = followers - @following = following + @inbox = inbox + @outbox = outbox + @followers = followers + @following = following end def to_h diff --git a/lib/activitypub/object.rb b/lib/activitypub/object.rb index 3661fbf..41a93f7 100644 --- a/lib/activitypub/object.rb +++ b/lib/activitypub/object.rb @@ -40,7 +40,6 @@ def self.from_h(hash) end end - =begin obj = ActivityPub::Object.new(id: 'https://example.com/objects/1', content: 'Hello world!') puts obj.to_json @@ -48,4 +47,4 @@ def self.from_h(hash) loaded_obj = ActivityPub::Object.from_h(JSON.parse(obj.to_json)) puts loaded_obj.content # => "Hello world!" -=end \ No newline at end of file +=end diff --git a/lib/activitypub/signature.rb b/lib/activitypub/signature.rb index f43dcbf..b05bfee 100644 --- a/lib/activitypub/signature.rb +++ b/lib/activitypub/signature.rb @@ -1,8 +1,8 @@ require 'openssl' -# Digital signatures are essential in federated networks +# Digital signatures are essential in federated networks # like ActivityPub to ensure data integrity and authenticity. -# A commonly used algorithm for generating these signatures +# A commonly used algorithm for generating these signatures # in the ActivityPub community is the RSA-SHA256 algorithm. module ActivityPub diff --git a/spec/activity_spec.rb b/spec/activity_spec.rb index 8b975a7..1ec5d4d 100644 --- a/spec/activity_spec.rb +++ b/spec/activity_spec.rb @@ -33,4 +33,4 @@ expect(activity.object).to eq('https://example.com/posts/1') end end -end \ No newline at end of file +end diff --git a/spec/actor_spec.rb b/spec/actor_spec.rb index 6251488..4e0cd5d 100644 --- a/spec/actor_spec.rb +++ b/spec/actor_spec.rb @@ -67,4 +67,4 @@ expect(actor.outbox).to eq('https://example.com/users/alice/outbox') end end -end \ No newline at end of file +end diff --git a/spec/object_spec.rb b/spec/object_spec.rb index 606dd17..58d8abb 100644 --- a/spec/object_spec.rb +++ b/spec/object_spec.rb @@ -1,6 +1,5 @@ # spec/activitypub/object_spec.rb - RSpec.describe ActivityPub::Object do let(:current_time) { Time.now.utc.iso8601 } diff --git a/spec/outbox_spec.rb b/spec/outbox_spec.rb index 9270420..80c29f1 100644 --- a/spec/outbox_spec.rb +++ b/spec/outbox_spec.rb @@ -5,7 +5,7 @@ let(:inbox_url) { "https://recipient.com/actors/2/inbox" } let(:keypair) { ActivityPub::Signature.generate_keypair } let(:activity_data) { '{"type":"Note","content":"Hello from outbox!"}' } - + subject { described_class.new(actor_id: actor_id, private_key: keypair[:private]) } # Stubbing the HTTP request to avoid actual posts during tests @@ -14,10 +14,10 @@ .with( body: activity_data, headers: { - 'Accept'=>'*/*', - 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type' => 'application/ld+json', - 'User-Agent'=>'Ruby', + 'User-Agent' => 'Ruby', 'Signature' => ActivityPub::Signature.sign(activity_data, keypair[:private]) } ) diff --git a/spec/signature_spec.rb b/spec/signature_spec.rb index de01d1a..bfdcb4b 100644 --- a/spec/signature_spec.rb +++ b/spec/signature_spec.rb @@ -1,17 +1,16 @@ # spec/activitypub/signature_spec.rb - RSpec.describe ActivityPub::Signature do let(:keypair) { described_class.generate_keypair } let(:data) { "Important data that needs to be signed" } - + describe '.generate_keypair' do it 'generates a valid RSA key pair' do expect(keypair[:private]).to be_a(String) expect(keypair[:public]).to be_a(String) end end - + describe '.sign' do let(:signature) { described_class.sign(data, keypair[:private]) } @@ -21,7 +20,7 @@ # or perhaps try verifying the signature as a test. end end - + describe '.verify?' do let(:signature) { described_class.sign(data, keypair[:private]) }