Class: HCl::Net
- Inherits:
-
Object
- Object
- HCl::Net
- Defined in:
- lib/hcl/net.rb
Constant Summary collapse
- CONFIG_VARS =
configuration accessors
[ :login, :password, :subdomain ].freeze. each { |config_var| attr_reader config_var }
Instance Method Summary collapse
- #config_hash ⇒ Object
- #delete(action) ⇒ Object
- #get(action) ⇒ Object
-
#initialize(opts) ⇒ Net
constructor
A new instance of Net.
- #post(action, data) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Net
Returns a new instance of Net.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hcl/net.rb', line 14 def initialize opts @login = opts['login'].freeze @password = opts['password'].freeze @subdomain = opts['subdomain'].freeze @http = Faraday.new( "https://#{subdomain}.harvestapp.com" ) do |f| f.use :harvest, login, password if opts['test_adapter'] f.adapter :test, opts['test_adapter'] else f.adapter Faraday.default_adapter end end end |
Instance Method Details
#config_hash ⇒ Object
10 11 12 |
# File 'lib/hcl/net.rb', line 10 def config_hash CONFIG_VARS.inject({}) {|c,k| c.update(k => send(k)) } end |
#delete(action) ⇒ Object
38 39 40 |
# File 'lib/hcl/net.rb', line 38 def delete action @http.delete(action).body end |
#get(action) ⇒ Object
30 31 32 |
# File 'lib/hcl/net.rb', line 30 def get action @http.get(action).body end |
#post(action, data) ⇒ Object
34 35 36 |
# File 'lib/hcl/net.rb', line 34 def post action, data @http.post(action, data).body end |