youtrack 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/features/client/new_client_session.feature +8 -1
- data/features/step_definitions/client/client_steps.rb +27 -2
- data/features/support/env.rb +6 -2
- data/features/support/webmock.rb +0 -19
- data/features/support/world.rb +1 -1
- data/lib/youtrack.rb +6 -2
- data/lib/youtrack/client.rb +45 -6
- data/lib/youtrack/resources/base.rb +53 -0
- data/lib/youtrack/resources/issue.rb +22 -0
- data/lib/youtrack/resources/project.rb +43 -0
- data/lib/youtrack/resources/user.rb +14 -0
- data/lib/youtrack/version.rb +1 -1
- data/spec/fixtures/login_body_error.xml +1 -0
- data/spec/fixtures/login_body_ok.xml +1 -0
- data/spec/fixtures/login_header.json +10 -0
- data/spec/spec_helper.rb +1 -0
- metadata +15 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07d949e716b29198f4623d61816059a3a1c0e4d9
|
4
|
+
data.tar.gz: d1a7bf3b1853e5439a116f8188fe31e71dcac0a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f39f8d9e6e52a8b715aa5dd79715c2aaf6d35ff31ef972f9ceb672722474f7682f97693f5be34b46057ed57c37edd72124fba8a56a5f0dced0d6e0b6638fdcd2
|
7
|
+
data.tar.gz: a842b493ddacb75d251a4c519150af698c3b17fe31953badcff263ba311344b93f2875be76cd07514afa7342f48ae13ae6664bca43e2033b06642e9e0c39427f
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
youtrack
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
@@ -8,5 +8,12 @@ Feature: New Client Session
|
|
8
8
|
Given I create a new Client
|
9
9
|
When I set the Client url to point to the Server
|
10
10
|
And I enter the correct login credentials
|
11
|
-
And I connect
|
11
|
+
And I connect ok
|
12
12
|
Then I should be connected to the Server
|
13
|
+
|
14
|
+
Scenario: failing to start a new session
|
15
|
+
Given I create a new Client
|
16
|
+
When I set the Client url to point to the Server
|
17
|
+
And I enter incorrect login credentials
|
18
|
+
And I connect with error
|
19
|
+
Then I should receive an error Response
|
@@ -1,3 +1,10 @@
|
|
1
|
+
def login_stub
|
2
|
+
stub_request(:post, YServer::Endpoint + "/login").with( body: @client.credentials_hash )
|
3
|
+
end
|
4
|
+
|
5
|
+
def fixture(filename)
|
6
|
+
File.join(YServer::FIXTURE_PATH, filename)
|
7
|
+
end
|
1
8
|
|
2
9
|
Given /^I create a new Client$/ do
|
3
10
|
@client = Youtrack::Client.new
|
@@ -8,12 +15,23 @@ Given /^I enter the correct login credentials$/ do
|
|
8
15
|
step "I set the Client#password= to <#{YServer::Password}>"
|
9
16
|
end
|
10
17
|
|
18
|
+
Given /^I enter incorrect login credentials$/ do
|
19
|
+
step "I set the Client#login= to <#{YServer::Lorem}>"
|
20
|
+
step "I set the Client#password= to <#{YServer::Lorem}>"
|
21
|
+
end
|
22
|
+
|
11
23
|
Given /^I set the Client url to point to the Server$/ do
|
12
24
|
@client.url = YServer::URL
|
13
25
|
end
|
14
26
|
|
15
|
-
Given /^I connect$/ do
|
16
|
-
|
27
|
+
Given /^I connect ok$/ do
|
28
|
+
login_stub.to_return( body: fixture('login_body_ok.xml'), headers: { 'Content-Type' => 'application/xml; charset=UTF-8' } )
|
29
|
+
@client.connect!
|
30
|
+
end
|
31
|
+
|
32
|
+
Given /^I connect with error$/ do
|
33
|
+
login_stub.to_return( body: fixture('login_body_error.xml'), headers: { 'Content-Type' => 'application/xml; charset=UTF-8' } )
|
34
|
+
@client.connect!
|
17
35
|
end
|
18
36
|
|
19
37
|
Given /^I set the Client#([a-zA-Z_=]+) to <([a-zA-Z0-9_-]+)>$/ do |method, value|
|
@@ -23,3 +41,10 @@ end
|
|
23
41
|
Then /^I should be connected to the Server$/ do
|
24
42
|
@client.response.parsed_response["login"].should eq("ok")
|
25
43
|
end
|
44
|
+
|
45
|
+
Then /^I should receive an error response from the Server$/ do
|
46
|
+
end
|
47
|
+
|
48
|
+
Then(/^I should receive an error Response$/) do
|
49
|
+
@client.response.parsed_response['error'].should eq('Incorrect login or password.')
|
50
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
require "youtrack"
|
2
|
-
require "webmock/cucumber"
|
3
2
|
|
4
3
|
module YServer
|
5
4
|
URL = "https://youtrackserver.com"
|
5
|
+
Endpoint = "#{URL}/rest"
|
6
6
|
Login = "root"
|
7
|
+
Lorem = 'lorem'
|
7
8
|
Password = "root"
|
9
|
+
FIXTURE_PATH = File.expand_path('../../../spec/fixtures', __FILE__ )
|
8
10
|
end
|
9
11
|
|
10
|
-
|
12
|
+
require 'webmock/cucumber'
|
13
|
+
World(WebMock::API, WebMock::Matchers)
|
14
|
+
WebMock.allow_net_connect!
|
data/features/support/webmock.rb
CHANGED
@@ -1,20 +1 @@
|
|
1
|
-
include WebMock::API
|
2
1
|
|
3
|
-
def server_url_for(endpoint, options={})
|
4
|
-
base = "#{YServer::URL}/rest/#{endpoint}"
|
5
|
-
if options[:query]
|
6
|
-
base += "?#{options[:query]}"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
# STUBS
|
12
|
-
|
13
|
-
# login
|
14
|
-
stub_request(:post, server_url_for("login", query: "login=#{YServer::Password}&password=#{YServer::Login}"))
|
15
|
-
.to_return(
|
16
|
-
body: "<login>ok</login>",
|
17
|
-
headers: {
|
18
|
-
"Server" => "Jetty(6.1.23)",
|
19
|
-
"Content-Type" => "application/xml;charset=UTF-8"
|
20
|
-
})
|
data/features/support/world.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
World(YServer)
|
1
|
+
World(YServer)
|
data/lib/youtrack.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "httparty"
|
2
2
|
|
3
3
|
module Youtrack
|
4
|
-
autoload :Client,
|
5
|
-
autoload :VERSION,
|
4
|
+
autoload :Client, "youtrack/client"
|
5
|
+
autoload :VERSION, "youtrack/version"
|
6
|
+
autoload :Base, "youtrack/resources/base"
|
7
|
+
autoload :Issue, "youtrack/resources/issue"
|
8
|
+
autoload :Project, "youtrack/resources/project"
|
9
|
+
autoload :User, "youtrack/resources/user"
|
6
10
|
end
|
data/lib/youtrack/client.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Youtrack
|
2
2
|
class Client
|
3
|
-
include HTTParty
|
4
3
|
|
5
4
|
# holds the youTrack Server url
|
6
5
|
# defaults to nil
|
@@ -15,22 +14,62 @@ module Youtrack
|
|
15
14
|
attr_accessor :password
|
16
15
|
|
17
16
|
# stores the response object
|
18
|
-
attr_accessor :
|
17
|
+
attr_accessor :connection
|
18
|
+
|
19
|
+
# stores the auth_headers
|
20
|
+
attr_accessor :cookies
|
21
|
+
|
22
|
+
# stores the scope of all subsequent api calls
|
23
|
+
attr_accessor :admin
|
24
|
+
|
25
|
+
def admin?
|
26
|
+
true == @admin
|
27
|
+
end
|
19
28
|
|
20
29
|
def initialize(options={})
|
30
|
+
@cookies = {}
|
31
|
+
@admin = false
|
21
32
|
end
|
22
33
|
|
23
|
-
|
24
|
-
|
34
|
+
# the server endpoint
|
35
|
+
def endpoint
|
36
|
+
@endpoint = File.join(url, 'rest')
|
25
37
|
end
|
26
38
|
|
27
39
|
def credentials_hash
|
28
40
|
{ login: login, password: password }
|
29
41
|
end
|
30
42
|
|
31
|
-
|
32
|
-
|
43
|
+
|
44
|
+
# Makes a login call and sets the Cookie headers
|
45
|
+
#
|
46
|
+
# Returns the status code of the connection call
|
47
|
+
def connect!
|
48
|
+
@connection = HTTParty.post(File.join(url, "rest/user/login"), body: credentials_hash )
|
49
|
+
@cookies['Cookie'] = @connection.headers['set-cookie']
|
50
|
+
@connection.code
|
51
|
+
end
|
52
|
+
|
53
|
+
def connected?
|
54
|
+
!!(connection && connection.headers['set-cookie'])
|
33
55
|
end
|
34
56
|
|
57
|
+
def users
|
58
|
+
resource(:user).new(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def projects
|
62
|
+
resource(:project).new(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
def issues
|
66
|
+
resource(:issue).new(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def resource(resource_name)
|
72
|
+
Youtrack.const_get(resource_name.to_s.capitalize)
|
73
|
+
end
|
35
74
|
end
|
36
75
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Youtrack
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
# The base route URL
|
6
|
+
attr_accessor :base_url
|
7
|
+
|
8
|
+
# The Server Endpoint
|
9
|
+
attr_accessor :service
|
10
|
+
|
11
|
+
# Stores the response of the previous request
|
12
|
+
attr_accessor :response
|
13
|
+
|
14
|
+
|
15
|
+
def initialize(client)
|
16
|
+
@service = client
|
17
|
+
@base_url = @service.endpoint
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def join(*args)
|
23
|
+
File.join(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def prepare_options(options={})
|
27
|
+
options[:headers] ||= {}
|
28
|
+
options[:headers]['Cookie'] = service.cookies['Cookie']
|
29
|
+
options
|
30
|
+
end
|
31
|
+
|
32
|
+
def post(path, options={})
|
33
|
+
options = prepare_options(options)
|
34
|
+
@response = self.class.post( join(base_url, path), options )
|
35
|
+
end
|
36
|
+
|
37
|
+
def put(path, options={})
|
38
|
+
options = prepare_options(options)
|
39
|
+
@response = self.class.put( join(base_url, path), options )
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(path, options={})
|
43
|
+
options = prepare_options(options)
|
44
|
+
@response = self.class.get( join(base_url, path), options )
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete(path, options={})
|
48
|
+
options = prepare_options(options)
|
49
|
+
@response = self.class.delete( join(base_url, path), options )
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Youtrack
|
2
|
+
class Issue < Base
|
3
|
+
|
4
|
+
|
5
|
+
# ==================
|
6
|
+
# USER Methods
|
7
|
+
# ==================
|
8
|
+
|
9
|
+
|
10
|
+
# Create a New Issue
|
11
|
+
# project string ID of a project to add new issue to.
|
12
|
+
# summary string Short summary for the new issue.
|
13
|
+
# description string Description for the new issue.
|
14
|
+
# attachments file in "multipart/form-data" format One or several files in "multipart/form-data" format that should be attached to the new issue.
|
15
|
+
# permittedGroup string Set visibility for the new issue, that is: Specify a user group to which the issue will be visible.
|
16
|
+
def create(attributes={})
|
17
|
+
put("/issue", body: attributes)
|
18
|
+
response
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Youtrack
|
2
|
+
class Project < Base
|
3
|
+
|
4
|
+
# ==================
|
5
|
+
# USER Methods
|
6
|
+
# ==================
|
7
|
+
def accessible_projects
|
8
|
+
get('/project/all')
|
9
|
+
response.parsed_response
|
10
|
+
end
|
11
|
+
|
12
|
+
# ==================
|
13
|
+
# ADMIN Methods
|
14
|
+
# ==================
|
15
|
+
def all
|
16
|
+
get('/admin/project')
|
17
|
+
response.parsed_response
|
18
|
+
end
|
19
|
+
|
20
|
+
def find(project_id)
|
21
|
+
get("/admin/project/#{project_id}")
|
22
|
+
response.parsed_response
|
23
|
+
end
|
24
|
+
|
25
|
+
# required attributes
|
26
|
+
#
|
27
|
+
# projectId string required Unique identifier of a project to be created. This short name will be used as prefix in issue IDs for this project.
|
28
|
+
# projectName string required Full name of a new project. Must be unique.
|
29
|
+
# startingNumber integer required Number to assign to the next manually created issue.
|
30
|
+
# projectLeadLogin string required Login name of a user to be assigned as a project leader.
|
31
|
+
# description string Optional description of the new project
|
32
|
+
def create(attributes={})
|
33
|
+
put("admin/project/#{attributes[:projectId]}", body: attributes)
|
34
|
+
response
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy(project_id)
|
38
|
+
delete("/admin/project/#{project_id}")
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/youtrack/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><error>Incorrect login or password.</error>
|
@@ -0,0 +1 @@
|
|
1
|
+
<login>ok</login>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"Server": "nginx",
|
3
|
+
"Date": "Fri, 24 Jan 2014 07:49:19 GMT",
|
4
|
+
"Content-Type": "application/xml; charset=UTF-8",
|
5
|
+
"Set-Cookie": "jetbrains.charisma.main.security.PRINCIPAL=NmZkNDc3NDgxZjBhOWNjMTVjNDQwNTljNTE1NzM1ODEwM2I3MjgyMDlkZDAzZGJhYTAzYzU1ZmYyZGUyZWMxNzpyb290;Path=/youtrack;Expires=Sat, 24-Jan-2015 07:49:19 GMT",
|
6
|
+
"Expires": "Thu, 01 Jan 1970 00:00:00 GMT",
|
7
|
+
"Access-Control-Allow-Origin": "chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo",
|
8
|
+
"Access-Control-Allow-Credentials": "true",
|
9
|
+
"Cache-Control": "no-cache, no-store, no-transform, must-revalidate"
|
10
|
+
}
|
data/spec/spec_helper.rb
CHANGED
@@ -11,6 +11,7 @@ RSpec.configure do |config|
|
|
11
11
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
12
|
config.run_all_when_everything_filtered = true
|
13
13
|
config.filter_run :focus
|
14
|
+
config.syntax = :expect
|
14
15
|
|
15
16
|
# Run specs in random order to surface order dependencies. If you find an
|
16
17
|
# order dependency and want to debug it, you can fix the order by providing
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youtrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Faucett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -103,6 +103,8 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- .gitignore
|
105
105
|
- .rspec
|
106
|
+
- .ruby-gemset
|
107
|
+
- .ruby-version
|
106
108
|
- .travis.yml
|
107
109
|
- Gemfile
|
108
110
|
- LICENSE.txt
|
@@ -115,7 +117,14 @@ files:
|
|
115
117
|
- features/support/world.rb
|
116
118
|
- lib/youtrack.rb
|
117
119
|
- lib/youtrack/client.rb
|
120
|
+
- lib/youtrack/resources/base.rb
|
121
|
+
- lib/youtrack/resources/issue.rb
|
122
|
+
- lib/youtrack/resources/project.rb
|
123
|
+
- lib/youtrack/resources/user.rb
|
118
124
|
- lib/youtrack/version.rb
|
125
|
+
- spec/fixtures/login_body_error.xml
|
126
|
+
- spec/fixtures/login_body_ok.xml
|
127
|
+
- spec/fixtures/login_header.json
|
119
128
|
- spec/spec_helper.rb
|
120
129
|
- youtrack.gemspec
|
121
130
|
homepage: ''
|
@@ -138,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
147
|
version: '0'
|
139
148
|
requirements: []
|
140
149
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.0.
|
150
|
+
rubygems_version: 2.0.6
|
142
151
|
signing_key:
|
143
152
|
specification_version: 4
|
144
153
|
summary: A Ruby REST API Client for JetBrains youTrack software
|
@@ -148,4 +157,7 @@ test_files:
|
|
148
157
|
- features/support/env.rb
|
149
158
|
- features/support/webmock.rb
|
150
159
|
- features/support/world.rb
|
160
|
+
- spec/fixtures/login_body_error.xml
|
161
|
+
- spec/fixtures/login_body_ok.xml
|
162
|
+
- spec/fixtures/login_header.json
|
151
163
|
- spec/spec_helper.rb
|