Merge branch 'salmon' of github.com:SuperTux88/diaspora_federation into salmon
This commit is contained in:
commit
1a3ba7e0fd
11 changed files with 203 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "base64"
|
||||||
|
|
||||||
require "diaspora_federation/logging"
|
require "diaspora_federation/logging"
|
||||||
|
|
||||||
require "diaspora_federation/callbacks"
|
require "diaspora_federation/callbacks"
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,7 @@ end
|
||||||
|
|
||||||
require "diaspora_federation/entities/profile"
|
require "diaspora_federation/entities/profile"
|
||||||
require "diaspora_federation/entities/person"
|
require "diaspora_federation/entities/person"
|
||||||
|
require "diaspora_federation/entities/location"
|
||||||
|
require "diaspora_federation/entities/photo"
|
||||||
|
require "diaspora_federation/entities/status_message"
|
||||||
|
require "diaspora_federation/entities/request"
|
||||||
|
|
|
||||||
9
lib/diaspora_federation/entities/location.rb
Normal file
9
lib/diaspora_federation/entities/location.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class Location < Entity
|
||||||
|
property :address
|
||||||
|
property :lat
|
||||||
|
property :lng
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
16
lib/diaspora_federation/entities/photo.rb
Normal file
16
lib/diaspora_federation/entities/photo.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class Photo < Entity
|
||||||
|
property :guid
|
||||||
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
property :public, default: false
|
||||||
|
property :created_at, default: -> { Time.now.utc }
|
||||||
|
property :remote_photo_path
|
||||||
|
property :remote_photo_name
|
||||||
|
property :text, default: nil
|
||||||
|
property :status_message_guid
|
||||||
|
property :height
|
||||||
|
property :width
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
8
lib/diaspora_federation/entities/request.rb
Normal file
8
lib/diaspora_federation/entities/request.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class Request < Entity
|
||||||
|
property :sender_id, xml_name: :sender_handle
|
||||||
|
property :recipient_id, xml_name: :recipient_handle
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
lib/diaspora_federation/entities/status_message.rb
Normal file
14
lib/diaspora_federation/entities/status_message.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
module Entities
|
||||||
|
class StatusMessage < Entity
|
||||||
|
property :raw_message
|
||||||
|
entity :photos, [Entities::Photo], default: []
|
||||||
|
entity :location, Entities::Location, default: nil
|
||||||
|
property :guid
|
||||||
|
property :diaspora_id, xml_name: :diaspora_handle
|
||||||
|
property :public, default: false
|
||||||
|
property :created_at, default: -> { Time.now.utc }
|
||||||
|
property :provider_display_name, default: nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -68,4 +68,23 @@ FactoryGirl.define do
|
||||||
nsfw false
|
nsfw false
|
||||||
tag_string "#i #love #tags"
|
tag_string "#i #love #tags"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :location_entity, class: DiasporaFederation::Entities::Location do
|
||||||
|
address "Vienna, Austria"
|
||||||
|
lat 48.208174.to_s
|
||||||
|
lng 16.373819.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :photo_entity, class: DiasporaFederation::Entities::Photo do
|
||||||
|
guid
|
||||||
|
diaspora_id
|
||||||
|
public(true)
|
||||||
|
created_at { Time.zone.now }
|
||||||
|
remote_photo_path "https://diaspora.example.tld/uploads/images/"
|
||||||
|
remote_photo_name "f2a41e9d2db4d9a199c8.jpg"
|
||||||
|
text "what you see here..."
|
||||||
|
status_message_guid { guid }
|
||||||
|
height 480
|
||||||
|
width 800
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
19
spec/lib/diaspora_federation/entities/location_spec.rb
Normal file
19
spec/lib/diaspora_federation/entities/location_spec.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Location do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:location_entity) }
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<location>
|
||||||
|
<address>#{data[:address]}</address>
|
||||||
|
<lat>#{data[:lat]}</lat>
|
||||||
|
<lng>#{data[:lng]}</lng>
|
||||||
|
</location>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass" do
|
||||||
|
let(:klass) { Entities::Location }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
26
spec/lib/diaspora_federation/entities/photo_spec.rb
Normal file
26
spec/lib/diaspora_federation/entities/photo_spec.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Photo do
|
||||||
|
let(:data) { FactoryGirl.attributes_for(:photo_entity) }
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<photo>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
|
<public>#{data[:public]}</public>
|
||||||
|
<created_at>#{data[:created_at]}</created_at>
|
||||||
|
<remote_photo_path>#{data[:remote_photo_path]}</remote_photo_path>
|
||||||
|
<remote_photo_name>#{data[:remote_photo_name]}</remote_photo_name>
|
||||||
|
<text>#{data[:text]}</text>
|
||||||
|
<status_message_guid>#{data[:status_message_guid]}</status_message_guid>
|
||||||
|
<height>#{data[:height]}</height>
|
||||||
|
<width>#{data[:width]}</width>
|
||||||
|
</photo>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass" do
|
||||||
|
let(:klass) { Entities::Photo }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
21
spec/lib/diaspora_federation/entities/request_spec.rb
Normal file
21
spec/lib/diaspora_federation/entities/request_spec.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::Request do
|
||||||
|
let(:data) {
|
||||||
|
{sender_id: "alice@somepod.org",
|
||||||
|
recipient_id: "bob@otherpod.net"}
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<request>
|
||||||
|
<sender_handle>alice@somepod.org</sender_handle>
|
||||||
|
<recipient_handle>bob@otherpod.net</recipient_handle>
|
||||||
|
</request>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass" do
|
||||||
|
let(:klass) { Entities::Request }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
65
spec/lib/diaspora_federation/entities/status_message_spec.rb
Normal file
65
spec/lib/diaspora_federation/entities/status_message_spec.rb
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
module DiasporaFederation
|
||||||
|
describe Entities::StatusMessage do
|
||||||
|
let(:photo1) { Entities::Photo.new(FactoryGirl.attributes_for(:photo_entity)) }
|
||||||
|
let(:photo2) { Entities::Photo.new(FactoryGirl.attributes_for(:photo_entity)) }
|
||||||
|
let(:location) { Entities::Location.new(FactoryGirl.attributes_for(:location_entity)) }
|
||||||
|
let(:data) {
|
||||||
|
{
|
||||||
|
raw_message: "this is such an interesting text",
|
||||||
|
photos: [photo1, photo2],
|
||||||
|
location: location,
|
||||||
|
guid: FactoryGirl.generate(:guid),
|
||||||
|
diaspora_id: FactoryGirl.generate(:diaspora_id),
|
||||||
|
public: true,
|
||||||
|
created_at: Time.zone.now,
|
||||||
|
provider_display_name: "something"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
|
<status_message>
|
||||||
|
<raw_message>#{data[:raw_message]}</raw_message>
|
||||||
|
<photo>
|
||||||
|
<guid>#{photo1.guid}</guid>
|
||||||
|
<diaspora_handle>#{photo1.diaspora_id}</diaspora_handle>
|
||||||
|
<public>#{photo1.public}</public>
|
||||||
|
<created_at>#{photo1.created_at}</created_at>
|
||||||
|
<remote_photo_path>#{photo1.remote_photo_path}</remote_photo_path>
|
||||||
|
<remote_photo_name>#{photo1.remote_photo_name}</remote_photo_name>
|
||||||
|
<text>#{photo1.text}</text>
|
||||||
|
<status_message_guid>#{photo1.status_message_guid}</status_message_guid>
|
||||||
|
<height>#{photo1.height}</height>
|
||||||
|
<width>#{photo1.width}</width>
|
||||||
|
</photo>
|
||||||
|
<photo>
|
||||||
|
<guid>#{photo2.guid}</guid>
|
||||||
|
<diaspora_handle>#{photo2.diaspora_id}</diaspora_handle>
|
||||||
|
<public>#{photo2.public}</public>
|
||||||
|
<created_at>#{photo2.created_at}</created_at>
|
||||||
|
<remote_photo_path>#{photo2.remote_photo_path}</remote_photo_path>
|
||||||
|
<remote_photo_name>#{photo2.remote_photo_name}</remote_photo_name>
|
||||||
|
<text>#{photo2.text}</text>
|
||||||
|
<status_message_guid>#{photo2.status_message_guid}</status_message_guid>
|
||||||
|
<height>#{photo2.height}</height>
|
||||||
|
<width>#{photo2.width}</width>
|
||||||
|
</photo>
|
||||||
|
<location>
|
||||||
|
<address>#{location.address}</address>
|
||||||
|
<lat>#{location.lat}</lat>
|
||||||
|
<lng>#{location.lng}</lng>
|
||||||
|
</location>
|
||||||
|
<guid>#{data[:guid]}</guid>
|
||||||
|
<diaspora_handle>#{data[:diaspora_id]}</diaspora_handle>
|
||||||
|
<public>#{data[:public]}</public>
|
||||||
|
<created_at>#{data[:created_at]}</created_at>
|
||||||
|
<provider_display_name>#{data[:provider_display_name]}</provider_display_name>
|
||||||
|
</status_message>
|
||||||
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
|
it_behaves_like "an Entity subclass" do
|
||||||
|
let(:klass) { Entities::StatusMessage }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue