lib/mite-rb.rb in mite-rb-0.2.4 vs lib/mite-rb.rb in mite-rb-0.3.0

- old
+ new

@@ -1,15 +1,16 @@ require 'active_support' require 'active_resource' +require 'yaml' # The official ruby library for interacting with the RESTful API of mite, # a sleek time tracking webapp. module Mite class << self - attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port + attr_accessor :email, :password, :host_format, :domain_format, :protocol, :port, :user_agent attr_reader :account, :key # Sets the account name, and updates all resources with the new domain. def account=(name) resources.each do |klass| @@ -34,10 +35,18 @@ resources.each do |klass| klass.headers['X-MiteApiKey'] = value end @key = value end + + # Sets the mite.user_agent for all resources. + def user_agent=(user_agent) + resources.each do |klass| + klass.headers['User-Agent'] = user_agent + end + @user_agent = user_agent + end def resources @resources ||= [] end @@ -50,16 +59,26 @@ # Same as validate_connection # but raises http-error when connection is invalid def validate! !!Mite::Account.find end + + def version + @version ||= begin + config = YAML.load(File.read(File.join(File.dirname(__FILE__), "..", "VERSION.yml"))) + "#{config[:major]}.#{config[:minor]}.#{config[:patch]}" + rescue + "0.0.0" + end + end end self.host_format = '%s://%s%s' self.domain_format = '%s.mite.yo.lk' self.protocol = 'http' self.port = '' + self.user_agent = "mite-rb/#{Mite.version}" class MethodNotAvaible < StandardError; end module ResourceWithoutWriteAccess def save @@ -98,9 +117,10 @@ unless base == Mite::SingletonBase Mite.resources << base class << base attr_accessor :site_format end + base.headers['User-Agent'] = Mite.user_agent base.site_format = '%s' base.timeout = 20 end super end