-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a03d21a
commit d29d47e
Showing
6 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
require "hipmost/version" | ||
|
||
module Hipmost | ||
# Your code goes here... | ||
class CLI | ||
def self.run(args) | ||
binding.pry | ||
new(**args).run | ||
end | ||
|
||
def initialize(path:, rooms:) | ||
@path = Pathname.new(path).expand_path | ||
@outpath = @path.join("..", "out").expand_path | ||
@rooms = rooms | ||
end | ||
|
||
def run | ||
load_metadata | ||
|
||
parse_rooms | ||
|
||
save | ||
end | ||
|
||
def load_metadata | ||
@users = UserRepository.load_from(@path) | ||
@rooms = RoomRepository.load_from(@path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'json' | ||
|
||
module Hipmost | ||
class RoomRepository | ||
attr_accessor :rooms, :name_index | ||
extend Forwardable | ||
|
||
def_delegators :@rooms, :size, :[], :select | ||
|
||
|
||
def load_from(path) | ||
new(path).load | ||
end | ||
|
||
def initialize(path) | ||
@path = Pathname.new(path).join("rooms.json") | ||
@rooms = {} | ||
@name_index = {} | ||
end | ||
|
||
def load(data = file_data) | ||
json = JSON.load(data) | ||
|
||
json.each do |room_obj| | ||
room = room_obj["Room"] | ||
@rooms[room["id"]] = Room.new(room) | ||
@name_index[room["name"]] = room["id"] | ||
end | ||
end | ||
|
||
def find_by_name(name) | ||
self[name_index[name]] | ||
end | ||
|
||
def file_data | ||
File.read(@path) | ||
end | ||
|
||
class Room | ||
def initialize(attrs) | ||
@id = attrs["id"] | ||
@attrs = attrs | ||
end | ||
attr_reader :id, :attrs | ||
|
||
def method_missing(method) | ||
attrs[method.to_s] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ def inactive? | |
end | ||
|
||
def method_missing(method) | ||
attrs[method] | ||
attrs[method.to_s] | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require_relative '../lib/hipmost/room_repository' | ||
|
||
RSpec.describe Hipmost::RoomRepository do | ||
it "loads room data" do | ||
repo = described_class.new(".") | ||
repo.load(data) | ||
|
||
expect(repo.size).to eq(2) | ||
|
||
room = repo[206455] | ||
expect(room).to be_a(Hipmost::RoomRepository::Room) | ||
|
||
room_by_name = repo.find_by_name(room.name) | ||
expect(room_by_name).to eq(room) | ||
end | ||
|
||
let(:data) do | ||
<<-JSON | ||
[ | ||
{ | ||
"Room": { | ||
"created": "2013-05-27T13:29:02+00:00", | ||
"guest_access_url": null, | ||
"id": 206455, | ||
"is_archived": false, | ||
"members": [ | ||
752160, | ||
1002528, | ||
844771, | ||
340070, | ||
1017103, | ||
340825 | ||
], | ||
"name": "Orbital Impact", | ||
"owner": 340070, | ||
"participants": [], | ||
"privacy": "private", | ||
"topic": "Welcome! Send this link to coworkers who need accounts: https://www.hipchat.com/invite/50371/3c380f069e21ba92e3441c57952e4ed0" | ||
} | ||
}, | ||
{ | ||
"Room": { | ||
"created": "2013-05-28T14:12:28+00:00", | ||
"guest_access_url": null, | ||
"id": 206977, | ||
"is_archived": false, | ||
"members": [], | ||
"name": "CFXWare", | ||
"owner": 340070, | ||
"participants": [], | ||
"privacy": "public", | ||
"topic": "CFXWare" | ||
} | ||
} | ||
] | ||
JSON | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters