Sha256: 3d45a5ac122baee5bac8a813434f6099f14e8cb89a2ad45e9732fd0bf3c4ee4e

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

class TMS::Connection
  attr_accessor :username, :password, :api_root, :connection, :logger

  def get(href)
    resp = connection.get("#{href}.json")
    if resp.status != 200
      raise RecordNotFound.new("Could not find resource at #{href} (status #{resp.status})")
    else
      resp.body
    end
  end

  def initialize(opts={})
    self.username = opts[:username]
    self.password = opts[:password]
    self.api_root = opts[:api_root]
    self.logger   = opts[:logger]
    setup_connection
  end

  def setup_connection
    self.connection = Faraday.new(:url => self.api_root) do |faraday|
      faraday.use TMS::Logger, self.logger if self.logger
      faraday.request :json
      faraday.basic_auth(self.username, self.password)
      faraday.response :json, :content_type => /\bjson$/
      faraday.adapter :net_http
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tms_client-0.1.1 lib/tms_client/connection.rb
tms_client-0.1.0 lib/tms_client/connection.rb
tms_client-0.0.3 lib/tms_client/connection.rb
tms_client-0.0.2 lib/tms_client/connection.rb