summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hcl/commands.rb3
-rw-r--r--lib/hcl/net.rb73
2 files changed, 34 insertions, 42 deletions
diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb
index cf8ddc5..98daff5 100644
--- a/lib/hcl/commands.rb
+++ b/lib/hcl/commands.rb
@@ -7,8 +7,7 @@ module HCl
# Display a sanitized view of your auth credentials.
def config
- Net.config_hash.merge(password:'***').
- map {|k,v| "#{k}: #{v}" }.join("\n")
+ Net.config_hash.merge(password:'***').map {|k,v| "#{k}: #{v}" }.join("\n")
end
def tasks project_code=nil
diff --git a/lib/hcl/net.rb b/lib/hcl/net.rb
index 2339f1d..874240c 100644
--- a/lib/hcl/net.rb
+++ b/lib/hcl/net.rb
@@ -2,54 +2,47 @@ require 'faraday_middleware'
module HCl
module Net
- # configuration accessors
- CONFIG_VARS = [ :login, :password, :subdomain, :ssl ].freeze
- CONFIG_VARS.each do |config_var|
- class_eval <<-EOC
- def self.#{config_var}= arg
- @@#{config_var} = arg
- end
- def self.#{config_var}
- @@#{config_var}
- end
- EOC
- end
+ class << self
+ # configuration accessors
+ CONFIG_VARS = [ :login, :password, :subdomain, :ssl ].freeze
+ CONFIG_VARS.each { |config_var| attr_accessor config_var }
- def self.configure opts = nil
- if opts
- self.login = opts['login']
- self.password = opts['password']
- self.subdomain = opts['subdomain']
- self.ssl = opts['ssl']
+ def config_hash
+ CONFIG_VARS.inject({}) {|c,k| c.update(k => send(k)) }
end
- end
- def self.config_hash
- CONFIG_VARS.inject({}) {|c,k| c.update(k => send(k)) }
- end
+ def configure opts = nil
+ if opts
+ self.login = opts['login']
+ self.password = opts['password']
+ self.subdomain = opts['subdomain']
+ self.ssl = opts['ssl']
+ end
+ end
- def self.faraday
- @faraday ||= Faraday.new(
- "http#{ssl && 's'}://#{subdomain}.harvestapp.com"
- ) do |f|
- f.headers['Accept'] = 'application/json'
- f.request :json
- f.request :basic_auth, login, password
- f.use HCl::HarvestMiddleware, content_type: /\bjson\b/
- f.adapter Faraday.default_adapter
+ def faraday
+ @faraday ||= Faraday.new(
+ "http#{ssl && 's'}://#{subdomain}.harvestapp.com"
+ ) do |f|
+ f.headers['Accept'] = 'application/json'
+ f.request :json
+ f.request :basic_auth, login, password
+ f.use HCl::HarvestMiddleware, content_type: /\bjson\b/
+ f.adapter Faraday.default_adapter
+ end
end
- end
- def self.get action
- faraday.get(action).body
- end
+ def get action
+ faraday.get(action).body
+ end
- def self.post action, data
- faraday.post(action, data).body
- end
+ def post action, data
+ faraday.post(action, data).body
+ end
- def self.delete action
- faraday.delete(action).body
+ def delete action
+ faraday.delete(action).body
+ end
end
end
end