diff --git a/.gitignore b/.gitignore index 8c5e48e..0d406a1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ *.a mkmf.log test.rb +Barkfile +*.bark diff --git a/lib/barkdog.rb b/lib/barkdog.rb index bb73be8..d79318f 100644 --- a/lib/barkdog.rb +++ b/lib/barkdog.rb @@ -2,6 +2,7 @@ module Barkdog; end +require 'barkdog/client' require 'barkdog/dsl' require 'barkdog/dsl/context' require 'barkdog/dsl/context/monitor' diff --git a/lib/barkdog/client.rb b/lib/barkdog/client.rb new file mode 100644 index 0000000..aac65e8 --- /dev/null +++ b/lib/barkdog/client.rb @@ -0,0 +1,42 @@ +class Barkdog::Client + def initialize(options = {}) + @options = options + + api_key, app_key = @options.values_at(:api_key, :application_key) + raise 'API Key does not exist' unless api_key + raise 'Application Key does not exist' unless app_key + + @dog = Dogapi::Client.new(api_key, app_key) + end + + def export(export_options = {}) + exported = Barkdog::Exporter.export(@dog, @options) + Barkdog::DSL.convert(exported, @options) + end + + def apply(file) + walk(file) + end + + private + + def walk(file) + expected = load_file(file) + actual = Barkdog::Exporter.export(@dog, @options) + + # XXX: + [expected, actual] + end + + def load_file(file) + if file.kind_of?(String) + open(file) do |f| + Barkdog::DSL.parse(f.read, file) + end + elsif [File, Tempfile].any? {|i| file.kind_of?(i) } + Barkdog::DSL.parse(file.read, file.path) + else + raise TypeError, "can't convert #{file} into File" + end + end +end