Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
yolk committed Jan 27, 2011
0 parents commit e1f1119
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg/*
*.gem
.bundle
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use ruby-1.9.2@aua-mite
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### dev

[full changelog](http://github.com/yolk/aua-mite/compare/v0.0.1...master)

### 0.0.1 / 2011-01-27

* Initial version
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in aua.gemspec
gemspec
45 changes: 45 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
PATH
remote: .
specs:
aua-mite (0.0.1)
aua (>= 0.1.0)

GEM
remote: http://rubygems.org/
specs:
aua (0.1.0)
configuration (1.2.0)
diff-lcs (1.1.2)
growl (1.0.3)
guard (0.3.0)
open_gem (~> 1.4.2)
thor (~> 0.14.6)
guard-rspec (0.1.9)
guard (>= 0.2.2)
launchy (0.3.7)
configuration (>= 0.0.5)
rake (>= 0.8.1)
open_gem (1.4.2)
launchy (~> 0.3.5)
rake (0.8.7)
rb-fsevent (0.3.9)
rspec (2.4.0)
rspec-core (~> 2.4.0)
rspec-expectations (~> 2.4.0)
rspec-mocks (~> 2.4.0)
rspec-core (2.4.0)
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
thor (0.14.6)

PLATFORMS
ruby

DEPENDENCIES
aua (>= 0.1.0)
aua-mite!
growl (>= 1.0.3)
guard-rspec (>= 0.1.9)
rb-fsevent (>= 0.3.9)
rspec (>= 2.4.0)
5 changes: 5 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
guard 'rspec', :version => 2 do
watch(/^spec\/(.*)_spec\.rb/) { "spec" }
watch(/^lib\/(.*)\.rb/) { "spec" } # { |m| "spec/#{m[1]}_spec.rb" }
watch(/^spec\/spec_helper\.rb/) { "spec" }
end
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 Yolk Sebastian Munz & Julia Soergel GbR

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
aua-mite
=============

Extension for [aua](https://github.com/yolk/aua) to recognize custom mite api clients by there user agent string.

Not very useful for anyone outside of mite/yolk. But maybe handy as a example of extending aua.

Installation
-------

gem install aua-mite


BlaBla
-------

Copyright (c) 2011 Yolk Sebastian Munz & Julia Soergel GbR

Beyond that, the implementation is licensed under the MIT License.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
28 changes: 28 additions & 0 deletions aua-mite.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "aua-mite/version"

Gem::Specification.new do |s|
s.name = "aua-mite"
s.version = AuaMite::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Sebastian Munz"]
s.email = ["sebastian@yo.lk"]
s.homepage = "https://github.com/yolk/aua-mite"
s.summary = %q{Extension for aua to recognize custom mite api clients by there user agent string.}
s.description = %q{Extension for aua (https://github.com/yolk/aua) to recognize custom mite api clients by there user agent string. Not very useful for anyone outside of mite/yolk. But maybe handy as a example of extending aua.}

s.rubyforge_project = "aua-mite"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency 'aua', '>= 0.1.0'

s.add_development_dependency 'rspec', '>= 2.4.0'
s.add_development_dependency 'guard-rspec', '>=0.1.9'
s.add_development_dependency 'growl', '>=1.0.3'
s.add_development_dependency 'rb-fsevent', '>=0.3.9'
end
3 changes: 3 additions & 0 deletions lib/aua-mite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'aua'
require 'aua-mite/version'
require 'aua-mite/agents'
6 changes: 6 additions & 0 deletions lib/aua-mite/agents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dir["#{File.dirname(__FILE__)}/agents/*.rb"].each do |agent|
require(agent)
end

Aua::Agents.default << Aua::Agents::Fuerst << Aua::Agents::MiteGo <<
Aua::Agents::StandardMiteClient << Aua::Agents::AllMite
20 changes: 20 additions & 0 deletions lib/aua-mite/agents/all_mite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Aua::Agents::AllMite

PATTERN = /^All\.mite\-v([\d\.]+)/

def self.extend?(agent)
agent.app =~ PATTERN
end

def type
:ApiClient
end

def name
@name ||= :"All.mite"
end

def version
@version ||= app =~ PATTERN && $1
end
end
22 changes: 22 additions & 0 deletions lib/aua-mite/agents/fuerst.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Aua::Agents::Fuerst

def self.extend?(agent)
agent.app == "DynaMite" || agent.app == "GrandTotal" ||
agent.app =~ /^DynaMite/ || agent.app =~ /^GrandTotal/
end

def type
:ApiClient
end

def name
@name ||= app =~ /^GrandTotal/ ? :GrandTotal : :DynaMite
end

def version
@version ||= begin
return versions.first if app == "DynaMite" || app == "GrandTotal"
app.sub(/^DynaMite|GrandTotal/, "")
end
end
end
37 changes: 37 additions & 0 deletions lib/aua-mite/agents/mite_go.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Aua::Agents::MiteGo

def self.extend?(agent)
agent.app == "mite.go" &&
((agent.products.index("Darwin") && agent.products[agent.products.index("Darwin")] = "NoDarwin") || true)
end

def type
:ApiClient
end

def name
@name ||= :"mite.go"
end

def platform
@platform ||= begin
if app_comments.first =~ /^iPod/
:iPod
else
:iPhone
end
end
end

def os_version
@os_version ||= begin
if app_comments[1] =~ /iPhone OS ([\d\.]+)/
$1
end
end
end

def os_name
:iOS
end
end
21 changes: 21 additions & 0 deletions lib/aua-mite/agents/standard_mite_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Aua::Agents::StandardMiteClient

KNOWN_CLIENTS = %w(mite.php mite.desk mite-rb jmite Redmine2mite Mantis2mite Billomat hearttp centralstationcrm)

def self.extend?(agent)
KNOWN_CLIENTS.include?(agent.app)
end

def type
return :HttpChecker if app == "hearttp"
:ApiClient
end

def name
@name ||= app.to_sym
end

def version
super
end
end
3 changes: 3 additions & 0 deletions lib/aua-mite/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module AuaMite
VERSION = '0.0.1'
end
5 changes: 5 additions & 0 deletions spec/aua-mite_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe AuaMite do

end
66 changes: 66 additions & 0 deletions spec/aua_mite_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'spec_helper'
require 'aua/extensions/mite'

describe "Mite Extension" do

EXAMPLES_MITE = {
# DynaMite
"DynaMite/2.0.2 CFNetwork/454.11.5 Darwin/10.6.0 (i386) (MacBookPro4%2C1)" =>
{ :type => :ApiClient, :name => :DynaMite, :version => "2.0.2", :os_name => :MacOSX, :os_version => "10.6.6", :platform => :Macintosh },
"DynaMite/2.0b5 CFNetwork/454.11.5 Darwin/10.6.0 (i386) (iMac10%2C1)" =>
{ :type => :ApiClient, :name => :DynaMite, :version => "2.0b5", :os_name => :MacOSX, :os_version => "10.6.6", :platform => :Macintosh },
"DynaMite2.0.3 CFNetwork/438.14 Darwin/9.8.0 (i386) (iMac7%2C1)" =>
{ :type => :ApiClient, :name => :DynaMite, :version => "2.0.3", :os_name => :MacOSX, :os_version => "10.5.8", :platform => :Macintosh },

# Billomat
"Billomat" =>
{ :type => :ApiClient, :name => :Billomat, :version => nil, :os_name => nil, :os_version => nil, :platform => nil },

# All.mite
"All.mite-v1.4.0.0" =>
{ :type => :ApiClient, :name => :"All.mite", :version => "1.4.0.0", :os_name => nil, :os_version => nil, :platform => nil },

# Standard mite clients
"mite.php/v1.2" =>
{ :type => :ApiClient, :name => :"mite.php", :version => "v1.2", :os_name => nil, :os_version => nil, :platform => nil },
"mite.desk/1.2.14" =>
{ :type => :ApiClient, :name => :"mite.desk", :version => "1.2.14", :os_name => nil, :os_version => nil, :platform => nil },
"mite-rb/0.3.0" =>
{ :type => :ApiClient, :name => :"mite-rb", :version => "0.3.0", :os_name => nil, :os_version => nil, :platform => nil },
"jmite/0.1" =>
{ :type => :ApiClient, :name => :"jmite", :version => "0.1", :os_name => nil, :os_version => nil, :platform => nil },
"Redmine2mite/v1.2.1" =>
{ :type => :ApiClient, :name => :"Redmine2mite", :version => "v1.2.1", :os_name => nil, :os_version => nil, :platform => nil },
"Mantis2mite/v1.2.4" =>
{ :type => :ApiClient, :name => :"Mantis2mite", :version => "v1.2.4", :os_name => nil, :os_version => nil, :platform => nil },
"GrandTotal/1.6.5b2 CFNetwork/454.11.5 Darwin/10.6.0 (i386) (iMac11%2C1)" =>
{ :type => :ApiClient, :name => :GrandTotal, :version => "1.6.5b2", :os_name => :MacOSX, :os_version => "10.6.6", :platform => :Macintosh },
"GrandTotal1.6.4 CFNetwork/438.16 Darwin/9.8.0 (i386) (MacBook5%2C2)" =>
{ :type => :ApiClient, :name => :GrandTotal, :version => "1.6.4", :os_name => :MacOSX, :os_version => "10.5.8", :platform => :Macintosh },
"centralstationcrm" =>
{ :type => :ApiClient, :name => :centralstationcrm, :version => nil, :os_name => nil, :os_version => nil, :platform => nil },

# mite.go
"mite.go/1.0 CFNetwork/459 Darwin/10.0.0d3" =>
{ :type => :ApiClient, :name => :"mite.go", :version => "1.0", :os_name => :iOS, :os_version => nil, :platform => :iPhone },
"mite.go/1.1 (iPhone1,2; iPhone OS 4.2.1; de)" =>
{ :type => :ApiClient, :name => :"mite.go", :version => "1.1", :os_name => :iOS, :os_version => "4.2.1", :platform => :iPhone },

# hearttp
"hearttp/0.0.1" =>
{ :type => :HttpChecker, :name => :"hearttp", :version => "0.0.1", :os_name => nil, :os_version => nil, :platform => nil}
}

EXAMPLES_MITE.each do |string, values|
context "when parsing #{string.inspect}" do
let(:user_agent) { Aua.parse(string) }
values.each do |key, value|
it "should return #{value} for #{key}" do
user_agent.send(key).should eql(value)
end
end
end
end

end

3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rspec'
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)) + '/../../aua/lib/')
require File.dirname(__FILE__) + '/../lib/aua-mite.rb'

0 comments on commit e1f1119

Please sign in to comment.