youtrack 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07d949e716b29198f4623d61816059a3a1c0e4d9
4
- data.tar.gz: d1a7bf3b1853e5439a116f8188fe31e71dcac0a6
3
+ metadata.gz: 6d332f1738efe2fa6653b60f7e2eb4ac371b2905
4
+ data.tar.gz: f58bfa3b9da88f4a64f1f7441aa9fd6daac30e33
5
5
  SHA512:
6
- metadata.gz: f39f8d9e6e52a8b715aa5dd79715c2aaf6d35ff31ef972f9ceb672722474f7682f97693f5be34b46057ed57c37edd72124fba8a56a5f0dced0d6e0b6638fdcd2
7
- data.tar.gz: a842b493ddacb75d251a4c519150af698c3b17fe31953badcff263ba311344b93f2875be76cd07514afa7342f48ae13ae6664bca43e2033b06642e9e0c39427f
6
+ metadata.gz: e848683023577490326a9b9bd98cfcf407ac82ea29fcb94518d9e5239fd7293074c0683887f5bbda30646a98904dd1c62ec14320cee73a118bb1078852041c82
7
+ data.tar.gz: 2800801d1e604688feb686984554834dd4dd1b6439be38eb62aa1f1add2af00ff840c91a46013c7d400d129b0d070bd5573f6f754dbfe4788ce5eb871064cce3
@@ -1,13 +1,10 @@
1
- def login_stub
2
- stub_request(:post, YServer::Endpoint + "/login").with( body: @client.credentials_hash )
3
- end
4
1
 
5
2
  def fixture(filename)
6
3
  File.join(YServer::FIXTURE_PATH, filename)
7
4
  end
8
5
 
9
6
  Given /^I create a new Client$/ do
10
- @client = Youtrack::Client.new
7
+ @client.is_a?(Youtrack::Client).should eq(true)
11
8
  end
12
9
 
13
10
  Given /^I enter the correct login credentials$/ do
@@ -25,12 +22,10 @@ Given /^I set the Client url to point to the Server$/ do
25
22
  end
26
23
 
27
24
  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
25
  @client.connect!
30
26
  end
31
27
 
32
28
  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
29
  @client.connect!
35
30
  end
36
31
 
@@ -39,12 +34,13 @@ Given /^I set the Client#([a-zA-Z_=]+) to <([a-zA-Z0-9_-]+)>$/ do |method, value
39
34
  end
40
35
 
41
36
  Then /^I should be connected to the Server$/ do
42
- @client.response.parsed_response["login"].should eq("ok")
37
+ @client.connected?.should eq(true)
43
38
  end
44
39
 
45
40
  Then /^I should receive an error response from the Server$/ do
41
+ @client.connected?.should eq(false)
46
42
  end
47
43
 
48
44
  Then(/^I should receive an error Response$/) do
49
- @client.response.parsed_response['error'].should eq('Incorrect login or password.')
45
+ @client.connected?.should eq(false)
50
46
  end
@@ -1,4 +1,6 @@
1
1
  require "youtrack"
2
+ require "webmock"
3
+ include WebMock::API
2
4
 
3
5
  module YServer
4
6
  URL = "https://youtrackserver.com"
@@ -7,8 +9,21 @@ module YServer
7
9
  Lorem = 'lorem'
8
10
  Password = "root"
9
11
  FIXTURE_PATH = File.expand_path('../../../spec/fixtures', __FILE__ )
12
+ COOKIE = "jetbrains.charisma.main.security.PRINCIPAL=NmZkNDc3NDgxZjBhOWNjMTVjNDQwNTljNTE1NzM1ODEwM2I3MjgyMDlkZDAzZGJhYTAzYzU1ZmYyZGUyZWMxNzpyb290;Path=/youtrack;Expires=Sat, 24-Jan-2015 07:49:19 GMT"
10
13
  end
11
14
 
12
- require 'webmock/cucumber'
13
- World(WebMock::API, WebMock::Matchers)
14
- WebMock.allow_net_connect!
15
+ def fixture(filename)
16
+ File.read(YServer::FIXTURE_PATH + "/#{filename}")
17
+ end
18
+
19
+ #=========================
20
+ # Request Stubs
21
+ #=========================
22
+
23
+ stub_request(:post, "#{YServer::Endpoint}/user/login").
24
+ with(:body => "login=#{YServer::Login}&password=#{YServer::Password}").
25
+ to_return(:status => 200, body: fixture('login_body_ok.xml'), :headers => { 'set-cookie' => YServer::COOKIE })
26
+
27
+ stub_request(:post, "#{YServer::Endpoint}/user/login").
28
+ with(:body => "login=#{YServer::Lorem}&password=#{YServer::Lorem}").
29
+ to_return(:status => 403, body: fixture('login_body_error.xml'), :headers => { 'set-cookie' => YServer::COOKIE })
@@ -0,0 +1,4 @@
1
+
2
+ Before do
3
+ @client = Youtrack::Client.new
4
+ end
@@ -26,9 +26,11 @@ module Youtrack
26
26
  true == @admin
27
27
  end
28
28
 
29
- def initialize(options={})
29
+ def initialize(options={}, &block)
30
30
  @cookies = {}
31
31
  @admin = false
32
+
33
+ yield(self) if block_given?
32
34
  end
33
35
 
34
36
  # the server endpoint
@@ -51,7 +53,7 @@ module Youtrack
51
53
  end
52
54
 
53
55
  def connected?
54
- !!(connection && connection.headers['set-cookie'])
56
+ !!(connection && connection.headers['set-cookie'] && connection.code == 200)
55
57
  end
56
58
 
57
59
  def users
@@ -1,3 +1,5 @@
1
+ require 'net/http/post/multipart'
2
+
1
3
  module Youtrack
2
4
  class Issue < Base
3
5
 
@@ -14,7 +16,65 @@ module Youtrack
14
16
  # 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
17
  # permittedGroup string Set visibility for the new issue, that is: Specify a user group to which the issue will be visible.
16
18
  def create(attributes={})
17
- put("/issue", body: attributes)
19
+ put("issue", body: attributes)
20
+ response
21
+ end
22
+
23
+ def find(issue_id)
24
+ get("issue/#{issue_id}")
25
+ response.parsed_response
26
+ end
27
+
28
+ def get_history_for(issue_id)
29
+ get("issue/#{issue_id}/history")
30
+ response.parsed_response
31
+ end
32
+
33
+ def get_changes_for(issue_id)
34
+ get("issue/#{issue_id}/changes")
35
+ response.parsed_response
36
+ end
37
+
38
+ def exists?(issue_id)
39
+ get("issue/#{issue_id}/exists")
40
+ response.code == 200
41
+ end
42
+
43
+ def get_attachments_for(issue_id)
44
+ get("issue/#{issue_id}/attachment")
45
+ response.parsed_response
46
+ end
47
+
48
+ def get_comments_for(issue_id)
49
+ get("issue/#{issue_id}/comment")
50
+ response.parsed_response
51
+ end
52
+
53
+ def get_links_for(issue_id)
54
+ get("issue/#{issue_id}/link")
55
+ response.parsed_response
56
+ end
57
+
58
+
59
+
60
+ # issueID string ID of an issue that should be updated.
61
+ # summary string New summary for the specified issue.
62
+ # description string Updated description for the specified issue.
63
+ def update(issue_id, attributes={})
64
+ post("issue/#{issue_id}", body: attributes)
65
+ response.parsed_response
66
+ end
67
+
68
+ def destroy(issue_id)
69
+ delete("issue/#{issue_id}")
70
+ response
71
+ end
72
+
73
+ def add_attachment(issue_id, data, content_type, filename)
74
+ url = URI.parse(join(base_url, "issue/#{issue_id}/attachment"))
75
+ req = Net::HTTP::Post::Multipart.new( url.path, "file" => UploadIO.new(data, content_type, filename))
76
+ req['Cookie'] = service.cookies['Cookie']
77
+ response = Net::HTTP.start(url.host, url.port) { |http| http.request(req) }
18
78
  response
19
79
  end
20
80
 
@@ -5,7 +5,17 @@ module Youtrack
5
5
  # USER Methods
6
6
  # ==================
7
7
  def accessible_projects
8
- get('/project/all')
8
+ get('project/all')
9
+ response.parsed_response
10
+ end
11
+
12
+ # filter string Apply a filter to issues in a project.
13
+ # after Integer A number of issues to skip before getting a list of issues. That is, when you specify, for example, after=12 in request,
14
+ # then in the response you will get all issues matching request but without first twelve issues found .
15
+ # max Integer Maximum number of issues to be imported. If not provided, 10 issues will be imported, by default.
16
+ # updatedAfter Long Filter issues by the date of the most recent update. Only issues imported after the specified date will be gotten.
17
+ def get_issues_for(project_id, options={})
18
+ get("issue/byproject/#{project_id}")
9
19
  response.parsed_response
10
20
  end
11
21
 
@@ -13,12 +23,12 @@ module Youtrack
13
23
  # ADMIN Methods
14
24
  # ==================
15
25
  def all
16
- get('/admin/project')
26
+ get('admin/project')
17
27
  response.parsed_response
18
28
  end
19
29
 
20
30
  def find(project_id)
21
- get("/admin/project/#{project_id}")
31
+ get("admin/project/#{project_id}")
22
32
  response.parsed_response
23
33
  end
24
34
 
@@ -35,7 +45,7 @@ module Youtrack
35
45
  end
36
46
 
37
47
  def destroy(project_id)
38
- delete("/admin/project/#{project_id}")
48
+ delete("admin/project/#{project_id}")
39
49
  response
40
50
  end
41
51
 
@@ -2,13 +2,77 @@ module Youtrack
2
2
  class User < Base
3
3
 
4
4
 
5
+ # ==================
5
6
  # USER Methods
7
+ # ==================
6
8
  def current
7
- get('current')
9
+ get('user/current')
8
10
  response.parsed_response
9
11
  end
10
12
 
13
+ def get_by_login(login_name)
14
+ get("user/#{login_name}")
15
+ response.parsed_response
16
+ end
17
+
18
+ def get_saved_searches_for(login_name)
19
+ get("user/#{login_name}/filter")
20
+ response.parsed_response
21
+ end
22
+
23
+ def get_saved_searches
24
+ get("user/search")
25
+ response.parsed_response
26
+ end
27
+
28
+ def get_saved_search_by_name(query_name)
29
+ get("user/search/#{query_name}")
30
+ response.parsed_response
31
+ end
32
+
33
+ # ==================
11
34
  # ADMIN Methods
35
+ # ==================
36
+ def find(login_name)
37
+ get("admin/user/#{login_name}")
38
+ response.parsed_response
39
+ end
40
+
41
+ def all
42
+ get("admin/user")
43
+ response.parsed_response
44
+ end
45
+
46
+ # login string Login name of a user to be created. Required.
47
+ # fullName string User full name (optional).
48
+ # email string User email (required for new user).
49
+ # jabber string User jabber account (optional).
50
+ # password string Password for the new user. If skipped, by default the new user account will be created with auto-generated password
51
+ def create(attributes)
52
+ put("admin/user", body: attributes)
53
+ response
54
+ end
55
+
56
+ # User will be created if not already exist
57
+ def update(attributes)
58
+ post("admin/user", body: attributes)
59
+ response
60
+ end
61
+
62
+ def destroy(login_name)
63
+ delete("admin/user/#{login_name}")
64
+ response
65
+ end
66
+
67
+ def get_roles_for(login_name)
68
+ get("admin/user/#{login_name}/roles")
69
+ response.parsed_response
70
+ end
71
+
72
+ def get_groups_for(login_name)
73
+ get("admin/user/#{login_name}/groups")
74
+ response.parsed_response
75
+ end
12
76
 
13
77
  end
14
78
  end
@@ -1,3 +1,3 @@
1
1
  module Youtrack
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -6,12 +6,12 @@
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
 
8
8
  require "webmock/rspec"
9
+ require "youtrack"
9
10
 
10
11
  RSpec.configure do |config|
11
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
13
  config.run_all_when_everything_filtered = true
13
14
  config.filter_run :focus
14
- config.syntax = :expect
15
15
 
16
16
  # Run specs in random order to surface order dependencies. If you find an
17
17
  # order dependency and want to debug it, you can fix the order by providing
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe Youtrack::Client do
4
+ let(:client) { Youtrack::Client.new }
5
+
6
+ describe "attributes" do
7
+
8
+ # Mutators
9
+ it { should respond_to(:url=) }
10
+ it { should respond_to(:login=) }
11
+ it { should respond_to(:password=) }
12
+ it { should respond_to(:cookies=) }
13
+ it { should respond_to(:connection=) }
14
+ it { should respond_to(:admin=) }
15
+
16
+ # Accessors
17
+ it { should respond_to(:admin?) }
18
+ it { should respond_to(:connected?) }
19
+ it { should respond_to(:credentials_hash) }
20
+ it { should respond_to(:endpoint) }
21
+ end
22
+
23
+ describe "resources" do
24
+ it { should respond_to(:users) }
25
+ it { should respond_to(:projects) }
26
+ it { should respond_to(:issues) }
27
+ end
28
+
29
+ end
data/youtrack.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  # HARD DEPENDENCY
22
22
  spec.add_dependency "httparty", "~> 0.12.0"
23
+ spec.add_dependency "multipart-post", "~> 2.0.0"
23
24
 
24
25
  # DEVELOPMENT
25
26
  spec.add_development_dependency "bundler", "~> 1.3"
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.2
4
+ version: 0.0.3
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-24 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: multipart-post
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -113,7 +127,7 @@ files:
113
127
  - features/client/new_client_session.feature
114
128
  - features/step_definitions/client/client_steps.rb
115
129
  - features/support/env.rb
116
- - features/support/webmock.rb
130
+ - features/support/hooks.rb
117
131
  - features/support/world.rb
118
132
  - lib/youtrack.rb
119
133
  - lib/youtrack/client.rb
@@ -126,6 +140,7 @@ files:
126
140
  - spec/fixtures/login_body_ok.xml
127
141
  - spec/fixtures/login_header.json
128
142
  - spec/spec_helper.rb
143
+ - spec/youtrack/client_spec.rb
129
144
  - youtrack.gemspec
130
145
  homepage: ''
131
146
  licenses:
@@ -155,9 +170,10 @@ test_files:
155
170
  - features/client/new_client_session.feature
156
171
  - features/step_definitions/client/client_steps.rb
157
172
  - features/support/env.rb
158
- - features/support/webmock.rb
173
+ - features/support/hooks.rb
159
174
  - features/support/world.rb
160
175
  - spec/fixtures/login_body_error.xml
161
176
  - spec/fixtures/login_body_ok.xml
162
177
  - spec/fixtures/login_header.json
163
178
  - spec/spec_helper.rb
179
+ - spec/youtrack/client_spec.rb
@@ -1 +0,0 @@
1
-