Skip to content

Commit

Permalink
pass rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Sep 12, 2023
1 parent 0ce6a49 commit 9a3043e
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Layout/LineLength:
Max: 120
Max: 190
4 changes: 1 addition & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
[200, "Activity received"]
end



get '/' do
%(
"ActivityPub Sinatra Example"
Expand All @@ -49,4 +47,4 @@
<input type="submit" value="Send to our Inbox">
</form>
)
end
end
1 change: 1 addition & 0 deletions lib/activitypub.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "json"
require 'time'
require 'base64'
Expand Down
29 changes: 13 additions & 16 deletions lib/activitypub/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
# ...

Expand Down Expand Up @@ -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.
14 changes: 7 additions & 7 deletions lib/activitypub/actor.rb
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/activitypub/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ 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
loaded_obj = ActivityPub::Object.from_h(JSON.parse(obj.to_json))
puts loaded_obj.content # => "Hello world!"
=end
=end
4 changes: 2 additions & 2 deletions lib/activitypub/signature.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
expect(activity.object).to eq('https://example.com/posts/1')
end
end
end
end
2 changes: 1 addition & 1 deletion spec/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
expect(actor.outbox).to eq('https://example.com/users/alice/outbox')
end
end
end
end
1 change: 0 additions & 1 deletion spec/object_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# spec/activitypub/object_spec.rb


RSpec.describe ActivityPub::Object do
let(:current_time) { Time.now.utc.iso8601 }

Expand Down
8 changes: 4 additions & 4 deletions spec/outbox_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
}
)
Expand Down
7 changes: 3 additions & 4 deletions spec/signature_spec.rb
Original file line number Diff line number Diff line change
@@ -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]) }

Expand All @@ -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]) }

Expand Down

0 comments on commit 9a3043e

Please sign in to comment.