fiddler 0.0.1alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ Fiddler
2
+ =======
3
+
4
+ Ruby gem to provide an easy interface to Request Tracker Installation.
5
+
6
+ Supported Versions of Request Tracker
7
+ -------------------------------------
8
+ * 4.0.4
9
+
10
+ License
11
+ -------
12
+ Do you what-ever you can with this product license.
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Fiddler'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,6 @@
1
+ require 'fiddler/configuration'
2
+ require 'fiddler/helper'
3
+ require 'fiddler/errors'
4
+ require 'fiddler/parsers'
5
+ require 'fiddler/ticket'
6
+ require 'fiddler/connection_manager'
@@ -0,0 +1,20 @@
1
+ module Fiddler
2
+ # Based on the Clearance gem configuration - https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
3
+ class Configuration
4
+ attr_accessor :server_url, :username, :password, :use_cookies, :cookie_domain, :ssl_verify
5
+
6
+ def initialize
7
+ @use_cookies = false
8
+ @ssl_verify = true
9
+ end
10
+ end
11
+
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configure
17
+ self.configuration ||= Configuration.new
18
+ yield configuration
19
+ end
20
+ end
@@ -0,0 +1,64 @@
1
+ require 'httpclient'
2
+
3
+ module Fiddler
4
+ module ConnectionManager
5
+
6
+ class Connection
7
+ attr_accessor :client
8
+ def initialize
9
+ @client = HTTPClient.new
10
+ @client.set_cookie_store("cookies.dat")
11
+ end
12
+
13
+ def base_url
14
+ "#{Fiddler.configuration.server_url}/REST/1.0/"
15
+ end
16
+
17
+ def get(url,options)
18
+ url = "#{base_url}#{url}"
19
+ @client.get(url,options_with_login(options)).content
20
+ end
21
+
22
+ def post
23
+ end
24
+
25
+ def options_with_login(options)
26
+ unless Fiddler.configuration.use_cookies
27
+ options.merge({ :user => Fiddler.configuration.username, :pass => Fiddler.configuration.password })
28
+ end
29
+ end
30
+ end
31
+
32
+ class << self
33
+ attr_accessor :client_connection
34
+
35
+ def connection
36
+ self.client_connection ||= Connection.new
37
+ end
38
+
39
+ def get(url,options={})
40
+ check_config
41
+ connection.get(url,options)
42
+ end
43
+
44
+ def post(url,data,options={})
45
+ check_config
46
+ connection.post(url,options)
47
+ end
48
+
49
+ protected
50
+
51
+ def check_config
52
+ config = Fiddler.configuration
53
+ raise InvalidConfigurationError unless Helper.valid?(config.server_url)
54
+ unless Helper.valid?(config.username) and Helper.valid?(config.password)
55
+ raise InvalidConfigurationError unless config.use_cookies
56
+ end
57
+ end
58
+
59
+ def debug
60
+ end
61
+
62
+ end # end class method definitions
63
+ end # end ConnectionManager module definition
64
+ end # end main module
@@ -0,0 +1,6 @@
1
+ module Fiddler
2
+ class FiddlerError < StandardError; end
3
+ class TicketNotFoundError < StandardError; end
4
+ class InvalidConfigurationError < StandardError; end
5
+ class TicketAccessDeniedError < StandardError; end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Fiddler
2
+ module Helper
3
+ class << self
4
+ def valid?(value)
5
+ ( value.nil? or value == "" ) ? false : true
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'fiddler/parsers/base_parser'
2
+ require 'fiddler/parsers/ticket_parser'
@@ -0,0 +1,14 @@
1
+ module Fiddler
2
+ module Parsers
3
+ class BaseParser
4
+ def self.successful?(response)
5
+ lines = response.split("\n")
6
+ lines.first =~ /200/ ? true : false
7
+ end
8
+
9
+ def self.message(response)
10
+ # strip out the message from the first line and return it
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module Fiddler
2
+ module Parsers
3
+ class TicketParser < BaseParser
4
+ def self.parse(response)
5
+ success = self.successful?(response)
6
+ puts success ? "Successful" : "Failed"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,49 @@
1
+ module Fiddler
2
+ class Ticket
3
+ attr_accessor :id, :subject, :status, :queue, :owner, :creator, :histories, :content, :last_updated
4
+
5
+ # Initializes a new instance of ticket object
6
+ #
7
+ # @params [Hash] of the initial options
8
+ def initialize(options={})
9
+ options = { :queue => "General", :owner => "Nobody", :status => "new"}.merge options
10
+ options.each do |key,value|
11
+ send "#{key}=", value
12
+ end
13
+ @id = "ticket/new"
14
+ end
15
+
16
+ # Class methods
17
+ class << self
18
+ # Gets the ticket with given id
19
+ #
20
+ # @params [int] id for the ticket
21
+ # @returns [Ticket] returns ticket the ticket object
22
+ def get(id)
23
+ url = "ticket/#{id}"
24
+ response = Fiddler::ConnectionManager.get(url)
25
+ ticket = Fiddler::Parsers::TicketParser.parse(response)
26
+ end
27
+
28
+ # Creates a new ticket with the given options, it will not save the ticket
29
+ #
30
+ # @params [Hash] of the options to be added to the new ticket
31
+ # @returns [Ticket] returns new ticket object
32
+ def create(options)
33
+ end
34
+
35
+ # Saves the changes to the ticket object
36
+ #
37
+ # @returns [boolean] save succcessful or not
38
+ def save
39
+ end
40
+
41
+ # Find the tickets with the given options
42
+ #
43
+ # @params [Hash] of options
44
+ # @returns [Array<Ticket>] of ticket matching the criteria
45
+ def find(options={})
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Fiddler
2
+ VERSION = "0.0.1alpha"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :fiddler do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,17 @@
1
+ def test_config
2
+ Fiddler.configure do |config|
3
+ config.server_url = "http://ticketsdev.cybersecure.local/rt/"
4
+ config.username = "jais.cheema"
5
+ config.password = "killzone"
6
+ end
7
+ end
8
+
9
+ def reset_config
10
+ Fiddler.configure do |config|
11
+ config.server_url = nil
12
+ config.username = nil
13
+ config.password = nil
14
+ config.use_cookies = false
15
+ config.ssl_verify = true
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fiddler::Configuration do
4
+ describe 'when no options are given' do
5
+ before do
6
+ Fiddler.configure do |config|
7
+ end
8
+ end
9
+
10
+ it 'defaults to using no cookies' do
11
+ Fiddler.configuration.use_cookies.should be_false
12
+ end
13
+
14
+ it 'defaults to verifying the ssl connection' do
15
+ Fiddler.configuration.ssl_verify.should be_true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fiddler::ConnectionManager do
4
+ before do
5
+ reset_config
6
+ end
7
+
8
+ describe "without proper config" do
9
+ it "should raise invalid Configuration error for missing configuration" do
10
+ Fiddler.configure do |config|
11
+ end
12
+ expect { Fiddler::ConnectionManager.get("https://www.google.com") }.to raise_error(Fiddler::InvalidConfigurationError)
13
+ end
14
+
15
+ it "should raise invalid Configuration error for missing credentials if cookies are not enabled" do
16
+ Fiddler.configure do |config|
17
+ config.server_url = "https://some_server"
18
+ end
19
+ expect { Fiddler::ConnectionManager.get("https://www.google.com") }.to raise_error(Fiddler::InvalidConfigurationError)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ PROJECT_ROOT = File.expand_path('../..', __FILE__)
2
+ $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
3
+
4
+ require 'fiddler'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ config.order = 'random'
11
+ end
12
+
13
+ # create a file named config.rb here with the two methods
14
+ # def test_config
15
+ # Fiddler.configure do |config|
16
+ # config.server_url = "some_url"
17
+ # config.username = "username"
18
+ # config.password = "password"
19
+ # end
20
+ # end
21
+ # def reset_config
22
+ # Fiddler.configure do |config|
23
+ # config.server_url = nil
24
+ # config.username = nil
25
+ # config.password = nil
26
+ # config.use_cookies = false
27
+ # config.ssl_verify = true
28
+ # end
29
+ # end
30
+
31
+ require 'config'
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fiddler::Ticket do
4
+ before do
5
+ test_config
6
+ end
7
+
8
+ it "should find a ticket with given id" do
9
+ Fiddler::Ticket.get(4200).should_not be_nil
10
+ end
11
+
12
+ it "should raise exception for invalid id" do
13
+ expect { Fiddler::Ticket.get(50000) }.to raise_error(Fiddler::TicketNotFoundError)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiddler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 5
5
+ version: 0.0.1alpha
6
+ platform: ruby
7
+ authors:
8
+ - Jais Cheema
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-10-03 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httpclient
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.2.7
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 3.2.8
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: This is the interface to request tracker based on Roart Gem
49
+ email:
50
+ - jaischeema@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - lib/fiddler.rb
59
+ - lib/tasks/fiddler_tasks.rake
60
+ - lib/fiddler/version.rb
61
+ - lib/fiddler/errors.rb
62
+ - lib/fiddler/connection_manager.rb
63
+ - lib/fiddler/parsers.rb
64
+ - lib/fiddler/configuration.rb
65
+ - lib/fiddler/helper.rb
66
+ - lib/fiddler/ticket.rb
67
+ - lib/fiddler/parsers/ticket_parser.rb
68
+ - lib/fiddler/parsers/base_parser.rb
69
+ - spec/spec_helper.rb
70
+ - spec/ticket_spec.rb
71
+ - spec/configuration_spec.rb
72
+ - spec/config.rb
73
+ - spec/connection_manager_spec.rb
74
+ - Rakefile
75
+ - README.md
76
+ homepage: https://github.com/jaischeema/fiddler
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.1
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.24
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Interface to Request Tracker based on Roart Gem
103
+ test_files:
104
+ - spec/spec_helper.rb
105
+ - spec/ticket_spec.rb
106
+ - spec/configuration_spec.rb
107
+ - spec/config.rb
108
+ - spec/connection_manager_spec.rb