Sha256: 17f0268b21d838bd6d27bf561d6946081df8c59f6b44e615f415c8cea86d9319
Contents?: true
Size: 1.55 KB
Versions: 2
Compression:
Stored size: 1.55 KB
Contents
module Mettlr class Connection def self.connection @connection = Faraday.new('http://api.mettl.com/v1') do |c| c.options.params_encoder = Faraday::FlatParamsEncoder c.request :url_encoded # c.request :json c.response :mashify c.response :json, content_type: /\bjson$/ c.response :logger c.use :instrumentation c.adapter :net_http end end def self.get(path) connection.get do |req| req.path = path req.params['ak'] = Mettlr::METTL_PUBLIC_KEY req.params['ts'] = Time.now.to_i.to_s req.params = Hash[req.params.sort_by {|k,v| k.downcase}] req.params['asgn'] = Mettlr::Signature.new(req).signature end end def self.post(path, options) connection.post do |req| req.path = path req.params['ak'] = Mettlr::METTL_PUBLIC_KEY req.params['ts'] = Time.now.to_i.to_s options.each do |k,v| if v.is_a?(Hash) req.params[k] = v.to_json else req.params[k] = v end end req.params = Hash[req.params.sort_by {|k,v| k.downcase}] req.params['asgn'] = Mettlr::Signature.new(req).signature end end def self.delete(path) connection.delete do |req| req.path = path req.params['ak'] = Mettlr::METTL_PUBLIC_KEY req.params['ts'] = Time.now.to_i.to_s req.params = Hash[req.params.sort_by {|k,v| k.downcase}] req.params['asgn'] = Mettlr::Signature.new(req).signature end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mettlr-0.1.4 | lib/mettlr/connection.rb |
mettlr-0.1.3 | lib/mettlr/connection.rb |