From 70c58f3d7d4672c98f956cfe4f0d95babd5776c8 Mon Sep 17 00:00:00 2001 From: Zack Hobson Date: Fri, 27 Dec 2013 08:16:06 -0800 Subject: fix cancel --- lib/hcl/day_entry.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index 645bb3d..bea1b82 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -21,7 +21,7 @@ module HCl def cancel begin - DayEntry.delete("daily/delete/#{id}") + Net.delete("daily/delete/#{id}") rescue HarvestMiddleware::Failure return false end -- cgit v1.2.3 From 72cca121915b150d093887891f5118808803f704 Mon Sep 17 00:00:00 2001 From: Zack Hobson Date: Fri, 27 Dec 2013 08:27:35 -0800 Subject: fix middleware --- lib/hcl/harvest_middleware.rb | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/hcl/harvest_middleware.rb b/lib/hcl/harvest_middleware.rb index edf3b01..1af6ce0 100644 --- a/lib/hcl/harvest_middleware.rb +++ b/lib/hcl/harvest_middleware.rb @@ -1,6 +1,6 @@ require 'faraday' -class HCl::HarvestMiddleware < Faraday::Middleware +class HCl::HarvestMiddleware < Faraday::Request::BasicAuthentication Faraday.register_middleware harvest: ->{ self } MIME_TYPE = 'application/json'.freeze @@ -9,22 +9,14 @@ class HCl::HarvestMiddleware < Faraday::Middleware require 'escape_utils' end - def initialize app, user, password - super app - @auth = Faraday::Request::BasicAuthentication.new app, user, password - end - def call(env) - # basic authentication - @auth.call(env) - # encode with and accept json env[:request_headers]['Accept'] = MIME_TYPE env[:request_headers]['Content-Type'] = MIME_TYPE env[:body] = Yajl::Encoder.encode(env[:body]) # response processing - @app.call(env).on_complete do |env| + super(env).on_complete do |env| case env[:status] when 200..299 begin -- cgit v1.2.3 From f489d2095b9377ac78d3149c6007265fcbda9727 Mon Sep 17 00:00:00 2001 From: Zack Hobson Date: Fri, 27 Dec 2013 08:51:43 -0800 Subject: net: read-only config --- lib/hcl/net.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/hcl/net.rb b/lib/hcl/net.rb index 67e3086..70a14c7 100644 --- a/lib/hcl/net.rb +++ b/lib/hcl/net.rb @@ -5,19 +5,17 @@ module HCl class << self # configuration accessors CONFIG_VARS = [ :login, :password, :subdomain, :ssl ].freeze - CONFIG_VARS.each { |config_var| attr_accessor config_var } + CONFIG_VARS.each { |config_var| attr_reader config_var } def 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 + def configure opts + @login = opts['login'].freeze + @password = opts['password'].freeze + @subdomain = opts['subdomain'].freeze + @ssl = !!opts['ssl'] end def http -- cgit v1.2.3