ruby-fogbugz 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-fogbugz.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # ruby-fogbugz
2
+
3
+ Readme coming soon to a repo near you.
4
+
5
+ For now, check out [Foghub](https://github.com/firmafon/foghub) where this was extracted from for usage.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "lib"
7
+ t.libs << "test"
8
+ t.pattern = "test/**/*_test.rb"
9
+ end
data/lib/fogbugz.rb ADDED
@@ -0,0 +1,14 @@
1
+ require_relative 'ruby_fogbugz/adapters/http/typhoeus'
2
+ require_relative 'ruby_fogbugz/adapters/xml/cracker'
3
+ require_relative 'ruby_fogbugz/interface'
4
+
5
+ module Fogbugz
6
+ class << self
7
+ attr_accessor :adapter
8
+ end
9
+
10
+ self.adapter = {
11
+ :xml => Adapter::XML::Cracker,
12
+ :http => Adapter::HTTP::Typhoeuser
13
+ }
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'typhoeus'
2
+
3
+ module Fogbugz
4
+ module Adapter
5
+ module HTTP
6
+ class Typhoeuser
7
+ attr_accessor :uri, :requester
8
+
9
+ def initialize(options = {})
10
+ @uri = options[:uri]
11
+ @requester = Typhoeus::Request
12
+ end
13
+
14
+ def request(action, options)
15
+ params = {:cmd => action}.merge(options[:params])
16
+ query = @requester.get("#{uri}/api.asp",
17
+ :params => params)
18
+ query.body
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'crack/xml'
2
+
3
+ module Fogbugz
4
+ module Adapter
5
+ module XML
6
+ class Cracker
7
+ def self.parse(xml)
8
+ Crack::XML.parse(xml)["response"]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ module Fogbugz
2
+ class Interface
3
+ class RequestError < StandardError; end
4
+ class InitializationError < StandardError; end
5
+
6
+ attr_accessor :options, :http, :xml, :token
7
+
8
+ def initialize(options = {})
9
+ @options = {}.merge(options)
10
+
11
+ raise InitializationError, "Must supply URI (e.g. http://fogbugz.company.com)" unless options[:uri]
12
+ @http = Fogbugz.adapter[:http].new(:uri => options[:uri])
13
+ @xml = Fogbugz.adapter[:xml]
14
+ end
15
+
16
+ def authenticate
17
+ response = @http.request :logon, {
18
+ :params => {
19
+ :email => @options[:email],
20
+ :password => @options[:password]
21
+ }
22
+ }
23
+
24
+ @token ||= @xml.parse(response)["token"]
25
+ end
26
+
27
+ def command(action, parameters = {})
28
+ raise RequestError, 'No token available, #authenticate first' unless @token
29
+ parameters[:token] = @token
30
+
31
+ response = @http.request action, {
32
+ :params => parameters.merge(options[:params] || {})
33
+ }
34
+
35
+ @xml.parse(response)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Fogbugz
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ruby_fogbugz/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ruby-fogbugz"
7
+ s.version = Fogbugz::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Simon Hørup Eskildsen"]
10
+ s.email = ["sirup@sirupsen.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Ruby wrapper for the Fogbugz API }
13
+ s.description = %q{A simple Ruby wrapper for the Fogbugz XML API}
14
+
15
+ s.rubyforge_project = "ruby-fogbugz"
16
+
17
+ s.add_dependency('typhoeus')
18
+ s.add_dependency('crack')
19
+
20
+ s.add_development_dependency('minitest')
21
+ s.add_development_dependency('mocha')
22
+
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../../test_helper.rb'
2
+ require 'ruby_fogbugz/adapters/http/typhoeus'
3
+
4
+ class Typhoeuser < FogTest
5
+ test '#request should order the params right' do
6
+ response = mock()
7
+ response.expects(:body)
8
+
9
+ t = Fogbugz::Adapter::HTTP::Typhoeuser.new(:uri => 'http://test.com')
10
+ t.requester.expects(:get).returns(response)
11
+ t.request(:action, :params => {:one => "two", :three => "four"})
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../../test_helper.rb'
2
+ require 'ruby_fogbugz/adapters/xml/cracker'
3
+
4
+ class Cracker < FogTest
5
+ test 'should parse XML and get rid of the response namespace' do
6
+ XML = <<-xml
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <response>
9
+ <version>2</version>
10
+ </response>
11
+ xml
12
+
13
+ assert_equal({"version" => "2"}, Fogbugz::Adapter::XML::Cracker.parse(XML))
14
+ end
15
+ end
@@ -0,0 +1,61 @@
1
+ require_relative './test_helper.rb'
2
+
3
+ class FogTest
4
+ CREDENTIALS = {
5
+ :email => "test@test.com",
6
+ :password => 'seekrit',
7
+ :uri => 'http://fogbugz.test.com'
8
+ }
9
+ end
10
+
11
+ class BasicInterface < FogTest
12
+ def setup
13
+ Fogbugz.adapter[:http] = mock()
14
+ Fogbugz.adapter[:http].expects(:new)
15
+
16
+ Fogbugz.adapter[:xml] = mock()
17
+
18
+ @fogbugz = Fogbugz::Interface.new(CREDENTIALS)
19
+ end
20
+
21
+ test 'when instantiating options should be overwriting and be publicly available' do
22
+ assert_equal CREDENTIALS, @fogbugz.options
23
+ end
24
+ end
25
+
26
+ class InterfaceRequests < FogTest
27
+ def setup
28
+ Fogbugz.adapter[:http].expects(:new)
29
+ end
30
+
31
+ test 'authentication should send correct parameters' do
32
+
33
+ fogbugz = Fogbugz::Interface.new(CREDENTIALS)
34
+ fogbugz.http.expects(:request).with(:logon,
35
+ :params => {
36
+ :email => CREDENTIALS[:email],
37
+ :password => CREDENTIALS[:password]
38
+ }).returns("token")
39
+
40
+ fogbugz.xml.expects(:parse).with("token").returns({"token" => "22"})
41
+
42
+ fogbugz.authenticate
43
+ end
44
+
45
+ test 'requesting with an action should send along token and correct parameters' do
46
+ fogbugz = Fogbugz::Interface.new(CREDENTIALS)
47
+ fogbugz.token = 'token'
48
+ fogbugz.http.expects(:request).with(:search, {:params => {:q => 'case', :token => 'token'}}).returns("omgxml")
49
+ fogbugz.xml.expects(:parse).with("omgxml")
50
+ fogbugz.command(:search, :q => 'case')
51
+ end
52
+
53
+ test 'throws an exception if #command is requested with no token' do
54
+ fogbugz = Fogbugz::Interface.new(CREDENTIALS)
55
+ fogbugz.token = nil
56
+
57
+ assert_raises Fogbugz::Interface::RequestError do
58
+ fogbugz.command(:search, :q => 'case')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ gem 'minitest' # ensures you're using the gem, and not the built in MT
3
+ $: << File.expand_path(File.dirname(__FILE__) + "../lib")
4
+
5
+ require 'minitest/autorun'
6
+ require 'minitest/pride'
7
+ require 'mocha'
8
+
9
+ require 'fogbugz'
10
+
11
+ class FogTest < MiniTest::Unit::TestCase
12
+ def self.test(description, &block)
13
+ define_method("test_" + description.split.join('_').gsub(/\W/, ''), block)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-fogbugz
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - "Simon H\xC3\xB8rup Eskildsen"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-22 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: typhoeus
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: crack
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: minitest
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: mocha
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
60
+ description: A simple Ruby wrapper for the Fogbugz XML API
61
+ email:
62
+ - sirup@sirupsen.com
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - lib/fogbugz.rb
75
+ - lib/ruby_fogbugz/adapters/http/typhoeus.rb
76
+ - lib/ruby_fogbugz/adapters/xml/cracker.rb
77
+ - lib/ruby_fogbugz/interface.rb
78
+ - lib/ruby_fogbugz/version.rb
79
+ - ruby-fogbugz.gemspec
80
+ - test/adapters/http/typhoeus_test.rb
81
+ - test/adapters/xml/crack_test.rb
82
+ - test/interface_test.rb
83
+ - test/test_helper.rb
84
+ has_rdoc: true
85
+ homepage: ""
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project: ruby-fogbugz
108
+ rubygems_version: 1.6.2
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Ruby wrapper for the Fogbugz API
112
+ test_files:
113
+ - test/adapters/http/typhoeus_test.rb
114
+ - test/adapters/xml/crack_test.rb
115
+ - test/interface_test.rb
116
+ - test/test_helper.rb