Skip to content

Commit

Permalink
Add client
Browse files Browse the repository at this point in the history
  • Loading branch information
Genki Sugawara committed May 17, 2015
1 parent 53b6e39 commit 335f305
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,5 @@
*.a
mkmf.log
test.rb
Barkfile
*.bark
1 change: 1 addition & 0 deletions lib/barkdog.rb
Expand Up @@ -2,6 +2,7 @@

module Barkdog; end

require 'barkdog/client'
require 'barkdog/dsl'
require 'barkdog/dsl/context'
require 'barkdog/dsl/context/monitor'
Expand Down
42 changes: 42 additions & 0 deletions 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

0 comments on commit 335f305

Please sign in to comment.