youtrack_on_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGYzNWQzNDZhOTAyZDc1OWVjYmRhZjA5MDM1ODI0NDYxMWVhMTFlMg==
5
+ data.tar.gz: !binary |-
6
+ YTE0YWU0MWUyZjg3YjQ3YTk3MDA5ZGI0ZGM2OTU4NjlmZGM1YTU0MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZmJhMzg0OTllMDY1OTM5ZDVmMGRmODlmNThlYzE4MjY0YmI1ZDUzMzMzOGMw
10
+ YjFjNzliNjVhMWRjN2U4NzNiMzU3MTI0ZWI0MDJiYTFmMDBmODU3MTVkNjlk
11
+ YzI3YWQzNTE5ZDI5YzQ0NWFmZWEyOTA1YjFjZGZlYjUzN2MyMTc=
12
+ data.tar.gz: !binary |-
13
+ MzI3YzI0NDI2MWZlODY1NTAwYTMyN2ZiZmU0MDllZmRiZmNhNDhhOTY4YmNl
14
+ YWE1M2U2M2U2ZTFmZjk4NGFiMzNkODhlODQxOTM2NjAwNWQ3MDYyZTIwNjk5
15
+ NzQyYzgyMGJlMDlhYWM1YjcwNDJlMmRkNWQ5MDk1YjliOWY4OGE=
@@ -0,0 +1,15 @@
1
+ #http://confluence.jetbrains.com/display/YTD5/YouTrack+REST+API+Reference
2
+
3
+ module YoutrackOnRails
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Connection
7
+ autoload :Requests
8
+ autoload :Responses
9
+
10
+ mattr_accessor :login, :password, :url
11
+
12
+ def self.setup
13
+ yield self
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ module YoutrackOnRails
2
+ module Requests
3
+ class Base
4
+ attr_reader :connection, :raw_body, :content_type, :params
5
+ delegate :cookie, to: :connection
6
+ delegate :uri, to: :connection, prefix: true
7
+
8
+ def initialize(connection, params={})
9
+ @connection = connection
10
+ @params = params
11
+ @content_type = @params.delete(:content_type)
12
+ @raw_body = @params.delete(:raw_body)
13
+ end
14
+
15
+ def perform
16
+ response.process
17
+ end
18
+
19
+ def response
20
+ response_class.new(http_response)
21
+ end
22
+
23
+ private
24
+
25
+ def response_class
26
+ "YoutrackOnRails::Responses::#{self.class.name.demodulize}".constantize
27
+ end
28
+
29
+ def processed_url
30
+ url.gsub(/\/(:\w+)/) { |match| match.gsub($1, params.delete($1[1..-1].to_sym).to_s) }
31
+ end
32
+
33
+ def http_request
34
+ http_class.new(endpoint_uri).tap do |request|
35
+ request.body = raw_body.to_s
36
+ request.add_field("Cookie", cookie) if cookie
37
+ request.set_content_type(content_type) if content_type
38
+ request.set_form_data(params) if params.present?
39
+ end
40
+ end
41
+
42
+ def endpoint_uri
43
+ (connection_uri.path + processed_url).tap do |_endpoint_uri|
44
+ _endpoint_uri += "?#{URI.encode_www_form(params)}" if http_method == 'get'
45
+ end
46
+ end
47
+
48
+ def http_response
49
+ connection.request(http_request)
50
+ end
51
+
52
+ def http_class
53
+ "Net::HTTP::#{http_method.camelize}".constantize
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ module YoutrackOnRails
2
+ module Requests
3
+ class Get < Base
4
+ def http_method
5
+ 'get'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module YoutrackOnRails
2
+ module Requests
3
+ class ListProjects < Get
4
+ def url
5
+ '/rest/project/all'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module YoutrackOnRails
2
+ module Requests
3
+ class Post < Base
4
+ def http_method
5
+ 'post'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module YoutrackOnRails
2
+ module Requests
3
+ class SignIn < Post
4
+ def url
5
+ '/rest/user/login'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module YoutrackOnRails
5
+ class Connection
6
+ attr_reader :http, :uri, :cookie
7
+ delegate :request, to: :http
8
+ private :http
9
+
10
+ def initialize
11
+ @uri = URI.parse(YoutrackOnRails.url)
12
+ @http = Net::HTTP.new(@uri.host, @uri.port)
13
+
14
+ if @uri.is_a? URI::HTTPS
15
+ @http.use_ssl = true
16
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
17
+ end
18
+
19
+ response = YoutrackOnRails::Requests::SignIn.new(self,
20
+ login: YoutrackOnRails.login,
21
+ password: YoutrackOnRails.password).response
22
+
23
+ @cookie = response.cookie
24
+ end
25
+
26
+ def method_missing(method_name, *args, &block)
27
+ if (request_class = request_class_for_method(method_name))
28
+ params = args.extract_options!
29
+ return request_class.new(self, params).perform
30
+ end
31
+ super
32
+ end
33
+
34
+ private
35
+
36
+ def request_class_for_method(method_name)
37
+ begin
38
+ "YoutrackOnRails::Requests::#{method_name.to_s.camelize}".constantize
39
+ rescue NameError
40
+ nil
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ module YoutrackOnRails
2
+ module Requests
3
+ autoload :Base, 'youtrack_on_rails/requests/base'
4
+
5
+ autoload :Get, 'youtrack_on_rails/requests/get'
6
+ autoload :Post, 'youtrack_on_rails/requests/post'
7
+
8
+ autoload :ListProjects, 'youtrack_on_rails/requests/list_projects'
9
+ autoload :SignIn, 'youtrack_on_rails/requests/sign_in'
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module YoutrackOnRails
2
+ module Responses
3
+ autoload :Base, 'youtrack_on_rails/responses/base'
4
+
5
+ autoload :SimpleResponse, 'youtrack_on_rails/responses/simple_response'
6
+ autoload :CollectionResponse, 'youtrack_on_rails/responses/collection_response'
7
+
8
+ autoload :ListProjects, 'youtrack_on_rails/responses/list_projects'
9
+ autoload :SignIn, 'youtrack_on_rails/responses/sign_in'
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ module YoutrackOnRails::Responses
2
+ class Base
3
+ SUCCESSFUL_RESPONSE_CODES = %w(200 201 202)
4
+
5
+ attr_reader :code, :xml, :http_response
6
+
7
+ def initialize(http_response)
8
+ @http_response = http_response
9
+ @code = http_response.code
10
+ @xml = Nokogiri::XML(http_response.body)
11
+ end
12
+
13
+ def process
14
+ raise NotImplementedError
15
+ end
16
+
17
+ def cookie
18
+ http_response['set-cookie']
19
+ end
20
+
21
+ def success?
22
+ SUCCESSFUL_RESPONSE_CODES.include?(code)
23
+ end
24
+
25
+ def errors
26
+ xml.css('error').map(&:content).join(' ')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ module YoutrackOnRails
2
+ module Responses
3
+ class CollectionResponse < Base
4
+ def process
5
+ xml.xpath('//projects/project').map do |project_node|
6
+ @attributes ||= project_node.attributes.keys
7
+
8
+ hash = @attributes.each_with_object({}) do |attribute_key, hash|
9
+ hash[attribute_key.underscore] = project_node[attribute_key]
10
+ end
11
+
12
+ Dish(hash)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def resource_name
19
+ 'project'
20
+ end
21
+
22
+ def xpath
23
+ "//#{resource_name.pluralize}/#{resource_name}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module YoutrackOnRails
2
+ module Responses
3
+ class ListProjects < CollectionResponse
4
+ private
5
+
6
+ def resource_name
7
+ 'project'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module YoutrackOnRails
2
+ module Responses
3
+ class SignIn < SimpleResponse
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module YoutrackOnRails::Responses
2
+ class SimpleResponse < Base
3
+ def process
4
+ success?
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ module YoutrackOnRails
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: youtrack_on_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - stevo
8
+ - tbprojects
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Youtrack API wrapper for ruby
15
+ email:
16
+ - b.kosmowski@selleo.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/youtrack_on_rails.rb
22
+ - lib/youtrack_on_rails/Requests/base.rb
23
+ - lib/youtrack_on_rails/Requests/get.rb
24
+ - lib/youtrack_on_rails/Requests/list_projects.rb
25
+ - lib/youtrack_on_rails/Requests/post.rb
26
+ - lib/youtrack_on_rails/Requests/sign_in.rb
27
+ - lib/youtrack_on_rails/connection.rb
28
+ - lib/youtrack_on_rails/requests.rb
29
+ - lib/youtrack_on_rails/responses.rb
30
+ - lib/youtrack_on_rails/responses/base.rb
31
+ - lib/youtrack_on_rails/responses/collection_response.rb
32
+ - lib/youtrack_on_rails/responses/list_projects.rb
33
+ - lib/youtrack_on_rails/responses/sign_in.rb
34
+ - lib/youtrack_on_rails/responses/simple_response.rb
35
+ - lib/youtrack_on_rails/version.rb
36
+ homepage: https://github.com//youtrack_on_rails
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: ! '[none]'
55
+ rubygems_version: 2.1.10
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Youtrack API wrapper for ruby
59
+ test_files: []